Avoid check_api_state in websocket _can_send if we are already connected (#4446)

This commit is contained in:
J. Nick Koston 2023-07-20 04:20:02 -05:00 committed by GitHub
parent 4bd2000174
commit 5266927bf7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -212,7 +212,11 @@ class HomeAssistantWebSocket(CoreSysAttributes):
"""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