From 5462de70c008b428bf2b5748ee1ca726e1f075d0 Mon Sep 17 00:00:00 2001 From: Alone Date: Wed, 17 Mar 2021 16:45:51 +0800 Subject: [PATCH] =?UTF-8?q?=F0=9F=94=A7=20fix=20for=20same=20services=20in?= =?UTF-8?q?=20a=20device?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- custom_components/xiaomi_miot/__init__.py | 5 ++++- custom_components/xiaomi_miot/core/miot_spec.py | 9 ++++++--- custom_components/xiaomi_miot/sensor.py | 2 +- 3 files changed, 11 insertions(+), 5 deletions(-) diff --git a/custom_components/xiaomi_miot/__init__.py b/custom_components/xiaomi_miot/__init__.py index da699331b..4f8eaddbe 100644 --- a/custom_components/xiaomi_miot/__init__.py +++ b/custom_components/xiaomi_miot/__init__.py @@ -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: @@ -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') @@ -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) diff --git a/custom_components/xiaomi_miot/core/miot_spec.py b/custom_components/xiaomi_miot/core/miot_spec.py index a20abee64..bcef70ea7 100644 --- a/custom_components/xiaomi_miot/core/miot_spec.py +++ b/custom_components/xiaomi_miot/core/miot_spec.py @@ -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 @@ -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) @@ -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(): diff --git a/custom_components/xiaomi_miot/sensor.py b/custom_components/xiaomi_miot/sensor.py index 8a61ca7cc..f67a7f573 100644 --- a/custom_components/xiaomi_miot/sensor.py +++ b/custom_components/xiaomi_miot/sensor.py @@ -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: