mirror of
https://github.com/home-assistant/supervisor.git
synced 2025-07-19 15:16:33 +00:00
Guard against multiple client creations (#2809)
This commit is contained in:
parent
4a53c62af8
commit
dd10d3e037
@ -86,17 +86,22 @@ class HomeAssistantWebSocket(CoreSysAttributes):
|
|||||||
"""Initialize Home Assistant object."""
|
"""Initialize Home Assistant object."""
|
||||||
self.coresys: CoreSys = coresys
|
self.coresys: CoreSys = coresys
|
||||||
self._client: Optional[WSClient] = None
|
self._client: Optional[WSClient] = None
|
||||||
|
self._lock: asyncio.Lock = asyncio.Lock()
|
||||||
|
|
||||||
async def _get_ws_client(self) -> WSClient:
|
async def _get_ws_client(self) -> WSClient:
|
||||||
"""Return a websocket client."""
|
"""Return a websocket client."""
|
||||||
await self.sys_homeassistant.api.ensure_access_token()
|
async with self._lock:
|
||||||
client = await WSClient.connect_with_auth(
|
if self._client is not None:
|
||||||
self.sys_websession_ssl,
|
return self._client
|
||||||
f"{self.sys_homeassistant.api_url}/api/websocket",
|
|
||||||
self.sys_homeassistant.api.access_token,
|
|
||||||
)
|
|
||||||
|
|
||||||
return client
|
await self.sys_homeassistant.api.ensure_access_token()
|
||||||
|
client = await WSClient.connect_with_auth(
|
||||||
|
self.sys_websession_ssl,
|
||||||
|
f"{self.sys_homeassistant.api_url}/api/websocket",
|
||||||
|
self.sys_homeassistant.api.access_token,
|
||||||
|
)
|
||||||
|
|
||||||
|
return client
|
||||||
|
|
||||||
async def async_send_command(self, message: Dict[str, Any]):
|
async def async_send_command(self, message: Dict[str, Any]):
|
||||||
"""Send a command with the WS client."""
|
"""Send a command with the WS client."""
|
||||||
|
Loading…
x
Reference in New Issue
Block a user