Skip to content

Commit

Permalink
Add device triggers for Sonoff SNZB-01P smart button (#2833)
Browse files Browse the repository at this point in the history
  • Loading branch information
theorlangur authored Dec 20, 2023
1 parent 6f07f6a commit 5ee17b9
Show file tree
Hide file tree
Showing 2 changed files with 121 additions and 0 deletions.
30 changes: 30 additions & 0 deletions tests/test_sonoff.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
"""Tests for Sonoff quirks."""


import zhaquirks
import zhaquirks.sonoff.snzb01p

zhaquirks.setup()


def test_sonoff_snzb01p(assert_signature_matches_quirk):
"""Test 'Sonoff SNZB-01P smart button' signature is matched to its quirk."""

signature = {
"node_descriptor": "NodeDescriptor(logical_type=<LogicalType.EndDevice: 2>, complex_descriptor_available=0, user_descriptor_available=0, reserved=0, aps_flags=0, frequency_band=<FrequencyBand.Freq2400MHz: 8>, mac_capability_flags=<MACCapabilityFlags.AllocateAddress: 128>, manufacturer_code=4742, maximum_buffer_size=82, maximum_incoming_transfer_size=255, server_mask=11264, maximum_outgoing_transfer_size=255, descriptor_capability_field=<DescriptorCapability.NONE: 0>, *allocate_address=True, *is_alternate_pan_coordinator=False, *is_coordinator=False, *is_end_device=True, *is_full_function_device=False, *is_mains_powered=False, *is_receiver_on_when_idle=False, *is_router=False, *is_security_capable=False)",
"endpoints": {
"1": {
"profile_id": 260,
"device_type": "0x0000",
"in_clusters": ["0x0000", "0x0001", "0x0003", "0x0020", "0xfc57"],
"out_clusters": ["0x0003", "0x0006", "0x0019"],
}
},
"manufacturer": "eWeLink",
"model": "SNZB-01P",
"class": "sonoff.snzb01p.SonoffSmartButtonSNZB01P",
}

assert_signature_matches_quirk(
zhaquirks.sonoff.snzb01p.SonoffSmartButtonSNZB01P, signature
)
91 changes: 91 additions & 0 deletions zhaquirks/sonoff/snzb01p.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
"""Sonoff Smart Button SNZB-01P"""
from zigpy.profiles import zha
from zigpy.quirks import CustomDevice
from zigpy.zcl.clusters.general import (
Basic,
Identify,
OnOff,
Ota,
PollControl,
PowerConfiguration,
)

from zhaquirks.const import (
BUTTON,
CLUSTER_ID,
COMMAND,
COMMAND_OFF,
COMMAND_ON,
COMMAND_TOGGLE,
DEVICE_TYPE,
DOUBLE_PRESS,
ENDPOINT_ID,
ENDPOINTS,
INPUT_CLUSTERS,
LONG_PRESS,
MODELS_INFO,
OUTPUT_CLUSTERS,
PROFILE_ID,
SHORT_PRESS,
)

SONOFF_CLUSTER_ID = 0xFC57


class SonoffSmartButtonSNZB01P(CustomDevice):
"""Sonoff smart button remote - model SNZB-01P"""

signature = {
# <SimpleDescriptor endpoint=1 profile=260 device_type=0
# device_version=1
# input_clusters=[0, 1, 3, 32, 64599]
# output_clusters=[3, 6, 25]>
MODELS_INFO: [
("eWeLink", "SNZB-01P"),
],
ENDPOINTS: {
1: {
PROFILE_ID: zha.PROFILE_ID,
DEVICE_TYPE: zha.DeviceType.ON_OFF_SWITCH,
INPUT_CLUSTERS: [
Basic.cluster_id,
PowerConfiguration.cluster_id,
Identify.cluster_id,
PollControl.cluster_id,
SONOFF_CLUSTER_ID,
],
OUTPUT_CLUSTERS: [
Identify.cluster_id,
OnOff.cluster_id,
Ota.cluster_id,
],
},
},
}

replacement = {
ENDPOINTS: {
1: {
PROFILE_ID: zha.PROFILE_ID,
DEVICE_TYPE: zha.DeviceType.ON_OFF_SWITCH,
INPUT_CLUSTERS: [
Basic.cluster_id,
PowerConfiguration.cluster_id,
Identify.cluster_id,
PollControl.cluster_id,
SONOFF_CLUSTER_ID,
],
OUTPUT_CLUSTERS: [
Identify.cluster_id,
OnOff.cluster_id,
Ota.cluster_id,
],
},
},
}

device_automation_triggers = {
(SHORT_PRESS, BUTTON): {COMMAND: COMMAND_TOGGLE, CLUSTER_ID: 6, ENDPOINT_ID: 1},
(DOUBLE_PRESS, BUTTON): {COMMAND: COMMAND_ON, CLUSTER_ID: 6, ENDPOINT_ID: 1},
(LONG_PRESS, BUTTON): {COMMAND: COMMAND_OFF, CLUSTER_ID: 6, ENDPOINT_ID: 1},
}

0 comments on commit 5ee17b9

Please sign in to comment.