From 61e98978486039ef5854dd9c053c25b74c07a9d4 Mon Sep 17 00:00:00 2001 From: LiShuzhen Date: Tue, 1 Apr 2025 11:05:09 +0800 Subject: [PATCH] fix: hyd.airer.lyjpro light service --- custom_components/xiaomi_home/__init__.py | 3 ++- custom_components/xiaomi_home/miot/miot_device.py | 8 +++++--- custom_components/xiaomi_home/miot/miot_spec.py | 4 ++-- custom_components/xiaomi_home/miot/specs/spec_modify.yaml | 7 +++++++ 4 files changed, 16 insertions(+), 6 deletions(-) diff --git a/custom_components/xiaomi_home/__init__.py b/custom_components/xiaomi_home/__init__.py index fb1b5c7..b26cf0a 100644 --- a/custom_components/xiaomi_home/__init__.py +++ b/custom_components/xiaomi_home/__init__.py @@ -156,7 +156,8 @@ async def async_setup_entry( device.entity_list[platform].remove(entity) entity_id = device.gen_service_entity_id( ha_domain=platform, - siid=entity.spec.iid) # type: ignore + siid=entity.spec.iid, + description=entity.spec.description) if er.async_get(entity_id_or_uuid=entity_id): er.async_remove(entity_id=entity_id) if platform in device.prop_list: diff --git a/custom_components/xiaomi_home/miot/miot_device.py b/custom_components/xiaomi_home/miot/miot_device.py index 13bc68b..fafff87 100644 --- a/custom_components/xiaomi_home/miot/miot_device.py +++ b/custom_components/xiaomi_home/miot/miot_device.py @@ -345,10 +345,11 @@ class MIoTDevice: f'{ha_domain}.{self._model_strs[0][:9]}_{self.did_tag}_' f'{self._model_strs[-1][:20]}') - def gen_service_entity_id(self, ha_domain: str, siid: int) -> str: + def gen_service_entity_id(self, ha_domain: str, siid: int, + description: str) -> str: return ( f'{ha_domain}.{self._model_strs[0][:9]}_{self.did_tag}_' - f'{self._model_strs[-1][:20]}_s_{siid}') + f'{self._model_strs[-1][:20]}_s_{siid}_{description}') def gen_prop_entity_id( self, ha_domain: str, spec_name: str, siid: int, piid: int @@ -894,7 +895,8 @@ class MIoTServiceEntity(Entity): self._attr_name = f' {self.entity_data.spec.description_trans}' elif isinstance(self.entity_data.spec, MIoTSpecService): self.entity_id = miot_device.gen_service_entity_id( - DOMAIN, siid=self.entity_data.spec.iid) + DOMAIN, siid=self.entity_data.spec.iid, + description=self.entity_data.spec.description) self._attr_name = ( f'{"* "if self.entity_data.spec.proprietary else " "}' f'{self.entity_data.spec.description_trans}') diff --git a/custom_components/xiaomi_home/miot/miot_spec.py b/custom_components/xiaomi_home/miot/miot_spec.py index 0494f3a..31b4d47 100644 --- a/custom_components/xiaomi_home/miot/miot_spec.py +++ b/custom_components/xiaomi_home/miot/miot_spec.py @@ -1093,7 +1093,7 @@ class _SpecFilter: class _SpecAdd: """MIoT-Spec-V2 add for entity conversion.""" - _SPEC_ADD_FILE = 'specs/spec_add.yaml' + _SPEC_ADD_FILE = 'specs/spec_add.json' _main_loop: asyncio.AbstractEventLoop _data: Optional[dict] _selected: Optional[dict] @@ -1121,7 +1121,7 @@ class _SpecAdd: _LOGGER.error('spec add, invalid spec add content') return for key, value in add_data.items(): - if not isinstance(key, str) or not isinstance(value, (dict, str)): + if not isinstance(key, str) or not isinstance(value, (list, str)): _LOGGER.error('spec add, invalid spec modify data') return diff --git a/custom_components/xiaomi_home/miot/specs/spec_modify.yaml b/custom_components/xiaomi_home/miot/specs/spec_modify.yaml index 2497073..cb24026 100644 --- a/custom_components/xiaomi_home/miot/specs/spec_modify.yaml +++ b/custom_components/xiaomi_home/miot/specs/spec_modify.yaml @@ -145,3 +145,10 @@ urn:miot-spec-v2:device:water-purifier:0000A013:roswan-lte01:1:0000D05A: unit: ppm prop.4.2: unit: ppm +urn:miot-spec-v2:device:airer:0000A00D:hyd-lyjpro:1: + prop.2.3: + name: current-position-a + prop.2.8: + name: target-position-a + prop.2.9: + name: target-position-b