Skip to content

Commit ef83953

Browse files
authored
Convert Sonoff buttons to v2 quirk (#3050)
* Add Sonoff button `SNZB-01P` variant * Inherit `SonoffSmartButtonSNZB01P` to use existing device triggers * Initial v2 quirk conversion for Sonoff button * Remove signature test for Sonoff button * Also convert other Sonoff button to v2 * Merge Sonoff button quirks into one file * Combine both v2 quirks into one, use less strict device triggers
1 parent c8276b7 commit ef83953

File tree

3 files changed

+12
-179
lines changed

3 files changed

+12
-179
lines changed

tests/test_sonoff.py

Lines changed: 0 additions & 30 deletions
This file was deleted.

zhaquirks/sonoff/button.py

Lines changed: 12 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -1,70 +1,25 @@
1-
"""Device handler for eWeLink WB01."""
2-
from zigpy.profiles import zha
3-
from zigpy.quirks import CustomDevice
4-
from zigpy.zcl.clusters.general import Basic, Identify, OnOff, PowerConfiguration
1+
"""Device handler for Sonoff buttons."""
2+
from zigpy.quirks.v2 import add_to_registry_v2
53

64
from zhaquirks.const import (
75
BUTTON,
86
COMMAND,
97
COMMAND_OFF,
108
COMMAND_ON,
119
COMMAND_TOGGLE,
12-
DEVICE_TYPE,
1310
DOUBLE_PRESS,
14-
ENDPOINTS,
15-
INPUT_CLUSTERS,
1611
LONG_PRESS,
17-
MODELS_INFO,
18-
OUTPUT_CLUSTERS,
19-
PROFILE_ID,
2012
SHORT_PRESS,
2113
)
2214

23-
24-
class SonoffButton(CustomDevice):
25-
"""Custom device representing sonoff devices."""
26-
27-
signature = {
28-
# <SimpleDescriptor endpoint=1 profile=260 device_type=0 device_version=0
29-
# input_clusters=[0, 3, 1] output_clusters=[6, 3]>
30-
MODELS_INFO: [("eWeLink", "WB01")],
31-
ENDPOINTS: {
32-
1: {
33-
PROFILE_ID: zha.PROFILE_ID,
34-
DEVICE_TYPE: zha.DeviceType.ON_OFF_SWITCH,
35-
INPUT_CLUSTERS: [
36-
Basic.cluster_id,
37-
PowerConfiguration.cluster_id,
38-
Identify.cluster_id,
39-
],
40-
OUTPUT_CLUSTERS: [
41-
Identify.cluster_id,
42-
OnOff.cluster_id,
43-
],
44-
},
45-
},
46-
}
47-
48-
replacement = {
49-
ENDPOINTS: {
50-
1: {
51-
PROFILE_ID: zha.PROFILE_ID,
52-
DEVICE_TYPE: zha.DeviceType.ON_OFF_SWITCH,
53-
INPUT_CLUSTERS: [
54-
Basic.cluster_id,
55-
PowerConfiguration.cluster_id,
56-
Identify.cluster_id,
57-
],
58-
OUTPUT_CLUSTERS: [
59-
Identify.cluster_id,
60-
OnOff.cluster_id,
61-
],
62-
},
15+
(
16+
add_to_registry_v2("eWeLink", "WB01")
17+
.also_applies_to("eWeLink", "SNZB-01P")
18+
.device_automation_triggers(
19+
{
20+
(SHORT_PRESS, BUTTON): {COMMAND: COMMAND_TOGGLE},
21+
(DOUBLE_PRESS, BUTTON): {COMMAND: COMMAND_ON},
22+
(LONG_PRESS, BUTTON): {COMMAND: COMMAND_OFF},
6323
}
64-
}
65-
66-
device_automation_triggers = {
67-
(SHORT_PRESS, BUTTON): {COMMAND: COMMAND_TOGGLE},
68-
(DOUBLE_PRESS, BUTTON): {COMMAND: COMMAND_ON},
69-
(LONG_PRESS, BUTTON): {COMMAND: COMMAND_OFF},
70-
}
24+
)
25+
)

zhaquirks/sonoff/snzb01p.py

Lines changed: 0 additions & 92 deletions
This file was deleted.

0 commit comments

Comments
 (0)