diff --git a/homeassistant/components/sonos/speaker.py b/homeassistant/components/sonos/speaker.py index 055b4ce6845..dc610cee38a 100644 --- a/homeassistant/components/sonos/speaker.py +++ b/homeassistant/components/sonos/speaker.py @@ -382,6 +382,14 @@ class SonosSpeaker: """Update device properties from an event.""" if more_info := event.variables.get("more_info"): battery_dict = dict(x.split(":") for x in more_info.split(",")) + if "BattChg" not in battery_dict: + _LOGGER.debug( + "Unknown device properties update for %s (%s), please report an issue: '%s'", + self.zone_name, + self.model_name, + more_info, + ) + return await self.async_update_battery_info(battery_dict) self.async_write_entity_states() diff --git a/tests/components/sonos/test_sensor.py b/tests/components/sonos/test_sensor.py index 12c12821a0d..8d402b589b0 100644 --- a/tests/components/sonos/test_sensor.py +++ b/tests/components/sonos/test_sensor.py @@ -83,3 +83,23 @@ async def test_battery_on_S1(hass, config_entry, config, soco, battery_event): power_state = hass.states.get(power.entity_id) assert power_state.state == STATE_OFF assert power_state.attributes.get(ATTR_BATTERY_POWER_SOURCE) == "BATTERY" + + +async def test_device_payload_without_battery( + hass, config_entry, config, soco, battery_event, caplog +): + """Test device properties event update without battery info.""" + soco.get_battery_info.return_value = None + + await setup_platform(hass, config_entry, config) + + subscription = soco.deviceProperties.subscribe.return_value + sub_callback = subscription.callback + + bad_payload = "BadKey:BadValue" + battery_event.variables["more_info"] = bad_payload + + sub_callback(battery_event) + await hass.async_block_till_done() + + assert bad_payload in caplog.text