diff --git a/tests/data/devices/tze200-2aaelwxk-ts0225.json b/tests/data/devices/tze200-2aaelwxk-ts0225.json index 4c6863c3e..c82dfa914 100644 --- a/tests/data/devices/tze200-2aaelwxk-ts0225.json +++ b/tests/data/devices/tze200-2aaelwxk-ts0225.json @@ -501,7 +501,7 @@ "entity_category": null, "entity_registry_enabled_default": true, "enabled": true, - "primary": false, + "primary": true, "cluster_handlers": [ { "class_name": "OccupancySensingClusterHandler", @@ -1427,48 +1427,6 @@ } ], "switch": [ - { - "info_object": { - "fallback_name": null, - "unique_id": "ab:cd:ef:12:94:85:f7:5f-1-6", - "migrate_unique_ids": [], - "platform": "switch", - "class_name": "Switch", - "translation_key": "switch", - "translation_placeholders": null, - "device_class": null, - "state_class": null, - "entity_category": null, - "entity_registry_enabled_default": true, - "enabled": true, - "primary": true, - "cluster_handlers": [ - { - "class_name": "OnOffClusterHandler", - "generic_id": "cluster_handler_0x0006", - "endpoint_id": 1, - "cluster": { - "id": 6, - "name": "On/Off", - "type": "server" - }, - "id": "1:0x0006", - "unique_id": "ab:cd:ef:12:94:85:f7:5f:1:0x0006", - "status": "INITIALIZED", - "value_attribute": "on_off" - } - ], - "device_ieee": "ab:cd:ef:12:94:85:f7:5f", - "endpoint_id": 1, - "available": true, - "group_id": null - }, - "state": { - "class_name": "Switch", - "state": false, - "available": true - } - }, { "info_object": { "fallback_name": "LED indicator", diff --git a/zha/application/platforms/switch.py b/zha/application/platforms/switch.py index e1d98e8f7..9fab50d83 100644 --- a/zha/application/platforms/switch.py +++ b/zha/application/platforms/switch.py @@ -111,6 +111,7 @@ class Switch(PlatformEntity, BaseSwitch): _attr_translation_key = "switch" _attr_primary_weight = 10 + _attribute_name = OnOff.AttributeDefs.on_off.name def __init__( self, @@ -135,12 +136,26 @@ def on_add(self) -> None: ) ) + def _is_supported(self) -> bool: + if ( + self._attribute_name + in self._on_off_cluster_handler.cluster.unsupported_attributes + ): + _LOGGER.debug( + "%s is not supported - skipping %s entity creation", + self._attribute_name, + self.__class__.__name__, + ) + return False + + return super()._is_supported() + def handle_cluster_handler_attribute_updated( self, event: ClusterAttributeUpdatedEvent, # pylint: disable=unused-argument ) -> None: """Handle state update from cluster handler.""" - if event.attribute_name == OnOff.AttributeDefs.on_off.name: + if event.attribute_name == self._attribute_name: self.maybe_emit_state_changed_event()