mirror of
https://github.com/no2chem/wideq.git
synced 2025-05-18 08:10:17 -07:00
Merge pull request #7 from NorDroN/master
Decode binary monitoring status data
This commit is contained in:
commit
49350f6fd2
@ -42,7 +42,7 @@ def mon(client, device_id):
|
|||||||
data = mon.poll()
|
data = mon.poll()
|
||||||
if data:
|
if data:
|
||||||
try:
|
try:
|
||||||
res = mon.decode_json(data)
|
res = model.decode_monitor(data)
|
||||||
except ValueError:
|
except ValueError:
|
||||||
print('status data: {!r}'.format(data))
|
print('status data: {!r}'.format(data))
|
||||||
else:
|
else:
|
||||||
@ -58,7 +58,6 @@ def mon(client, device_id):
|
|||||||
elif isinstance(desc, wideq.RangeValue):
|
elif isinstance(desc, wideq.RangeValue):
|
||||||
print('- {0}: {1} ({2.min}-{2.max})'.format(
|
print('- {0}: {1} ({2.min}-{2.max})'.format(
|
||||||
key, value, desc,
|
key, value, desc,
|
||||||
|
|
||||||
))
|
))
|
||||||
|
|
||||||
except KeyboardInterrupt:
|
except KeyboardInterrupt:
|
||||||
|
33
wideq.py
33
wideq.py
@ -685,6 +685,39 @@ class ModelInfo(object):
|
|||||||
options = self.value(key).options
|
options = self.value(key).options
|
||||||
return options[value]
|
return options[value]
|
||||||
|
|
||||||
|
@property
|
||||||
|
def binary_monitor_data(self):
|
||||||
|
"""Check that type of monitoring is BINARY(BYTE).
|
||||||
|
"""
|
||||||
|
|
||||||
|
return self.data['Monitoring']['type'] == 'BINARY(BYTE)'
|
||||||
|
|
||||||
|
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 v in data[item['startByte']:item['startByte'] + item['length']]:
|
||||||
|
value = (value << 8) + v
|
||||||
|
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.binary_monitor_data:
|
||||||
|
return self.decode_monitor_binary(data)
|
||||||
|
else:
|
||||||
|
return self.decode_monitor_json(data)
|
||||||
|
|
||||||
|
|
||||||
class Device(object):
|
class Device(object):
|
||||||
"""A higher-level interface to a specific device.
|
"""A higher-level interface to a specific device.
|
||||||
|
Loading…
x
Reference in New Issue
Block a user