diff --git a/custom_components/xiaomi_home/miot/miot_spec.py b/custom_components/xiaomi_home/miot/miot_spec.py index 7ee69a7..1980cc4 100644 --- a/custom_components/xiaomi_home/miot/miot_spec.py +++ b/custom_components/xiaomi_home/miot/miot_spec.py @@ -784,8 +784,11 @@ class MIoTSpecParser: _LOGGER.debug('parse urn, %s', urn) # Load spec instance instance: dict = await self.__get_instance(urn=urn) + urn_strs: list[str] = urn.split(':') + urn_key: str = ':'.join(urn_strs[:6]) # Modify the spec instance by custom spec - instance = self._custom_service.modify_spec(urn=urn, spec=instance) + instance = self._custom_service.modify_spec(urn_key=urn_key, spec=instance) + # Check required fields in the device instance if ( not isinstance(instance, dict) or 'type' not in instance @@ -803,8 +806,6 @@ class MIoTSpecParser: or not isinstance(res_trans['data'], dict) ): raise MIoTSpecError('invalid translation data') - urn_strs: list[str] = urn.split(':') - urn_key: str = ':'.join(urn_strs[:6]) trans_data: dict[str, str] = None if self._lang == 'zh-Hans': # Simplified Chinese diff --git a/custom_components/xiaomi_home/miot/miot_storage.py b/custom_components/xiaomi_home/miot/miot_storage.py index 099b6db..dbbc734 100644 --- a/custom_components/xiaomi_home/miot/miot_storage.py +++ b/custom_components/xiaomi_home/miot/miot_storage.py @@ -1071,17 +1071,17 @@ class SpecCustomService: async def deinit_async(self) -> None: self._data = None - def modify_spec(self, urn: str, spec: dict) -> dict | None: + def modify_spec(self, urn_key: str, spec: dict) -> dict | None: """MUST call init_async() first.""" if not self._data: _LOGGER.error('self._data is None') return spec - if urn not in self._data: + if urn_key not in self._data: return spec if 'services' not in spec: return spec spec_services = spec['services'] - custom_spec = self._data.get(urn, None) + custom_spec = self._data.get(urn_key, None) # Replace services by custom defined spec for i, service in enumerate(spec_services): siid = str(service['iid']) diff --git a/custom_components/xiaomi_home/miot/specs/custom_service.json b/custom_components/xiaomi_home/miot/specs/custom_service.json index 1bc4bc6..70cc46c 100644 --- a/custom_components/xiaomi_home/miot/specs/custom_service.json +++ b/custom_components/xiaomi_home/miot/specs/custom_service.json @@ -1,5 +1,5 @@ { - "urn:miot-spec-v2:device:airer:0000A00D:hyd-lyjpro:1": { + "urn:miot-spec-v2:device:airer:0000A00D:hyd-lyjpro": { "3": { "iid": 3, "type": "urn:miot-spec-v2:service:light:00007802:hyd-lyjpro:1", diff --git a/custom_components/xiaomi_home/miot/specs/multi_lang.json b/custom_components/xiaomi_home/miot/specs/multi_lang.json index 5e48bcc..7f16732 100644 --- a/custom_components/xiaomi_home/miot/specs/multi_lang.json +++ b/custom_components/xiaomi_home/miot/specs/multi_lang.json @@ -155,7 +155,7 @@ "service:004:property:001": "事件名稱" } }, - "urn:miot-spec-v2:device:switch:0000A003:lumi-acn040:1": { + "urn:miot-spec-v2:device:switch:0000A003:lumi-acn040": { "en": { "service:011": "Right Button On and Off", "service:011:property:001": "Right Button On and Off",