Skip to content

Commit

Permalink
Start live history/logbook with eager tasks (home-assistant#113779)
Browse files Browse the repository at this point in the history
  • Loading branch information
bdraco authored Mar 19, 2024
1 parent e3ae66c commit 8b9a8a3
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
5 changes: 3 additions & 2 deletions homeassistant/components/history/websocket_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
async_track_state_change_event,
)
from homeassistant.helpers.json import json_bytes
from homeassistant.util.async_ import create_eager_task
import homeassistant.util.dt as dt_util

from .const import EVENT_COALESCE_TIME, MAX_PENDING_HISTORY_STATES
Expand Down Expand Up @@ -536,7 +537,7 @@ def _queue_or_cancel(event: Event) -> None:
# Unsubscribe happened while sending historical states
return

live_stream.task = asyncio.create_task(
live_stream.task = create_eager_task(
_async_events_consumer(
subscriptions_setup_complete_time,
connection,
Expand All @@ -546,7 +547,7 @@ def _queue_or_cancel(event: Event) -> None:
)
)

live_stream.wait_sync_task = asyncio.create_task(
live_stream.wait_sync_task = create_eager_task(
get_instance(hass).async_block_till_done()
)
await live_stream.wait_sync_task
Expand Down
5 changes: 3 additions & 2 deletions homeassistant/components/logbook/websocket_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
from homeassistant.core import CALLBACK_TYPE, Event, HomeAssistant, callback
from homeassistant.helpers.event import async_track_point_in_utc_time
from homeassistant.helpers.json import json_bytes
from homeassistant.util.async_ import create_eager_task
import homeassistant.util.dt as dt_util

from .const import DOMAIN
Expand Down Expand Up @@ -395,7 +396,7 @@ def _queue_or_cancel(event: Event) -> None:
# Unsubscribe happened while sending historical events
return

live_stream.task = asyncio.create_task(
live_stream.task = create_eager_task(
_async_events_consumer(
subscriptions_setup_complete_time,
connection,
Expand All @@ -405,7 +406,7 @@ def _queue_or_cancel(event: Event) -> None:
)
)

live_stream.wait_sync_task = asyncio.create_task(
live_stream.wait_sync_task = create_eager_task(
get_instance(hass).async_block_till_done()
)
await live_stream.wait_sync_task
Expand Down

0 comments on commit 8b9a8a3

Please sign in to comment.