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.""" diff --git a/zhaquirks/konke/motion.py b/zhaquirks/konke/motion.py index 932a61e4b3..723f28b2bc 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, Ota, PowerConfiguration +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], + } + } + }