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:
parent
0ee80dd122
commit
910e55d018
@ -42,7 +42,10 @@ def mon(client, device_id):
|
|||||||
data = mon.poll()
|
data = mon.poll()
|
||||||
if data:
|
if data:
|
||||||
try:
|
try:
|
||||||
res = mon.decode_json(data)
|
if model.monitor_type == 1:
|
||||||
|
res = model.decode_monitor_binary(data)
|
||||||
|
else:
|
||||||
|
res = mon.decode_json(data)
|
||||||
except ValueError:
|
except ValueError:
|
||||||
print('status data: {!r}'.format(data))
|
print('status data: {!r}'.format(data))
|
||||||
else:
|
else:
|
||||||
|
22
wideq.py
22
wideq.py
@ -679,6 +679,28 @@ class ModelInfo(object):
|
|||||||
options = self.value(key).options
|
options = self.value(key).options
|
||||||
return options[value]
|
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):
|
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