mirror of
https://github.com/XiaoMi/ha_xiaomi_home.git
synced 2026-01-19 16:59:36 +08:00
fix: rules take effect
This commit is contained in:
parent
5dd0047094
commit
d5373e55b4
@ -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
|
||||||
|
|||||||
@ -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'])
|
||||||
|
|||||||
@ -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",
|
||||||
|
|||||||
@ -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",
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user