-
-
Notifications
You must be signed in to change notification settings - Fork 34.2k
Allow core integrations to describe their conditions #147529
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
Conversation
Hey there @home-assistant/core, mind taking a look at this pull request as it has been labeled with an integration ( Code owner commandsCode owners of
|
You missed committing the hassfest.conditions module? |
CI is failing:
|
homeassistant/helpers/condition.py
Outdated
tasks: list[asyncio.Task[None]] = [ | ||
create_eager_task(listener(new_conditions)) | ||
for listener in hass.data[CONDITION_PLATFORM_SUBSCRIPTIONS] | ||
] | ||
await asyncio.gather(*tasks) |
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.
If these don't ever yield to the loop its faster to await in a loop so the tasks don't have to be scheduled
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.
In the PR, listeners are added by WS command "condition_platforms/subscribe", which calls condition.async_get_all_descriptions
.
condition.async_get_all_descriptions
will yield in case of a cache miss in order to do file I/O, otherwise not.
Once startup is complete and platforms with conditions are all loaded, this will never yield.
However, why doesn't asyncio.gather
eagerly run tasks? Is there no such option?
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.
The tasks do still start eagerly with asyncio.gather
, but there's overhead from scheduling and wrapping each one into a Task
. If only the first call is expected to yield and the rest will run synchronously afterward, then awaiting them in sequence is likely to perform better. Once that initial I/O completes, the remaining calls should just run straight through without suspension, so there's little benefit to parallelizing them.
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.
Also since async_get_all_descriptions
doesn't have a lock (thats fine as more efficient most of the time), you might have a thundering heard trying to build the cache if you end up in the executor because the cache is stale. I haven't fully analyzed the flow though.
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.
Changed to not gather in a39c774
Co-authored-by: Abílio Costa <abmantis@users.noreply.github.com>
Proposed change
Allow core integrations to describe their conditions
This is the same as #147075, which adds support for integrations to describe their triggers, but for conditions
Type of change
Additional information
Checklist
ruff format homeassistant tests
)If user exposed functionality or configuration variables are added/changed:
If the code communicates with devices, web services, or third-party tools:
Updated and included derived files by running:
python3 -m script.hassfest
.requirements_all.txt
.Updated by running
python3 -m script.gen_requirements_all
.To help with the load of incoming pull requests: