summaryrefslogtreecommitdiff
path: root/src/inverter_bot.py
diff options
context:
space:
mode:
authorEvgeny Zinoviev <me@ch1p.io>2022-08-30 21:30:49 +0300
committerEvgeny Zinoviev <me@ch1p.io>2022-08-30 21:30:49 +0300
commit85251ec5c3d4f05705e9a74cc7339004f7e7986f (patch)
tree2ecf18ce743289607b006173267f087195059cd7 /src/inverter_bot.py
parent15744c94c34aba55785c666050ab70896de118c3 (diff)
inverter: fix generator/utilities label in status report
Diffstat (limited to 'src/inverter_bot.py')
-rwxr-xr-xsrc/inverter_bot.py15
1 files changed, 8 insertions, 7 deletions
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<b>{ctx.lang("gen_input_power")}:</b> %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<b>{ctx.lang("generator")}:</b> %s %s' % (gs['grid_voltage']['unit'], gs['grid_voltage']['value'])
+ ac_mode = getacmode()
+ html += f'\n<b>{ctx.lang(ac_mode.value)}:</b> %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)