Skip to content

Commit

Permalink
setup listener in contextmanager
Browse files Browse the repository at this point in the history
  • Loading branch information
marcelveldt committed Jul 5, 2024
1 parent d4090b3 commit 772a86b
Showing 1 changed file with 2 additions and 0 deletions.
2 changes: 2 additions & 0 deletions hass_client/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ def __init__(
self._result_futures: dict[str, asyncio.Future] = {}
self._shutdown_complete_event: asyncio.Event | None = None
self._msg_id_lock = asyncio.Lock()
self._listener_task: asyncio.Task | None = None

@property
def connected(self) -> bool:
Expand Down Expand Up @@ -410,6 +411,7 @@ async def _send_json_message(self, message: dict[str, Any]) -> None:
async def __aenter__(self) -> HomeAssistantClient:
"""Connect to the websocket."""
await self.connect()
self._listener_task = asyncio.create_task(self.start_listening())
return self

async def __aexit__(
Expand Down

0 comments on commit 772a86b

Please sign in to comment.