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

DeviceInfo decodes monitor status data

This commit is contained in:
krocans 2018-08-12 10:33:27 +03:00
parent 910e55d018
commit 5a5e8bf47d
2 changed files with 14 additions and 4 deletions

View File

@ -42,10 +42,7 @@ 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)
res = model.decode_monitor(data)
except ValueError:
print('status data: {!r}'.format(data))
else:

View File

@ -702,6 +702,19 @@ class ModelInfo(object):
decoded[key] = str(value)
return decoded
def decode_monitor_json(self, data):
"""Decode a bytestring that encodes JSON status data."""
return json.loads(data.decode('utf8'))
def decode_monitor(self, data):
"""Decode status data."""
if self.monitor_type == 1:
return self.decode_monitor_binary(data)
else:
return self.decode_monitor_json(data)
class Device(object):
"""A higher-level interface to a specific device.