From 2d484717f4d4dbcb5c4a6f47aeff01bf09113af2 Mon Sep 17 00:00:00 2001 From: ludeeus Date: Thu, 29 Feb 2024 10:03:32 +0000 Subject: [PATCH 1/2] Add 5min heartbeat to WebSocket connections --- hass_nabucasa/iot_base.py | 1 + 1 file changed, 1 insertion(+) diff --git a/hass_nabucasa/iot_base.py b/hass_nabucasa/iot_base.py index 99d65141f..29a017b87 100644 --- a/hass_nabucasa/iot_base.py +++ b/hass_nabucasa/iot_base.py @@ -201,6 +201,7 @@ async def _handle_connection(self) -> None: try: self.client = await self.cloud.websession.ws_connect( self.ws_server_url, + heartbeat=300, headers={ hdrs.AUTHORIZATION: f"Bearer {self.cloud.id_token}", hdrs.USER_AGENT: self.cloud.client.client_name, From 8844f85e7a3091f822d143fc939da8b7569f6f70 Mon Sep 17 00:00:00 2001 From: ludeeus Date: Fri, 1 Mar 2024 06:13:54 +0000 Subject: [PATCH 2/2] Limit to the CloudIoT class --- hass_nabucasa/iot.py | 5 +++++ hass_nabucasa/iot_base.py | 7 ++++++- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/hass_nabucasa/iot.py b/hass_nabucasa/iot.py index 37a6ec090..e0be4b042 100644 --- a/hass_nabucasa/iot.py +++ b/hass_nabucasa/iot.py @@ -63,6 +63,11 @@ def package_name(self) -> str: """Return the package name for logging.""" return __name__ + @property + def ws_heartbeat(self) -> float | None: + """Server to connect to.""" + return 300 + @property def ws_server_url(self) -> str: """Server to connect to.""" diff --git a/hass_nabucasa/iot_base.py b/hass_nabucasa/iot_base.py index bf0391c52..733180180 100644 --- a/hass_nabucasa/iot_base.py +++ b/hass_nabucasa/iot_base.py @@ -75,6 +75,11 @@ def package_name(self) -> str: """Return package name for logging.""" raise NotImplementedError + @property + def ws_heartbeat(self) -> float | None: + """Server to connect to.""" + return None + @property def ws_server_url(self) -> str: """Server to connect to.""" @@ -202,7 +207,7 @@ async def _handle_connection(self) -> None: try: self.client = await self.cloud.websession.ws_connect( self.ws_server_url, - heartbeat=300, + heartbeat=self.ws_heartbeat, headers={ hdrs.AUTHORIZATION: f"Bearer {self.cloud.id_token}", hdrs.USER_AGENT: self.cloud.client.client_name,