From 38296132a62b185f8b65ef02f667a0d7c1cd1939 Mon Sep 17 00:00:00 2001 From: LiShuzhen Date: Fri, 3 Jan 2025 12:57:20 +0800 Subject: [PATCH] feat: yeelink.light.ceiling19 ambient light --- .../xiaomi_home/miot/miot_storage.py | 2 + .../miot/specs/custom_service.json | 71 +++++++++++++++++++ test/check_rule_format.py | 18 ++++- 3 files changed, 88 insertions(+), 3 deletions(-) diff --git a/custom_components/xiaomi_home/miot/miot_storage.py b/custom_components/xiaomi_home/miot/miot_storage.py index dbbc734..bd763ee 100644 --- a/custom_components/xiaomi_home/miot/miot_storage.py +++ b/custom_components/xiaomi_home/miot/miot_storage.py @@ -1080,6 +1080,8 @@ class SpecCustomService: return spec if 'services' not in spec: return spec + if isinstance(self._data[urn_key], str): + urn_key = self._data[urn_key] spec_services = spec['services'] custom_spec = self._data.get(urn_key, None) # Replace services by custom defined spec diff --git a/custom_components/xiaomi_home/miot/specs/custom_service.json b/custom_components/xiaomi_home/miot/specs/custom_service.json index 43f278b..8498d99 100644 --- a/custom_components/xiaomi_home/miot/specs/custom_service.json +++ b/custom_components/xiaomi_home/miot/specs/custom_service.json @@ -56,6 +56,77 @@ } ] }, + "urn:miot-spec-v2:device:light:0000A001:yeelink-ceiling19": "urn:miot-spec-v2:device:light:0000A001:yeelink-ceiling4", + "urn:miot-spec-v2:device:light:0000A001:yeelink-ceiling20": "urn:miot-spec-v2:device:light:0000A001:yeelink-ceiling4", + "urn:miot-spec-v2:device:light:0000A001:yeelink-ceiling4": { + "new": [ + { + "iid": 200, + "type": "urn:miot-spec-v2:service:ambient-light:0000789D:yeelink-ceiling4:1", + "description": "Ambient Light", + "properties": [ + { + "iid": 201, + "type": "urn:miot-spec-v2:property:on:00000006:yeelink-ceiling4:1", + "description": "Switch Status", + "format": "bool", + "access": [ + "read", + "write" + ] + }, + { + "iid": 202, + "type": "urn:miot-spec-v2:property:brightness:0000000D:yeelink-ceiling4:1", + "description": "Brightness", + "format": "uint8", + "access": [ + "read", + "write" + ], + "unit": "percentage", + "value-range": [ + 1, + 100, + 1 + ] + }, + { + "iid": 203, + "type": "urn:miot-spec-v2:property:color-temperature:0000000F:yeelink-ceiling4:1", + "description": "Color Temperature", + "format": "uint32", + "access": [ + "read", + "write" + ], + "unit": "kelvin", + "value-range": [ + 1700, + 6500, + 1 + ] + }, + { + "iid": 204, + "type": "urn:miot-spec-v2:property:color:0000000E:yeelink-ceiling4:1", + "description": "Color", + "format": "uint32", + "access": [ + "read", + "write" + ], + "unit": "rgb", + "value-range": [ + 1, + 16777215, + 1 + ] + } + ] + } + ] + }, "urn:miot-spec-v2:device:water-heater:0000A02A:zimi-h03": { "new": [ { diff --git a/test/check_rule_format.py b/test/check_rule_format.py index 30952a8..fb16958 100644 --- a/test/check_rule_format.py +++ b/test/check_rule_format.py @@ -203,12 +203,21 @@ def is_integer(s: str) -> bool: def custom_service(d: dict) -> bool: - """restricted format: dict[str, dict[str, Any]]""" - if not dict_str_dict(d): + """restricted format: dict[str, dict[str, Any]] or dict[str, str]""" + if not isinstance(d, dict): return False + for k, v in d.items(): + if not isinstance(k, str): + return False + if not (isinstance(v, dict) or isinstance(v, str)): + return False if not urn_key(d, CUSTOM_SERVICE_URN_KEY_COLON_NUM): return False for v in d.values(): + if isinstance(v, str): + if CUSTOM_SERVICE_URN_KEY_COLON_NUM != v.count(':'): + return False + continue for key, value in v.items(): if key=='new': if not isinstance(value, list): @@ -312,7 +321,10 @@ def sort_custom_service(file_path: str): service_data: dict = load_json_file(file_path=file_path) service_data = dict(sorted(service_data.items())) for urn, spec in service_data.items(): - service_data[urn] = dict(sorted(spec.items())) + if isinstance(spec, dict): + service_data[urn] = dict(sorted(spec.items())) + else: + service_data[urn] = spec return service_data