Skip to content

Commit

Permalink
Use piid-siid instead of did for mapping genericmiot responses (#1620)
Browse files Browse the repository at this point in the history
Some devices (like zhimi.heater.mc2) do not mirror the did back, so this
converts to use the (siid, piid) combination for obtaining the property
for generic miot responses.
  • Loading branch information
rytilahti authored Dec 6, 2022
1 parent 340a579 commit e198638
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions miio/integrations/genericmiot/genericmiot.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,9 +76,12 @@ class GenericMiotStatus(DeviceStatus):
"""Generic status for miot devices."""

def __init__(self, response, dev):
self._model = dev._miot_model
self._model: DeviceModel = dev._miot_model
self._dev = dev
self._data = {elem["did"]: elem["value"] for elem in response}
self._data_by_siid_piid = {
(elem["siid"], elem["piid"]): elem["value"] for elem in response
}

def __getattr__(self, item):
"""Return attribute for name.
Expand All @@ -103,13 +106,14 @@ def __getattr__(self, item):
return self._data[item]

def property_dict(self) -> Dict[str, MiotProperty]:
"""Return (siid, piid)-keyed dictionary of properties."""
"""Return name-keyed dictionary of properties."""
res = {}
for did, value in self._data.items():
service, prop_name = did.split(":")
prop = self._model.get_property(service, prop_name)

# We use (siid, piid) to locate the property as not all devices mirror the did in response
for (siid, piid), value in self._data_by_siid_piid.items():
prop = self._model.get_property_by_siid_piid(siid, piid)
prop.value = value
res[did] = prop
res[prop.name] = prop

return res

Expand Down

0 comments on commit e198638

Please sign in to comment.