Skip to content

Commit 3dacffa

Browse files
PeteRagerfrenck
authored andcommitted
Fix Sonos Dialog Select type conversion (home-assistant#151649)
1 parent d90f2a1 commit 3dacffa

File tree

3 files changed

+19
-7
lines changed

3 files changed

+19
-7
lines changed

homeassistant/components/sonos/select.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,15 @@ def available_soco_attributes(
6161
if (
6262
state := getattr(speaker.soco, select_data.soco_attribute, None)
6363
) is not None:
64-
setattr(speaker, select_data.speaker_attribute, state)
65-
features.append(select_data)
64+
try:
65+
setattr(speaker, select_data.speaker_attribute, int(state))
66+
features.append(select_data)
67+
except ValueError:
68+
_LOGGER.error(
69+
"Invalid value for %s %s",
70+
select_data.speaker_attribute,
71+
state,
72+
)
6673
return features
6774

6875
async def _async_create_entities(speaker: SonosSpeaker) -> None:

homeassistant/components/sonos/speaker.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -599,7 +599,12 @@ def async_update_volume(self, event: SonosEvent) -> None:
599599

600600
for enum_var in (ATTR_DIALOG_LEVEL,):
601601
if enum_var in variables:
602-
setattr(self, f"{enum_var}_enum", variables[enum_var])
602+
try:
603+
setattr(self, f"{enum_var}_enum", int(variables[enum_var]))
604+
except ValueError:
605+
_LOGGER.error(
606+
"Invalid value for %s %s", enum_var, variables[enum_var]
607+
)
603608

604609
self.async_write_entity_states()
605610

tests/components/sonos/test_select.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,9 @@ async def platform_binary_sensor_fixture():
3838
[
3939
(0, "off"),
4040
(1, "low"),
41-
(2, "medium"),
42-
(3, "high"),
43-
(4, "max"),
41+
("2", "medium"),
42+
("3", "high"),
43+
("4", "max"),
4444
],
4545
)
4646
async def test_select_dialog_level(
@@ -49,7 +49,7 @@ async def test_select_dialog_level(
4949
soco,
5050
entity_registry: er.EntityRegistry,
5151
speaker_info: dict[str, str],
52-
level: int,
52+
level: int | str,
5353
result: str,
5454
) -> None:
5555
"""Test dialog level select entity."""

0 commit comments

Comments
 (0)