mirror of
https://github.com/home-assistant/core.git
synced 2025-07-24 21:57:51 +00:00
Migrate more sonos tasks to use eager_start (#114697)
This commit is contained in:
parent
b0d1b6555d
commit
e0e54ab9d3
@ -230,7 +230,8 @@ class SonosDiscoveryManager:
|
|||||||
return
|
return
|
||||||
|
|
||||||
self.hass.async_create_task(
|
self.hass.async_create_task(
|
||||||
self.async_add_speakers(zones_to_add, subscription, soco.uid)
|
self.async_add_speakers(zones_to_add, subscription, soco.uid),
|
||||||
|
eager_start=True,
|
||||||
)
|
)
|
||||||
|
|
||||||
async def async_subscription_failed(now: datetime.datetime) -> None:
|
async def async_subscription_failed(now: datetime.datetime) -> None:
|
||||||
|
@ -407,7 +407,9 @@ class SonosSpeaker:
|
|||||||
@callback
|
@callback
|
||||||
def async_renew_failed(self, exception: Exception) -> None:
|
def async_renew_failed(self, exception: Exception) -> None:
|
||||||
"""Handle a failed subscription renewal."""
|
"""Handle a failed subscription renewal."""
|
||||||
self.hass.async_create_task(self._async_renew_failed(exception))
|
self.hass.async_create_task(
|
||||||
|
self._async_renew_failed(exception), eager_start=True
|
||||||
|
)
|
||||||
|
|
||||||
async def _async_renew_failed(self, exception: Exception) -> None:
|
async def _async_renew_failed(self, exception: Exception) -> None:
|
||||||
"""Mark the speaker as offline after a subscription renewal failure.
|
"""Mark the speaker as offline after a subscription renewal failure.
|
||||||
@ -449,7 +451,9 @@ class SonosSpeaker:
|
|||||||
"""Add the soco instance associated with the event to the callback."""
|
"""Add the soco instance associated with the event to the callback."""
|
||||||
if "alarm_list_version" not in event.variables:
|
if "alarm_list_version" not in event.variables:
|
||||||
return
|
return
|
||||||
self.hass.async_create_task(self.alarms.async_process_event(event, self))
|
self.hass.async_create_task(
|
||||||
|
self.alarms.async_process_event(event, self), eager_start=True
|
||||||
|
)
|
||||||
|
|
||||||
@callback
|
@callback
|
||||||
def async_dispatch_device_properties(self, event: SonosEvent) -> None:
|
def async_dispatch_device_properties(self, event: SonosEvent) -> None:
|
||||||
@ -479,7 +483,9 @@ class SonosSpeaker:
|
|||||||
return
|
return
|
||||||
if "container_update_i_ds" not in event.variables:
|
if "container_update_i_ds" not in event.variables:
|
||||||
return
|
return
|
||||||
self.hass.async_create_task(self.favorites.async_process_event(event, self))
|
self.hass.async_create_task(
|
||||||
|
self.favorites.async_process_event(event, self), eager_start=True
|
||||||
|
)
|
||||||
|
|
||||||
@callback
|
@callback
|
||||||
def async_dispatch_media_update(self, event: SonosEvent) -> None:
|
def async_dispatch_media_update(self, event: SonosEvent) -> None:
|
||||||
@ -601,7 +607,7 @@ class SonosSpeaker:
|
|||||||
self.available = True
|
self.available = True
|
||||||
if not was_available:
|
if not was_available:
|
||||||
self.async_write_entity_states()
|
self.async_write_entity_states()
|
||||||
self.hass.async_create_task(self.async_subscribe())
|
self.hass.async_create_task(self.async_subscribe(), eager_start=True)
|
||||||
|
|
||||||
@callback
|
@callback
|
||||||
def async_check_activity(self, now: datetime.datetime) -> None:
|
def async_check_activity(self, now: datetime.datetime) -> None:
|
||||||
@ -818,7 +824,9 @@ class SonosSpeaker:
|
|||||||
if "zone_player_uui_ds_in_group" not in event.variables:
|
if "zone_player_uui_ds_in_group" not in event.variables:
|
||||||
return
|
return
|
||||||
self.event_stats.process(event)
|
self.event_stats.process(event)
|
||||||
self.hass.async_create_task(self.create_update_groups_coro(event))
|
self.hass.async_create_task(
|
||||||
|
self.create_update_groups_coro(event), eager_start=True
|
||||||
|
)
|
||||||
|
|
||||||
def create_update_groups_coro(self, event: SonosEvent | None = None) -> Coroutine:
|
def create_update_groups_coro(self, event: SonosEvent | None = None) -> Coroutine:
|
||||||
"""Handle callback for topology change event."""
|
"""Handle callback for topology change event."""
|
||||||
|
@ -494,6 +494,6 @@ def zgs_event_fixture(hass: HomeAssistant, soco: SoCo, zgs_discovery: str):
|
|||||||
subscription: SonosMockSubscribe = soco.zoneGroupTopology.subscribe.return_value
|
subscription: SonosMockSubscribe = soco.zoneGroupTopology.subscribe.return_value
|
||||||
sub_callback = await subscription.wait_for_callback_to_be_set()
|
sub_callback = await subscription.wait_for_callback_to_be_set()
|
||||||
sub_callback(event)
|
sub_callback(event)
|
||||||
await hass.async_block_till_done()
|
await hass.async_block_till_done(wait_background_tasks=True)
|
||||||
|
|
||||||
return _wrapper
|
return _wrapper
|
||||||
|
@ -242,7 +242,6 @@ async def test_favorites_sensor(
|
|||||||
|
|
||||||
# Trigger subscription callback for speaker discovery
|
# Trigger subscription callback for speaker discovery
|
||||||
await fire_zgs_event()
|
await fire_zgs_event()
|
||||||
await hass.async_block_till_done(wait_background_tasks=True)
|
|
||||||
|
|
||||||
favorites_updated_event = SonosMockEvent(
|
favorites_updated_event = SonosMockEvent(
|
||||||
soco, service, {"favorites_update_id": "2", "container_update_i_ds": "FV:2,2"}
|
soco, service, {"favorites_update_id": "2", "container_update_i_ds": "FV:2,2"}
|
||||||
|
@ -117,12 +117,11 @@ async def test_switch_attributes(
|
|||||||
hass,
|
hass,
|
||||||
dt_util.utcnow() + timedelta(seconds=RELOAD_AFTER_UPDATE_DELAY + 1),
|
dt_util.utcnow() + timedelta(seconds=RELOAD_AFTER_UPDATE_DELAY + 1),
|
||||||
)
|
)
|
||||||
await hass.async_block_till_done()
|
await hass.async_block_till_done(wait_background_tasks=True)
|
||||||
assert m.called
|
assert m.called
|
||||||
|
|
||||||
# Trigger subscription callback for speaker discovery
|
# Trigger subscription callback for speaker discovery
|
||||||
await fire_zgs_event()
|
await fire_zgs_event()
|
||||||
await hass.async_block_till_done(wait_background_tasks=True)
|
|
||||||
|
|
||||||
status_light_state = hass.states.get(status_light.entity_id)
|
status_light_state = hass.states.get(status_light.entity_id)
|
||||||
assert status_light_state.state == STATE_ON
|
assert status_light_state.state == STATE_ON
|
||||||
|
Loading…
x
Reference in New Issue
Block a user