1
0
mirror of https://github.com/no2chem/wideq.git synced 2025-05-18 00:00:17 -07:00

Refactoring

This commit is contained in:
nordron 2018-09-11 23:53:32 +03:00
parent 93151962e9
commit 4ca839c2a9

View File

@ -680,14 +680,11 @@ class ModelInfo(object):
return options[value] return options[value]
@property @property
def monitor_type(self): def binary_monitor_data(self):
"""Get type of monitoring return data. """Check that type of monitoring is BINARY(BYTE).
""" """
if self.data['Monitoring']['type'] == 'BINARY(BYTE)': return self.data['Monitoring']['type'] == 'BINARY(BYTE)'
return 1
else:
return 0
def decode_monitor_binary(self, data): def decode_monitor_binary(self, data):
"""Decode binary encoded status data. """Decode binary encoded status data.
@ -695,10 +692,11 @@ class ModelInfo(object):
decoded = {} decoded = {}
for item in self.data['Monitoring']['protocol']: for item in self.data['Monitoring']['protocol']:
key = item['value']
value = 0 value = 0
for i in range(item['startByte'], item['startByte'] + item['length']): for v in data[item['startByte']:item['startByte'] + item['length']]:
value = value * 256 + data[i] value = (value << 8) + v
decoded[item['value']] = str(value) decoded[key] = str(value)
return decoded return decoded
def decode_monitor_json(self, data): def decode_monitor_json(self, data):
@ -709,11 +707,12 @@ class ModelInfo(object):
def decode_monitor(self, data): def decode_monitor(self, data):
"""Decode status data.""" """Decode status data."""
if self.monitor_type == 1: if self.binary_monitor_data:
return self.decode_monitor_binary(data) return self.decode_monitor_binary(data)
else: else:
return self.decode_monitor_json(data) 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.