Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Konke motion sensor variants #3493

Draft
wants to merge 3 commits into
base: dev
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion tests/test_konke.py
Original file line number Diff line number Diff line change
Expand Up @@ -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."""
Expand All @@ -33,7 +39,7 @@
motion_cluster = motion_dev.endpoints[1].ias_zone
motion_listener = ClusterListener(motion_cluster)

occupancy_cluster = motion_dev.endpoints[1].occupancy

Check failure on line 42 in tests/test_konke.py

View workflow job for this annotation

GitHub Actions / shared-ci / Run tests Python 3.12

test_konke_motion[KonkeMotionC] AttributeError

Check failure on line 42 in tests/test_konke.py

View workflow job for this annotation

GitHub Actions / shared-ci / Run tests Python 3.12

test_konke_motion[KonkeMotionD] AttributeError

Check failure on line 42 in tests/test_konke.py

View workflow job for this annotation

GitHub Actions / shared-ci / Run tests Python 3.13

test_konke_motion[KonkeMotionC] AttributeError

Check failure on line 42 in tests/test_konke.py

View workflow job for this annotation

GitHub Actions / shared-ci / Run tests Python 3.13

test_konke_motion[KonkeMotionD] AttributeError
occupancy_listener = ClusterListener(occupancy_cluster)

p1 = mock.patch.object(motion_cluster, "reset_s", 0)
Expand Down
127 changes: 124 additions & 3 deletions zhaquirks/konke/motion.py
Original file line number Diff line number Diff line change
@@ -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,
Expand All @@ -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."""

Expand Down Expand Up @@ -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 = {
# <SimpleDescriptor endpoint=1 profile=0x0104 device_type=0x0402
# device_version=0
# input_clusters=[0, 1, 3, 1280, 2821, 64704]
# output_clusters=[25, 64704]>
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 = {
# <SimpleDescriptor endpoint=1 profile=0x0104 device_type=0x0402
# device_version=0
# input_clusters=[0, 3, 1024, 1280, 2821, 64704]
# output_clusters=[0, 25, 64704]>
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],
}
}
}
Loading