Brynley McDonald
26dc526234
Add slugify as a template filter ( #58724 )
2021-12-21 11:35:54 +01:00
Jan Bouwhuis
3188a364e2
Add template filters pack and unpack ( #60836 )
...
* 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" ( #60854 )
2021-12-03 08:50:29 +01:00
Erik Montnemery
a07f75c6b0
Revert "Allow template int filter to render from a bytes based integer" ( #60855 )
2021-12-02 14:37:19 -08:00
Jan Bouwhuis
f07e676c82
Allow template int filter to render from a bytes based integer ( #60452 )
...
* 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 ( #60291 )
...
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 ( #60211 )
...
* 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 ( #60126 )
2021-11-24 09:51:56 +01:00
Jan Bouwhuis
fa0d3a6c48
Change output template filters `timestamp_local` and `timestamp_utc` to isoformat ( #60269 )
2021-11-24 09:49:03 +01:00
Marcel van der Veldt
902da4daf8
Add integration_entities template helper ( #59841 )
2021-11-20 14:43:31 -08:00
rianadon
ecf00a1eae
Add accumulated precipitation to unit system ( #59657 )
...
* Add accumulated precipitation to unit system
* Fix template test
* Fix typo of testing pressure instead of precipitation
* Add extra arguments so unit system test passes
2021-11-19 09:18:44 +01:00
rianadon
7cc7bbb76d
Add speed to units system ( #58437 )
...
* Use speed units in unit system
* Use more obvious conversion factor for unit system speed test
* Use wind_speed instead of speed, use m/s
2021-11-18 16:08:42 +01:00
Chris Browet
4224cb043b
Allow overriding ensure_ascii in the "to_json" template filter ( #54527 )
...
* FIX: "ensureascii" to to_json
* fixup: parameter name
2021-11-08 15:49:10 +01:00
Franck Nijhof
bf693e85b1
Revert "Add warning when entity used in template doesn't exist" ( #58527 )
2021-10-27 13:53:26 +02:00
Petro31
11034a93c3
Add average template function and filter ( #57727 )
2021-10-26 22:43:45 +02:00
avee87
d9b87ee5c5
Add warning when entity used in template doesn't exist ( #57316 )
2021-10-22 20:09:54 +02:00
Raman Gupta
e5255cf21f
Add area_entities and area_devices template functions/filters ( #55228 )
2021-10-22 19:59:01 +02:00
Petro31
806dc51125
Add datetime_today template method ( #57435 )
2021-10-22 19:51:22 +02:00
Erik Montnemery
df1154395e
Revert "Swap order of int template helper kwargs ( #57729 )" ( #58015 )
...
This reverts commit f8dbcb953c
.
2021-10-21 15:03:33 +02:00
Petro31
f8dbcb953c
Swap order of int template helper kwargs ( #57729 )
...
* 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 ( #57470 )
2021-10-12 00:12:42 +02:00
Erik Montnemery
ef13e473cf
Warn if template functions fail and no default is specified ( #56453 )
...
Co-authored-by: Martin Hjelmare <marhje52@gmail.com>
Co-authored-by: Paulus Schoutsen <balloob@gmail.com>
2021-09-29 20:16:02 +02:00
Erik Montnemery
14a1bb423c
Add is_number template filter and function ( #56705 )
2021-09-27 10:47:57 +02:00
Chris Browet
5a2bcd2763
ADD: generalize regex_findall ( #54584 )
2021-09-05 12:41:39 +02:00
Raman Gupta
4d98a7e156
Allow device_id template function to use device name as input ( #55474 )
2021-08-31 14:56:47 +02:00
Raman Gupta
1d1b5ab345
Fix area_id and area_name template functions ( #55470 )
2021-08-30 13:09:41 -07:00
Raman Gupta
2f7a7b0309
Add template functions to get area_id and area_name ( #54248 )
...
* 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
Raman Gupta
73bc0267e9
Add DeviceRegistry template functions ( #53131 )
2021-07-27 18:55:55 -04:00
Ville Skyttä
7d03b02192
Spelling fixes ( #51642 )
2021-06-11 13:35:03 +02:00
Franck Nijhof
4c51299dcc
Add easy converting string timestamps/dates to datetime objects in templates ( #51576 )
2021-06-07 15:02:15 +02:00
J. Nick Koston
bf2d40adfe
Migrate from pytz to python-dateutil ( #49643 )
...
Co-authored-by: Paulus Schoutsen <balloob@gmail.com>
2021-05-07 22:46:26 -07:00
Ville Skyttä
77d5244577
Use device registry CONNECTION_* constants ( #49923 )
2021-04-30 23:58:50 +02:00
Mike Degatano
236d274351
Add `search` and `match` as Jinja tests ( #49229 )
2021-04-15 20:13:27 +02:00
Franck Nijhof
a610076001
Support min()/max() as template function ( #48996 )
2021-04-12 10:02:04 +02:00
Erik Montnemery
16196e2e16
Don't log template errors from developer tool ( #48933 )
2021-04-09 12:10:02 -07:00
Erik Montnemery
9f5db2ce3f
Improve warnings on undefined template errors ( #48713 )
2021-04-06 12:11:42 -07:00
Erik Montnemery
f8755a52c2
Warn on undefined variables in templates ( #48140 )
...
* Warn on undefined variables in templates
* Add test
* fix tests
* fix tests
2021-03-20 15:16:04 +01:00
Franck Nijhof
5a2b5fe7c5
Yoda assertion style removed is ( #48142 )
2021-03-20 13:55:10 +01:00
Erik Montnemery
54cf954353
Add device_entities template function/filter ( #46406 )
2021-02-19 21:50:59 -08:00
Franck Nijhof
65cf2fcb6f
Drop asynctest ( #44746 )
2021-01-01 22:31:56 +01:00
Paulus Schoutsen
1de2554f70
Tweak template digit detection ( #43621 )
2020-11-25 16:10:33 +01:00
Paulus Schoutsen
8dbd54bed1
Disable parsing scientific/complex number notation in template type ( #43170 )
2020-11-13 13:22:29 +01:00
J. Nick Koston
7f1683c731
Remove legacy template extract_entities ( #42601 )
2020-10-30 00:06:08 +01:00
Paulus Schoutsen
e21e28e49f
Fix string representation of template result wrappers ( #42494 )
2020-10-28 09:11:08 +01:00
Paulus Schoutsen
d4efa938dd
Improve mqtt test ( #42490 )
2020-10-27 23:22:59 +01:00
Paulus Schoutsen
711b7d4605
Make result wrappers more robust ( #42488 )
2020-10-27 22:51:58 +01:00
Franck Nijhof
45aba9bdf2
Allow skip parsing template result ( #42401 )
2020-10-26 16:01:09 +01:00
Paulus Schoutsen
e552c9ba96
Store original result on template results ( #42391 )
...
* Store original result on template results
* Fix shell command test
2020-10-26 11:30:58 +01:00
J. Nick Koston
31c21126a8
Implement time tracking in templates ( #41147 )
...
Co-authored-by: Anders Melchiorsen <amelchio@nogoto.net>
2020-10-19 11:02:43 +02:00
J. Nick Koston
77b95ae8a1
Reduce domain states rate limit to 1 per second ( #42004 )
2020-10-19 10:18:25 +02:00
J. Nick Koston
b897ca7260
Ensure all template errors are caught and the websocket api reports them ( #41719 )
2020-10-12 16:38:24 +02:00
Franck Nijhof
ee914366a8
Add native Python types support to templates ( #41227 )
...
Co-authored-by: Paulus Schoutsen <balloob@gmail.com>
2020-10-07 00:05:52 +02:00
J. Nick Koston
2fabd4edb8
Prevent collecting states already referenced by domain or all ( #41308 )
...
The template engine would collect all the states in
a domain or all states while iterating even though
they were already included in all or the domain
This lead to the rate limit not being applied to
templates that iterated all states that also
accessed a collectable property because the engine
incorrectly believed they were specifically
referenced.
2020-10-06 07:25:05 +02:00
J. Nick Koston
51da605b9f
Remove manual rate_limit control directive from templates ( #41225 )
...
Increase default rate limit for all states and entire
domain states to one minute
Ensure specifically referenced entities are excluded from
the rate limit
2020-10-04 22:40:04 +02:00
J. Nick Koston
b45215f1d2
Implement template rate_limit directive ( #40667 )
2020-10-01 21:39:44 +02:00
J. Nick Koston
9ccebdb8d5
Refactor group to extend domains that can be grouped ( #40607 )
...
Co-authored-by: Paulus Schoutsen <paulus@home-assistant.io>
2020-09-30 09:13:53 -05:00
J. Nick Koston
e564af0b5b
Improve performance of accessing template state ( #40323 )
...
Co-authored-by: Paulus Schoutsen <paulus@home-assistant.io>
2020-09-28 10:35:12 -05:00
J. Nick Koston
e08ee282ab
Abort execution of template renders that overwhelm the system ( #40647 )
2020-09-28 14:43:22 +02:00
J. Nick Koston
3261a904da
Reduce the number of template re-renders when we are only counting states ( #40272 )
2020-09-26 16:29:49 -05:00
J. Nick Koston
35533407fe
Improve performance of counting and iterating states in templates ( #40250 )
...
Co-authored-by: Anders Melchiorsen <amelchio@nogoto.net>
2020-09-26 11:36:47 -05:00
Ville Skyttä
5e90a4d000
Use more state attribute name constants ( #40428 )
2020-09-21 23:03:39 +02:00
Jakob Schlyter
9b49ca3820
Add template filter timedelta_seconds to create a timedelta from seconds ( #39608 )
2020-09-11 15:07:31 -05:00
J. Nick Koston
fb31b04c08
Increase template test coverage. ( #39908 )
2020-09-10 20:43:45 +02:00
J. Nick Koston
5e83feeabf
Increase test coverage for template sandbox ( #39750 )
2020-09-07 17:33:22 +02:00
J. Nick Koston
a096c20930
Fix missing assert in template test ( #39648 )
2020-09-04 16:28:56 +02:00
J. Nick Koston
35e84d0427
Add as_local convenience function to jinja templates ( #39618 )
2020-09-03 14:35:16 -05:00
J. Nick Koston
e55a014e94
Undecorate RenderInfo result property ( #39108 )
2020-09-02 10:35:15 +02:00
Paulus Schoutsen
190611a079
Detect comments in jinja templates ( #39496 )
2020-08-31 10:51:30 +02:00
Franck Nijhof
1c2ebdf307
Upgrade black to 20.8b1 ( #39287 )
2020-08-27 13:56:20 +02:00
J. Nick Koston
c3ad493bb7
Report usage of extract_entities by custom components ( #39185 )
...
Block core usage usage of extract_entities
Suggest event.async_track_template_result instead.
2020-08-23 19:38:45 +02:00
J. Nick Koston
7d0e356560
Add track_template_result method to events ( #38802 )
...
* Merge original changes from #23590
* guard
* adjust
* adjust
* adjust
* Update async_render_to_info for recent codebase changes
* no more protected access
* do not fire right away per review comments
* update test to not fire right away
* closer
* rework tests for non firing first
* augment coverage
* remove cruft
* test for complex listen add/remove
* update docs to match review feedback to not fire right away
* preserve existing behavior
* fix test
* Ensure listeners are cleaned up
* de-dupe and comment
* de-dupe and comment
* coverage
* test to login again if we go from exception to ok to exception
* Update homeassistant/core.py
Co-authored-by: Paulus Schoutsen <paulus@home-assistant.io>
* Update homeassistant/helpers/event.py
Co-authored-by: Paulus Schoutsen <paulus@home-assistant.io>
* rename _boolean_coerce to result_as_boolean and move it out of event
* additional coverage
* Add more tests (may still be able to trim this down)
Co-authored-by: Swamp-Ig <github@ninjateaparty.com>
Co-authored-by: Paulus Schoutsen <paulus@home-assistant.io>
2020-08-15 19:53:03 -05:00
J. Nick Koston
ef8e74786f
Support extracting entities by domain from templates ( #38647 )
2020-08-09 13:44:09 +02:00
J. Nick Koston
62c664fbbd
Reduce time to reload yaml and check configuration ( #38469 )
...
* Reduce time to reload yaml and check configuration
We spend a significant amount of time compiling templates
that we have already compiled.
Use an LRU cache to avoid re-compiling templates that
we frequently use.
* pylint
* switch to WeakValueDictionary
* preen
2020-08-04 03:00:44 +02:00
Jakob Schlyter
dbcd5f4c2c
Add urlencode template filter ( #37753 )
...
* add urlencode template filter
* fix flake8
* add test to string ang integer
* better test vectors
2020-07-13 16:48:29 +02:00
Thomas Hollstegge
8f285c15d3
Listen for group member state changes when using `expand` in templates ( #35398 )
...
* Re-evaluate template on group member state change
* Use named groups for entity extraction regex
This will avoid unnecessary edits of match indices if the regex is
amended in the future
* Improve test coverage
2020-05-10 10:48:56 -05:00
Paulus Schoutsen
2af984917e
Use asynctest-mock in most places ( #35109 )
...
* Use asynctest-mock in most places
* Fix broken patch in pilight
2020-05-03 11:27:19 -07:00
Mikael Svensson
ccc818266b
Fix relative_time datetime object without timezone ( #34273 )
2020-04-20 10:29:12 -07:00
Franck Nijhof
d7e9959442
String formatting improvements for tests (2) ( #33666 )
2020-04-05 00:33:07 +02:00
Ville Skyttä
5216477353
Be consistent with Home Assistant and Hass.io spelling ( #30500 )
...
* Be consistent with Home Assistant spelling
* Be consistent with Hass.io spelling
2020-01-05 14:09:17 +02:00
Ville Skyttä
fa4fa30461
Various string cleanups ( #30435 )
...
* Remove some unnecessary string concatenations
* Replace some simple str.formats with f-strings
* Replace some string concatenations with f-strings
2020-01-03 14:47:06 +01:00
Ville Skyttä
e6388e186c
Remove unnecessary string literal concatenations ( #30360 )
2020-01-02 21:17:10 +02:00
Bas Nijholt
f60125b5c9
Sort imports according to PEP8 for 'tests' ( #29791 )
2019-12-09 16:52:24 +01:00
Paulus Schoutsen
eef91f843d
Rendering complex template objects to leave non-template values alone ( #29353 )
2019-12-03 14:15:45 -08:00
Tobias Perschon
d92f48646a
Add round to half template method ( #28948 )
...
* added round to half method
Signed-off-by: Tobias Perschon <tobias@perschon.at>
* testcase for new round method
Signed-off-by: Tobias Perschon <tobias@perschon.at>
2019-11-22 10:08:41 -08:00
SteveDinn
25fd930d67
Add template filters to convert objects to and from JSON strings ( #27909 )
...
* Added filters to convert objects to and from JSON strings.
* Added extra spacing.
* Removed try/catch to get native exceptions
* Added tests.
2019-10-22 22:51:29 -07:00
Tomi Lehto
5b516fc0cd
Add arcus trigonometry functions to templates ( #25510 )
2019-08-09 11:16:47 -07:00
Paulus Schoutsen
4de97abc3a
Black
2019-07-31 12:25:30 -07:00
aschamberger
3512d05467
Add ord() to template filters ( #25398 )
...
* Add ord() to template filters
* Remove trailing whitespace
* add test
2019-07-25 15:06:51 -07:00
Penny Wood
22d9bee41a
Template: Expand method to expand groups, and closest as filter ( #23691 )
...
* Implement expand method
* Allow expand and closest to be used as filters
* Correct patch
* Addresses review comments
2019-06-22 00:32:32 -07:00
Penny Wood
5b9d01139d
render_with_collect method for template ( #23283 )
...
* Make entity_filter be a modifiable builder
* Add render_with_collect method
* Use sync render_with_collect and non-class based test case
* Refactor: Template renders to RenderInfo
* Freeze with exception too
* Finish merging test changes
* Removed unused sync interface
* Final bits of the diff
2019-05-01 10:54:25 +08:00
Erik Montnemery
407e0c58f9
Migrate tests to pytest ( #23544 )
...
* Migrate tests to pytest
* Fixup
* Use loop fixture in test_check_config
* Lint
2019-04-30 09:20:38 -07:00
Moritz Fey
f272ed3b91
Add 'method' parameter to forgiving_round method ( #21708 )
...
* Add 'method' parameter to forgiving_round method
Fixes #21707
* fix rounding behavior in round() filter
* add test cases for new rounding behaviour
2019-03-24 18:10:49 -07:00
MatthewFlamm
ed93c3b2c1
Fix pressure in dark sky and openweathermap and add pressure utility ( #21210 )
2019-03-24 18:37:31 +01:00
Phil Bruckner
935e5c67a3
Handle non-string values in JSON renderer ( #20233 )
...
Handle the case of async_render_with_possible_json_value's value argument
being something other than a string. This can happen, e.g., when using the
SQL sensor to extract a datetime column such as last_changed and also using
its value_template to convert that datetime to another format. This was
causing a TypeError from json.loads, but async_render_with_possible_json_value
was only catching ValueError's.
2019-01-20 16:46:14 -08:00
Mahasri Kalavala
c23792d1fb
Added new filters for templates ( #18125 )
...
* added additional filters
Added base64_encode, base64_decode and ordinal filters.
* added test cases
added test cases for base64_encode, base64_decode and ordinal filters.
* forgot to add filters :)
2018-12-01 10:38:10 +01:00
Neil Crosby
865ea82432
Allow jinja namespace command to work. ( #18011 )
2018-10-30 19:13:20 +01:00
Anders Melchiorsen
3de822a0e2
RFC: Static templates match no entities, not all ( #17991 )
...
* Static templates match no entities, not all
* Clean up test values
2018-10-30 12:03:27 +01:00
Paulus Schoutsen
08fe7c3ece
Pytest tests ( #17750 )
...
* Convert core tests
* Convert component tests to use pytest assert
* Lint 🤷♂️
* Fix test
* Fix 3 typos in docs
2018-10-24 12:10:05 +02:00
Markus Nigbur
670c75e844
Added resolve_state to template distance function ( #17290 )
...
_resolve_state was already used in the "closest" function, to allow for states and entity ids
2018-10-10 11:49:24 +02:00
Blake Blackshear
f13f723a04
Add bitwise operations as template helpers ( #16833 )
2018-09-26 11:57:16 +02:00