From 30bbcae36e1fdb3b7f6b003e2ec27cab7f51c984 Mon Sep 17 00:00:00 2001 From: mozzie1121 Date: Fri, 8 Nov 2024 19:06:47 +0800 Subject: [PATCH 1/3] Update motion.py --- zhaquirks/konke/motion.py | 127 +++++++++++++++++++++++++++++++++++++- 1 file changed, 124 insertions(+), 3 deletions(-) diff --git a/zhaquirks/konke/motion.py b/zhaquirks/konke/motion.py index 932a61e4b3..ea91819824 100644 --- a/zhaquirks/konke/motion.py +++ b/zhaquirks/konke/motion.py @@ -1,11 +1,15 @@ """Konke motion sensor.""" +import math + from zigpy.profiles import zha -from zigpy.quirks import CustomDevice -from zigpy.zcl.clusters.general import Basic, Identify, PowerConfiguration +from zigpy.quirks import CustomCluster, CustomDevice +from zigpy.zcl.clusters.general import Basic, Identify, PowerConfiguration, Ota +from zigpy.zcl.clusters.homeautomation import Diagnostic +from zigpy.zcl.clusters.measurement import IlluminanceMeasurement from zigpy.zcl.clusters.security import IasZone -from zhaquirks import Bus, PowerConfigurationCluster +from zhaquirks import Bus, MotionWithReset, PowerConfigurationCluster from zhaquirks.const import ( DEVICE_TYPE, ENDPOINTS, @@ -19,6 +23,23 @@ KONKE_CLUSTER_ID = 0xFCC0 +class IlluminanceMeasurementCluster(CustomCluster, IlluminanceMeasurement): + """Terncy Illuminance Measurement Cluster.""" + + ATTR_ID = 0 + + def _update_attribute(self, attrid, value): + if attrid == self.ATTR_ID and value > 0: + value = 10000 * math.log10(value) + 1 + super()._update_attribute(attrid, value) + + +class MotionClusterC(MotionWithReset): + """Motion cluster.""" + + reset_s: int = 60 + + class KonkeMotion(CustomDevice): """Custom device representing konke motion sensors.""" @@ -117,3 +138,103 @@ def __init__(self, *args, **kwargs): } } } + + +class KonkeMotionC(CustomDevice): + """Custom device representing konke motion sensors.""" + + def __init__(self, *args, **kwargs): + """Init.""" + self.occupancy_bus = Bus() + super().__init__(*args, **kwargs) + + signature = { + # + MODELS_INFO: [ + (KONKE, "3AFE08010402100D"), + ], + ENDPOINTS: { + 1: { + PROFILE_ID: zha.PROFILE_ID, + DEVICE_TYPE: zha.DeviceType.IAS_ZONE, + INPUT_CLUSTERS: [ + Basic.cluster_id, # 0 + PowerConfiguration.cluster_id, # 1 + Identify.cluster_id, # 3 + IasZone.cluster_id, # 1280 + Diagnostic.cluster_id, # 2821 + KONKE_CLUSTER_ID, # 64704 + ], + OUTPUT_CLUSTERS: [Ota.cluster_id, KONKE_CLUSTER_ID], + } + }, + } + + replacement = { + ENDPOINTS: { + 1: { + INPUT_CLUSTERS: [ + Basic.cluster_id, + PowerConfigurationCluster, + Identify.cluster_id, + MotionClusterC, + Diagnostic.cluster_id, + KONKE_CLUSTER_ID, + ], + OUTPUT_CLUSTERS: [Ota.cluster_id, KONKE_CLUSTER_ID], + } + } + } + + +class KonkeMotionD(CustomDevice): + """Custom device representing konke motion sensors.""" + + def __init__(self, *args, **kwargs): + """Init.""" + self.occupancy_bus = Bus() + super().__init__(*args, **kwargs) + + signature = { + # + MODELS_INFO: [ + (KONKE, "3AFE13010402020D"), + ], + ENDPOINTS: { + 1: { + PROFILE_ID: zha.PROFILE_ID, + DEVICE_TYPE: zha.DeviceType.IAS_ZONE, + INPUT_CLUSTERS: [ + Basic.cluster_id, # 0 + Identify.cluster_id, # 3 + IlluminanceMeasurement.cluster_id, # 400 + IasZone.cluster_id, # 500 + Diagnostic.cluster_id, + KONKE_CLUSTER_ID, + ], + OUTPUT_CLUSTERS: [Basic.cluster_id, Ota.cluster_id, KONKE_CLUSTER_ID], + } + }, + } + + replacement = { + ENDPOINTS: { + 1: { + INPUT_CLUSTERS: [ + Basic.cluster_id, # 0 + Identify.cluster_id, # 3 + IlluminanceMeasurementCluster, + IasZone.cluster_id, # 500 + Diagnostic.cluster_id, + KONKE_CLUSTER_ID, + ], + OUTPUT_CLUSTERS: [Basic.cluster_id, Ota.cluster_id, KONKE_CLUSTER_ID], + } + } + } From d65fcfee8721cd3ca5e360a8bc043a6aa0c2a769 Mon Sep 17 00:00:00 2001 From: mozzie1121 Date: Fri, 8 Nov 2024 19:07:27 +0800 Subject: [PATCH 2/3] Update test_konke.py --- tests/test_konke.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/tests/test_konke.py b/tests/test_konke.py index 00d90f09f9..2c803e7be3 100644 --- a/tests/test_konke.py +++ b/tests/test_konke.py @@ -23,7 +23,13 @@ @pytest.mark.parametrize( - "quirk", (zhaquirks.konke.motion.KonkeMotion, zhaquirks.konke.motion.KonkeMotionB) + "quirk", + ( + zhaquirks.konke.motion.KonkeMotion, + zhaquirks.konke.motion.KonkeMotionB, + zhaquirks.konke.motion.KonkeMotionC, + zhaquirks.konke.motion.KonkeMotionD, + ), ) async def test_konke_motion(zigpy_device_from_quirk, quirk): """Test konke motion sensor.""" From ad3274afc88b6ffef0a559381443e5ebd2485200 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Fri, 8 Nov 2024 11:08:17 +0000 Subject: [PATCH 3/3] Apply pre-commit auto fixes --- zhaquirks/konke/motion.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/zhaquirks/konke/motion.py b/zhaquirks/konke/motion.py index ea91819824..723f28b2bc 100644 --- a/zhaquirks/konke/motion.py +++ b/zhaquirks/konke/motion.py @@ -4,7 +4,7 @@ from zigpy.profiles import zha from zigpy.quirks import CustomCluster, CustomDevice -from zigpy.zcl.clusters.general import Basic, Identify, PowerConfiguration, Ota +from zigpy.zcl.clusters.general import Basic, Identify, Ota, PowerConfiguration from zigpy.zcl.clusters.homeautomation import Diagnostic from zigpy.zcl.clusters.measurement import IlluminanceMeasurement from zigpy.zcl.clusters.security import IasZone