Jc2k / aiohomekit

asyncio for homekit
Apache License 2.0
52 stars 19 forks source link

Recover CoAP pairing when remote device stops responding #358

Closed Jc2k closed 8 months ago

Jc2k commented 8 months ago

Prior to this change if a remote device stopped responding (e.g. packet loss) we would never recover - we'd just keep incrementing the encryption counter making it further and further away from the truth.

The only way to recover from this right now is to restart HA which obviously resets the encryption session.

This patch can't fix the buggy device, unstable network or packet loss that lead to a timeout in the first place but it can help things recover without needing a full HA restart.

Tested by a community member with a very unstable set of Nanoleaf devices (multiple devices go offline at same time, and with this patch they actually recover by themselves).

codecov[bot] commented 8 months ago

Codecov Report

Attention: 4 lines in your changes are missing coverage. Please review.

Comparison is base (d7acbf8) 74.54% compared to head (db39883) 74.51%.

Files Patch % Lines
aiohomekit/controller/coap/connection.py 0.00% 4 Missing :warning:
Additional details and impacted files ```diff @@ Coverage Diff @@ ## main #358 +/- ## ========================================== - Coverage 74.54% 74.51% -0.04% ========================================== Files 99 99 Lines 9327 9331 +4 ========================================== Hits 6953 6953 - Misses 2374 2378 +4 ```

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.

Jc2k commented 8 months ago

Cheers

codyc1515 commented 8 months ago

Fantastic to see! We really appreciate it.

Do you have an issue # on here where someone faced this issue that you expect it would be resolved? i.e. is this just going to fix (workaround) the encryption counter issue or we would expect it to also fix ones like below

Logger: aiohomekit.controller.coap.pdu
Source: components/homekit_controller/connection.py:283
First occurred: 13:56:35 (6 occurrences)
Last logged: 15:33:15

Transaction 0 failed with error 6 (Invalid request
Jc2k commented 8 months ago

No, it's just something we worked through on discord.

It will just stop (some?) devices getting stuck offline.

I seem to remember your error was known to the original dev of coap support, and it was harmless.

codyc1515 commented 8 months ago

Mint. I see no Unavailable messages in my logs anymore, so was curious what changed. Thank you so much.