Ignore unused keys from Sonos device properties callback (#52660)

* Ignore known but unused keys from device callback

* Fix bug, add test
This commit is contained in:
jjlawren 2021-07-08 04:56:50 -05:00 committed by GitHub
parent 1c11b247e4
commit 578c897161
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 25 additions and 0 deletions

View File

@ -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'",

View File

@ -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