diff --git a/homeassistant/components/sonos/select.py b/homeassistant/components/sonos/select.py index 052a1d879676..0a56e37e75c0 100644 --- a/homeassistant/components/sonos/select.py +++ b/homeassistant/components/sonos/select.py @@ -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: diff --git a/homeassistant/components/sonos/speaker.py b/homeassistant/components/sonos/speaker.py index 427f02f04798..acf1b08cd36e 100644 --- a/homeassistant/components/sonos/speaker.py +++ b/homeassistant/components/sonos/speaker.py @@ -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() diff --git a/tests/components/sonos/test_select.py b/tests/components/sonos/test_select.py index ada48de21f39..dbbf28a52d74 100644 --- a/tests/components/sonos/test_select.py +++ b/tests/components/sonos/test_select.py @@ -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."""