Commit Graph
219 Commits
Author SHA1 Message Date
J. Nick KostonandGitHub c9d1b127d8 Improve error message when template is rendered from wrong thread (#117822)
* Improve error message when template is rendered from wrong thread

* Improve error message when template is rendered from wrong thread
2024-05-20 23:26:48 -04:00
J. Nick KostonandGitHub 5a609c34bb Fix blocking I/O in the event loop when loading timezones (#117721) 2024-05-20 11:06:03 +02:00
cc99a9b62a Add an add template filter (#109884)
* Addition of add filter

This change adds an `add` filter, the addition equivalent of the existing `multiply` filter.

* Test for add filter

* Update test_template.py

* Update tests/helpers/test_template.py

---------

Co-authored-by: Erik Montnemery <[email protected]>
2024-05-08 15:39:36 +02:00
SidandGitHub e662e3b65c Bump ruff to 0.4.2 (#116201)
* Bump ruff to 0.4.2

* review comments
2024-04-26 08:48:32 +02:00
6bff0c384f Remove deprecation warnings for relative_time (#116144)
* Remove deprecation warnings for relative_time

* Update homeassistant/helpers/template.py

Co-authored-by: Simon <[email protected]>

---------

Co-authored-by: Simon <[email protected]>
2024-04-25 13:02:18 +02:00
2e88ba40ff Fix lying docstring for relative_time template function (#116146)
* Fix lying docstring for relative_time template function

* Update homeassistant/helpers/template.py

Co-authored-by: Martin Hjelmare <[email protected]>

---------

Co-authored-by: Martin Hjelmare <[email protected]>
2024-04-25 13:01:41 +02:00
1120246194 Deprecate relative_time() in favor of time_since() and time_until() (#111177)
* add time_since/time_until.  add deprecation of relative_time

* fix merge conflicts

* Apply suggestions from code review

* Update homeassistant/helpers/template.py

* Update homeassistant/helpers/template.py

* Update homeassistant/helpers/template.py

---------

Co-authored-by: Erik Montnemery <[email protected]>
2024-04-24 11:13:07 +02:00
J. Nick KostonandGitHub 53a179088f Add debug mode to catch unsafe thread operations using core helpers (#115390)
* adjust

* adjust

* fixes

* one more

* test

* debug

* move to config

* cover

* Update homeassistant/core.py

* set debug from RuntimeConfig

* reduce

* fix message

* raise

* Update homeassistant/core.py

* Update homeassistant/core.py

* no flood check for raise

* cover
2024-04-24 03:36:05 +02:00
e90d76b18d Don't raise errors when using datetime objects in as_datetime Jinja function/filter (#109062)
* add support for datetime objects to as_datetime

* change import of datetime.date

---------

Co-authored-by: Erik Montnemery <[email protected]>
2024-04-23 09:55:58 +02:00
J. Nick KostonandGitHub 33412dd9f6 Remove unused legacy state translations (#112023)
* Remove unused state translations

There have been replaced with entity translations
https://github.com/home-assistant/developers.home-assistant/pull/1557
https://github.com/home-assistant/core/pull/82701

* nothing does merging anymore

* useless dispatch

* remove

* remove platform code from hassfest

* preen

* Update homeassistant/helpers/translation.py

* ruff

* fix merge

* check is impossible now since we already know if translations exist or not

* keep the function for now

* remove unreachable code since we filter out `.` before now

* reduce

* reduce

* fix merge conflict (again)
2024-04-14 07:13:17 -04:00
SidandGitHub d61db732da Enable Ruff SLOT rules (#115043) 2024-04-09 18:57:27 -10:00
SidandGitHub 9cbed10372 Enable Ruff PYI041 (#115229) 2024-04-08 09:29:05 -10:00
Robert ReschandGitHub 7adced6876 Allow passing area/device/entity IDs to floor_id and floor_name (#114748) 2024-04-03 16:33:58 +02:00
Franck NijhofandGitHub 5c69e0d2c6 Add label template functions (#111024) 2024-03-26 10:32:29 +01:00
Franck NijhofandGitHub fc6a83559f Add floor template functions (#110847) 2024-03-20 11:58:04 +01:00
00ec7f11f0 Enable Ruff rule PT007 (#113764)
Co-authored-by: Franck Nijhof <[email protected]>
2024-03-19 09:01:07 +01:00
Marc MuellerandGitHub 19ab3d6daf Add empty line after module docstring [helpers + other] (#112707) 2024-03-08 10:36:11 -05:00
Erik MontnemeryandGitHub 8c2c3e0839 Improve integration_entities template function (#111943) 2024-03-06 11:05:06 +01:00
b381922a20 Issues template function (#95206)
* Add 'issues' template function for listing active issues.

* Add issue template function test

* Add 'issue' template function for getting specific issue by domain and issue_id

* Remove comment

* Fix function description

* Remove reduntant function,
Fix tests

* remove pass_context

* remove issues filter

Co-authored-by: Erik Montnemery <[email protected]>

---------

Co-authored-by: Erik Montnemery <[email protected]>
2024-03-04 14:22:14 +01:00
J. Nick KostonandGitHub 16653ff5d0 Group loading of translations for integrations to reduce executor jobs at startup (#110674) 2024-02-17 21:08:55 -06:00
a2f4e99994 Add state_translated function to jinja templates (#96906)
* Add state_translated jinja function

* Add tests for load_state_translations_to_cache and get_cached_translations

* Cleanup state_translated template

* Add tests for state_translated jinja function

* Apply black formatting

* Improve code quality

* Apply suggestions from code review

Co-authored-by: Erik Montnemery <[email protected]>

* Apply suggestions from code review

* Prevent invalid components from loading translations

* Refactor loading translations to cache

* Adjust code issues

* Update homeassistant/helpers/translation.py

Co-authored-by: Erik Montnemery <[email protected]>

* Refactor listeners that trigger translation loading

* Apply suggestions from code review

Co-authored-by: Erik Montnemery <[email protected]>

* Apply suggestions from code review

* Adjust invalid function calls, fix code styling

* Adjust code quality

* Extract async_translate_state function

* Apply suggestions from code review

Co-authored-by: Erik Montnemery <[email protected]>

* Apply suggestions from code review

* Fix tests

* Fix tests

---------

Co-authored-by: Piotr Machowski <[email protected]>
Co-authored-by: Erik Montnemery <[email protected]>
2024-02-10 10:47:56 +01:00
b386960661 Add default parameter to as_datetime template function/filter (#107229)
* improve as_datetime

* Improve `as_datetime` Jinja filter/function

* review

* resolve more review items

* change test for datetime input

* Update docstring

* update docstrings for tests

* remove whitespace

* only_default

* Update do string and comment

* improve comment

* Adjust comment

---------

Co-authored-by: Martin Hjelmare <[email protected]>
2024-01-29 18:05:44 +01:00
DanielandGitHub a67113a95a Parse template result in async_render_with_possible_json_value (#99670)
* Optionally parse templates rendered with possible json

* Remove duplicate strip

* Add tests for parsing template result
2024-01-24 12:12:28 +01:00
bf6b9175a1 Add 'bitwise_xor' filter to jinja templates (#104942)
Co-authored-by: Robert Resch <[email protected]>
2024-01-10 09:40:52 +01:00
a823edf1c2 Jinja filter and function for median and statistical_mode (#105554)
Co-authored-by: Joost Lekkerkerker <[email protected]>
Co-authored-by: Franck Nijhof <[email protected]>
2023-12-27 15:14:20 +01:00
Robert ReschandGitHub fbcb31b103 Deprecate deprecated unit of measurement constants (#106455) 2023-12-27 09:04:25 +01:00
4bb0e13cda Workaround to_json template filter in parsing dict key (#105327)
* Work-a-round orjson for `to_json` fiter in case dict key is str subclass

* Add option instead

* Remove json.dumps work-a-round

* Update homeassistant/helpers/template.py

* Fix test

---------

Co-authored-by: Erik Montnemery <[email protected]>
2023-12-08 20:57:53 +01:00
Jan-Philipp BeneckeandGitHub d1aa690c24 Migrate non-component tests to use freezegun/freezer (#105142) 2023-12-07 22:58:09 +01:00
Franck NijhofandGitHub 70ad5ab3e4 Update helper tests to use device & entity registry fixtures (#103710) 2023-11-10 09:32:19 +01:00
Erik MontnemeryandGitHub 03d3a87f23 Small cleanup of legacy groups (#102918)
* Small cleanup of legacy groups

* Update tests which create groups
2023-10-28 17:16:41 +02:00
35d18a9a3e Add tests for types and functions for type conversions in templates (#100807)
Co-authored-by: Robert Resch <[email protected]>
2023-10-25 13:20:34 +02:00
Erik MontnemeryandGitHub 48f7924e9e Allow specifying a custom log function for template render (#99572)
* Allow specifying a custom log function for template render

* Bypass template cache when reporting errors + fix tests

* Send errors as events

* Fix logic for creating new TemplateEnvironment

* Add strict mode back

* Only send error events if report_errors is True

* Force test of websocket_api only

* Debug test

* Run pytest with higher verbosity

* Timeout after 1 minute, enable syslog output

* Adjust timeout

* Add debug logs

* Fix unsafe call to WebSocketHandler._send_message

* Remove debug code

* Improve test coverage

* Revert accidental change

* Include severity in error events

* Remove redundant information from error events
2023-09-06 10:03:35 +02:00
Erik MontnemeryandGitHub c7b4d4f361 Adjust helpers tests which create devices (#98214) 2023-08-10 19:28:16 +02:00
Marc MuellerandGitHub f39a35c4ef Fix jinja2 DeprecationWarnings (#97728) 2023-08-04 11:25:08 +02:00
MeowandGitHub 6fd60024cc Refactored deprecated UNITS (#97368) 2023-08-03 21:12:01 +02:00
J. Nick KostonandGitHub b2e708834f Add slots to the StateMachine class (#95849) 2023-07-05 14:00:37 +02:00
J. Nick KostonandGitHub b24c6adc75 Avoid regex for negative zero check in sensor (#95691)
* Avoid regex for negative zero check in sensor

We can avoid calling the regex for every sensor value
since most of the time values are not negative zero

* tweak

* tweak

* Apply suggestions from code review

* simpler

* cover

* safer and still fast

* safer and still fast

* prep for py3.11

* fix check

* add missing cover

* more coverage

* coverage

* coverage
2023-07-02 21:53:50 -04:00
epenetandGitHub 6836e15d98 Add type hints to tests (#92477) 2023-05-04 11:25:35 +02:00
Franck NijhofandGitHub 65d7e48815 Update ruff to v0.0.262 (#91767) 2023-04-21 08:15:41 +02:00
ea12d7a86f Add pretty printing, key sorting, and better performance to to_json in Jinja (#91253)
Co-authored-by: J. Nick Koston <[email protected]>
Co-authored-by: epenet <[email protected]>
2023-04-13 00:32:13 +02:00
J. Nick KostonandGitHub edd93e989e Add render count to templates repr (#90753) 2023-04-03 19:38:15 -10:00
J. Nick KostonandGitHub 17719663f0 Fix memory churn in state templates (#90685)
* Fix memory churn in state templates

The LRU for state templates was limited to 512 states. As soon
as it was exaused, system performance would tank as each template
that iterated all states would have to create and GC any state
> 512

* does it scale?

* avoid copy on all

* comment

* preen

* cover

* cover

* comments

* comments

* comments

* preen

* preen
2023-04-02 20:51:25 -04:00
J. Nick KostonandGitHub f4c341253b Avoid sorting domain/all states in templates (#90608) 2023-03-31 11:27:55 -10:00
Petro31andGitHub 642984a042 Fix for is_hidden_entity when using it in select, selectattr, reject, and rejectattr (#90512)
fix
2023-03-30 09:14:58 -04:00
5bc9545b81 Rename custom_jinja to custom_templates (#90473)
Co-authored-by: Franck Nijhof <[email protected]>
2023-03-29 21:58:25 +02:00
ehendrix23andGitHub e45eab600f Add has_value function/test to Jinja2 template (#79550) 2023-03-28 17:04:29 +02:00
Petro31andGitHub 2123600039 Add minutely updates to relative_time and today_at template functions (#86815)
* add minutely update

* fix mypy
2023-03-28 15:10:28 +02:00
David PollandGitHub 0457bb2717 Add is_hidden_entity test for Jinja templates (#89011) 2023-03-13 18:20:33 +01:00
7284af6a3e Add an in-memory-preloading loader for Jinja imports (#88850)
* Adds a loader to enable jinja imports.

* Switch to in-memory

* Move loading custom_jinja off of the event loop

* Raise TemplateNotFound if template doesn't exist

* Fix docstring

* Adds a service to reload custom jinja

* Remove IO from test setup

* Improve coverage and small refactor

* Incorporate feedback and use .jinja extension

* Check the loaded sources in test.

* Incorporate PR feedback.

* Update homeassistant/helpers/template.py

Co-authored-by: Erik Montnemery <[email protected]>

---------

Co-authored-by: Erik Montnemery <[email protected]>
2023-03-13 11:00:05 +01:00
Lucas Mindêllo de AndradeandGitHub eed16dc185 Add list areas function to template (#88441) 2023-03-09 22:32:30 +01:00