mirror of
https://github.com/home-assistant/core.git
synced 2025-07-08 13:57:10 +00:00
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:
parent
1c11b247e4
commit
578c897161
@ -71,6 +71,7 @@ SUBSCRIPTION_SERVICES = [
|
|||||||
"zoneGroupTopology",
|
"zoneGroupTopology",
|
||||||
]
|
]
|
||||||
UNAVAILABLE_VALUES = {"", "NOT_IMPLEMENTED", None}
|
UNAVAILABLE_VALUES = {"", "NOT_IMPLEMENTED", None}
|
||||||
|
UNUSED_DEVICE_KEYS = ["SPID", "TargetRoomName"]
|
||||||
|
|
||||||
|
|
||||||
_LOGGER = logging.getLogger(__name__)
|
_LOGGER = logging.getLogger(__name__)
|
||||||
@ -407,6 +408,10 @@ class SonosSpeaker:
|
|||||||
"""Update device properties from an event."""
|
"""Update device properties from an event."""
|
||||||
if more_info := event.variables.get("more_info"):
|
if more_info := event.variables.get("more_info"):
|
||||||
battery_dict = dict(x.split(":") for x in more_info.split(","))
|
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:
|
if "BattChg" not in battery_dict:
|
||||||
_LOGGER.debug(
|
_LOGGER.debug(
|
||||||
"Unknown device properties update for %s (%s), please report an issue: '%s'",
|
"Unknown device properties update for %s (%s), please report an issue: '%s'",
|
||||||
|
@ -103,3 +103,23 @@ async def test_device_payload_without_battery(
|
|||||||
await hass.async_block_till_done()
|
await hass.async_block_till_done()
|
||||||
|
|
||||||
assert bad_payload in caplog.text
|
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
|
||||||
|
Loading…
x
Reference in New Issue
Block a user