From e3605be5cd560b19e10acced04c71bb44a563263 Mon Sep 17 00:00:00 2001 From: epenet <6771947+epenet@users.noreply.github.com> Date: Wed, 24 Jun 2026 11:54:13 +0200 Subject: [PATCH] Migrate siren entity attributes to StrEnum (#174616) --- homeassistant/components/siren/__init__.py | 11 ++++++++--- homeassistant/components/siren/const.py | 8 +++++++- .../devolo_home_control/snapshots/test_siren.ambr | 12 ++++++------ tests/components/ring/snapshots/test_siren.ambr | 4 ++-- tests/components/tplink/snapshots/test_siren.ambr | 4 ++-- 5 files changed, 25 insertions(+), 14 deletions(-) diff --git a/homeassistant/components/siren/__init__.py b/homeassistant/components/siren/__init__.py index e64751097bbf..90d105a38864 100644 --- a/homeassistant/components/siren/__init__.py +++ b/homeassistant/components/siren/__init__.py @@ -16,12 +16,13 @@ from homeassistant.helpers.entity_component import EntityComponent from homeassistant.helpers.typing import ConfigType, VolDictType from homeassistant.util.hass_dict import HassKey -from .const import ( +from .const import ( # noqa: F401 ATTR_AVAILABLE_TONES, ATTR_DURATION, ATTR_TONE, ATTR_VOLUME_LEVEL, DOMAIN, + SirenEntityCapabilityAttribute, SirenEntityFeature, ) @@ -154,7 +155,9 @@ CACHED_PROPERTIES_WITH_ATTR_ = { class SirenEntity(ToggleEntity, cached_properties=CACHED_PROPERTIES_WITH_ATTR_): """Representation of a siren device.""" - _entity_component_unrecorded_attributes = frozenset({ATTR_AVAILABLE_TONES}) + _entity_component_unrecorded_attributes = frozenset( + {SirenEntityCapabilityAttribute.AVAILABLE_TONES} + ) entity_description: SirenEntityDescription _attr_available_tones: list[int | str] | dict[int, str] | None @@ -169,7 +172,9 @@ class SirenEntity(ToggleEntity, cached_properties=CACHED_PROPERTIES_WITH_ATTR_): self.supported_features & SirenEntityFeature.TONES and self.available_tones is not None ): - return {ATTR_AVAILABLE_TONES: self.available_tones} + return { + SirenEntityCapabilityAttribute.AVAILABLE_TONES: self.available_tones + } return None diff --git a/homeassistant/components/siren/const.py b/homeassistant/components/siren/const.py index 26a158bd8ea9..cf89a003b589 100644 --- a/homeassistant/components/siren/const.py +++ b/homeassistant/components/siren/const.py @@ -1,6 +1,6 @@ """Constants for the siren component.""" -from enum import IntFlag +from enum import IntFlag, StrEnum from typing import Final DOMAIN: Final = "siren" @@ -12,6 +12,12 @@ ATTR_DURATION: Final = "duration" ATTR_VOLUME_LEVEL: Final = "volume_level" +class SirenEntityCapabilityAttribute(StrEnum): + """Capability attributes for siren entities.""" + + AVAILABLE_TONES = "available_tones" + + class SirenEntityFeature(IntFlag): """Supported features of the siren entity.""" diff --git a/tests/components/devolo_home_control/snapshots/test_siren.ambr b/tests/components/devolo_home_control/snapshots/test_siren.ambr index fbd93f39985f..8f2852d9be50 100644 --- a/tests/components/devolo_home_control/snapshots/test_siren.ambr +++ b/tests/components/devolo_home_control/snapshots/test_siren.ambr @@ -2,7 +2,7 @@ # name: test_siren StateSnapshot({ 'attributes': ReadOnlyDict({ - 'available_tones': list([ + : list([ 0, ]), 'friendly_name': 'Test', @@ -23,7 +23,7 @@ ]), 'area_id': None, 'capabilities': dict({ - 'available_tones': list([ + : list([ 0, ]), }), @@ -60,7 +60,7 @@ # name: test_siren_change_default_tone StateSnapshot({ 'attributes': ReadOnlyDict({ - 'available_tones': list([ + : list([ 0, ]), 'friendly_name': 'Test', @@ -81,7 +81,7 @@ ]), 'area_id': None, 'capabilities': dict({ - 'available_tones': list([ + : list([ 0, ]), }), @@ -118,7 +118,7 @@ # name: test_siren_switching StateSnapshot({ 'attributes': ReadOnlyDict({ - 'available_tones': list([ + : list([ 0, ]), 'friendly_name': 'Test', @@ -139,7 +139,7 @@ ]), 'area_id': None, 'capabilities': dict({ - 'available_tones': list([ + : list([ 0, ]), }), diff --git a/tests/components/ring/snapshots/test_siren.ambr b/tests/components/ring/snapshots/test_siren.ambr index 2a60737a0a53..1f8cc7343a5e 100644 --- a/tests/components/ring/snapshots/test_siren.ambr +++ b/tests/components/ring/snapshots/test_siren.ambr @@ -6,7 +6,7 @@ ]), 'area_id': None, 'capabilities': dict({ - 'available_tones': list([ + : list([ 'ding', 'motion', ]), @@ -45,7 +45,7 @@ StateSnapshot({ 'attributes': ReadOnlyDict({ 'attribution': 'Data provided by Ring.com', - 'available_tones': list([ + : list([ 'ding', 'motion', ]), diff --git a/tests/components/tplink/snapshots/test_siren.ambr b/tests/components/tplink/snapshots/test_siren.ambr index 84fddfbfc04c..ad33b12241fa 100644 --- a/tests/components/tplink/snapshots/test_siren.ambr +++ b/tests/components/tplink/snapshots/test_siren.ambr @@ -41,7 +41,7 @@ ]), 'area_id': None, 'capabilities': dict({ - 'available_tones': tuple( + : tuple( 'Foo', 'Bar', ), @@ -79,7 +79,7 @@ # name: test_states[siren.hub-state] StateSnapshot({ 'attributes': ReadOnlyDict({ - 'available_tones': tuple( + : tuple( 'Foo', 'Bar', ),