335 Commits

Author SHA1 Message Date
epenet
f8e6fb81d6
Improve template docstring (#128967) 2024-10-22 19:15:27 -10:00
G Johansson
959898e0fc
Fix merge_response template not mutate original object (#127865)
* Fix merge_response template not mutate original object

* Add comment
2024-10-08 18:35:06 +02:00
J. Nick Koston
db494de809
Restore __slots__ to core objects (#127441) 2024-10-03 22:23:47 +02:00
Erik Montnemery
851600630c
Log deprecation warning when template.Template is created without hass (#125142)
* Log deprecation warning when template.Template is created without hass

* Improve docstring
2024-09-03 14:28:33 +02:00
Erik Montnemery
df4bd721b5
Deprecate template.attach (#124843) 2024-09-02 15:33:10 +02:00
G Johansson
78cf7dc873
New template merge_response (#114204)
* New template merge_response

* Extending

* Extend comment

* Update

* Fixes

* Fix comments

* Mods

* snapshots

* Fixes from discussion
2024-09-02 08:13:10 +02:00
J. Nick Koston
0a9e20615e
Limit maximum template render output to 256KiB (#124946)
* Limit maximum template render output to 256KiB

fixes #124931

256KiB is likely to still block the event loop for an unreasonable amont of
time but its likely someone is using the template engine for large
blocks of data so we want a limit which still allows that but has
a reasonable safety to prevent the system from crashing down

* Update homeassistant/helpers/template.py
2024-08-30 22:33:57 +02:00
Petro31
5d64155bb6
Add zip to template engine (#122460)
* add zip to template engine

* fix doc strings
2024-08-22 19:11:08 +02:00
J. Nick Koston
a8cbfe5159
Make TemplateStateBase.entity_id a cached_property (#122279) 2024-07-21 07:49:59 -05:00
Sid
3142f52a79
Add Ruff refurb rules (#121701) 2024-07-10 21:47:40 +02:00
Marc Mueller
ca55986057
Import Generator from collections.abc (1) (#120914) 2024-07-01 11:51:51 +02:00
Paulus Schoutsen
bc45dcbad3
Add template config_entry_attr function (#119899)
* Template config_entry_attr function

* Complete test coverage

* Improve readability
2024-06-22 21:51:09 -04:00
Marc Mueller
f0452e9ba0
Update mypy dev 1.11.0a8 (#120032) 2024-06-21 13:15:18 +02:00
paulusbrand
624017a0f9
Add template Base64 decode encoding parameter (#116603)
Co-authored-by: Robert Resch <robert@resch.dev>
2024-06-07 17:01:35 +02:00
Marc Mueller
fe21e2b8ba
Import Generator from typing_extensions (1) (#118986) 2024-06-06 17:02:13 +02:00
J. Nick Koston
607aaa0efe
Speed up template result parsing (#118168) 2024-05-26 13:09:12 +02:00
J. Nick Koston
42232ecc8a
Remove unused code in template helper (#118075) 2024-05-24 17:44:24 -10:00
J. Nick Koston
6923fb1601
Avoid template context manager overhead when template is already compiled (#118079) 2024-05-24 17:44:02 -10:00
J. Nick Koston
5cb3bc19c0
Speed up async_render_with_possible_json_value (#118080) 2024-05-24 17:43:42 -10:00
J. Nick Koston
f026083712
Speed up is_template_string by avoiding regex engine (#118076) 2024-05-24 17:42:55 -10:00
Marc Mueller
905adb2431
Update codespell ignore list (#118018) 2024-05-24 10:24:34 +02:00
J. Nick Koston
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
Marc Mueller
900b6211ef
Use PEP 695 for function annotations (2) (#117659) 2024-05-18 11:44:39 +02:00
Troon
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 <erik@montnemery.com>
2024-05-08 15:39:36 +02:00
Marc Mueller
8f614fb06d
Use HassKey for helpers (2) (#117013) 2024-05-07 11:24:13 -05:00
Sid
2cc916db6d
Replace pylint broad-except with Ruff BLE001 (#116250) 2024-05-07 14:00:27 +02:00
Sid
b456d97e65
Replace pylint protected-access with Ruff SLF001 (#115735) 2024-05-06 20:33:26 +02:00
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