Commit Graph

83 Commits (d3210ada1dc4b6cf36b1f1f3d79ba4b6028e4a59)

Author SHA1 Message Date
Eduard van Valkenburg 779ef3c8e1
Add timedelta option for async_call_later (#50164) 2021-06-12 13:14:35 +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
FMKaiba 09eb74fd9d
Upgrade Astral to 2.2 (#48573) 2021-04-02 00:29:08 +02:00
Franck Nijhof 65cf2fcb6f
Drop asynctest (#44746) 2021-01-01 22:31:56 +01:00
J. Nick Koston 2ef25e7414
Fix script wait templates with now/utcnow (#44717) 2021-01-01 13:03:34 +01:00
Anders Melchiorsen 650c57db5b
Fix async_track_utc_time_change firing too early (#42176) 2020-11-05 16:34:56 +01:00
J. Nick Koston 8eb89cdb46
Fix flapping event template test (#42614) 2020-10-30 00:05:55 +01:00
Paulus Schoutsen bba770b411
Fix CI (#42397) 2020-10-26 13:36:03 +01:00
Anders Melchiorsen cb0c937b3e
Refresh now() templates on second=0 (#42225) 2020-10-23 00:11:02 +02:00
Paulus Schoutsen 8d4675713a
Fix event test (#42078) 2020-10-19 16:50:46 +02: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 3a9b2392f8
Suppress domain and all listeners during template rate limit (#42005) 2020-10-19 10:17:51 +02:00
J. Nick Koston 53a1d92f2b
Permit event trackers to accept an empty list of entities or domains (#41857) 2020-10-15 09:26:51 +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 7285c7806f
Seperate state change tracking from async_track_template_result into async_track_state_change_filtered (#40803) 2020-10-01 10:19:20 +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 e9abb357e4
Log template listeners when debug logging is on (#40180) 2020-09-17 14:45:30 -05:00
J. Nick Koston 741487a1fc
Return the listeners with the template result for the websocket api (#39925) 2020-09-11 13:18:40 -05:00
J. Nick Koston e208aac834
Add async_track_state_removed_domain to allow tracking when a state is removed from a domain (#39859)
when a state is removed from a domain
2020-09-11 13:03:31 +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 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
J. Nick Koston c87e03ee6f
Ensure template tracking can recover after the template generates an exception (#39256) 2020-08-26 00:33:08 +02:00
J. Nick Koston 20398cc0a6
Subscribe to state change events only if the template has entities (#39188) 2020-08-26 00:20:04 +02:00
J. Nick Koston 1381b279f0
Update template sensor to use async_track_template_result (#38940)
* Add template entity

* Update template tracking to work for template sensors

* add test for whitespace

* Update homeassistant/helpers/config_validation.py

* revert

* fix

* reduce

* fix _refresh missing decorator

* defer until start

* do not throw errors during startup

* defer tracking until start event

Co-authored-by: Swamp-Ig <github@ninjateaparty.com>
2020-08-20 08:06:41 -05:00
J. Nick Koston 472b12bef5
Update TrackTemplateResultInfo to remove side effects from init (#38934)
* Verify and case

* Review comments

* Update homeassistant/helpers/event.py

Co-authored-by: Martin Hjelmare <marhje52@gmail.com>

* Update homeassistant/helpers/event.py

Co-authored-by: Martin Hjelmare <marhje52@gmail.com>

Co-authored-by: Martin Hjelmare <marhje52@gmail.com>
2020-08-16 11:16:28 -05: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 45526f4e8a
Add async_track_state_added_domain for tracking when states are added to a domain (#38776)
* Fire event_state_added when a state is added after start

* async_track_state_added_domain

* test

* naming

* coverage
2020-08-12 13:30:40 -05:00
J. Nick Koston 34d01d5e47
Mark event tests to run as callbacks (#38212)
* Mark event tests to run as callbacks

* revert change to same state check that is expected to run in a thread
2020-07-25 17:52:48 -10:00
J. Nick Koston b868f13591
Ensure all track time change tests mock a specific start time (#38178)
* Ensure all track time change tests mock a specific start time

* make sure tests calling async_track_utc_time_change fire time in utc
2020-07-24 19:04:36 -07:00
J. Nick Koston 4015991622
Update tests that track time to account for microsecond precision (#38044) 2020-07-21 14:22:55 -07:00
J. Nick Koston 60009ec2f9
Use event loop scheduling for tracking time patterns (#38021)
* Use event loop scheduling for tracking time patterns

* make patching of time targetable

* patch time tests since time can tick to match during the test

* fix more tests

* time can only move forward

* time can only move forward

* back to 100% coverage

* simplify since the event loop time cannot move backwards

* simplify some more

* revert simplify

* Revert "revert simplify"

This reverts commit bd42f232f6.

* Revert "simplify some more"

This reverts commit 2a6c57d514.

* Revert "simplify since the event loop time cannot move backwards"

This reverts commit 3b13714ef4.

* Attempt another simplify

* time does not move backwards in the last two

* remove next_time <= now check

* fix previous merge error
2020-07-20 20:18:31 -10:00
J. Nick Koston 910b6c9c2c
Index entity_registry_updated listeners (#37940) 2020-07-17 21:59:18 -07:00
J. Nick Koston fa4e9c0485
Increase test line coverage of homeassistant/helpers/event.py to 100% (#37927)
* Increase test line coverage of homeassistant/helpers/event.py to 100%

* fix test
2020-07-16 21:47:53 -07:00
J. Nick Koston b6befa2e83
Ensure a state change tracker setup from inside a state change listener does not fire immediately (#37924)
Co-authored-by: Paulus Schoutsen <paulus@home-assistant.io>
2020-07-16 17:50:06 -07:00
J. Nick Koston 34ccb6588c
Cleanup async_track_state_change and augment docstring (#37251)
* Cleanup async_track_state_change and augment docstrings.

Skip from_state and to_state matching in
async_track_state_change when they are None

Optimize the state change listener for the most
common use case: no to_state and from_state
matching.

* Update benchmark to be more realistic (previously we assumed only one entity was present in the whole instance)

* Add more tests to ensure behavior is preserved

* Ensure new behavior matches test

* remove MATCH_ALL from zone automation since its the default anyways

* Might as well use async_track_state_change_event instead since MATCH_ALL is removed
2020-07-05 17:31:33 -05:00
J. Nick Koston 89a9634d35
Use eventloop for scheduling (#37184)
Co-authored-by: Paulus Schoutsen <balloob@gmail.com>
2020-06-29 09:39:24 -07:00
J. Nick Koston a63a11a11a
Ensure all async_track_state_change_event callbacks run if one throws (#37179) 2020-06-27 17:48:27 -07:00
J. Nick Koston 4acc6f333e
Improve scalability of state change event routing (#37174) 2020-06-27 14:46:45 -07: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
Franck Nijhof 60bc517d01
Collection of core tests improvements (#33757)
* Collection of core tests improvements

* Added some more

* Fix aiohttp client response release
2020-04-07 09:33:23 -07: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ä 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 4de97abc3a Black 2019-07-31 12:25:30 -07:00
Paulus Schoutsen 236c5deeee
Sun listener to adapt to core config updates (#24464)
* Adaptable sun listener

* Lint
2019-06-10 16:05:32 -07: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
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