diff --git a/example.py b/example.py index c5bf10f..faaed22 100644 --- a/example.py +++ b/example.py @@ -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: diff --git a/wideq.py b/wideq.py index c998247..32eacbb 100644 --- a/wideq.py +++ b/wideq.py @@ -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.