Skip to content

Commit 8a69336

Browse files
committed
Add tuya switch_mode for rotary knobs
1 parent 4b925d4 commit 8a69336

File tree

3 files changed

+70
-8
lines changed

3 files changed

+70
-8
lines changed

tests/data/devices/tz3000-gwkzibhs-ts004f.json

Lines changed: 56 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,12 @@
134134
"name": "on_off",
135135
"zcl_type": "bool",
136136
"unsupported": true
137+
},
138+
{
139+
"id": "0x8004",
140+
"name": "switch_mode",
141+
"zcl_type": "enum8",
142+
"value": 0
137143
}
138144
]
139145
},
@@ -162,14 +168,7 @@
162168
{
163169
"cluster_id": "0x0006",
164170
"endpoint_attribute": "TS004X_cluster",
165-
"attributes": [
166-
{
167-
"id": "0x8004",
168-
"name": "switch_mode",
169-
"zcl_type": "enum8",
170-
"value": 0
171-
}
172-
]
171+
"attributes": []
173172
},
174173
{
175174
"cluster_id": "0x0008",
@@ -311,6 +310,55 @@
311310
}
312311
}
313312
],
313+
"select": [
314+
{
315+
"info_object": {
316+
"fallback_name": null,
317+
"unique_id": "ab:cd:ef:12:e5:79:a6:00-1-6-switch_mode",
318+
"migrate_unique_ids": [],
319+
"platform": "select",
320+
"class_name": "TuyaSwitchModeSelectEntity",
321+
"translation_key": "switch_mode",
322+
"translation_placeholders": null,
323+
"device_class": null,
324+
"state_class": null,
325+
"entity_category": "config",
326+
"entity_registry_enabled_default": true,
327+
"enabled": true,
328+
"primary": false,
329+
"cluster_handlers": [
330+
{
331+
"class_name": "OnOffClusterHandler",
332+
"generic_id": "cluster_handler_0x0006",
333+
"endpoint_id": 1,
334+
"cluster": {
335+
"id": 6,
336+
"name": "On/Off",
337+
"type": "server"
338+
},
339+
"id": "1:0x0006",
340+
"unique_id": "ab:cd:ef:12:e5:79:a6:00:1:0x0006",
341+
"status": "INITIALIZED",
342+
"value_attribute": "on_off"
343+
}
344+
],
345+
"device_ieee": "ab:cd:ef:12:e5:79:a6:00",
346+
"endpoint_id": 1,
347+
"available": true,
348+
"group_id": null,
349+
"enum": "SwitchMode",
350+
"options": [
351+
"Command",
352+
"Event"
353+
]
354+
},
355+
"state": {
356+
"class_name": "TuyaSwitchModeSelectEntity",
357+
"available": true,
358+
"state": "Command"
359+
}
360+
}
361+
],
314362
"sensor": [
315363
{
316364
"info_object": {

zha/application/platforms/select.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import logging
99
from typing import TYPE_CHECKING, Any
1010

11+
from zhaquirks import tuya
1112
from zhaquirks.danfoss import thermostat as danfoss_thermostat
1213
from zhaquirks.quirk_ids import (
1314
DANFOSS_ALLY_THERMOSTAT,
@@ -317,6 +318,18 @@ class TuyaBacklightModeSelectEntity(ZCLEnumSelectEntity):
317318
_attr_translation_key: str = "backlight_mode"
318319

319320

321+
@CONFIG_DIAGNOSTIC_MATCH(
322+
cluster_handler_names=CLUSTER_HANDLER_ON_OFF, exposed_features=TUYA_PLUG_ONOFF
323+
)
324+
class TuyaSwitchModeSelectEntity(ZCLEnumSelectEntity):
325+
"""Representation of a ZHA backlight mode select entity."""
326+
327+
_unique_id_suffix = "switch_mode"
328+
_attribute_name = "switch_mode"
329+
_enum = tuya.SwitchMode
330+
_attr_translation_key: str = "switch_mode"
331+
332+
320333
class MoesBacklightMode(types.enum8):
321334
"""MOES switch backlight mode enum."""
322335

zha/zigbee/cluster_handlers/general.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -550,6 +550,7 @@ def __init__(self, cluster: zigpy.zcl.Cluster, endpoint: Endpoint) -> None:
550550
self.ZCL_INIT_ATTRS["backlight_mode"] = True
551551
self.ZCL_INIT_ATTRS["power_on_state"] = True
552552
self.ZCL_INIT_ATTRS["child_lock"] = True
553+
self.ZCL_INIT_ATTRS["switch_mode"] = True
553554

554555
@classmethod
555556
def matches(cls, cluster: zigpy.zcl.Cluster, endpoint: Endpoint) -> bool:

0 commit comments

Comments
 (0)