Skip to content

Commit

Permalink
🔧 fix for same services in a device
Browse files Browse the repository at this point in the history
  • Loading branch information
al-one committed Mar 17, 2021
1 parent 151497c commit 5462de7
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 5 deletions.
5 changes: 4 additions & 1 deletion custom_components/xiaomi_miot/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -635,6 +635,7 @@ async def async_update(self):
await asyncio.sleep(self._vars.get('delay_update'))
self._vars.pop('delay_update', 0)
updater = 'lan'
results = []
rmp = {}
try:
if self.miot_cloud:
Expand All @@ -644,7 +645,7 @@ async def async_update(self):
)
if self._device and self.custom_config('check_lan'):
await self.hass.async_add_executor_job(self._device.info)
else:
elif self._device:
for k, v in self.miot_mapping.items():
s = v.get('siid')
p = v.get('piid')
Expand All @@ -653,6 +654,8 @@ async def async_update(self):
results = await self.hass.async_add_executor_job(
partial(self._device.get_properties_for_mapping, max_properties=max_properties)
)
else:
_LOGGER.error('None local device and miot cloud not ready %s', self.name)
except DeviceException as exc:
self._available = False
_LOGGER.error('Got MiioException while fetching the state for %s: %s', self.name, exc)
Expand Down
9 changes: 6 additions & 3 deletions custom_components/xiaomi_miot/core/miot_spec.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@ def __init__(self, dat: dict):
if not srv.name:
continue
self.services.append(srv)
self.services_count.setdefault(srv.name, 0)
self.services_count[srv.name] += 1

def services_mapping(self, *args, **kwargs):
dat = None
Expand Down Expand Up @@ -108,8 +106,9 @@ def __init__(self, dat: dict, spec: MiotSpec):
self.type = str(dat.get('type') or '')
self.name = MiotSpec.name_by_type(self.type)
self.unique_name = f'{self.name}-{self.iid}'
self.name_count = self.spec.services_count.get(self.name) or 0
self.description = dat.get('description') or self.name
spec.services_count.setdefault(self.name, 0)
spec.services_count[self.name] += 1
self.properties = {}
for p in (dat.get('properties') or []):
prop = MiotProperty(p, self)
Expand All @@ -123,6 +122,10 @@ def __init__(self, dat: dict, spec: MiotSpec):
continue
self.actions[act.iid] = act

@property
def name_count(self):
return self.spec.services_count.get(self.name) or 0

def mapping(self):
dat = {}
for p in self.properties.values():
Expand Down
2 changes: 1 addition & 1 deletion custom_components/xiaomi_miot/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ async def async_setup_platform(hass, config, async_add_entities, discovery_info=
hass.data[DOMAIN]['add_entities'][ENTITY_DOMAIN] = async_add_entities
model = str(config.get(CONF_MODEL) or '')
entities = []
if model in ['yunmi.waterpuri.lx9', 'yunmi.waterpuri.lx11']:
if model in ['yunmi.waterpuri.lx9', 'yunmi.waterpuri.lx11-']:
entity = WaterPurifierYunmiEntity(config)
entities.append(entity)
else:
Expand Down

0 comments on commit 5462de7

Please sign in to comment.