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 state_translated function to jinja templates #96906
Add state_translated function to jinja templates #96906
Conversation
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.
Very nice @PiotrMachowski !
Some comments though.
Please take a look at the requested changes, and use the Ready for review button when you are done, thanks 👍 |
Co-authored-by: Erik Montnemery <erik@montnemery.com>
@emontnemery thank you for your review, I have adjusted the code according to your suggestions |
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.
Looks great, just a few minor remarks 👍
Co-authored-by: Erik Montnemery <erik@montnemery.com>
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.
Thanks, @PiotrMachowski 👍
Thank you, @emontnemery! |
It looks like we create a thundering heard of executor jobs after this PR. |
@bdraco Sorry |
No worries at all. It would be great if you could test #110674 to make sure it doesn't cause any regressions in the new functionality |
Sure, I'll check it out 👍 |
Proposed change
This pull requests adds possibility to translate entity's state in jinja templates. This feature makes it much easier for users to send notifications including entities' states (e.g. weather status), use TTS, present data in markdown cards and probably much more.
code:
result:
To achieve this functionality some small changes had to be done in translations loading process: state translations for configured language are loaded to cache at HA start.
Points to consider
localized
state.default.unavailable
,state.default.unknown
translations are at this moment available only on FEPossible future improvements
Previous approach to adding this functionality: #65743
Type of change
Additional information
Checklist
black --fast 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
..coveragerc
.To help with the load of incoming pull requests: