Marc Mueller
19ab3d6daf
Add empty line after module docstring [helpers + other] ( #112707 )
2024-03-08 10:36:11 -05:00
Erik Montnemery
8c2c3e0839
Improve integration_entities template function ( #111943 )
2024-03-06 11:05:06 +01:00
RoboMagus
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 <erik@montnemery.com>
---------
Co-authored-by: Erik Montnemery <erik@montnemery.com>
2024-03-04 14:22:14 +01:00
Erik Montnemery
3a8b6412ed
Remove areas template filter ( #111827 )
2024-02-29 10:52:26 -05:00
Piotr Machowski
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 <erik@montnemery.com>
* 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 <erik@montnemery.com>
* Refactor listeners that trigger translation loading
* Apply suggestions from code review
Co-authored-by: Erik Montnemery <erik@montnemery.com>
* 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 <erik@montnemery.com>
* Apply suggestions from code review
* Fix tests
* Fix tests
---------
Co-authored-by: Piotr Machowski <PiotrMachowski@users.noreply.github.com>
Co-authored-by: Erik Montnemery <erik@montnemery.com>
2024-02-10 10:47:56 +01:00
Marc Mueller
cd0ee98dba
Use builtin TimeoutError [core + helpers] ( #109684 )
2024-02-05 12:09:54 +01:00
Marc Mueller
d2dee9e327
Update ruff to 0.1.15 ( #109303 )
2024-02-01 13:29:01 +01:00
Martijn van der Pol
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 <marhje52@gmail.com>
2024-01-29 18:05:44 +01:00
Daniel
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
J. Nick Koston
fb0dad66db
Add jinja_pass_arg to reserved template names ( #107822 )
2024-01-12 09:34:49 +01:00
Lars R
bf6b9175a1
Add 'bitwise_xor' filter to jinja templates ( #104942 )
...
Co-authored-by: Robert Resch <robert@resch.dev>
2024-01-10 09:40:52 +01:00
J. Nick Koston
d04e2d56da
Add support for JSON fragments ( #107213 )
2024-01-07 17:36:31 -10:00
Jan-Philipp Benecke
e80138dfdf
Remove duplicate assignment of `median` and `statistical_mode` jinja2 filter ( #106953 )
2024-01-05 17:36:55 +01:00
Jan-Philipp Benecke
9d36b716e7
Use call_soon_threadsafe in render_will_timeout of template helper ( #106514 )
2023-12-30 13:55:53 +01:00
Martijn van der Pol
a823edf1c2
Jinja filter and function for `median` and `statistical_mode` ( #105554 )
...
Co-authored-by: Joost Lekkerkerker <joostlek@outlook.com>
Co-authored-by: Franck Nijhof <git@frenck.dev>
2023-12-27 15:14:20 +01:00
J. Nick Koston
5c503683b7
Bump lru-dict to 1.3.0 ( #105914 )
...
* Bump lru-dict to 1.3.0
changelog: https://github.com/amitdev/lru-dict/compare/v1.2.0...v1.3.0
* fix typing
* quote types
* quote types
2023-12-18 00:16:31 +01:00
Jan Bouwhuis
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 <erik@montnemery.com>
2023-12-08 20:57:53 +01:00
Marc Mueller
a70ec64408
Update mypy to 1.7.0 ( #103800 )
2023-11-11 23:31:04 +01:00
J. Nick Koston
68471b6da5
Reduce template render overhead ( #103343 )
...
The contextmanager decorator creates a new context manager every
time its run, but since we only have a single context var, we can
use the same one every time. Creating the contextmanager was roughly
20% of the time time of the template render
I was a bit suprised to find it creates a new context manager
object every time https://stackoverflow.com/questions/34872535/why-contextmanager-is-slow
2023-11-04 09:46:01 +01:00
Raman Gupta
35d18a9a3e
Add tests for types and functions for type conversions in templates ( #100807 )
...
Co-authored-by: Robert Resch <robert@resch.dev>
2023-10-25 13:20:34 +02:00
Marc Mueller
0b2b486754
Update mypy to 1.6.0 ( #101780 )
2023-10-11 13:25:11 +02:00
J. Nick Koston
547f32818c
Make core States use cached_property ( #100312 )
...
Need to validate this is worth removing __slots__
2023-09-13 20:33:25 -04:00
Erik Montnemery
09ad1a9a36
Remove unnecessary block use of pylint disable in components p-z ( #100192 )
2023-09-12 20:47:48 +02:00
Erik Montnemery
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 Montnemery
de73cafc8b
Small cleanup of TemplateEnvironment ( #99571 )
...
* Small cleanup of TemplateEnvironment
* Fix typo
2023-09-04 22:19:40 +02:00
Marc Mueller
a9ade1f84d
Use asyncio.timeout [core] ( #98447 )
2023-08-15 08:36:05 -05:00
Erik Montnemery
e1f0b44ba4
Use math.isfinite instead of explicitly checking for both nan and inf ( #98103 )
2023-08-09 14:13:57 +02:00
J. Nick Koston
aa937b1640
Use slots for template RenderInfo ( #93337 )
2023-05-22 08:52:49 +02:00
J. Nick Koston
3314eed8d1
Switch to using a ContextVar for template RenderInfo ( #93016 )
...
The ContextVar is about 40% faster than the attr
and dict lookups
2023-05-14 12:23:31 -04:00
J. Nick Koston
24284fe379
Speed up validating domains in templates ( #92975 )
...
This path gets called quite a bit since most templates
access the state via states.DOMAIN...
2023-05-12 14:57:51 +02:00
David Poll
ea12d7a86f
Add pretty printing, key sorting, and better performance to to_json in Jinja ( #91253 )
...
Co-authored-by: J. Nick Koston <nick@koston.org>
Co-authored-by: epenet <6771947+epenet@users.noreply.github.com>
2023-04-13 00:32:13 +02:00
Erik Montnemery
37661fe79f
Update template environment from the event loop ( #90758 )
2023-04-04 09:52:47 +02:00
J. Nick Koston
edd93e989e
Add render count to templates repr ( #90753 )
2023-04-03 19:38:15 -10:00
J. Nick Koston
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 Koston
f4c341253b
Avoid sorting domain/all states in templates ( #90608 )
2023-03-31 11:27:55 -10:00
Petro31
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
Erik Montnemery
5bc9545b81
Rename custom_jinja to custom_templates ( #90473 )
...
Co-authored-by: Franck Nijhof <git@frenck.dev>
2023-03-29 21:58:25 +02:00
ehendrix23
e45eab600f
Add has_value function/test to Jinja2 template ( #79550 )
2023-03-28 17:04:29 +02:00
Petro31
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 Poll
0457bb2717
Add is_hidden_entity test for Jinja templates ( #89011 )
2023-03-13 18:20:33 +01:00
David Poll
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 <erik@montnemery.com>
---------
Co-authored-by: Erik Montnemery <erik@montnemery.com>
2023-03-13 11:00:05 +01:00
Lucas Mindêllo de Andrade
eed16dc185
Add list areas function to template ( #88441 )
2023-03-09 22:32:30 +01:00
J. Nick Koston
cefba7c638
Avoid falling back to listening for all states when a template render raises an exception ( #89392 )
...
When a template render raised an exception we would start listening for
all states until the template did not raise an exception anymore. This
was not needed since the entity that is causing the exception was
already in the tracker.
Re-rendering on all state changes can be extremely expensive and can
bring an instance into a sluggish or unresponsive state when updating
from a much older version that did not raise ValueError when a default
was missing.
2023-03-08 15:50:34 -05:00
David Poll
af49b98475
Enable jinja loop controls (break/continue) ( #88625 )
...
Enables jinja loop controls (break/continue)
2023-02-23 22:14:28 -05:00
epenet
ba23816a0c
Inverse json import logic ( #88099 )
...
* Fix helpers and util
* Adjust components
* Move back errors
* Add report
* mypy
* mypy
* Assert deprecation messages
* Move test_json_loads_object
* Adjust tests
* Fix rebase
* Adjust pylint plugin
* Fix plugin
* Adjust references
* Adjust backup tests
2023-02-16 11:37:57 +01:00
Franck Nijhof
9030ca05b1
Enable Ruff SIM118 ( #87772 )
2023-02-15 12:39:12 +01:00
J. Nick Koston
ac97097167
Speed up template lru_caches ( #87942 )
...
By avoiding the argument unpacking these functions are faster
and reduce stack overhead
2023-02-12 14:13:13 -05:00
J. Nick Koston
e19f8595fa
Small cleanups to template helper ( #87944 )
...
- reduce dict lookups
- avoid split_entity_id
2023-02-12 14:11:48 -05:00
J. Nick Koston
aa8927c98c
Speed up loops with jinja templates ( #87945 )
2023-02-12 18:40:55 +01:00
Erik Montnemery
2d2ff19949
Round value in state_with_unit template function ( #87619 )
2023-02-09 12:54:59 +01:00