Fix sonos events delaying shutdown (#116337)

pull/116343/head
J. Nick Koston 2024-04-28 08:54:34 -05:00 committed by GitHub
parent c3aa238a33
commit bf91ab6e2b
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 16 additions and 10 deletions

View File

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

View File

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