forked from zigpy/zha-device-handlers
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
WIP: Add ts1001 (4 way switch for lights)
I was testing this against an older version of zhaquirks. At the time, some of the buttons did not reliably send events. I'm just uploading the current state in case someone else wants to look at this before I return to it.
- Loading branch information
Showing
3 changed files
with
204 additions
and
1 deletion.
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
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
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,157 @@ | ||
"""Tuya 4 Button Remote.""" | ||
|
||
from typing import Any, List, Optional, Union | ||
|
||
from zhaquirks import GroupBoundCluster | ||
from zigpy.profiles import zha | ||
from zigpy.quirks import CustomDevice | ||
import zigpy.types as t | ||
from zigpy.zcl import foundation | ||
from zigpy.zcl.clusters.general import Basic, Identify, LevelControl, OnOff, Ota, PowerConfiguration, Scenes, Time, Groups | ||
from zigpy.zcl.clusters.lightlink import LightLink | ||
|
||
from zhaquirks.const import ( | ||
TURN_ON, | ||
TURN_OFF, | ||
DIM_UP, | ||
DIM_DOWN, | ||
COMMAND, | ||
DEVICE_TYPE, | ||
DOUBLE_PRESS, | ||
ENDPOINT_ID, | ||
CLUSTER_ID, | ||
ENDPOINTS, | ||
INPUT_CLUSTERS, | ||
LONG_PRESS, | ||
MODELS_INFO, | ||
OUTPUT_CLUSTERS, | ||
PROFILE_ID, | ||
SHORT_PRESS, | ||
ZHA_SEND_EVENT, | ||
) | ||
from zhaquirks.tuya import TuyaManufClusterAttributes, TuyaOnOff, TuyaSmartRemoteOnOffCluster, TuyaSwitch | ||
|
||
class TuyaRemote1001OnOffCluster(TuyaSmartRemoteOnOffCluster): | ||
name = "TS1001_cluster" | ||
ep_attribute = "TS1001_cluster" | ||
cluster_id = 4 | ||
|
||
manufacturer_client_commands = { | ||
0x0002: ("press_type", (t.uint8_t,), True), | ||
} | ||
|
||
manufacturer_server_commands = { | ||
0xFD: ("press_type", (t.uint8_t,), False), | ||
} | ||
|
||
def handle_cluster_request( | ||
self, | ||
hdr: foundation.ZCLHeader, | ||
args: List[Any], | ||
*, | ||
dst_addressing: Optional[ | ||
Union[t.Addressing.Group, t.Addressing.IEEE, t.Addressing.NWK] | ||
] = None, | ||
): | ||
prev_tsn = self.last_tsn | ||
super().handle_cluster_request(hdr, args=args, dst_addressing=dst_addressing) | ||
|
||
if self.last_tsn == prev_tsn: | ||
# No command was processed | ||
return | ||
if hdr.command_id == 0x02: | ||
press_type = args[0] | ||
self.listener_event( | ||
#ZHA_SEND_EVENT, self.press_type.get(press_type, "unknown"), [] | ||
# Still need to work out different press types | ||
ZHA_SEND_EVENT, "remote_button_short_press", [] | ||
) | ||
|
||
class TuyaDimRemote1001(TuyaSwitch): | ||
"""Tuya 4-button remote device.""" | ||
|
||
signature = { | ||
MODELS_INFO: [("_TZ3000_ztrfrcsu", "TS1001")], | ||
ENDPOINTS: { | ||
1: { | ||
PROFILE_ID: zha.PROFILE_ID, | ||
DEVICE_TYPE: zha.DeviceType.DIMMER_SWITCH, | ||
INPUT_CLUSTERS: [ | ||
Basic.cluster_id, | ||
PowerConfiguration.cluster_id, | ||
Identify.cluster_id, | ||
Groups.cluster_id, | ||
LightLink.cluster_id, | ||
], | ||
OUTPUT_CLUSTERS: [ | ||
Identify.cluster_id, | ||
Groups.cluster_id, | ||
Scenes.cluster_id, | ||
OnOff.cluster_id, | ||
LevelControl.cluster_id, | ||
Time.cluster_id, | ||
Ota.cluster_id, | ||
LightLink.cluster_id, | ||
], | ||
}, | ||
}, | ||
} | ||
replacement = { | ||
ENDPOINTS: { | ||
1: { | ||
PROFILE_ID: zha.PROFILE_ID, | ||
DEVICE_TYPE: zha.DeviceType.REMOTE_CONTROL, | ||
INPUT_CLUSTERS: [ | ||
Basic.cluster_id, | ||
PowerConfiguration.cluster_id, | ||
Identify.cluster_id, | ||
Groups.cluster_id, | ||
LightLink.cluster_id, | ||
], | ||
OUTPUT_CLUSTERS: [ | ||
Identify.cluster_id, | ||
TuyaRemote1001OnOffCluster, | ||
Scenes.cluster_id, | ||
TuyaSmartRemoteOnOffCluster, | ||
LevelControl.cluster_id, | ||
Time.cluster_id, | ||
Ota.cluster_id, | ||
LightLink.cluster_id, | ||
], | ||
}, | ||
}, | ||
} | ||
device_automation_triggers = { | ||
(SHORT_PRESS, TURN_ON): {CLUSTER_ID: 6, COMMAND: SHORT_PRESS}, | ||
(LONG_PRESS, TURN_ON): {CLUSTER_ID: 6, COMMAND: LONG_PRESS}, | ||
(DOUBLE_PRESS, TURN_ON): {CLUSTER_ID: 6, COMMAND: DOUBLE_PRESS}, | ||
(SHORT_PRESS, TURN_OFF): {CLUSTER_ID: 6, COMMAND: SHORT_PRESS}, | ||
(LONG_PRESS, TURN_OFF): {CLUSTER_ID: 6, COMMAND: LONG_PRESS}, | ||
(DOUBLE_PRESS, TURN_OFF): {CLUSTER_ID: 6, COMMAND: DOUBLE_PRESS}, | ||
(SHORT_PRESS, DIM_UP): {CLUSTER_ID: 8, COMMAND: SHORT_PRESS}, | ||
(LONG_PRESS, DIM_UP): {CLUSTER_ID: 8, COMMAND: LONG_PRESS}, | ||
(DOUBLE_PRESS, DIM_UP): {CLUSTER_ID: 8, COMMAND: DOUBLE_PRESS}, | ||
(SHORT_PRESS, DIM_DOWN): {CLUSTER_ID: 8, COMMAND: SHORT_PRESS}, | ||
(LONG_PRESS, DIM_DOWN): {CLUSTER_ID: 8, COMMAND: LONG_PRESS}, | ||
(DOUBLE_PRESS, DIM_DOWN): {CLUSTER_ID: 8, COMMAND: DOUBLE_PRESS}, | ||
} | ||
|
||
# ON Button | ||
# [bellows.uart] Data frame: b'631bb157546f15b658924a24ab5593499cf0e767ca0b9874f9c77f74fc7c40447e' | ||
# [bellows.uart] Sending: b'87009f7e' | ||
# [bellows.ezsp.protocol] Application frame 69 (incomingMessageHandler) received: b'0004010600010100010000bec0cc27c5ffff04011cfd0002' | ||
# [bellows.zigbee.application] Received incomingMessageHandler frame with [<EmberIncomingMessageType.INCOMING_UNICAST: 0>, EmberApsFrame(profileId=260, clusterId=6, sourceEndpoint=1, destinationEndpoint=1, options=<EmberApsOption.APS_OPTION_ENABLE_ROUTE_DISCOVERY: 256>, groupId=0, sequence=190), 192, -52, 0xc527, 255, 255, b'\x01\x1c\xfd\x00'] | ||
# [zigpy.zcl] [0xc527:1:0x0006] ZCL deserialize: <ZCLHeader frame_control=<FrameControl frame_type=CLUSTER_COMMAND manufacturer_specific=False is_reply=False disable_default_response=False> manufacturer=None tsn=28 command_id=253> | ||
# [zigpy.zcl] [0xc527:1:0x0006] Unknown cluster-specific command 253 | ||
# [zigpy.zcl] [0xc527:1:0x0006] ZCL request 0x00fd: b'\x00' | ||
# [zigpy.zcl] [0xc527:1:0x0006] No handler for cluster command 253 | ||
|
||
# OFF button | ||
# [bellows.zigbee.application] Received incomingMessageHandler frame with [<EmberIncomingMessageType.INCOMING_UNICAST: 0>, EmberApsFrame(profileId=260, clusterId=4, sourceEndpoint=1, destinationEndpoint=1, options=<EmberApsOption.APS_OPTION_ENABLE_ROUTE_DISCOVERY|APS_OPTION_RETRY: 320>, groupId=0, sequence=193), 168, -58, 0xc527, 255, 255, b'\x19\xde\x02\xff\x00'] | ||
# [zigpy.zcl] [0xc527:1:0x0004] ZCL deserialize: <ZCLHeader frame_control=<FrameControl frame_type=CLUSTER_COMMAND manufacturer_specific=False is_reply=True disable_default_response=True> manufacturer=None tsn=222 command_id=2> | ||
# [zigpy.zcl] [0xc527:1:0x0004] ZCL request 0x0002: [255, []] | ||
# [zigpy.zcl] [0xc527:1:0x0004] No handler for cluster command 2 | ||
|
||
# Dim down button | ||
# [bellows.ezsp.protocol] Application frame 84 (customFrameHandler) received: b'1200100c00000800040101be01030201330a00' | ||
# [bellows.zigbee.application] Received customFrameHandler frame with [b'\x00\x10\x0c\x00\x00\x08\x00\x04\x01\x01\xbe\x01\x03\x02\x013\n\x00'] |