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
Vaarlion
3007e0259d
Add a `contains` jinja filter and test ( #86390 )
2023-01-25 11:51:47 +01:00
Marc Mueller
45b4b0e990
Import `ParamSpec` from typing [Py310] ( #86413 )
...
* Import ParamSpec from typing [Py310]
* Update additional imports
2023-01-23 07:28:43 +01:00
J. Nick Koston
ca4d7634a8
Switch an `asyncio.wait_for` in the template helper to `async_timeout` ( #86349 )
...
Switch an asyncio.wait_for in the template helper to async_timeout
Eliminates the extra task when calling async_render_will_timeout
2023-01-22 00:02:03 +02:00
Franck Nijhof
79b52a2b41
Stricter pylint message control ( #86154 )
2023-01-20 13:47:55 +01:00
Franck Nijhof
64c2340fab
Core code styling improvements ( #85963 )
2023-01-15 23:00:51 +01:00
Franck Nijhof
06a35fb7db
Code styling tweaks to core helpers ( #85441 )
2023-01-08 13:44:09 -10:00
Franck Nijhof
d4f69a3652
String formatting and max line length - Part 7 ( #84532 )
...
Co-authored-by: Martin Hjelmare <marhje52@gmail.com>
2022-12-27 11:18:56 +01:00
Michaël Arnauts
7142b4ecac
Fixes some grammar mistakes ( #84283 )
2022-12-20 11:10:31 +01:00
epenet
9f7fd8956f
Use new unit enums in helpers ( #83387 )
2022-12-06 22:20:17 +01:00
Mike Degatano
b3deb476ef
Allow is_state to accept a list of values ( #81877 )
...
* Allow is_state to accept a list of values
* Slightly more efficient
* Fix typing of state
Co-authored-by: Franck Nijhof <git@frenck.dev>
2022-11-30 22:54:14 +01:00
epenet
e386bab682
Add type hint to template wrapper ( #82563 )
...
* Add type to template hassfunction decorator
* Adjust to use EvalContext
* Use runtime.Context
* Use TypeVar for context
* Use jinja2.runtime.Context
* Reverse declarations
* Use Any
* Update homeassistant/helpers/template.py
Co-authored-by: Marc Mueller <30130371+cdce8p@users.noreply.github.com>
Co-authored-by: Marc Mueller <30130371+cdce8p@users.noreply.github.com>
2022-11-24 15:30:21 +01:00
epenet
b525259878
Add type hints to template result wrapper ( #82575 )
...
* Add type hints to template result wrapper
* Remove `ignore[call-arg]`
* Use tuple
* Alphabetise
2022-11-24 08:41:14 +01:00
On Freund
9dd1b85cbb
Allow `device_attr` and `is_device_attr` to be used as a filter and a test (respectively) ( #81924 )
...
Co-authored-by: Franck Nijhof <frenck@frenck.nl>
2022-11-24 08:31:17 +01:00
epenet
d7f0b904d0
Add type to template function ( #82564 )
2022-11-23 21:50:45 +01:00
epenet
f91e250e90
Fix TemplateError definition ( #82570 )
2022-11-23 20:30:32 +01:00
Jan Bouwhuis
23bc39b7f4
Add type hints on `Template().__init__()` ( #82574 )
2022-11-23 20:26:55 +01:00
epenet
aa02a53ac6
Add type hints to template states ( #82582 )
...
* Add type hints to template states
* Undo rename
* Remove invalid mypy issue link
2022-11-23 17:46:51 +01:00
epenet
5e05739019
Add type hints to template helper ( #81308 )
...
* Add type hints to template helper
* Update homeassistant/helpers/template.py
* Adjust use of ensure_compiled
2022-11-07 09:41:53 +01:00
Petro31
f73fc9e355
Adds states and state_attr as a filter, adds is_state and is_state_attr as a test. ( #79473 )
2022-10-25 19:49:51 +02:00
Franck Nijhof
326344db12
Rename entry_id template method to config_entry_id ( #80935 )
2022-10-25 12:11:14 +02:00
ehendrix23
47b40e1e61
Add optional default value to average template function/filter ( #77499 )
...
* Return None on empty list
* Updated to use default value
* Update comment.
2022-10-03 10:07:19 +02:00
Rami Mosleh
e7764b8bf1
Add ConfigEntry template function ( #78030 )
...
* Add ConfigEntry template function
* Remove looking up entry_id by entry title
2022-09-29 12:41:59 +02:00
J. Nick Koston
8dbbd0ded0
Cache template regex compiles ( #78529 )
2022-09-18 11:48:04 +02:00
Joakim Sørensen
8dbe293ae2
Add version to templates ( #78484 )
2022-09-15 15:01:40 +02:00
Marc Mueller
1210897f83
Update pylint to 2.15.0 ( #77408 )
...
* Update pylint to 2.15.0
* Remove useless suppressions
* Fix TypeVar name
2022-08-28 21:14:09 +02:00