Skip to content

Commit

Permalink
Avoid check_api_state in websocket _can_send if we are already connec…
Browse files Browse the repository at this point in the history
…ted (#4446)
  • Loading branch information
bdraco authored Jul 20, 2023
1 parent 4bd2000 commit 5266927
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion supervisor/homeassistant/websocket.py
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,11 @@ async def _can_send(self, message: dict[str, Any]) -> bool:
"""Determine if we can use WebSocket messages."""
if self.sys_core.state in CLOSING_STATES:
return False
if not await self.sys_homeassistant.api.check_api_state():

connected = self._client and self._client.connected
# If we are already connected, we can avoid the check_api_state call
# since it makes a new socket connection and we already have one.
if not connected and not await self.sys_homeassistant.api.check_api_state():
# No core access, don't try.
return False

Expand Down

0 comments on commit 5266927

Please sign in to comment.