Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions homeassistant/components/sonos/select.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,15 @@ def available_soco_attributes(
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:
Expand Down
7 changes: 6 additions & 1 deletion homeassistant/components/sonos/speaker.py
Original file line number Diff line number Diff line change
Expand Up @@ -599,7 +599,12 @@ def async_update_volume(self, event: SonosEvent) -> None:

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()

Expand Down
8 changes: 4 additions & 4 deletions tests/components/sonos/test_select.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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."""
Expand Down