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 support for QUAD-ZIG-SW from smarthjemmet.dk #3400

Open
wants to merge 19 commits into
base: dev
Choose a base branch
from
Open
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
1 change: 1 addition & 0 deletions zhaquirks/smarthjemmet/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
"""smarthjemmet.dk devices."""
87 changes: 87 additions & 0 deletions zhaquirks/smarthjemmet/quadzigsw.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
"""Device handler for smarthjemmet.dk QUAD-ZIG-SW."""

from zigpy.quirks import CustomCluster
from zigpy.quirks.v2 import QuirkBuilder
from zigpy.zcl import ClusterType
from zigpy.zcl.clusters.general import MultistateInput

from zhaquirks import PowerConfigurationCluster
from zhaquirks.const import (
COMMAND,
COMMAND_DOUBLE,
COMMAND_HOLD,
COMMAND_RELEASE,
COMMAND_SINGLE,
COMMAND_TRIPLE,
DOUBLE_PRESS,
ENDPOINT_ID,
LONG_PRESS,
LONG_RELEASE,
SHORT_PRESS,
TRIPLE_PRESS,
VALUE,
ZHA_SEND_EVENT,
)

MANUFACTURER = "smarthjemmet.dk"
MODEL_ID = "QUAD-ZIG-SW"

ACTION_TYPE = {
0: COMMAND_RELEASE,
1: COMMAND_SINGLE,
2: COMMAND_DOUBLE,
3: COMMAND_TRIPLE,
4: COMMAND_HOLD,
}


class CR2032PowerConfigurationCluster(PowerConfigurationCluster):
"""CR2032 Power Configuration Cluster."""

MIN_VOLTS = 2.2
MAX_VOLTS = 3.0


class CustomMultistateInputCluster(CustomCluster, MultistateInput):
"""Multistate input cluster."""

def _update_attribute(self, attrid, value):
super()._update_attribute(attrid, value)
if attrid == MultistateInput.AttributeDefs.present_value.id:
if action := ACTION_TYPE.get(value) is not None:
event_args = {VALUE: value}
self.listener_event(ZHA_SEND_EVENT, action, event_args)

Check warning on line 53 in zhaquirks/smarthjemmet/quadzigsw.py

View check run for this annotation

Codecov / codecov/patch

zhaquirks/smarthjemmet/quadzigsw.py#L49-L53

Added lines #L49 - L53 were not covered by tests

super()._update_attribute(0, action)

Check warning on line 55 in zhaquirks/smarthjemmet/quadzigsw.py

View check run for this annotation

Codecov / codecov/patch

zhaquirks/smarthjemmet/quadzigsw.py#L55

Added line #L55 was not covered by tests
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If the changes work, please also try and see what these additional changes to this line do:

  • replacing 0 with MultistateInput.AttributeDefs.present_value.id in this line (sensor entity in HA?)
  • completely removing this line

I believe this was copied from other quirks where it doesn't actually work, as there is no attribute with id=0 on this cluster.



(
QuirkBuilder(MANUFACTURER, MODEL_ID)
.skip_configuration()
.replaces(CR2032PowerConfigurationCluster)
.removes(MultistateInput.cluster_id, cluster_type=ClusterType.Client, endpoint_id=2)
.removes(MultistateInput.cluster_id, cluster_type=ClusterType.Client, endpoint_id=3)
.removes(MultistateInput.cluster_id, cluster_type=ClusterType.Client, endpoint_id=4)
.removes(MultistateInput.cluster_id, cluster_type=ClusterType.Client, endpoint_id=5)
.adds(CustomMultistateInputCluster, endpoint_id=2)
.adds(CustomMultistateInputCluster, endpoint_id=3)
.adds(CustomMultistateInputCluster, endpoint_id=4)
.adds(CustomMultistateInputCluster, endpoint_id=5)
.device_automation_triggers(
{
(press_type, f"button_{i}"): {
COMMAND: command,
ENDPOINT_ID: i + 1,
}
for i in range(1, 5)
for press_type, command in {
(SHORT_PRESS, COMMAND_SINGLE),
(DOUBLE_PRESS, COMMAND_DOUBLE),
(TRIPLE_PRESS, COMMAND_TRIPLE),
(LONG_PRESS, COMMAND_HOLD),
(LONG_RELEASE, COMMAND_RELEASE),
}
}
)
.add_to_registry()
)