Skip to content

Commit 2be434b

Browse files
committed
Add tuya switch_mode for rotary knobs
1 parent 7d24475 commit 2be434b

File tree

3 files changed

+33
-1
lines changed

3 files changed

+33
-1
lines changed

zha/application/platforms/select.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
TUYA_PLUG_MANUFACTURER,
1515
TUYA_PLUG_ONOFF,
1616
)
17+
from zhaquirks import tuya
1718
from zhaquirks.xiaomi.aqara.magnet_ac01 import OppleCluster as MagnetAC01OppleCluster
1819
from zhaquirks.xiaomi.aqara.switch_acn047 import OppleCluster as T2RelayOppleCluster
1920
from zigpy import types
@@ -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/application/platforms/switch.py

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,7 @@ class Switch(PlatformEntity, BaseSwitch):
111111

112112
_attr_translation_key = "switch"
113113
_attr_primary_weight = 10
114+
_attribute_name = OnOff.AttributeDefs.on_off.name
114115

115116
def __init__(
116117
self,
@@ -135,12 +136,29 @@ def on_add(self) -> None:
135136
)
136137
)
137138

139+
def _is_supported(self) -> bool:
140+
if (
141+
self._attribute_name
142+
in self._on_off_cluster_handler.cluster.unsupported_attributes
143+
or self._attribute_name
144+
not in self._on_off_cluster_handler.cluster.attributes_by_name
145+
or self._on_off_cluster_handler.cluster.get(self._attribute_name) is None
146+
):
147+
_LOGGER.debug(
148+
"%s is not supported - skipping %s entity creation",
149+
self._attribute_name,
150+
self.__class__.__name__,
151+
)
152+
return False
153+
154+
return super()._is_supported()
155+
138156
def handle_cluster_handler_attribute_updated(
139157
self,
140158
event: ClusterAttributeUpdatedEvent, # pylint: disable=unused-argument
141159
) -> None:
142160
"""Handle state update from cluster handler."""
143-
if event.attribute_name == OnOff.AttributeDefs.on_off.name:
161+
if event.attribute_name == self._attribute_name:
144162
self.maybe_emit_state_changed_event()
145163

146164

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)