Commit Graph

798 Commits (8901508df6b4f6bc44c1709eb8ba084f111c7b82)

Author SHA1 Message Date
Ville Skyttä 9b7e31eca3
Make f-strings without placeholder normal strings (#33938) 2020-04-10 09:59:06 +02:00
springstan 9a40d5b7ed
Use HTTP_NOT_FOUND constant (#33835) 2020-04-09 00:57:47 +02:00
springstan fca90a8ddc
Improve string formatting v5 (#33697)
* Improve string formatting v5

* Address review comments
2020-04-05 17:48:55 +02:00
Franck Nijhof 7d3c974747
Use set & dict literals (#33636)
Co-authored-by: Daniel Høyer Iversen <mail@dahoiv.net>
2020-04-04 20:05:15 +02:00
Franck Nijhof b9b1cee403
Enable pylint import-outside-toplevel (#33631) 2020-04-04 17:07:36 +02:00
Paulus Schoutsen dc7127aacf
Data Coordinator to return unsub func (#33588) 2020-04-03 20:15:42 +02: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
David F. Mulcahey 8b0a0ee521
Don't write storage to disk while stopping (#33456)
* Don't write storage to disk while stopping

* rework change

* lint

* remove delay save and schedule final write at stop

* update tests

* fix test component using private methods

* cleanup

* always listen

* use stop in restore state again

* whitelist JSON exceptions for later

* review comment

* make zwave tests use mock storage
2020-04-02 10:25:28 -07:00
Ziv 4dbbf93af9
Replace asyncio.wait with asyncio.gather since wait ignores exceptions (#33380)
* replace asyncio.wait with asyncio.gather since wait ignores exceptions
fix for test_entity_platform so it expects the exception

* changed to log on failed domains

* discovered that this fix actually removes other uncaught exceptions

* fix in the list of ignored exceptions

* replaced a few ignores on dyson tests that work locally but fail in the CI

* two more tests that are failing on the CI and not locally

* removed assertion on multiple entries with same unique_id - replaced with log and return
reverted test_entity_platform to its original since now there is no exception thrown

* entered all the dyson tests. they all pass locally and probabilistically fail in the CI

* removed unnecessary str() for exception

* added log message for duplicate entity_id / unique_id

* removed log in case of False return value

* added exc_info

* change the use of exc_info
2020-04-01 07:09:13 -07:00
David F. Mulcahey bcd1eb952c
RFC - Add a 3rd state to the HA shutdown sequence for writing… (#33358)
* add third stage to hass shutdown

* use 3rd stage in storage

* update core state

* add writing data to multi stop ignore

* update core test

* review comment

* update name based on feedback
2020-03-30 10:18:39 -07:00
Paulus Schoutsen 73c52e668e
Fix dispatcher logging (#33299) 2020-03-26 20:44:44 -07:00
Erik Montnemery 867630a4a7
Remove state when entity is removed from registry (#32184) 2020-03-26 16:33:50 -07:00
Fabian Affolter 2647296475
Refactor API documentation (#33217)
* Upgrade Sphinx to 2.4.4

* Refactor API documentation

* Remove left-over

* Remove Markdown from docstring

* Update titels
2020-03-25 13:21:04 -07:00
Eugenio Panadero fb22f6c301
Add Context support for async_entity removal (#33209)
* Add Context for async_remove

* Check context in state automation on entity removal
2020-03-24 09:59:17 -07: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 1ff245d9c2
Make sure entity platform services work for all platforms of d… (#33176)
* Make sure entity platform services work for all platforms of domain

* Register a bad service handler

* Fix cleaning up

* Tiny cleanup
2020-03-23 12:59:36 -07:00
Paulus Schoutsen f95c3e265d
Fix script logging with name (#33120) 2020-03-22 13:29:50 +01:00
Eugenio Panadero d5e606640c
Fix scheduled update time-drift in data update coordinator (#32974)
* Fix scheduled update time-drift in data update coordinator

As next schedule is calculated **after** the update is done,
setting now + update_interval makes 1 second drift in practice,
as the tick is 1Hz.

* Floor the utcnow timestamp

to remove sub-second error precision, and generate constant frequency updates
as long as the update takes < 1s.
2020-03-21 16:57:12 -07:00
Ville Skyttä 05abf37046
Type hint improvements (#32905)
* Complete helpers.entity_component type hints

* Add discovery info type
2020-03-18 19:27:25 +02:00
Franck Nijhof ff92a8b260
Add update class method to DataUpdateCoordinator (#32724)
* Add update class method to DataUpdateCoordinator

* Update homeassistant/helpers/update_coordinator.py

Co-Authored-By: Paulus Schoutsen <balloob@gmail.com>

* Move update_method param

* Rename async_update_data to _async_update_data

* Raise NotImplementedError

* Re-raise NotImplementedError

* Remove caplog, not needed anymore

* Don't set last_update_success on NotImplementedError

* Fix test

Co-authored-by: Paulus Schoutsen <balloob@gmail.com>
2020-03-13 00:27:19 +01: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
Phil Bruckner 5f5cb8bea8
Add support for simultaneous runs of Script helper - Part 2 (#32442)
* Add limit parameter to service call methods

* Break out prep part of async_call_from_config for use elsewhere

* Minor cleanup

* Fix improper use of asyncio.wait

* Fix state update

Call change listener immediately if its a callback

* Fix exception handling and logging

* Merge Script helper if_running/run_mode parameters into script_mode

- Remove background/blocking _ScriptRun subclasses which are no longer needed.

* Add queued script mode

* Disable timeout when making fully blocking script call

* Don't call change listener when restarting script

This makes restart mode behavior consistent with parallel & queue modes.

* Changes per review

- Call all script services (except script.turn_off) with no time limit.
- Fix handling of lock in _QueuedScriptRun and add comments to make it
  clearer how this code works.

* Changes per review 2

- Move cancel shielding "up" from _ScriptRun.async_run to Script.async_run
  (and apply to new style scripts only.) This makes sure Script class also
  properly handles cancellation which it wasn't doing before.
- In _ScriptRun._async_call_service_step, instead of using script.turn_off
  service, just cancel service call and let it handle the cancellation
  accordingly.

* Fix bugs

- Add missing call to change listener in Script.async_run
  in cancelled path.
- Cancel service task if ServiceRegistry.async_call cancelled.

* Revert last changes to ServiceRegistry.async_call

* Minor Script helper fixes & test improvements

- Don't log asyncio.CancelledError exceptions.
- Make change_listener a public attribute.
- Test overhaul
  - Parametrize tests.
  - Use common test functions.
  - Mock timeout so tests don't need to wait for real time to elapse.
  - Add common function for waiting for script action step.
2020-03-11 16:34:50 -07:00
Alexei Chetroi 440c837eb6
Allow sw_version update of a device registry entry. (#32630) 2020-03-11 09:31:02 -07:00
Paulus Schoutsen 6a21afa2a8
Improve script validation (#32461) 2020-03-05 11:44:42 -08:00
Paulus Schoutsen b27c46750c
Update error handling in update coordinator (#32452) 2020-03-04 08:05:46 -08:00
Paulus Schoutsen fcbea47c74
Coronavirus updates (#32417)
* Sort countries alphabetically

* Update sensor name

* Add migration to stable unique IDs

* Update sensor.py
2020-03-02 17:59:32 -08:00
Paulus Schoutsen deda2f86e7
Allow managing Lovelace storage dashboards (#32241)
* Allow managing Lovelace storage dashboards

* Make sure we do not allow duplicate url paths

* Allow setting sidebar to None

* Fix tests

* Delete storage file on delete

* List all dashboards
2020-02-28 12:43:17 -08:00
Balazs Sandor 75e8d49af1
Show kernel version on linux (#32276) 2020-02-27 13:59:30 -08:00
Paulus Schoutsen 2a88ae559e
Improve debounce cooldown (#32161) 2020-02-26 11:27:37 -08:00
Paulus Schoutsen 7d8da47309
Revert "Use orjson to parse json faster (#32153)" (#32185)
This reverts commit 2365e2e8cf.
2020-02-25 21:07:16 +01:00
Paulus Schoutsen 536b31305a
Support multiple Lovelace dashboards (#32134)
* Support multiple Lovelace dashboards

* Mark collection maintenance as unfinished

* Fix import

* Add websockets commands for resource management

* Revert "Add websockets commands for resource management"

This reverts commit 7d140b2bcc.

Co-authored-by: Bram Kragten <mail@bramkragten.nl>
2020-02-25 11:18:21 -08:00
Ruslan Sayfutdinov 2365e2e8cf
Use orjson to parse json faster (#32153)
* [recorder] Use orjson to parse json faster

* Remove from http manifest

* Bump to orjson 2.5.1

* Empty commit to trigger CI

Co-authored-by: Paulus Schoutsen <paulus@home-assistant.io>
2020-02-25 10:20:51 -08:00
Erik Montnemery 7e387f93d6
Add MQTT WS command to remove device (#31989)
* Add MQTT WS command to remove device

* Review comments, fix test

* Fix tests
2020-02-24 20:46:02 -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
Paulus Schoutsen ca01e9a537
Improve condition validation error msg (#32135) 2020-02-24 09:59:34 +01:00
MatthewFlamm 6c9d4a6d15
Add missing name to logging in DataUpdateCoordinator (#32023) 2020-02-20 16:51:15 +01:00
Paulus Schoutsen 7be3a4cd37
Fix entity registry not saving name/icon (#31932) 2020-02-18 08:32:34 -08:00
Ville Skyttä 03f7fe483b
Type hint improvements (#31876)
* Complete components.remote type hints

* Define ConfigType only in helpers.typing
2020-02-16 13:47:55 +01:00
jjlawren 91018034b6
Use new custom_serializer (#31871) 2020-02-15 15:36:57 -08:00
Ville Skyttä 733f1e1101
Helpers typing improvements (#31865) 2020-02-15 13:03:53 -08:00
Paulus Schoutsen 52b045ed30
Fix person device_trackers null (#31829) 2020-02-14 15:27:31 -08:00
Robert Svensson 043d36f7c6
Change multi_select config validator to class (#31828)
* Move multi_select to class

* Fix serializer and add test

* Serializer should also return options
2020-02-14 11:09:40 -08:00
Paulus Schoutsen e019280d94
Annotate more async functions correctly (#31802) 2020-02-14 10:00:22 -08:00
Robert Svensson 6211a2bb98
Add multi select support to config validation and to custom serializer (#31798) 2020-02-13 13:12:09 -08:00
Paulus Schoutsen 9e7185c676
Write state if schedule update state from async context (#31758)
* Write state if schedule update state from async context

* Fix most tests

* Fix test and PS4 I/O in event loop

* Fix ps4 better
2020-02-13 10:22:06 -08:00
Paulus Schoutsen 51c35ab9a8
Entity Registry to store and restore name/icon (#31714)
* Entity Registry to store and restore name/icon

* Update test_entity_registry.py

* Add original name/icon to JSON result
2020-02-11 09:40:50 -08:00
Paulus Schoutsen 5a0f21cbe3
Adjust entity slow warning for custom component (#31711) 2020-02-10 16:32:47 -08:00
Paulus Schoutsen 12de3f1e47 Clean up frontend services and events (#31654)
* Clean up frontend services and events

* Fix bug in core instead

* Add test that core works correctly with callback marked async funcs
2020-02-09 19:47:16 -08:00
Paulus Schoutsen 0d474e1183
Update the update coordinator API to make it easier to use (#31471)
* Update the update coordinator API to make it easier to use

* failed_last_update -> last_update_success
2020-02-06 09:29:29 -08:00