Catch unexpected battery update payloads on Sonos (#52040)
parent
067b5258c6
commit
7b5ed8faa8
|
@ -407,6 +407,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()
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue