-
Notifications
You must be signed in to change notification settings - Fork 716
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
mortenmoulder
wants to merge
19
commits into
zigpy:dev
Choose a base branch
from
mortenmoulder:dev
base: dev
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
b05cfbe
Add support for QUAD-ZIG-SW from smarthjemmet.dk
mortenmoulder 312e1d6
Apply pre-commit auto fixes
pre-commit-ci[bot] 9bd1af7
Fix docstrings
mortenmoulder d4eb649
Merge branch 'dev' of https://github.com/mortenmoulder/zha-device-han…
mortenmoulder 04baa50
Apply pre-commit auto fixes
pre-commit-ci[bot] 745b05d
Update file name and add tests
mortenmoulder 1170d36
Apply pre-commit auto fixes
pre-commit-ci[bot] df836e2
Fix docstring
mortenmoulder 367ea10
Merge branch 'dev' of https://github.com/mortenmoulder/zha-device-han…
mortenmoulder 65d32f6
Remove empty `__init__`
TheJulianJES e4fd04f
Remove unused `_current_state`
TheJulianJES c303d4e
Use walrus operator for `action`
TheJulianJES 8619f67
Refactor quirk `CustomDevice` classes
TheJulianJES d14e974
Replace with v2 quirk
TheJulianJES a246d9c
Remove test
TheJulianJES 1568a8a
Remove copied code from `LocalDataCluster`
TheJulianJES c34f6f2
Adjust device trigger range to range(1, 5)
TheJulianJES 5143bc1
Remove output clusters, re-add as input clusters
TheJulianJES 544880b
Use `AttributeDefs` in `_update_attribute`
TheJulianJES File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
"""smarthjemmet.dk devices.""" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
|
||
super()._update_attribute(0, action) | ||
|
||
|
||
( | ||
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() | ||
) |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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:
MultistateInput.AttributeDefs.present_value.id
in this line (sensor entity in HA?)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.