Allow filter functions to be async #597
Open
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Hi,
this is a simple PR that adds an "await" around the filter function calling.
Motivation:
This allows especially the
fn
filter to define anasync
function.This can be very useful, e.g. if you want to plot the result of a service call directly, without having to create intermediate template sensors just to deliver data to the frontend.
intermediate template sensors are sometimes not great when you want to display a lot of data, since the amount of bytes a state or state attributes can have is very limited (state 255 bytes AFAIK, and state attributes 16kb).
This limitation is there for a good reason: home-assistant/core#149316 (comment)
Also, they fill up your recorder with information that might not be desirable to be stored long term.
With this PR, it is now possible to do this: