From 4b69e2df16673f71bddb0a41c7660e4baf115cda Mon Sep 17 00:00:00 2001 From: Sebastian Muszynski Date: Wed, 7 Nov 2018 11:57:28 +0100 Subject: [PATCH] Waterpurifier: Divide properties into multiple requests (Closes: #73) --- miio/waterpurifier.py | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/miio/waterpurifier.py b/miio/waterpurifier.py index 5fb11b825..579a1fa8c 100644 --- a/miio/waterpurifier.py +++ b/miio/waterpurifier.py @@ -164,21 +164,22 @@ def status(self) -> WaterPurifierStatus: 'volume', 'filter', 'usage', 'temperature', 'uv_life', 'uv_state', 'elecval_state'] - values = self.send( - "get_prop", - properties - ) + _props_per_request = 1 + _props = properties.copy() + values = [] + while _props: + values.extend(self.send("get_prop", _props[:_props_per_request])) + _props[:] = _props[_props_per_request:] properties_count = len(properties) values_count = len(values) if properties_count != values_count: - _LOGGER.debug( + _LOGGER.error( "Count (%s) of requested properties does not match the " "count (%s) of received values.", properties_count, values_count) - return WaterPurifierStatus( - defaultdict(lambda: None, zip(properties, values))) + return WaterPurifierStatus(dict(zip(properties, values))) @command( default_output=format_output("Powering on"),