1
0
mirror of https://github.com/no2chem/wideq.git synced 2025-05-16 07:10:09 -07:00

Decode binary monitoring status data

This commit is contained in:
krocans 2018-08-12 10:16:23 +03:00
parent 0ee80dd122
commit 910e55d018
2 changed files with 26 additions and 1 deletions

View File

@ -42,6 +42,9 @@ def mon(client, device_id):
data = mon.poll()
if data:
try:
if model.monitor_type == 1:
res = model.decode_monitor_binary(data)
else:
res = mon.decode_json(data)
except ValueError:
print('status data: {!r}'.format(data))

View File

@ -679,6 +679,28 @@ class ModelInfo(object):
options = self.value(key).options
return options[value]
@property
def monitor_type(self):
"""Get type of monitoring return data.
"""
if self.data['Monitoring']['type'] == 'BINARY(BYTE)':
return 1
else:
return 0
def decode_monitor_binary(self, data):
"""Decode binary encoded status data.
"""
decoded = {}
for item in self.data['Monitoring']['protocol']:
key = item['value']
value = 0
for i in range(item['startByte'], item['startByte'] + item['length']):
value = value * 256 + data[i - 1]
decoded[key] = str(value)
return decoded
class Device(object):
"""A higher-level interface to a specific device.