Erik Montnemery
6bff0c384f
Remove deprecation warnings for relative_time ( #116144 )
...
* Remove deprecation warnings for relative_time
* Update homeassistant/helpers/template.py
Co-authored-by: Simon <80467011+sorgfresser@users.noreply.github.com>
---------
Co-authored-by: Simon <80467011+sorgfresser@users.noreply.github.com>
2024-04-25 13:02:18 +02:00
Erik Montnemery
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 <marhje52@gmail.com>
---------
Co-authored-by: Martin Hjelmare <marhje52@gmail.com>
2024-04-25 13:01:41 +02:00
rlippmann
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 <erik@montnemery.com>
2024-04-24 11:13:07 +02:00
J. Nick Koston
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
Martijn van der Pol
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 <erik@montnemery.com>
2024-04-23 09:55:58 +02:00
Sid
895f73d8e4
Enable Ruff A001 ( #115654 )
2024-04-21 23:25:27 +02:00
J. Nick Koston
11931cdb56
Simplify labels and areas template calls ( #115673 )
...
The labels and areas are already exposed on the object
2024-04-17 21:28:09 +02:00
Sid
d61db732da
Enable Ruff SLOT rules ( #115043 )
2024-04-09 18:57:27 -10:00
J. Nick Koston
ca5ed274cb
Deprecate calling async_listen and async_listen_once with run_immediately ( #115169 )
2024-04-08 10:07:54 -10:00
Sid
8e98ba7312
Add first batch of Ruff PYI rules ( #115100 )
...
Co-authored-by: Jan Bouwhuis <jbouwh@users.noreply.github.com>
2024-04-07 11:30:50 -10:00
Robert Resch
7adced6876
Allow passing area/device/entity IDs to floor_id and floor_name ( #114748 )
2024-04-03 16:33:58 +02:00
Sid
f7b7f74d10
Enable Ruff TRY201 ( #114269 )
...
* Enable Ruff TRY201
* remove redundant rules
2024-03-28 10:18:07 +01:00
Franck Nijhof
5c69e0d2c6
Add label template functions ( #111024 )
2024-03-26 10:32:29 +01:00
Joost Lekkerkerker
6bb4e7d62c
Bump ruff to 0.3.4 ( #112690 )
...
Co-authored-by: Sid <27780930+autinerd@users.noreply.github.com>
Co-authored-by: Marc Mueller <30130371+cdce8p@users.noreply.github.com>
Co-authored-by: J. Nick Koston <nick@koston.org>
2024-03-26 00:02:16 +01:00
J. Nick Koston
de831b6e87
Small performance improvement to template expand ( #114086 )
...
* Small performance improvement to template expand
- Avoid fetching entity sources each loop
- Skip already found entities
- Avoid startswith in favor of equality check
* unneeded changes
2024-03-24 00:24:52 -04:00
J. Nick Koston
b574220247
Refactor rate limit helper to track time in seconds ( #113898 )
...
* Refactor rate limit helper to track time in seconds
Currently we created datetime and timedelta objects to enforce the
rate limit. When the rate limit was being hit hard, this got expensive.
We now use floats everywhere instead as they are much cheaper which
is important when we are running up against a rate limit, which is
by definition a hot path
The rate limit helper is currently only used for templates and
we do not have any code in the code base that directly passes
in a rate limit so the impact to custom components is expected
to be negligible if any
* misesd two
2024-03-20 19:49:37 -04:00
Erik Montnemery
426f73b1f4
Add State.last_reported ( #113511 )
...
* Add State.last_reported
* Update tests
* Update test snapshots
* Call state_reported listeners when firing state_changed event
* Add tests
2024-03-20 21:05:07 +01:00
Franck Nijhof
fc6a83559f
Add floor template functions ( #110847 )
2024-03-20 11:58:04 +01:00
J. Nick Koston
4d75940cd2
Start and stop template cache watcher to run_immediately ( #113644 )
2024-03-17 08:16:26 -10:00
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