Fix sonos events delaying shutdown (#116337)
parent
c3aa238a33
commit
bf91ab6e2b
|
@ -407,8 +407,8 @@ class SonosSpeaker:
|
|||
@callback
|
||||
def async_renew_failed(self, exception: Exception) -> None:
|
||||
"""Handle a failed subscription renewal."""
|
||||
self.hass.async_create_task(
|
||||
self._async_renew_failed(exception), eager_start=True
|
||||
self.hass.async_create_background_task(
|
||||
self._async_renew_failed(exception), "sonos renew failed", eager_start=True
|
||||
)
|
||||
|
||||
async def _async_renew_failed(self, exception: Exception) -> None:
|
||||
|
@ -451,16 +451,20 @@ class SonosSpeaker:
|
|||
"""Add the soco instance associated with the event to the callback."""
|
||||
if "alarm_list_version" not in event.variables:
|
||||
return
|
||||
self.hass.async_create_task(
|
||||
self.alarms.async_process_event(event, self), eager_start=True
|
||||
self.hass.async_create_background_task(
|
||||
self.alarms.async_process_event(event, self),
|
||||
"sonos process event",
|
||||
eager_start=True,
|
||||
)
|
||||
|
||||
@callback
|
||||
def async_dispatch_device_properties(self, event: SonosEvent) -> None:
|
||||
"""Update device properties from an event."""
|
||||
self.event_stats.process(event)
|
||||
self.hass.async_create_task(
|
||||
self.async_update_device_properties(event), eager_start=True
|
||||
self.hass.async_create_background_task(
|
||||
self.async_update_device_properties(event),
|
||||
"sonos device properties",
|
||||
eager_start=True,
|
||||
)
|
||||
|
||||
async def async_update_device_properties(self, event: SonosEvent) -> None:
|
||||
|
@ -483,8 +487,10 @@ class SonosSpeaker:
|
|||
return
|
||||
if "container_update_i_ds" not in event.variables:
|
||||
return
|
||||
self.hass.async_create_task(
|
||||
self.favorites.async_process_event(event, self), eager_start=True
|
||||
self.hass.async_create_background_task(
|
||||
self.favorites.async_process_event(event, self),
|
||||
"sonos dispatch favorites",
|
||||
eager_start=True,
|
||||
)
|
||||
|
||||
@callback
|
||||
|
|
|
@ -157,7 +157,7 @@ async def test_alarm_create_delete(
|
|||
alarm_event.variables["alarm_list_version"] = two_alarms["CurrentAlarmListVersion"]
|
||||
|
||||
sub_callback(event=alarm_event)
|
||||
await hass.async_block_till_done()
|
||||
await hass.async_block_till_done(wait_background_tasks=True)
|
||||
|
||||
assert "switch.sonos_alarm_14" in entity_registry.entities
|
||||
assert "switch.sonos_alarm_15" in entity_registry.entities
|
||||
|
@ -169,7 +169,7 @@ async def test_alarm_create_delete(
|
|||
alarm_clock.ListAlarms.return_value = one_alarm
|
||||
|
||||
sub_callback(event=alarm_event)
|
||||
await hass.async_block_till_done()
|
||||
await hass.async_block_till_done(wait_background_tasks=True)
|
||||
|
||||
assert "switch.sonos_alarm_14" in entity_registry.entities
|
||||
assert "switch.sonos_alarm_15" not in entity_registry.entities
|
||||
|
|
Loading…
Reference in New Issue