Commit graph

100 commits

Author SHA1 Message Date
J. Nick Koston
53a1d92f2b
Permit event trackers to accept an empty list of entities or domains () 2020-10-15 09:26:51 +02:00
J. Nick Koston
1bcedd15b3
Update sun listeners to use HassJob ()
Avoids checking the callable type every time sun events trigger
2020-10-13 21:37:10 +02:00
J. Nick Koston
3a863c4a0f
Fully convert async_track_time_interval to use HassJob ()
The callback type for interval_listener was being determined
each time the interval hit.

This was missed in the original conversion.
2020-10-09 09:35:09 +02:00
J. Nick Koston
9e1461da62
Determine how to run listeners at setup time instead of execution time () 2020-10-07 16:51:50 +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
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
ab17b4ab70
Simplify template tracking and make it easier to follow () 2020-10-02 07:27:39 -05:00
J. Nick Koston
b45215f1d2
Implement template rate_limit directive () 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 () 2020-10-01 10:19:20 +02:00
J. Nick Koston
205cf57a77
Code cleanups for async_track_template_result () 2020-09-30 13:00:21 +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
e9abb357e4
Log template listeners when debug logging is on () 2020-09-17 14:45:30 -05:00
J. Nick Koston
949bd8d738
Reduce listener cancelation code in template tracker () 2020-09-14 21:43:00 +02:00
J. Nick Koston
aaa8083d49
Change template loop detection strategy to allow self-referencing updates when there are multiple templates () 2020-09-12 14:20:21 +02:00
J. Nick Koston
741487a1fc
Return the listeners with the template result for the websocket api () 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 ()
when a state is removed from a domain
2020-09-11 13:03:31 +02:00
J. Nick Koston
fd8a4182d9
Detect self-referencing loops in template entities and log a warning () 2020-09-10 20:50:11 +02: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
Ville Skyttä
1bf2c4d976
Upgrade pylint to 2.6.0 () 2020-08-29 07:59:24 +02:00
J. Nick Koston
f8704a2dfc
Ensure we always fire time pattern changes after microsecond 0 () 2020-08-28 16:27:25 +02:00
J. Nick Koston
715fe4eef8
Fix time pattern listener firing a few microseconds early () 2020-08-26 17:50:25 +02:00
J. Nick Koston
c87e03ee6f
Ensure template tracking can recover after the template generates an exception () 2020-08-26 00:33:08 +02:00
J. Nick Koston
20398cc0a6
Subscribe to state change events only if the template has entities () 2020-08-26 00:20:04 +02:00
J. Nick Koston
1381b279f0
Update template sensor to use async_track_template_result ()
* 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 ()
* 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 ()
* 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
45526f4e8a
Add async_track_state_added_domain for tracking when states are added to a domain ()
* 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
60009ec2f9
Use event loop scheduling for tracking time patterns ()
* 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 () 2020-07-17 21:59:18 -07:00
J. Nick Koston
fa4e9c0485
Increase test line coverage of homeassistant/helpers/event.py to 100% ()
* 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 ()
Co-authored-by: Paulus Schoutsen <paulus@home-assistant.io>
2020-07-16 17:50:06 -07:00
J. Nick Koston
41cd90648e
Have async_track_point_in_utc_time call async_run_job directly from call_at ()
We do not need a nested function here since call_at
takes args
2020-07-14 17:24:36 -10:00
Ville Skyttä
ac0dbb17af
Attrs cleanups () 2020-07-14 10:30:30 -07:00
J. Nick Koston
34ccb6588c
Cleanup async_track_state_change and augment docstring ()
* 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 ()
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 () 2020-06-27 17:48:27 -07:00
J. Nick Koston
4acc6f333e
Improve scalability of state change event routing () 2020-06-27 14:46:45 -07:00
Paulus Schoutsen
5a9970e63c
Dump states in event handler for HA_Stop ()
* Dump states in event handler for HA_Stop

* Fix type
2020-04-13 17:41:01 -07:00
Franck Nijhof
b9b1cee403
Enable pylint import-outside-toplevel () 2020-04-04 17:07:36 +02:00
Eugenio Panadero
cd57b764ce
Fix state_automation_listener when new state is None ()
* Fix state_automation_listener when new state is None (fix )

* Listen to EVENT_STATE_CHANGED instead of using async_track_state_change

and use the event context on automation trigger.

* Share `process_state_match` with helpers/event

* Add test for state change automation on entity removal
2020-03-23 16:05:21 -07:00
Paulus Schoutsen
166d770ddd
Update Hue data fetching ()
* Refactor Hue Lights to use DataCoordinator

* Redo how Hue updates data

* Address comments

* Inherit from Entity and remove pylint disable

* Add tests for debounce
2020-01-31 14:47:40 -08:00
Bas Nijholt
67c56c860d Sort imports according to PEP8 for 'homeassistant' folder ()
Components are already done
2019-12-09 16:42:10 +01:00
Ville Skyttä
f88ead597a Type hint improvements ()
* 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
Ville Skyttä
70ddab2f3c
Helpers type hint additions and improvements ()
* Helpers type hint additions and improvements

* Fix async setup dump callback signature
2019-10-21 17:54:59 +03:00
Ville Skyttä
33e1b44b3a
Use PEP 526 type annotations, add some type hints ()
* Add some more type hints to helpers.event

* Change most type comments to variable types

* Remove some superfluous type hints
2019-09-07 09:48:58 +03:00
Paulus Schoutsen
4de97abc3a Black 2019-07-31 12:25:30 -07:00
Ville Skyttä
d64f1e767c Type check all helpers ()
* 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
Paulus Schoutsen
236c5deeee
Sun listener to adapt to core config updates ()
* Adaptable sun listener

* Lint
2019-06-10 16:05:32 -07:00