Refactor Bluetooth Tracker to async#26614
Conversation
|
@MartinHjelmare Many thanks for the review, I think I understood your comments about running blocking I/O in the executor thread pool. Can you review it again please? |
|
|
||
| interval = config.get(CONF_SCAN_INTERVAL, SCAN_INTERVAL) | ||
| if mac in devices_to_track: | ||
| await see_device(hass, async_see, mac, device_name) |
There was a problem hiding this comment.
We could optimize this by using asyncio.wait to await all these tasks concurrently.
tasks = []
for mac, device_name in devices:
...
tasks.append(see_device(hass, async_see, mac, device_name))
if tasks:
await asyncio.wait(tasks)| if not devices_to_track and not track_new: | ||
| _LOGGER.debug("No Bluetooth devices to track and not tracking new devices") | ||
|
|
||
| if track_new: |
There was a problem hiding this comment.
@MartinHjelmare What do you think about removing this? I'm talking about this block. We call update_bluetooth immediately on bootstrap (https://github.com/home-assistant/home-assistant/pull/26614/files#diff-a1148ba3a37cfd77fa0c986c69f86b2dR1980) which is a much more complete solution
There was a problem hiding this comment.
I guess the difference is that the bluetooth update takes longer time? But it looks like we can remove it.
There was a problem hiding this comment.
They both run at startup one after the other, the 2nd run being a more complete discovery and update, so I would say the 1st was redundant
|
Can be merged when build passes. |
|
Thanks @MartinHjelmare - appreciate the great assistance! |
Description:
This PR refactors the Bluetooth Tracker code to async. It has much better control flow, and code is simplified. It also leaves room for creating race timeouts on some of the bluetooth methods in case they are not working correctly.
Also added locking to the
update_bluetoothmethod to prevent parallel runs if an execution runs too long.Checklist:
tox. Your PR cannot be merged unless tests pass