-
-
Notifications
You must be signed in to change notification settings - Fork 31.5k
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
Add storage for cacheable homekit entity maps. #23191
Conversation
"""Set up for Homekit devices.""" | ||
# pylint: disable=import-error | ||
import homekit | ||
from homekit.controller.ip_implementation import IpPairing | ||
|
||
map_storage = hass.data[ENTITY_MAP] = EntityMapStorage(hass) | ||
await map_storage.async_initialize() | ||
|
||
hass.data[CONTROLLER] = controller = homekit.Controller() | ||
|
||
for hkid, pairing_data in load_old_pairings(hass).items(): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This does I/O, which isn't allowed in a coroutine. Please add it as an executor job.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oops. We already made this async in config flow and hadn't originally split this PR apart from config flow. Will fix this one now.
return | ||
for accessory in data: | ||
|
||
self.hass.data[ENTITY_MAP].async_create_or_update_map( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Don't call async functions from sync context and vice versa.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's not actually a coroutine, but it does call store.async_delay_save
and is, I believe, 'async safe'. So I could mark it with @callback or drop the async_ prefix?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Async callbacks should also only be executed in the event loop.
I would recommend not adding this to 0.92. Let it go out in 0.93 and the config entry can come in 0.94. |
Description:
Non-breaking change to cache the output of
/accessories
in a storage. This data should be refreshed when a change is announced by the device (the c# zeroconf field for IP, the same field in the Manufacturer Data field for BLE). The goal of this is:I've tested pairing from a clean env, and i've tested upgrading an existing env. Works as expected in both cases.
This is the last change before the main homekit_controller config entries pull request. I'd like to get this PR into a release and then do config entries in release after. After config entires is merged coverage will be high enough to remove homekit_controller from coveragerc!
Checklist:
tox
. Your PR cannot be merged unless tests pass