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

Implement async_reachable to see if a device is reachable on the network #370

Merged
merged 19 commits into from
Jul 17, 2024

Conversation

bdraco
Copy link
Collaborator

@bdraco bdraco commented Apr 26, 2024

For zeroconf based devices we check if the A/AAAA records are still published. This means we will know if the device is offline within 120s since A/AAAA records typically have a TTL of 120s

For BLE based devices we will check if the BLE device is in range and seen by the adapter. This will vary by BLE adapter, but it will likely mean we will know within a few minutes as well

For zeroconf based devices we check if the A/AAAA records are still
published. This means we will know if the device is offline within
120s since A/AAAA records typically have a TTL of 120s

For BLE based devices we will check if the BLE device is in range and
seen by the adapter. This will vary by BLE adapter, but it will likely
mean we will know within a few minutes as well
async with asyncio_timeout(timeout):
if discovery := await waiter:
return discovery
if discovery := await waiter:
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

There was a risk we could raise cancellation into the caller so I used a call later instead of async_timeout here

@bdraco
Copy link
Collaborator Author

bdraco commented Apr 26, 2024

I need to write a test for the zeroconf case

@bdraco
Copy link
Collaborator Author

bdraco commented Apr 26, 2024

Keep getting distracted by beta issues so will have to come back to writing the tests later

@bdraco bdraco marked this pull request as ready for review April 27, 2024 12:37
@bdraco
Copy link
Collaborator Author

bdraco commented May 1, 2024

I've been running this for a few days, and all seems well here

@bdraco
Copy link
Collaborator Author

bdraco commented May 20, 2024

No crashes on the device now. I think this will solve the problem

@bdraco
Copy link
Collaborator Author

bdraco commented Jul 17, 2024

I haven't had one crash on the device since implementing this. This puts us much more in-line with the native HomeKit behavior.

@bdraco
Copy link
Collaborator Author

bdraco commented Jul 17, 2024

Retested with Jc2k SO_KEEPALIVE idea. All good 👍

@bdraco bdraco merged commit b217e66 into main Jul 17, 2024
10 checks passed
@bdraco bdraco deleted the async_reachable branch July 17, 2024 19:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant