Skip to content

Commit 5298684

Browse files
committed
Avoid adding switch if not supported
Some weird devices have OnOff clusters with only partial attributes. Tuya remotes are one such device.
1 parent 7d24475 commit 5298684

File tree

4 files changed

+41
-44
lines changed

4 files changed

+41
-44
lines changed

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

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,18 @@
123123
"endpoint_attribute": "groups",
124124
"attributes": []
125125
},
126+
{
127+
"cluster_id": "0x0006",
128+
"endpoint_attribute": "on_off",
129+
"attributes": [
130+
{
131+
"id": "0x0000",
132+
"name": "on_off",
133+
"zcl_type": "bool",
134+
"unsupported": true
135+
}
136+
]
137+
},
126138
{
127139
"cluster_id": "0x1000",
128140
"endpoint_attribute": "lightlink",

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

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,18 @@
9999
"endpoint_attribute": "groups",
100100
"attributes": []
101101
},
102+
{
103+
"cluster_id": "0x0006",
104+
"endpoint_attribute": "on_off",
105+
"attributes": [
106+
{
107+
"id": "0x0000",
108+
"name": "on_off",
109+
"zcl_type": "bool",
110+
"unsupported": true
111+
}
112+
]
113+
},
102114
{
103115
"cluster_id": "0x1000",
104116
"endpoint_attribute": "lightlink",

tests/data/devices/tze200-2aaelwxk-ts0225.json

Lines changed: 1 addition & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -501,7 +501,7 @@
501501
"entity_category": null,
502502
"entity_registry_enabled_default": true,
503503
"enabled": true,
504-
"primary": false,
504+
"primary": true,
505505
"cluster_handlers": [
506506
{
507507
"class_name": "OccupancySensingClusterHandler",
@@ -1427,48 +1427,6 @@
14271427
}
14281428
],
14291429
"switch": [
1430-
{
1431-
"info_object": {
1432-
"fallback_name": null,
1433-
"unique_id": "ab:cd:ef:12:94:85:f7:5f-1-6",
1434-
"migrate_unique_ids": [],
1435-
"platform": "switch",
1436-
"class_name": "Switch",
1437-
"translation_key": "switch",
1438-
"translation_placeholders": null,
1439-
"device_class": null,
1440-
"state_class": null,
1441-
"entity_category": null,
1442-
"entity_registry_enabled_default": true,
1443-
"enabled": true,
1444-
"primary": true,
1445-
"cluster_handlers": [
1446-
{
1447-
"class_name": "OnOffClusterHandler",
1448-
"generic_id": "cluster_handler_0x0006",
1449-
"endpoint_id": 1,
1450-
"cluster": {
1451-
"id": 6,
1452-
"name": "On/Off",
1453-
"type": "server"
1454-
},
1455-
"id": "1:0x0006",
1456-
"unique_id": "ab:cd:ef:12:94:85:f7:5f:1:0x0006",
1457-
"status": "INITIALIZED",
1458-
"value_attribute": "on_off"
1459-
}
1460-
],
1461-
"device_ieee": "ab:cd:ef:12:94:85:f7:5f",
1462-
"endpoint_id": 1,
1463-
"available": true,
1464-
"group_id": null
1465-
},
1466-
"state": {
1467-
"class_name": "Switch",
1468-
"state": false,
1469-
"available": true
1470-
}
1471-
},
14721430
{
14731431
"info_object": {
14741432
"fallback_name": "LED indicator",

zha/application/platforms/switch.py

Lines changed: 16 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,26 @@ 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+
):
144+
_LOGGER.debug(
145+
"%s is not supported - skipping %s entity creation",
146+
self._attribute_name,
147+
self.__class__.__name__,
148+
)
149+
return False
150+
151+
return super()._is_supported()
152+
138153
def handle_cluster_handler_attribute_updated(
139154
self,
140155
event: ClusterAttributeUpdatedEvent, # pylint: disable=unused-argument
141156
) -> None:
142157
"""Handle state update from cluster handler."""
143-
if event.attribute_name == OnOff.AttributeDefs.on_off.name:
158+
if event.attribute_name == self._attribute_name:
144159
self.maybe_emit_state_changed_event()
145160

146161

0 commit comments

Comments
 (0)