Skip to content

Commit

Permalink
Add setting iBat1 to negative value when battery is discharging
Browse files Browse the repository at this point in the history
  • Loading branch information
subs1stem committed Oct 23, 2024
1 parent 79bc11a commit 4f02739
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions wb_shtyl/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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,
Expand All @@ -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,
Expand Down

0 comments on commit 4f02739

Please sign in to comment.