Version of the custom_component
Latest version via HACS (installed 2026-03-09)
Configuration
# Hilo integration configuration via UI
# No custom yaml configuration - using default settings
Describe the bug
The Hilo integration is experiencing WebSocket connection issues that cause it to lose real-time connectivity and enter a reconnection loop. The integration periodically loses connection to Hilo services and gets stuck attempting to reconnect with authentication errors (401/404). This affects core functionality like real-time device updates and challenge notifications.
The issue appears to be in the WebSocket reconnection logic where token refresh attempts are made but the integration continues to use expired credentials, leading to endless reconnection loops every few minutes.
Debug log
2026-03-09 06:30:12.725 ERROR (MainThread) [pyhilo] Websocket: Received event to close connection: 257
2026-03-09 06:30:12.728 ERROR (MainThread) [pyhilo] Websocket: Closed while listening: Connection was closed.
2026-03-09 06:30:12.731 ERROR (MainThread) [pyhilo] Connection was closed.
Traceback (most recent call last):
File "/usr/local/lib/python3.14/site-packages/pyhilo/websocket.py", line 351, in async_listen
messages = await self._async_receive_json()
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.14/site-packages/pyhilo/websocket.py", line 179, in _async_receive_json
raise ConnectionClosedError("Connection was closed.")
pyhilo.exceptions.ConnectionClosedError: Connection was closed.
2026-03-09 06:30:17.875 ERROR (MainThread) [pyhilo] Unable to connect to WS server 401, message='Invalid response status', url='https://device.hiloenergie.com/client/?hub=devicehub&asrs.op=%2FDeviceHub&asrs_request_id=S6RSmf4CAAA%3D&id=6YGmcN_mDL-nNVdZyaU_KwW5wjaAo02&access_token=[REDACTED_TOKEN]
2026-03-09 06:30:17.878 WARNING (MainThread) [custom_components.hilo] Invalid credentials? Refreshing websocket infos
2026-03-09 06:30:22.722 ERROR (MainThread) [pyhilo] Websocket: Received event to close connection: 257
2026-03-09 06:30:22.723 ERROR (MainThread) [pyhilo] Websocket: Closed while listening: Connection was closed.
2026-03-09 06:30:22.723 ERROR (MainThread) [pyhilo] Connection was closed.
Traceback (most recent call last):
File "/usr/local/lib/python3.14/site-packages/pyhilo/websocket.py", line 351, in async_listen
messages = await self._async_receive_json()
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.14/site-packages/pyhilo/websocket.py", line 179, in _async_receive_json
raise ConnectionClosedError("Connection was closed.")
pyhilo.exceptions.ConnectionClosedError: Connection was closed.
2026-03-09 06:30:23.505 ERROR (MainThread) [pyhilo] Unable to connect to WS server 404, message='Invalid response status', url='https://device.hiloenergie.com/client/?hub=devicehub&asrs.op=%2FDeviceHub&asrs_request_id=4XSmFywDAAA%3D&id=LU2yMDobKNbI7TdFm4jDkgW5wjaAo02&access_token=[REDACTED_TOKEN]
2026-03-09 06:30:23.505 WARNING (MainThread) [custom_components.hilo] Invalid credentials? Refreshing websocket infos
2026-03-09 08:00:58.724 ERROR (MainThread) [pyhilo] Websocket: Received event to close connection: 257
pyhilo.exceptions.ConnectionClosedError: Connection was closed.
2026-03-09 08:01:01.724 ERROR (MainThread) [pyhilo] Websocket: Received event to close connection: 257
pyhilo.exceptions.NotConnectedError
Additional Analysis
After reviewing the source code, the issue appears to be in the WebSocket reconnection logic in custom_components/hilo/__init__.py lines 796-814:
- Token refresh logic order: The code cancels the WebSocket connection before refreshing the token, then attempts reconnection regardless of whether refresh succeeded
- Missing token validation: No validation that token refresh was successful before reconnecting
- Incomplete error handling:
ConnectionClosedError not explicitly handled
- Fixed reconnect delay: 5-second delay for all errors creates rapid loops
- No exponential backoff: Failed auth attempts don't use backoff
Potential Solutions
- Fix token refresh logic order (refresh before cancel)
- Add token refresh validation
- Add specific
ConnectionClosedError handling
- Implement exponential backoff for auth errors
- Use error-specific reconnection strategies
Version of the custom_component
Latest version via HACS (installed 2026-03-09)
Configuration
Describe the bug
The Hilo integration is experiencing WebSocket connection issues that cause it to lose real-time connectivity and enter a reconnection loop. The integration periodically loses connection to Hilo services and gets stuck attempting to reconnect with authentication errors (401/404). This affects core functionality like real-time device updates and challenge notifications.
The issue appears to be in the WebSocket reconnection logic where token refresh attempts are made but the integration continues to use expired credentials, leading to endless reconnection loops every few minutes.
Debug log
Additional Analysis
After reviewing the source code, the issue appears to be in the WebSocket reconnection logic in
custom_components/hilo/__init__.pylines 796-814:ConnectionClosedErrornot explicitly handledPotential Solutions
ConnectionClosedErrorhandling