Skip to content

Commit e045063

Browse files
committed
Add tuya switch_mode for rotary knobs
1 parent 5298684 commit e045063

File tree

4 files changed

+76
-10
lines changed

4 files changed

+76
-10
lines changed

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

Lines changed: 59 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,9 @@
99
"name": "_TZ3000_gwkzibhs TS004F",
1010
"quirk_applied": true,
1111
"quirk_class": "zhaquirks.tuya.ts004f.TuyaSmartRemote004FROK",
12-
"exposes_features": [],
12+
"exposes_features": [
13+
"tuya.plug_on_off_attributes"
14+
],
1315
"manufacturer_code": 4742,
1416
"power_source": "Battery or Unknown",
1517
"lqi": 182,
@@ -132,6 +134,12 @@
132134
"name": "on_off",
133135
"zcl_type": "bool",
134136
"unsupported": true
137+
},
138+
{
139+
"id": "0x8004",
140+
"name": "switch_mode",
141+
"zcl_type": "enum8",
142+
"value": 0
135143
}
136144
]
137145
},
@@ -160,14 +168,7 @@
160168
{
161169
"cluster_id": "0x0006",
162170
"endpoint_attribute": "TS004X_cluster",
163-
"attributes": [
164-
{
165-
"id": "0x8004",
166-
"name": "switch_mode",
167-
"zcl_type": "enum8",
168-
"value": 0
169-
}
170-
]
171+
"attributes": []
171172
},
172173
{
173174
"cluster_id": "0x0008",
@@ -309,6 +310,55 @@
309310
}
310311
}
311312
],
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+
],
312362
"sensor": [
313363
{
314364
"info_object": {

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,9 @@
99
"name": "_TZ3000_kjfzuycl TS004F",
1010
"quirk_applied": true,
1111
"quirk_class": "zhaquirks.tuya.ts004f.TuyaSmartRemote004FSK",
12-
"exposes_features": [],
12+
"exposes_features": [
13+
"tuya.plug_on_off_attributes"
14+
],
1315
"manufacturer_code": 4098,
1416
"power_source": "Battery or Unknown",
1517
"lqi": null,

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)