Skip to content

Commit

Permalink
Waterpurifier: Divide properties into multiple requests (Closes: #73)
Browse files Browse the repository at this point in the history
  • Loading branch information
syssi committed Nov 7, 2018
1 parent 087c2a3 commit 4b69e2d
Showing 1 changed file with 8 additions and 7 deletions.
15 changes: 8 additions & 7 deletions miio/waterpurifier.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
Expand Down

0 comments on commit 4b69e2d

Please sign in to comment.