Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add 5 min heartbeat to the CloudIoT WebSocket connection #584

Merged
merged 5 commits into from
Mar 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions hass_nabucasa/iot.py
Original file line number Diff line number Diff line change
Expand Up @@ -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."""
Expand Down
6 changes: 6 additions & 0 deletions hass_nabucasa/iot_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,11 @@ def package_name(self) -> str:
"""Return package name for logging."""
raise NotImplementedError

@property
def ws_heartbeat(self) -> float | None:
Copy link
Contributor Author

@ludeeus ludeeus Mar 1, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Only the CloudIoT class can use this for now, so made it a property (like ws_server_url) to allow those who inherit this base class to override it, with a default to None (current behavior).

"""Server to connect to."""
return None

@property
def ws_server_url(self) -> str:
"""Server to connect to."""
Expand Down Expand Up @@ -202,6 +207,7 @@ async def _handle_connection(self) -> None:
try:
self.client = await self.cloud.websession.ws_connect(
self.ws_server_url,
heartbeat=self.ws_heartbeat,
headers={
hdrs.AUTHORIZATION: f"Bearer {self.cloud.id_token}",
hdrs.USER_AGENT: self.cloud.client.client_name,
Expand Down