Commit graph

134 commits

Author SHA1 Message Date
tkdrob
c2302784c2
Use core constants for helpers () 2021-02-08 22:53:17 +01:00
Erik Montnemery
047f16772f
Support templating MQTT triggers ()
* Add support for limited templates (no HASS access)

* Pass variables to automation triggers

* Support templates in MQTT triggers

* Spelling

* Handle trigger referenced by variables

* Raise on unsupported function in limited templates

* Validate MQTT trigger schema in MQTT device trigger

* Add trigger_variables to automation config schema

* Don't print stacktrace when setting up trigger throws

* Make pylint happy

* Add trigger_variables to variables

* Add debug prints, document limited template

* Add tests

* Validate MQTT trigger topic early when possible

* Improve valid_subscribe_topic_template
2021-02-08 10:50:38 +01:00
Ville Skyttä
3a88a4120e
Helpers type hint improvements () 2021-01-09 00:08:34 +01:00
Paulus Schoutsen
1de2554f70
Tweak template digit detection () 2020-11-25 16:10:33 +01:00
Paulus Schoutsen
8dbd54bed1
Disable parsing scientific/complex number notation in template type () 2020-11-13 13:22:29 +01:00
Tom Parker-Shemilt
b1ed5a3e79
Fix circular import of config_validation and template () 2020-11-04 19:06:19 -10:00
J. Nick Koston
df552f08c3
Purge unused constants from template helper () 2020-10-30 09:29:12 +01:00
J. Nick Koston
7f1683c731
Remove legacy template extract_entities () 2020-10-30 00:06:08 +01:00
Paulus Schoutsen
e21e28e49f
Fix string representation of template result wrappers () 2020-10-28 09:11:08 +01:00
Paulus Schoutsen
d4efa938dd
Improve mqtt test () 2020-10-27 23:22:59 +01:00
Paulus Schoutsen
711b7d4605
Make result wrappers more robust () 2020-10-27 22:51:58 +01:00
Franck Nijhof
45aba9bdf2
Allow skip parsing template result () 2020-10-26 16:01:09 +01:00
Paulus Schoutsen
bba770b411
Fix CI () 2020-10-26 13:36:03 +01:00
Paulus Schoutsen
e552c9ba96
Store original result on template results ()
* 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 ()
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 () 2020-10-19 10:18:25 +02:00
J. Nick Koston
21cc23244d
Improve template ratelimit performance () 2020-10-15 12:02:05 +02:00
J. Nick Koston
b897ca7260
Ensure all template errors are caught and the websocket api reports them () 2020-10-12 16:38:24 +02:00
Franck Nijhof
ee914366a8
Add native Python types support to templates ()
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 ()
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 ()
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 () 2020-10-01 21:39:44 +02:00
J. Nick Koston
e564af0b5b
Improve performance of accessing template state ()
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 () 2020-09-28 14:43:22 +02:00
J. Nick Koston
57b7559832
Ensure all jinja2 errors are trapped and displayed in the developer tools ()
Co-authored-by: Paulus Schoutsen <paulus@home-assistant.io>
2020-09-26 17:03:32 -05:00
J. Nick Koston
3261a904da
Reduce the number of template re-renders when we are only counting states () 2020-09-26 16:29:49 -05:00
J. Nick Koston
35533407fe
Improve performance of counting and iterating states in templates ()
Co-authored-by: Anders Melchiorsen <amelchio@nogoto.net>
2020-09-26 11:36:47 -05:00
Philip Allgaier
ddbcfe83dd
Catch TypeError in strptime() template helper () 2020-09-18 15:29:40 +02:00
J. Nick Koston
ff4bb962c4
Cleanup and reduce duplicate code from recent template changes ()
As a result of refactoring, there is duplicate code
we can now reduce.

Additionally `_wrap_state` can be removed because
it had unreachable checks for `None`
2020-09-13 09:21:11 -05:00
Jakob Schlyter
9b49ca3820
Add template filter timedelta_seconds to create a timedelta from seconds () 2020-09-11 15:07:31 -05:00
Paulus Schoutsen
aa9dff572e
Add default variables to script helper () 2020-09-10 20:41:42 +02:00
J. Nick Koston
90d574e521
Ensure static templates are still called back on first refresh () 2020-09-07 17:19:39 +02:00
J. Nick Koston
2e6cd4f12b
Optimize template sandbox for Home Assistant () 2020-09-07 09:17:41 +02:00
J. Nick Koston
251d8919ea
Add domain filter support to async_all to match async_entity_ids ()
This avoids copying all the states before applying
the filter
2020-09-06 23:20:32 +02:00
J. Nick Koston
35e84d0427
Add as_local convenience function to jinja templates () 2020-09-03 14:35:16 -05:00
J. Nick Koston
e55a014e94
Undecorate RenderInfo result property () 2020-09-02 10:35:15 +02:00
J. Nick Koston
a77e09b2c2
Make async_track_template_result track multiple templates ()
* Make async_track_template_result track multiple templates

Combine template entity updates to only write ha
state once per template group update

* Make async_track_template_result use dataclasses for input/output

* black versions

* naming
2020-08-31 19:07:40 -05:00
Paulus Schoutsen
190611a079
Detect comments in jinja templates () 2020-08-31 10:51:30 +02:00
Ville Skyttä
b4bac0f7a0
Exception chaining and wrapping improvements ()
* Remove unnecessary exception re-wraps

* Preserve exception chains on re-raise

We slap "from cause" to almost all possible cases here. In some cases it
could conceivably be better to do "from None" if we really want to hide
the cause. However those should be in the minority, and "from cause"
should be an improvement over the corresponding raise without a "from"
in all cases anyway.

The only case where we raise from None here is in plex, where the
exception for an original invalid SSL cert is not the root cause for
failure to validate a newly fetched one.

Follow local convention on exception variable names if there is a
consistent one, otherwise `err` to match with majority of codebase.

* Fix mistaken re-wrap in homematicip_cloud/hap.py

Missed the difference between HmipConnectionError and
HmipcConnectionError.

* Do not hide original error on plex new cert validation error

Original is not the cause for the new one, but showing old in the
traceback is useful nevertheless.
2020-08-28 13:50:32 +02:00
Paulus Schoutsen
fefa1a7259
Add shortcuts when we know template is static ()
Co-authored-by: Franck Nijhof <git@frenck.dev>
2020-08-24 13:40:34 +02:00
J. Nick Koston
c3ad493bb7
Report usage of extract_entities by custom components ()
Block core usage usage of extract_entities

Suggest event.async_track_template_result instead.
2020-08-23 19:38:45 +02:00
Bas Nijholt
a9ffc149f8
Allow templating keys in data_template ()
Co-authored-by: Paulus Schoutsen <paulus@home-assistant.io>
Co-authored-by: Paulus Schoutsen <balloob@gmail.com>
2020-08-21 22:42:05 +02:00
J. Nick Koston
7d0e356560
Add track_template_result method to events ()
* Merge original changes from 

* 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 () 2020-08-09 13:44:09 +02:00
J. Nick Koston
62c664fbbd
Reduce time to reload yaml and check configuration ()
* 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 ()
* 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 ()
* 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
Ville Skyttä
752679c55d
Check isinstance on collections.abc, not typing classes () 2020-05-02 23:57:48 +02:00
Mikael Svensson
ccc818266b
Fix relative_time datetime object without timezone () 2020-04-20 10:29:12 -07:00
Ville Skyttä
267d98b5eb
Type hint improvements () 2020-04-17 11:33:58 -07:00