diff --git a/example.py b/example.py index 44457ea..c5bf10f 100644 --- a/example.py +++ b/example.py @@ -42,7 +42,10 @@ def mon(client, device_id): data = mon.poll() if data: 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: print('status data: {!r}'.format(data)) else: diff --git a/wideq.py b/wideq.py index e3bf450..c998247 100644 --- a/wideq.py +++ b/wideq.py @@ -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.