fix: rules take effect

This commit is contained in:
LiShuzhen 2024-12-25 20:51:43 +08:00
parent 5dd0047094
commit d5373e55b4
4 changed files with 9 additions and 8 deletions

View File

@ -784,8 +784,11 @@ class MIoTSpecParser:
_LOGGER.debug('parse urn, %s', urn) _LOGGER.debug('parse urn, %s', urn)
# Load spec instance # Load spec instance
instance: dict = await self.__get_instance(urn=urn) 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 # 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 ( if (
not isinstance(instance, dict) not isinstance(instance, dict)
or 'type' not in instance or 'type' not in instance
@ -803,8 +806,6 @@ class MIoTSpecParser:
or not isinstance(res_trans['data'], dict) or not isinstance(res_trans['data'], dict)
): ):
raise MIoTSpecError('invalid translation data') raise MIoTSpecError('invalid translation data')
urn_strs: list[str] = urn.split(':')
urn_key: str = ':'.join(urn_strs[:6])
trans_data: dict[str, str] = None trans_data: dict[str, str] = None
if self._lang == 'zh-Hans': if self._lang == 'zh-Hans':
# Simplified Chinese # Simplified Chinese

View File

@ -1071,17 +1071,17 @@ class SpecCustomService:
async def deinit_async(self) -> None: async def deinit_async(self) -> None:
self._data = 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.""" """MUST call init_async() first."""
if not self._data: if not self._data:
_LOGGER.error('self._data is None') _LOGGER.error('self._data is None')
return spec return spec
if urn not in self._data: if urn_key not in self._data:
return spec return spec
if 'services' not in spec: if 'services' not in spec:
return spec return spec
spec_services = spec['services'] 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 # Replace services by custom defined spec
for i, service in enumerate(spec_services): for i, service in enumerate(spec_services):
siid = str(service['iid']) siid = str(service['iid'])

View File

@ -1,5 +1,5 @@
{ {
"urn:miot-spec-v2:device:airer:0000A00D:hyd-lyjpro:1": { "urn:miot-spec-v2:device:airer:0000A00D:hyd-lyjpro": {
"3": { "3": {
"iid": 3, "iid": 3,
"type": "urn:miot-spec-v2:service:light:00007802:hyd-lyjpro:1", "type": "urn:miot-spec-v2:service:light:00007802:hyd-lyjpro:1",

View File

@ -155,7 +155,7 @@
"service:004:property:001": "事件名稱" "service:004:property:001": "事件名稱"
} }
}, },
"urn:miot-spec-v2:device:switch:0000A003:lumi-acn040:1": { "urn:miot-spec-v2:device:switch:0000A003:lumi-acn040": {
"en": { "en": {
"service:011": "Right Button On and Off", "service:011": "Right Button On and Off",
"service:011:property:001": "Right Button On and Off", "service:011:property:001": "Right Button On and Off",