mirror of
https://github.com/esphome/aioesphomeapi.git
synced 2024-12-27 17:37:39 +01:00
Make creating background tasks in the client a bound method (#778)
This commit is contained in:
parent
d40acb1f85
commit
b3a621f809
@ -1259,9 +1259,7 @@ class APIClient:
|
|||||||
# We hold a reference to the start_task in unsub function
|
# We hold a reference to the start_task in unsub function
|
||||||
# so we don't need to add it to the background tasks.
|
# so we don't need to add it to the background tasks.
|
||||||
else:
|
else:
|
||||||
stop_task = asyncio.create_task(handle_stop())
|
self._create_background_task(handle_stop())
|
||||||
self._background_tasks.add(stop_task)
|
|
||||||
stop_task.add_done_callback(self._background_tasks.discard)
|
|
||||||
|
|
||||||
connection.send_message(SubscribeVoiceAssistantRequest(subscribe=True))
|
connection.send_message(SubscribeVoiceAssistantRequest(subscribe=True))
|
||||||
|
|
||||||
@ -1283,6 +1281,12 @@ class APIClient:
|
|||||||
|
|
||||||
return unsub
|
return unsub
|
||||||
|
|
||||||
|
def _create_background_task(self, coro: Coroutine[Any, Any, None]) -> None:
|
||||||
|
"""Create a background task and add it to the background tasks set."""
|
||||||
|
task = asyncio.create_task(coro)
|
||||||
|
self._background_tasks.add(task)
|
||||||
|
task.add_done_callback(self._background_tasks.discard)
|
||||||
|
|
||||||
def send_voice_assistant_event(
|
def send_voice_assistant_event(
|
||||||
self, event_type: VoiceAssistantEventType, data: dict[str, str] | None
|
self, event_type: VoiceAssistantEventType, data: dict[str, str] | None
|
||||||
) -> None:
|
) -> None:
|
||||||
|
Loading…
Reference in New Issue
Block a user