diff --git a/homeassistant/components/sonos/speaker.py b/homeassistant/components/sonos/speaker.py index ec59d946c09..14adbc337fb 100644 --- a/homeassistant/components/sonos/speaker.py +++ b/homeassistant/components/sonos/speaker.py @@ -71,6 +71,7 @@ SUBSCRIPTION_SERVICES = [ "zoneGroupTopology", ] UNAVAILABLE_VALUES = {"", "NOT_IMPLEMENTED", None} +UNUSED_DEVICE_KEYS = ["SPID", "TargetRoomName"] _LOGGER = logging.getLogger(__name__) @@ -407,6 +408,10 @@ 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(",")) + for unused in UNUSED_DEVICE_KEYS: + battery_dict.pop(unused, None) + if not battery_dict: + return if "BattChg" not in battery_dict: _LOGGER.debug( "Unknown device properties update for %s (%s), please report an issue: '%s'", diff --git a/tests/components/sonos/test_sensor.py b/tests/components/sonos/test_sensor.py index 8d402b589b0..80f050fe6fc 100644 --- a/tests/components/sonos/test_sensor.py +++ b/tests/components/sonos/test_sensor.py @@ -103,3 +103,23 @@ async def test_device_payload_without_battery( await hass.async_block_till_done() assert bad_payload in caplog.text + + +async def test_device_payload_without_battery_and_ignored_keys( + hass, config_entry, config, soco, battery_event, caplog +): + """Test device properties event update without battery info and ignored keys.""" + soco.get_battery_info.return_value = None + + await setup_platform(hass, config_entry, config) + + subscription = soco.deviceProperties.subscribe.return_value + sub_callback = subscription.callback + + ignored_payload = "SPID:InCeiling,TargetRoomName:Bouncy House" + battery_event.variables["more_info"] = ignored_payload + + sub_callback(battery_event) + await hass.async_block_till_done() + + assert ignored_payload not in caplog.text