Commit Graph

114 Commits (999eeb39b919b4549fd912d4b2d311c634f48bf3)

Author SHA1 Message Date
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 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 57b7559832
Ensure all jinja2 errors are trapped and displayed in the developer tools (#40624)
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 (#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
Philip Allgaier ddbcfe83dd
Catch TypeError in strptime() template helper (#40226) 2020-09-18 15:29:40 +02:00
J. Nick Koston ff4bb962c4
Cleanup and reduce duplicate code from recent template changes (#40012)
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 (#39608) 2020-09-11 15:07:31 -05:00
Paulus Schoutsen aa9dff572e
Add default variables to script helper (#39895) 2020-09-10 20:41:42 +02:00
J. Nick Koston 90d574e521
Ensure static templates are still called back on first refresh (#39753) 2020-09-07 17:19:39 +02:00
J. Nick Koston 2e6cd4f12b
Optimize template sandbox for Home Assistant (#39731) 2020-09-07 09:17:41 +02:00
J. Nick Koston 251d8919ea
Add domain filter support to async_all to match async_entity_ids (#39725)
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 (#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
J. Nick Koston a77e09b2c2
Make async_track_template_result track multiple templates (#39371)
* 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 (#39496) 2020-08-31 10:51:30 +02:00
Ville Skyttä b4bac0f7a0
Exception chaining and wrapping improvements (#39320)
* 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 (#39208)
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 (#39185)
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 (#39008)
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 (#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
Ville Skyttä 752679c55d
Check isinstance on collections.abc, not typing classes (#35087) 2020-05-02 23:57:48 +02:00
Mikael Svensson ccc818266b
Fix relative_time datetime object without timezone (#34273) 2020-04-20 10:29:12 -07:00
Ville Skyttä 267d98b5eb
Type hint improvements (#33082) 2020-04-17 11:33:58 -07:00
springstan 00b6409b76
Use LENGTH_METERS constant (#34110) 2020-04-12 21:44:56 +02:00
Franck Nijhof b9b1cee403
Enable pylint import-outside-toplevel (#33631) 2020-04-04 17:07:36 +02:00
Ville Skyttä 221d5205e4
Upgrade mypy to 0.770, tighten config a bit (#32715)
* Upgrade mypy to 0.770, related cleanups

https://mypy-lang.blogspot.com/2020/03/mypy-0770-released.html

* Clean up config and make it a notch stricter, address findings
2020-03-12 11:52:20 +01:00
Ville Skyttä 733f1e1101
Helpers typing improvements (#31865) 2020-02-15 13:03:53 -08:00
Christian Clauss df7d2b3aeb
Fix typos found by codespell (#31243)
* Fix typos found by codespell

* Fix typos found by codespell

* codespell: Furture  ==> Future

* Update test_config_flow.py

* Update __init__.py

* Spellcheck: successfull  ==> successful

* Codespell: unsuccesful  ==> unsuccessful

* Codespell: cant  ==> can't

* Codespell: firware ==> firmware

* Codespell: mimick  ==> mimic
2020-01-31 08:33:00 -08: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 67c56c860d Sort imports according to PEP8 for 'homeassistant' folder (#29789)
Components are already done
2019-12-09 16:42:10 +01:00
Paulus Schoutsen eef91f843d
Rendering complex template objects to leave non-template values alone (#29353) 2019-12-03 14:15:45 -08:00
Ville Skyttä 99c7608fb4 Lint config cleanups (#28864)
* Remove bunch of unneeded lint exclusions

* Use symbolic names instead of identifiers in pylint disables

* Tighten scope of some pylint disables
2019-11-25 22:40:08 -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
Ville Skyttä f88ead597a Type hint improvements (#28260)
* Add and improve core and config_entries type hints

* Complete and improve config_entries type hints

* More entity registry type hints

* Complete helpers.event type hints
2019-10-28 13:36:26 -07: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
Ville Skyttä 54242cd65c Type hint additions (#26765) 2019-09-20 08:23:34 -07:00
Franck Nijhof decf13b948 Use literal string interpolation in core (f-strings) (#26166) 2019-08-23 09:53:33 -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
Ville Skyttä d64f1e767c Type check all helpers (#25373)
* Type check all helpers, add inline exclusions for work in progress

* Remove unused Script._template_cache

* Add some missing type hints

* Remove unneeded type: ignore

* Type hint fixes

* Mypy assistance tweaks

* Don't look for None in deprecated config "at most once" check

* Avoid None name slugify attempt when generating entity id

* Avoid None state store attempt on entity remove
2019-07-21 09:59:02 -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