Fix Sonos Dialog Select type conversion (#151649)

This commit is contained in:
Pete Sage
2025-09-04 03:33:43 -04:00
committed by GitHub
parent c2290d6edb
commit 3bc772a196
3 changed files with 19 additions and 7 deletions
+9 -2
View File
@@ -61,8 +61,15 @@ async def async_setup_entry(
if (
state := getattr(speaker.soco, select_data.soco_attribute, None)
) is not None:
setattr(speaker, select_data.speaker_attribute, state)
features.append(select_data)
try:
setattr(speaker, select_data.speaker_attribute, int(state))
features.append(select_data)
except ValueError:
_LOGGER.error(
"Invalid value for %s %s",
select_data.speaker_attribute,
state,
)
return features
async def _async_create_entities(speaker: SonosSpeaker) -> None:
+6 -1
View File
@@ -599,7 +599,12 @@ class SonosSpeaker:
for enum_var in (ATTR_DIALOG_LEVEL,):
if enum_var in variables:
setattr(self, f"{enum_var}_enum", variables[enum_var])
try:
setattr(self, f"{enum_var}_enum", int(variables[enum_var]))
except ValueError:
_LOGGER.error(
"Invalid value for %s %s", enum_var, variables[enum_var]
)
self.async_write_entity_states()
+4 -4
View File
@@ -38,9 +38,9 @@ async def platform_binary_sensor_fixture():
[
(0, "off"),
(1, "low"),
(2, "medium"),
(3, "high"),
(4, "max"),
("2", "medium"),
("3", "high"),
("4", "max"),
],
)
async def test_select_dialog_level(
@@ -49,7 +49,7 @@ async def test_select_dialog_level(
soco,
entity_registry: er.EntityRegistry,
speaker_info: dict[str, str],
level: int,
level: int | str,
result: str,
) -> None:
"""Test dialog level select entity."""