From 85251ec5c3d4f05705e9a74cc7339004f7e7986f Mon Sep 17 00:00:00 2001 From: Evgeny Zinoviev Date: Tue, 30 Aug 2022 21:30:49 +0300 Subject: inverter: fix generator/utilities label in status report --- src/inverter_bot.py | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) (limited to 'src') diff --git a/src/inverter_bot.py b/src/inverter_bot.py index c7801b4..f2a625b 100755 --- a/src/inverter_bot.py +++ b/src/inverter_bot.py @@ -37,6 +37,7 @@ from telegram.ext import ( monitor: Optional[InverterMonitor] = None bot: Optional[Wrapper] = None +db = None LT = escape('<=') flags_map = { 'buzzer': 'BUZZ', @@ -49,6 +50,7 @@ flags_map = { 'fault_code_record': 'FTCR', } logger = logging.getLogger(__name__) +SETACMODE_STARTED, = range(1) def monitor_charging(event: ChargingEvent, **kwargs) -> None: @@ -162,7 +164,8 @@ def status(ctx: Context) -> None: html += f'\n{ctx.lang("gen_input_power")}: %s %s' % (gs['pv1_input_power']['value'], gs['pv1_input_power']['unit']) if gs['grid_voltage']['value'] > 0 or gs['grid_freq']['value'] > 0: - html += f'\n{ctx.lang("generator")}: %s %s' % (gs['grid_voltage']['unit'], gs['grid_voltage']['value']) + ac_mode = getacmode() + html += f'\n{ctx.lang(ac_mode.value)}: %s %s' % (gs['grid_voltage']['unit'], gs['grid_voltage']['value']) html += ', %s %s' % (gs['grid_freq']['value'], gs['grid_freq']['unit']) # send response @@ -239,7 +242,8 @@ def setgenct(ctx: Context) -> None: }, language=ctx.user_lang)) -SETACMODE_STARTED, = range(1) +def getacmode() -> ACMode: + return ACMode(db.get_param('ac_mode', default=ACMode.GENERATOR)) def setacmode(mode: ACMode): @@ -589,13 +593,10 @@ class InverterStore(Store): self.commit() -db: Optional[InverterStore] = None - - if __name__ == '__main__': config.load('inverter_bot') - inverter.init(host=config['inverter']['ip'], port=config['inverter']['port']) + inverter.init(host=config['inverter']['ip'],port=config['inverter']['port']) db = InverterStore() @@ -605,7 +606,7 @@ if __name__ == '__main__': monitor.set_error_handler(monitor_error) monitor.start() - setacmode(ACMode(db.get_param('ac_mode', default=ACMode.GENERATOR))) + setacmode(getacmode()) bot = InverterBot(store=db) bot.enable_logging(BotType.INVERTER) -- cgit v1.2.3