diff options
author | Evgeny Zinoviev <me@ch1p.io> | 2021-11-03 19:17:04 +0300 |
---|---|---|
committer | Evgeny Zinoviev <me@ch1p.io> | 2021-11-03 19:17:16 +0300 |
commit | a96a90fcc2df7a6bb2aa02705c3539e33b89026d (patch) | |
tree | 046fa7b6e778623e344dba59790cf44282eb5a3b /src/inverter-bot | |
parent | 3887262236935c9f113d5e086d437bdea4e9cbf8 (diff) |
shit, i'm not ready for python 3.10, so rewrite match-case blocks with if-else
Diffstat (limited to 'src/inverter-bot')
-rwxr-xr-x | src/inverter-bot | 51 |
1 files changed, 23 insertions, 28 deletions
diff --git a/src/inverter-bot b/src/inverter-bot index 4fa18e0..66f4fb2 100755 --- a/src/inverter-bot +++ b/src/inverter-bot @@ -378,25 +378,21 @@ def on_button(update: Update, context: CallbackContext) -> None: # def monitor_charging_event_handler(event: ChargingEvent, **kwargs) -> None: - key = None args = [] - - match event: - case ChargingEvent.AC_CHARGING_STARTED: - key = 'started' - case ChargingEvent.AC_CHARGING_FINISHED: - key = 'finished' - case ChargingEvent.AC_DISCONNECTED: - key = 'disconnected' - case ChargingEvent.AC_NOT_CHARGING: - key = 'not_charging' - case ChargingEvent.AC_CURRENT_CHANGED: - key = 'current_changed' - args.append(kwargs['current']) - case ChargingEvent.AC_CHARGING_UNAVAILABLE_BECAUSE_SOLAR: - key = 'na_solar' - - if key is None: + if event == ChargingEvent.AC_CHARGING_STARTED: + key = 'started' + elif event == ChargingEvent.AC_CHARGING_FINISHED: + key = 'finished' + elif event == ChargingEvent.AC_DISCONNECTED: + key = 'disconnected' + elif event == ChargingEvent.AC_NOT_CHARGING: + key = 'not_charging' + elif event == ChargingEvent.AC_CURRENT_CHANGED: + key = 'current_changed' + args.append(kwargs['current']) + elif event == ChargingEvent.AC_CHARGING_UNAVAILABLE_BECAUSE_SOLAR: + key = 'na_solar' + else: logger.error('unknown charging event:', event) return @@ -404,16 +400,15 @@ def monitor_charging_event_handler(event: ChargingEvent, **kwargs) -> None: def monitor_battery_event_handler(state: BatteryState, v: float, load_watts: int) -> None: - match state: - case BatteryState.NORMAL: - label = '✅ Normal' - case BatteryState.LOW: - label = '⚠️ Low' - case BatteryState.CRITICAL: - label = '‼️ Critical' - case _: - logger.error('unknown battery state:', state) - return + if state == BatteryState.NORMAL: + label = '✅ Normal' + elif state == BatteryState.LOW: + label = '⚠️ Low' + elif state == BatteryState.CRITICAL: + label = '‼️ Critical' + else: + logger.error('unknown battery state:', state) + return notify_all(_('battery_level_changed', label, v, load_watts)) |