Skip to content

Commit

Permalink
fix: rules take effect
Browse files Browse the repository at this point in the history
  • Loading branch information
SusanPhevos committed Dec 25, 2024
1 parent 5dd0047 commit d5373e5
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 8 deletions.
7 changes: 4 additions & 3 deletions custom_components/xiaomi_home/miot/miot_spec.py
Original file line number Diff line number Diff line change
Expand Up @@ -784,8 +784,11 @@ async def __parse(self, urn: str) -> MIoTSpecInstance:
_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
Expand All @@ -803,8 +806,6 @@ async def __parse(self, urn: str) -> MIoTSpecInstance:
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
Expand Down
6 changes: 3 additions & 3 deletions custom_components/xiaomi_home/miot/miot_storage.py
Original file line number Diff line number Diff line change
Expand Up @@ -1071,17 +1071,17 @@ async def init_async(self) -> None:
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'])
Expand Down
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
2 changes: 1 addition & 1 deletion custom_components/xiaomi_home/miot/specs/multi_lang.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down

0 comments on commit d5373e5

Please sign in to comment.