comfoconnect
comfoconnect copied to clipboard
Improved connection robustness
By catching many more events that may result in an exception due to a broken connection By separating intended and non-intended disconnection events such that the library can reconnect automatically
I've updated my branch with the changes you requested.
I'm not convinced that this fixes all issues. The code currently doesn't detect when the bridge is unreachable as long as we don't send a command. I'll need to do something with the keepalives and the tcp timeout to check if the bridge is actually still connected.
I'm not convinced that this fixes all issues. The code currently doesn't detect when the bridge is unreachable as long as we don't send a command. I'll need to do something with the keepalives and the tcp timeout to check if the bridge is actually still connected.
Okay, I installed library from patch-3 on my side, there are still issues with reconnection, but there are more logs, take a look - maybe that will give you some more details.
During the day there are some warnings, but all worked fine (so I believe reconnections worked fine here)
Sep 7 17:13:12 srv hass[1058]: #033[33m2021-09-07 17:13:12 WARNING (Thread-86) [comfoconnect] THe connection was broken. We will try to reconnect later.#033[0m Sep 7 17:18:12 srv hass[1058]: #033[33m2021-09-07 17:18:12 WARNING (Thread-87) [comfoconnect] THe connection was broken. We will try to reconnect later.#033[0m Sep 7 17:23:13 srv hass[1058]: #033[33m2021-09-07 17:23:13 WARNING (Thread-88) [comfoconnect] THe connection was broken. We will try to reconnect later.#033[0m Sep 7 17:28:12 srv hass[1058]: #033[33m2021-09-07 17:28:12 WARNING (Thread-89) [comfoconnect] THe connection was broken. We will try to reconnect later.#033[0m Sep 7 17:33:12 srv hass[1058]: #033[33m2021-09-07 17:33:12 WARNING (Thread-90) [comfoconnect] THe connection was broken. We will try to reconnect later.#033[0m Sep 7 17:38:12 srv hass[1058]: #033[33m2021-09-07 17:38:12 WARNING (Thread-91) [comfoconnect] THe connection was broken. We will try to reconnect later.#033[0m Sep 7 17:43:12 srv hass[1058]: #033[33m2021-09-07 17:43:12 WARNING (Thread-92) [comfoconnect] THe connection was broken. We will try to reconnect later.#033[0m Sep 7 17:48:14 srv hass[1058]: #033[33m2021-09-07 17:48:14 WARNING (Thread-93) [comfoconnect] THe connection was broken. We will try to reconnect later.#033[0m Sep 7 17:53:12 srv hass[1058]: #033[33m2021-09-07 17:53:12 WARNING (Thread-94) [comfoconnect] THe connection was broken. We will try to reconnect later.#033[0m Sep 7 17:58:12 srv hass[1058]: #033[33m2021-09-07 17:58:12 WARNING (Thread-95) [comfoconnect] THe connection was broken. We will try to reconnect later.#033[0m Sep 7 18:03:12 srv hass[1058]: #033[33m2021-09-07 18:03:12 WARNING (Thread-96) [comfoconnect] THe connection was broken. We will try to reconnect later.#033[0m Sep 7 18:08:12 srv hass[1058]: #033[33m2021-09-07 18:08:12 WARNING (Thread-97) [comfoconnect] THe connection was broken. We will try to reconnect later.#033[0m Sep 7 18:13:12 srv hass[1058]: #033[33m2021-09-07 18:13:12 WARNING (Thread-98) [comfoconnect] THe connection was broken. We will try to reconnect later.#033[0m
Then I had probably some connectivity issues (I got notification on my zabbix regarding network outage) and comfoconnect was not able to connect anymore: https://pastebin.com/VhkUX6rG - HA restart is needed to fix that.
Iirc, the app does do a keepalive command. I remember seeing the same couple of commands every (few) second(s). I think CnTimeRequestType
was one of them.
Would it be an idea to implement in this lib as well? Then at least we can actively know if the connection broke and reconnect.
I've moved this logic out of the library in https://github.com/michaelarnauts/aiocomfoconnect. It's up to the user to reconnect if needed, what makes it much simpler.
In Home Assistant, I do it like this:
@callback
async def send_keepalive(now) -> None:
"""Send keepalive to the bridge."""
_LOGGER.debug("Sending keepalive...")
try:
await bridge.cmd_keepalive()
except AioComfoConnectNotConnected:
# Reconnect when connection has been dropped
await bridge.connect(entry.data[CONF_LOCAL_UUID])
entry.async_on_unload(
async_track_time_interval(hass, send_keepalive, KEEP_ALIVE_INTERVAL)
)