Commit graph

206 commits

Author SHA1 Message Date
Erik Montnemery
eba125b093
Ensure 'this' variable is always defined for template entities () 2022-05-03 07:43:44 -07:00
Franck Nijhof
a4682ae6e1
Adjust version number in template default deprecation warning () 2022-05-02 18:35:37 +03:00
Marc Mueller
9b9b553521
Disable no-self-use [pylint] ()
* Disable no-self-use

* Remove disable comments
2022-04-25 07:41:01 -07:00
Marc Mueller
90dab235f7
Update pylint to 2.13.7 ()
* Update pylint to 2.13.7

* Spelling

* Remove old pylint config value

* Code updates
2022-04-21 13:02:52 -07:00
akloeckner
d20a620590
Make this variable available in template entities ()
* feat: make this variable available in template entities

This makes the variable `this` available in template entities.
It will simplify the use of self-referencing template entities.
Because, without this, we have to repeat the entity id every time.
If we can solve this without explicitly spelling the entity id,
code can be re-used much better.

As a side-effect, this will allow to use `variables`-like patterns,
where attributes can be used as variables to calculate subsequent attributes or state.

Example:
```yaml
template:
  sensor:
    - name: test
      state: "{{ this.attributes.test }}"
      # not: "{{ state_attr('sensor.test', 'test' }}"
      attributes:
        test: "{{ now() }}"
```

* expose entity_id instead of this

* add test

* Refactor to expose this variable

* Tweak repr dunder

Co-authored-by: Erik <erik@montnemery.com>
2022-04-20 15:30:17 +02:00
Marc Mueller
e407960f68
Update pylint to 2.13.5 () 2022-04-13 18:36:05 +02:00
Franck Nijhof
6524dd8fb7
Add support for expanding zones in templates () 2022-04-11 12:59:45 +02:00
Paulus Schoutsen
206ea9d237
Expand group lights/covers etc ()
Co-authored-by: Franck Nijhof <git@frenck.dev>
2022-03-30 10:11:09 +02:00
Marc Mueller
bfb1abd3a2
Add type ignore error codes [helpers] () 2022-02-18 11:31:37 +01:00
Franck Nijhof
fa09cf663e
Update black to 22.1.0 () 2022-02-05 14:19:37 +01:00
Petro31
9c6c13a55c
Add is_number as a test for use in select, selectattr, reject, and re… () 2022-01-10 13:00:43 +01:00
avee87
04606f05a4
Use built-in Jinja min and max filters in templates ()
* Use built-in Jinja min and max filters in templates

* use built-in filter for global

* lint

* less generic name

* more tests

* even more tests
2022-01-04 10:07:23 +01:00
Ruslan Sayfutdinov
55f4962c06
Fix pylint plugin which checks relative imports () 2021-12-23 11:14:47 -08:00
Franck Nijhof
07e034c1c6
Add iif (immediate if) template function/filter () 2021-12-21 17:25:07 +01:00
Brynley McDonald
26dc526234
Add slugify as a template filter () 2021-12-21 11:35:54 +01:00
Paulus Schoutsen
17cf53677c
Rest fixes () 2021-12-08 14:35:50 -08:00
Franck Nijhof
74d1c340d7
Allow use of relative_time as a filter () 2021-12-03 19:30:12 +01:00
Jan Bouwhuis
3188a364e2
Add template filters pack and unpack ()
* add pack and unpack template filters

* Add unpack test with offset

* use unpack_from

* Simplify unpack_from statement
2021-12-03 08:58:15 +01:00
Erik Montnemery
9f4a99fe81
Revert "Add bytes support for bitwise template operations" () 2021-12-03 08:50:29 +01:00
Erik Montnemery
a07f75c6b0
Revert "Allow template int filter to render from a bytes based integer" () 2021-12-02 14:37:19 -08:00
Jan Bouwhuis
f07e676c82
Allow template int filter to render from a bytes based integer ()
* Allow template int to render bytes

* re-triggering tests

* Add warning when base !=10 and rendering bytes

* re-trigger tests

* Re-trigger tests

* remove period

* Update homeassistant/helpers/template.py

Co-authored-by: Erik Montnemery <erik@montnemery.com>

* Fix logger syntax

* remove parentheses

Co-authored-by: Erik Montnemery <erik@montnemery.com>
2021-11-30 15:01:43 +01:00
Erik Montnemery
7b57033265
Correct today_at template function / filter ()
Co-authored-by: Franck Nijhof <git@frenck.dev>
2021-11-24 15:51:43 +01:00
Jan Bouwhuis
d33457b7bc
Add bytes support for bitwise template operations ()
* Add bytes support for bitwise template operations

* spelling

* Update bitwise tests

* remove try block for bytes conversion

* do not accept empty `bytes` object
2021-11-24 15:15:27 +01:00
Jan Bouwhuis
d41d223033
Add UNIX timestamp detection to as_datetime template filter () 2021-11-24 09:51:56 +01:00
Jan Bouwhuis
fa0d3a6c48
Change output template filters timestamp_local and timestamp_utc to isoformat () 2021-11-24 09:49:03 +01:00
Marcel van der Veldt
902da4daf8
Add integration_entities template helper () 2021-11-20 14:43:31 -08:00
Chris Browet
4224cb043b
Allow overriding ensure_ascii in the "to_json" template filter ()
* FIX: "ensureascii" to to_json

* fixup: parameter name
2021-11-08 15:49:10 +01:00
Marc Mueller
3f1b4906bf
Use assignment expressions 35 () 2021-10-31 18:32:17 +01:00
Erik Montnemery
bed4096430
Allow specifying a super template for async_track_template_result () 2021-10-27 16:07:17 +02:00
Franck Nijhof
bf693e85b1
Revert "Add warning when entity used in template doesn't exist" () 2021-10-27 13:53:26 +02:00
Petro31
11034a93c3
Add average template function and filter () 2021-10-26 22:43:45 +02:00
avee87
d9b87ee5c5
Add warning when entity used in template doesn't exist () 2021-10-22 20:09:54 +02:00
Raman Gupta
e5255cf21f
Add area_entities and area_devices template functions/filters () 2021-10-22 19:59:01 +02:00
Petro31
806dc51125
Add datetime_today template method () 2021-10-22 19:51:22 +02:00
Erik Montnemery
df1154395e
Revert "Swap order of int template helper kwargs ()" ()
This reverts commit f8dbcb953c.
2021-10-21 15:03:33 +02:00
Marc Mueller
238b488642
Use assignment expressions 03 () 2021-10-17 20:08:11 +02:00
Petro31
f8dbcb953c
Swap order of int template helper kwargs ()
* swap order of int kwargs

* Add binary and kwargless base tests
2021-10-15 13:04:26 +02:00
Erik Montnemery
7acb1b6eb9
Override the jinja2 int filter () 2021-10-12 00:12:42 +02:00
Erik Montnemery
ef13e473cf
Warn if template functions fail and no default is specified ()
Co-authored-by: Martin Hjelmare <marhje52@gmail.com>
Co-authored-by: Paulus Schoutsen <balloob@gmail.com>
2021-09-29 20:16:02 +02:00
Marc Mueller
77ee72cbb9
Import Callable from collections.abc (1) () 2021-09-29 16:32:11 +02:00
Erik Montnemery
14a1bb423c
Add is_number template filter and function () 2021-09-27 10:47:57 +02:00
Chris Browet
5a2bcd2763
ADD: generalize regex_findall () 2021-09-05 12:41:39 +02:00
Raman Gupta
4d98a7e156
Allow device_id template function to use device name as input () 2021-08-31 14:56:47 +02:00
Raman Gupta
1d1b5ab345
Fix area_id and area_name template functions () 2021-08-30 13:09:41 -07:00
Raman Gupta
2f7a7b0309
Add template functions to get area_id and area_name ()
* Add template function to get area_id

* fix int bug

* Prefer area name lookup

* remove unnecessary checks

* fix import

* Add area_name function

* change behavior to fail in ambiguous scenarios

* Revert lotto winning exception checking

* review comments

* try except else
2021-08-25 15:16:51 -04:00
Ville Skyttä
de6e7ea016
Replace *args and **kwargs type hint collections with value types () 2021-08-21 10:20:09 +03:00
Paulus Schoutsen
1cc3ffe20d
Fix jinja warning () 2021-08-06 06:41:50 +02:00
Raman Gupta
73bc0267e9
Add DeviceRegistry template functions () 2021-07-27 18:55:55 -04:00
Franck Nijhof
4c51299dcc
Add easy converting string timestamps/dates to datetime objects in templates () 2021-06-07 15:02:15 +02:00
Matt Zimmerman
e964c607a3
jinja2.contextfilter decorator renamed to pass_context ()
* jinja2.contextfilter decorator renamed to pass_context

* bump jinja2 dependency
2021-05-24 17:38:37 +02:00