From 809b1eacf8700d7527ce59bc40c0cf8071fcbe7c Mon Sep 17 00:00:00 2001 From: Evgeny Zinoviev Date: Wed, 19 Oct 2022 05:07:09 +0300 Subject: inverter: utilities-related notifications (not tested yet) --- src/inverter_bot.py | 42 +++++++++++++++++++++++++++++++++++++++++- 1 file changed, 41 insertions(+), 1 deletion(-) (limited to 'src/inverter_bot.py') diff --git a/src/inverter_bot.py b/src/inverter_bot.py index 54b17c8..c647115 100755 --- a/src/inverter_bot.py +++ b/src/inverter_bot.py @@ -22,6 +22,7 @@ from home.inverter import ( InverterMonitor, ChargingEvent, + ACPresentEvent, BatteryState, ACMode ) @@ -55,6 +56,7 @@ SETACMODE_STARTED, = range(1) def monitor_charging(event: ChargingEvent, **kwargs) -> None: args = [] + is_util = False if event == ChargingEvent.AC_CHARGING_STARTED: key = 'started' elif event == ChargingEvent.AC_CHARGING_FINISHED: @@ -70,12 +72,24 @@ def monitor_charging(event: ChargingEvent, **kwargs) -> None: key = 'na_solar' elif event == ChargingEvent.AC_MOSTLY_CHARGED: key = 'mostly_charged' + elif event == ChargingEvent.UTIL_CHARGING_STOPPED: + key = 'started' + is_util = True + elif event == ChargingEvent.UTIL_CHARGING_STOPPED: + key = 'stopped' + is_util = True + elif event == ChargingEvent.UTIL_CHARGING_STOPPED_SOLAR: + key = 'stopped_solar' + is_util = True else: logger.error('unknown charging event:', event) return + key = f'chrg_evt_{key}' + if is_util: + key = f'util_{key}' bot.notify_all( - lambda lang: bot.lang.get(f'chrg_evt_{key}', lang, *args) + lambda lang: bot.lang.get(key, lang, *args) ) @@ -96,6 +110,17 @@ def monitor_battery(state: BatteryState, v: float, load_watts: int) -> None: ) +def monitor_util(event: ACPresentEvent): + if event == ACPresentEvent.CONNECTED: + key = 'connected' + else: + key = 'disconnected' + key = f'util_{key}' + bot.notify_all( + lambda lang: bot.lang.get(key, lang) + ) + + def monitor_error(error: str) -> None: bot.notify_all( lambda lang: bot.lang.get('error_message', lang, error) @@ -443,6 +468,13 @@ class InverterBot(Wrapper): battery_level_changed='Уровень заряда АКБ: %s %s (%0.1f V при нагрузке %d W)', error_message='Ошибка: %s.', + util_chrg_evt_started='✅ Начали заряжать от столба.', + util_chrg_evt_stopped='ℹ️ Перестали заряжать от столба.', + util_chrg_evt_stopped_solar='ℹ️ Перестали заряжать от столба из-за подключения панелей.', + + util_connected='✅️ Столб подключен.', + util_disconnected='‼️ Столб отключён.', + # other notifications ac_mode_changed_notification='Пользователь %s установил режим AC: %s.', @@ -506,6 +538,13 @@ class InverterBot(Wrapper): battery_level_changed='Battery level: %s (%0.1f V under %d W load)', error_message='Error: %s.', + util_chrg_evt_started='✅ Started charging from utilities.', + util_chrg_evt_stopped='ℹ️ Stopped charging from utilities.', + util_chrg_evt_stopped_solar='ℹ️ Stopped charging from utilities because solar panels were connected.', + + util_connected='✅️ Utilities connected.', + util_disconnected='‼️ Utilities disconected.', + # other notifications ac_mode_changed_notification='User %s set AC mode to %s.', @@ -603,6 +642,7 @@ if __name__ == '__main__': monitor = InverterMonitor() monitor.set_charging_event_handler(monitor_charging) monitor.set_battery_event_handler(monitor_battery) + monitor.set_util_event_handler(monitor_util) monitor.set_error_handler(monitor_error) monitor.start() -- cgit v1.2.3