Commit Graph

416 Commits (dc5888ab4af85bf62d01a8dcd891a400232d6a99)

Author SHA1 Message Date
Paulus Schoutsen a50e9812cb
Fix automations with traces. (#47705) 2021-03-09 22:40:17 -08:00
Erik Montnemery 704000c049
Add support for breakpoints in scripts (#47632) 2021-03-09 21:23:11 -08:00
Erik Montnemery fd1add8f15
Rename AutomationTrace.runid to AutomationTrace.run_id (#47669) 2021-03-09 15:49:41 +01:00
Erik Montnemery a243adc551
Add WS command to get a summary of automation traces (#47557)
* Add WS command to get a summary of automation traces

* Update tests

* Correct rebase mistake, update tests
2021-03-08 20:30:52 +01:00
Erik Montnemery 8fe51b8ea7
Store automation traces indexed by run_id (#47509)
* Store traces indexed by run_id

* Format

* Add test

* Add test

* Clarify comment
2021-03-08 18:04:41 +01:00
Erik Montnemery 2f9d03d115
Merge action and condition traces (#47373)
* Merge action and condition traces

* Update __init__.py

* Add typing to AutomationTrace

* Make trace_get prepare a new trace by default

* Correct typing of trace_cv

* Fix tests
2021-03-06 12:57:21 +01:00
tkdrob 3baeed3684
Clean up constants (#47323) 2021-03-05 19:08:04 +01:00
Erik Montnemery 17401cbc29
Initial automation tracing (#46755)
* Initial prototype of automation tracing

* Small fixes

* Lint

* Move trace helpers to its own file

* Improve trace for state and numeric_state conditions

* Tweaks + apply suggestions from code review

* Index traces by automation_id, trace while script is running

* Refactor condition tracing

* Improve WS API to get traces for single automation

* Add tests

* Fix imports

* Fix imports

* Address review comments

* Cap logging of loops

* Remove unused ContextVar action_config
2021-03-04 14:16:24 +01:00
Ville Skyttä dc880118a4
Lint suppression cleanups (#47248)
* Unused pylint suppression cleanups

* Remove outdated pylint bug references

* Add flake8-noqa config and note to run it every now and then

* Add codes to noqa's

* Unused noqa cleanups
2021-03-02 09:02:04 +01:00
Franck Nijhof ea4bbd771f
Add service names to previously enriched services (#46929)
Co-authored-by: Tobias Sauerwein <cgtobi@users.noreply.github.com>
2021-02-23 14:10:13 +01:00
Philip Allgaier 8ac9faef3b
Description tweaks for automation services (#46926) 2021-02-22 21:36:38 +01:00
Anders Melchiorsen b1a24c8bbb
Log the name of automations with condition errors (#46854) 2021-02-21 19:34:45 -10:00
Anders Melchiorsen d33a1a5ff8
Refine printing of ConditionError (#46838)
* Refine printing of ConditionError

* Improve coverage

* name -> type
2021-02-21 14:54:36 +01:00
Anders Melchiorsen bfea7d0baa
Raise ConditionError for and/or/not errors (#46767) 2021-02-19 13:15:30 +01:00
Franck Nijhof bc1cb8f0a0
Add selectors to Automation service definitions (#46629) 2021-02-18 12:25:25 +01:00
Erik Montnemery 047f16772f
Support templating MQTT triggers (#45614)
* 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
Anders Melchiorsen b9b1caf4d7
Raise ConditionError for numeric_state errors (#45923) 2021-02-08 10:47:57 +01:00
tkdrob bcefbe2dca
Use core constants for automation (#46016) 2021-02-04 21:41:43 -05:00
Marc Mueller 7673f57248
Add additional error handling for automation script run (#45613) 2021-01-28 09:26:41 +01:00
J. Nick Koston a7741be9bb
Wait for all triggers when one fails to attach (#45361) 2021-01-20 22:13:21 +01:00
Paulus Schoutsen 594e905742
Remove invalidation_version from deprecated (#44156)
* Remove invalidation_version from deprecated. We don't follow up and just hurts releases

* Revert change to ZHA
2020-12-12 22:24:16 +01:00
Paulus Schoutsen 262e77d969
Blueprint: descriptions + descriptive errors (#43899) 2020-12-03 16:44:18 +01:00
Paulus Schoutsen ff4897a09e
Fix using execute on the notify_leaving_zone (#43858) 2020-12-02 16:21:00 +01:00
Paulus Schoutsen 6c9c280bbb
Migrate notify-leaving-zone to use mobile app device action (#43832) 2020-12-02 13:07:04 +01:00
Paulus Schoutsen 648f9e100d
Use light turn on service (#43847) 2020-12-02 10:53:26 +01:00
Bram Kragten d93687b5ac
Update area and target selectors add sequence selector (#43831)
Co-authored-by: Paulus Schoutsen <balloob@gmail.com>
2020-12-02 09:30:49 +01:00
Paulus Schoutsen 1c9c99571e
Use !input instead of !placeholder (#43820)
* Use !input instead of !placeholder

* Update input name

* Lint

* Move tests around
2020-12-01 18:21:36 +01:00
Paulus Schoutsen e406a47293
Allow configuring the delay in the motion light blueprint (#43737) 2020-11-28 23:56:15 +01:00
Paulus Schoutsen dd513147a5
Add a service target (#43725) 2020-11-28 23:33:32 +01:00
Paulus Schoutsen b3be708db6
Add default config if not there (#43321)
Co-authored-by: Bram Kragten <mail@bramkragten.nl>
2020-11-25 15:10:04 +01:00
Paulus Schoutsen dc5f7aedd7
Verify that we register blueprints on automation setup (#43434) 2020-11-20 15:57:57 +01:00
Paulus Schoutsen df25b53bb8
Fix automation in packages (#43202) 2020-11-13 22:49:01 +01:00
Franck Nijhof 6f326a7ea4
Add support for multiple event triggers in automation (#43097)
Co-authored-by: Paulus Schoutsen <balloob@gmail.com>
2020-11-12 11:58:28 +01:00
HomeAssistant Azure 4b9ba79584 [ci skip] Translation update 2020-11-11 00:10:27 +00:00
Paulus Schoutsen 0fb587727c
Add initial blueprint support (#42469)
Co-authored-by: Martin Hjelmare <marhje52@gmail.com>
Co-authored-by: Franck Nijhof <git@frenck.dev>
2020-11-02 15:00:13 +01:00
HomeAssistant Azure b102ad731f [ci skip] Translation update 2020-10-22 00:09:52 +00:00
HomeAssistant Azure 994ae09f69 [ci skip] Translation update 2020-10-15 00:03:50 +00:00
HomeAssistant Azure 6ae12c3faf [ci skip] Translation update 2020-10-10 00:05:05 +00:00
Paulus Schoutsen 8ae3f575dd
Add extended validation for script repeat/choose (#41265) 2020-10-05 14:03:48 +02:00
Paulus Schoutsen 5117a16841
Extract variable rendering (#39934) 2020-09-11 12:24:16 +02:00
Paulus Schoutsen aa9dff572e
Add default variables to script helper (#39895) 2020-09-10 20:41:42 +02:00
Phil Bruckner 4486251382
Add max_exceeded log level option to automations & scripts (#39448) 2020-09-02 11:05:14 +02:00
HomeAssistant Azure 5ce62c8446 [ci skip] Translation update 2020-09-02 00:03:29 +00:00
J. Nick Koston dda4cf4d58
Tune logbook performance to accomodate recent changes (#39348) 2020-08-30 09:20:31 +02:00
Phil Bruckner b315df2118
Reduce automation state changes by using script helper's last_triggered attribute (#39323) 2020-08-28 14:51:15 -05:00
Phil Bruckner e6141ae558
Add description of what caused an automation trigger to fire (#39251)
Co-authored-by: J. Nick Koston <nick@koston.org>
2020-08-28 17:02:12 +02:00
Paulus Schoutsen 2a1fe9d29a
Add websocket trigger/condition commands (#39109) 2020-08-24 23:01:57 +02:00
Phil Bruckner 76ead858cf
Add wait_for_trigger script action (#38075)
* Add wait_for_trigger script action

* Add tests

* Change script integration to use config validator
2020-08-21 11:38:25 +02:00
Phil Bruckner ca9dd0c833
Reorganize trigger code (#38655) 2020-08-17 11:54:56 -05:00
Phil Bruckner 580e229cf2
Create variable with result of wait_template and accept template for timeout option (#38634) 2020-08-12 13:42:06 -05:00
Phil Bruckner 716fa63e73
Update script helper constructor parameters (#38763)
Add domain and make it and name required.

Add optional running_description.
2020-08-12 11:39:05 -05:00
Phil Bruckner 192fe58fc8
Time trigger can also accept an input_datetime Entity ID (#38698) 2020-08-11 15:16:28 -05:00
Phil Bruckner 9e12e3f96c
Allow automation to be turned off without stopping actions (#38436) 2020-08-01 21:31:47 -05:00
Franck Nijhof fa9866db96
Add support for multiple time triggers in automations (#37975)
* Add support for multiple time triggers in automations

* Attach with single callback

* Patch time in tests

* Improve test coverage

* Adjusting my facepalm moment
2020-07-29 14:51:30 -10:00
Phil Bruckner bbc8748e3b
Stop automation runs when turned off or reloaded (#38174)
* Add automation turn off / reload test

* Stop automation runs when turned off or reloaded
2020-07-25 12:19:55 +02:00
Eugenio Panadero 8cfffd00d6
Fix state automation trigger (#38014) (#38032)
for scenarios of enabling/disabling (~ creating/removing) entities,
so it does not trigger in removal if a `to: xxx` is defined, and also
does not trigger in creation if a `from: xxx` is present.
2020-07-23 14:17:11 -05:00
Phil Bruckner 65d1dfba62
Update automation logger to include object_id like scripts (#37948) 2020-07-22 10:55:49 -05:00
Pascal Vizeli f4c3f5d074
Revert breaking change for Automation (#37885)
Co-authored-by: Paulus Schoutsen <balloob@gmail.com>
2020-07-15 20:38:29 +02:00
Bram Kragten 7d77fa92c2
Add mode info attributes to script and automation (#37815)
Co-authored-by: J. Nick Koston <nick@koston.org>
2020-07-14 10:47:59 -07:00
Phil Bruckner 63e55bff52
Remove legacy script mode and simplify remaining modes (#37729) 2020-07-10 17:00:57 -07:00
Phil Bruckner 91271f388c
Add new repeat loop for scripts and automations (#37589) 2020-07-10 13:37:19 -05: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
Franck Nijhof 53545c984b
Log lines do not end with a full stop (#37527) 2020-07-05 23:04:19 +02:00
J. Nick Koston c1aaceebb6
Use async_track_state_change_event for automation numeric_state (#37255)
Calling async_track_state_change_event directly
is faster than async_track_state_change (see #37251) and has
slightly lower latency triggering state updates
2020-07-05 13:05:53 -07:00
Phil Bruckner f7c4900d5c
Enhance automation integration to use new features in script helper (#37479) 2020-07-05 09:25:15 -05:00
J. Nick Koston 4acc6f333e
Improve scalability of state change event routing (#37174) 2020-06-27 14:46:45 -07:00
Paulus Schoutsen 5bc6ed4cef
Add logbook platforms (#37078)
* Add logbook platforms

* Fix logbook describe test
2020-06-24 18:14:50 -07:00
Erik Montnemery 747490ab34
Support reconfiguring MQTT config entry (#36537) 2020-06-22 17:49:01 -07:00
Bas Nijholt dcb04acc65
Set automation last_triggered earlier (#35671)
Co-authored-by: Paulus Schoutsen <paulus@home-assistant.io>
2020-06-03 20:08:37 +02:00
Franck Nijhof e6fe34e64d
Migrate automation to use describe_event for logbook (#36356) 2020-06-01 17:18:40 -07:00
Franck Nijhof 1883b1d2a2
Add config reloaded events for automation and scene (#34664) 2020-06-01 15:19:00 -07:00
HomeAssistant Azure 9586e9ebef [ci skip] Translation update 2020-05-15 00:02:56 +00:00
Paulus Schoutsen 0efeefe3b2 Update translations 2020-05-13 11:27:21 -07:00
Franck Nijhof 8c65062271
Several optimizations to automations (#35007) 2020-05-01 16:37:25 +02:00
Paulus Schoutsen 77443b3d09
Add Home Assistant Started event (#34657) 2020-04-24 14:13:39 -07:00
Franck Nijhof c93c6a66e8
Add NOT condition helper (#34624) 2020-04-24 09:40:23 -07:00
Joakim Sørensen 730a257f3c
Rename translations dir for integrations (#34494) 2020-04-21 16:11:05 -07:00
Franck Nijhof bc5a2da7b7
Add transition support to scenes, cleanup blocking parameter (#34434) 2020-04-20 18:07:50 -07:00
Paulus Schoutsen 95357dfc55 Update translations 2020-04-20 16:33:54 -07:00
Paulus Schoutsen d560e8245a
Import state strings (#34451) 2020-04-20 16:25:35 -07:00
Paulus Schoutsen 0d60d40512 Update translations 2020-04-16 13:00:10 -07:00
Paulus Schoutsen 6119e79023
Migrate frontend translations of domains to backend (#34294) 2020-04-16 11:52:27 -07:00
Franck Nijhof 24840b54ac
Add yamllint (in pre-commit and CI) (#33676)
* Add yamllint (in pre-commit and CI)

* Fix linting for all YAML files

* Bump and add it to requirements

* Fix gen_requirements for pre-commit, remove 'v' from version
2020-04-05 10:33:45 +02:00
Paulus Schoutsen f1d3c0d19b
Remove unused manifest fields (#33595) 2020-04-03 12:58:19 -07:00
Paulus Schoutsen aef06a3544
Directly call write state 2 (#33513)
* Directly call async_write_ha_state pt2

* Directly call async_write_ha_state pt2

* Fix mock

* Address comments
2020-04-03 09:34:50 +02:00
Eugenio Panadero cd57b764ce
Fix state_automation_listener when new state is None (#32985)
* Fix state_automation_listener when new state is None (fix #32984)

* 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 397238372e
Remove group as a dependency from entity integrations (#32870)
* remove group dependency

* Update device sun light trigger

* Add zone dep back to device tracker
2020-03-16 14:47:44 -07:00
Paulus Schoutsen 4cf86262af
Numeric state trigger: validate that above is not above below (#32421)
* Numeric state trigger: validate that above is not above below

* Lint
2020-03-03 17:26:44 -08:00
Franck Nijhof ceb3985a99
Remove hide_entity property from automation integration (#32038)
* Remove hidden property from automation integration

* Allow configuration options untils 0.110
2020-02-25 11:21:05 -08:00
Ville Skyttä 9b2544c923
Remove some unneeded pylint suppressions (#32152) 2020-02-24 16:47:15 -08:00
Phil Bruckner b2d7bc40dc
Add support for simultaneous runs of Script helper (#31937)
* Add tests for legacy Script helper behavior

* Add Script helper if_running and run_mode options

- if_running controls what happens if Script run while previous run
  has not completed. Can be:
  - error: Raise an exception
  - ignore: Return without doing anything (previous run continues as-is)
  - parallel: Start run in new task
  - restart: Stop previous run before starting new run
- run_mode controls when call to async_run will return. Can be:
  - background: Returns immediately
  - legacy: Implements previous behavior, which is to return when done,
            or when suspended by delay or wait_template
  - blocking: Returns when run has completed
- If neither is specified, default is run_mode=legacy (and if_running
  is not used.) Otherwise, defaults are if_running=parallel and
  run_mode=background. If run_mode is set to legacy then if_running must
  be None.
- Caller may supply a logger which will be used throughout instead of
  default module logger.
- Move Script running state into new helper classes, comprised of an
  abstract base class and two concrete clases, one for legacy behavior
  and one for new behavior.
- Remove some non-async methods, as well as call_from_config which has
  only been used in tests.
- Adjust tests accordingly.

* Change per review

- Change run_mode default from background to blocking.
- Make sure change listener is called, even when there's an unexpected
  exception.
- Make _ScriptRun.async_stop more graceful by using an asyncio.Event for
  signaling instead of simply cancelling Task.
- Subclass _ScriptRun for background & blocking behavior.

Also:

- Fix timeouts in _ScriptRun by converting timedeltas to float seconds.
- General cleanup.

* Change per review 2

- Don't propagate exceptions if call from user has already returned
  (i.e., for background runs or legacy runs that have suspended.)
- Allow user to specify if exceptions should be logged. They will still
  be logged regardless if exception is not propagated.
- Rename _start_script_delay and _start_wait_template_delay for
  clarity.
- Remove return value from Script.async_run.
- Fix missing await.
- Change call to self.is_running in Script.async_run to direct test of
  self._runs.

* Change per review 3 and add tests

- Remove Script.set_logger().
- Enhance existing tests to check all run modes.
- Add tests for new features.
- Fix a few minor bugs found by tests.
2020-02-24 14:56:00 -08:00
springstan 524a1a7587
Use f-strings in integrations starting with "A" (#32110)
* Use f-strings in integrations starting with A

* Use f-strings in tests for integrations starting with A

* Fix pylint by renaming variable

* Fix nested for loop in f-string for aprs device_tracker

* Break long lines into multiple short lines

* Break long lines into multiple short lines v2
2020-02-23 13:38:05 -08:00
Erik Montnemery 60ae85564e
Add support for MQTT device triggers (#31679)
* Add support for MQTT device triggers

* Fix test, tweaks

* Improve test coverage

* Address review comments, improve tests

* Tidy up exception handling

* Fix abbreviations

* Rewrite to handle update of attached triggers

* Update abbreviation test

* Refactor according to review comments

* Refactor according to review comments

* Improve trigger removal

* Further refactoring
2020-02-18 13:51:10 -08:00
Paulus Schoutsen 44e243039c
Fix automation sun import (#31521) 2020-02-06 12:55:11 +01:00
Paulus Schoutsen 67680bcfa8
Automation device/entity extraction to include triggers + conditions (#31474)
* Add support for extracting triggers

* Add support for extracting triggers

* Fix test
2020-02-05 16:52:21 +01:00
Paulus Schoutsen 424e15c7a7
Find related items scripts/automations (#31293)
* Find related items scripts/automations

* Update manifest
2020-01-29 16:19:13 -08:00
Paulus Schoutsen e9e44dbd97
Fix callback and async (#31281)
* Fix callback and async

* Fix a return

* Fix test

* Fix mqtt tests

* Fix some more callbacks
2020-01-29 13:59:45 -08:00
Paulus Schoutsen 1f0f62de7f
Add unique IDs to automation/scenes (#31150)
* Add unique IDs to automation and scenes

* Fix typo
2020-01-26 23:01:35 -08:00
Paulus Schoutsen 80887d757a
Simplify automation services (#30996)
* Simplify automation services

* Empty commit to re-trigger build

Co-authored-by: Franck Nijhof <frenck@frenck.nl>
2020-01-22 17:46:12 -08:00
Franck Nijhof 1e2c3cacf9 Mark hide_entity deprecated in automation integration (#30799) 2020-01-15 11:53:52 -08:00