From 4f0273990015d179c09a083f60fcf698644f4823 Mon Sep 17 00:00:00 2001 From: subs1stem Date: Wed, 23 Oct 2024 15:05:12 +0300 Subject: [PATCH] Add setting `iBat1` to negative value when battery is discharging --- wb_shtyl/main.py | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/wb_shtyl/main.py b/wb_shtyl/main.py index 82685be..51e2f1a 100644 --- a/wb_shtyl/main.py +++ b/wb_shtyl/main.py @@ -21,6 +21,8 @@ manager = Manager(getenv('DEVICE_SNMP_COMMUNITY').encode()) host = getenv('DEVICE_SNMP_HOST') + battery_is_discharging = False + try: for key in CHANNELS: try: @@ -35,6 +37,11 @@ mqtt_type = table[name]['Type'] mqtt_units = table[name]['Units'] mqtt_order = table[name]['Order'] + + # Set iBat1 topic value to negative when battery is discharging + if name == 'iBat1' and battery_is_discharging: + mqtt_data = -abs(float(mqtt_data)) + mqtt.publish_control(data=mqtt_data, name=name, data_type=mqtt_type, @@ -46,6 +53,10 @@ mqtt_units = CHANNELS[key]['Units'] response = manager.get(host, oid) value = transform_item(response[0], key) + + if key == 'Work_status' and value == 'Разряд батарей': + battery_is_discharging = True + mqtt.publish_control(data=value, name=key, data_type=mqtt_type,