1
0
mirror of https://github.com/home-assistant/core.git synced 2026-07-07 06:46:17 +01:00

Migrate siren entity attributes to StrEnum (#174616)

This commit is contained in:
epenet
2026-06-24 11:54:13 +02:00
committed by GitHub
parent e87a41a01d
commit e3605be5cd
5 changed files with 25 additions and 14 deletions
+8 -3
View File
@@ -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
+7 -1
View File
@@ -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."""
@@ -2,7 +2,7 @@
# name: test_siren
StateSnapshot({
'attributes': ReadOnlyDict({
'available_tones': list([
<SirenEntityCapabilityAttribute.AVAILABLE_TONES: 'available_tones'>: list([
0,
]),
'friendly_name': 'Test',
@@ -23,7 +23,7 @@
]),
'area_id': None,
'capabilities': dict({
'available_tones': list([
<SirenEntityCapabilityAttribute.AVAILABLE_TONES: 'available_tones'>: list([
0,
]),
}),
@@ -60,7 +60,7 @@
# name: test_siren_change_default_tone
StateSnapshot({
'attributes': ReadOnlyDict({
'available_tones': list([
<SirenEntityCapabilityAttribute.AVAILABLE_TONES: 'available_tones'>: list([
0,
]),
'friendly_name': 'Test',
@@ -81,7 +81,7 @@
]),
'area_id': None,
'capabilities': dict({
'available_tones': list([
<SirenEntityCapabilityAttribute.AVAILABLE_TONES: 'available_tones'>: list([
0,
]),
}),
@@ -118,7 +118,7 @@
# name: test_siren_switching
StateSnapshot({
'attributes': ReadOnlyDict({
'available_tones': list([
<SirenEntityCapabilityAttribute.AVAILABLE_TONES: 'available_tones'>: list([
0,
]),
'friendly_name': 'Test',
@@ -139,7 +139,7 @@
]),
'area_id': None,
'capabilities': dict({
'available_tones': list([
<SirenEntityCapabilityAttribute.AVAILABLE_TONES: 'available_tones'>: list([
0,
]),
}),
@@ -6,7 +6,7 @@
]),
'area_id': None,
'capabilities': dict({
'available_tones': list([
<SirenEntityCapabilityAttribute.AVAILABLE_TONES: 'available_tones'>: list([
'ding',
'motion',
]),
@@ -45,7 +45,7 @@
StateSnapshot({
'attributes': ReadOnlyDict({
'attribution': 'Data provided by Ring.com',
'available_tones': list([
<SirenEntityCapabilityAttribute.AVAILABLE_TONES: 'available_tones'>: list([
'ding',
'motion',
]),
@@ -41,7 +41,7 @@
]),
'area_id': None,
'capabilities': dict({
'available_tones': tuple(
<SirenEntityCapabilityAttribute.AVAILABLE_TONES: 'available_tones'>: tuple(
'Foo',
'Bar',
),
@@ -79,7 +79,7 @@
# name: test_states[siren.hub-state]
StateSnapshot({
'attributes': ReadOnlyDict({
'available_tones': tuple(
<SirenEntityCapabilityAttribute.AVAILABLE_TONES: 'available_tones'>: tuple(
'Foo',
'Bar',
),