Commit Graph

130 Commits (1a68784852472c85a5fbb3ae7001283bd7a43b23)

Author SHA1 Message Date
Paulus Schoutsen a4d9019ffc
Refactor persistent notification to no longer route all data via a service ()
* Convert persistent notification tests to async

* Create/dismiss persistent notifications in exposed functions, not service calls

* Fix notify persistent_notification

* Remove setting up persistent_notification

* Drop more setups

* Empty methods

* Undeprecate sync methods because too big task

* Fix setup clearing notifications

* Fix a bunch of tests

* Fix more tests

* Uno mas

* Test persistent notification events

* Clean up stale comment

Co-authored-by: Martin Hjelmare <marhje52@gmail.com>
2021-10-07 12:58:00 +02:00
Erik Montnemery 69875cbd11
Improve sensor statistics validation () 2021-10-04 09:47:44 -07:00
Erik Montnemery 8567aa9e13
Evict purged states from recorder's old_state cache ()
Co-authored-by: J. Nick Koston <nick@koston.org>
2021-10-04 08:21:40 -07:00
Erik Montnemery 40ecf22bac
Remove automatic splitting of net meters from statistics () 2021-09-29 17:20:17 +02:00
Erik Montnemery 00651a4055
Optimize _get_states_with_session ()
* Optimize _get_states_with_session

* Move custom filters to derived table

* Remove useless derived table

* Filter old states after grouping

* Split query

* Add comments

* Simplify state update period criteria

* Only apply custom filters if we didn't get an include list of entities

Co-authored-by: J. Nick Koston <nick@koston.org>
2021-09-29 17:08:27 +02:00
Erik Montnemery 8ef123259e
Add WS API for updating unit_of_measurement in statistics metadata ()
* Add WS API for updating statistics metadata

* Update homeassistant/components/recorder/websocket_api.py

Co-authored-by: Bram Kragten <mail@bramkragten.nl>

* Update homeassistant/components/recorder/websocket_api.py

Co-authored-by: Paulus Schoutsen <balloob@gmail.com>

* Fix typo

Co-authored-by: Bram Kragten <mail@bramkragten.nl>
Co-authored-by: Paulus Schoutsen <balloob@gmail.com>
2021-09-28 00:43:29 +02:00
Erik Montnemery 5976f898da
Add WS API for removing statistics for a list of statistic_ids ()
* Add WS API for removing statistics for a list of statistic_ids

* Refactor according to code review, enable foreign keys support for sqlite

* Adjust tests

* Move clear_statistics WS API to recorder

* Adjust tests after rebase

* Update docstring

* Update homeassistant/components/recorder/websocket_api.py

Co-authored-by: Paulus Schoutsen <paulus@home-assistant.io>

* Adjust tests after rebase

Co-authored-by: Paulus Schoutsen <paulus@home-assistant.io>
2021-09-27 23:30:13 +02:00
Erik Montnemery 64393b462d
Add migration for 5-minute statistics ()
* Add migration for 5-minute statistics

* Tweaks
2021-09-24 09:19:22 +02:00
Erik Montnemery 92253f5192
Minor refactoring of periodic statistics () 2021-09-22 13:31:33 -07:00
Erik Montnemery 6f36419c6f
Improve statistics validation () 2021-09-20 17:54:25 +02:00
Erik Montnemery 8c5efafdd8
Add 5-minute statistics for sensors ()
* Add 5-minute statistics for sensors

* Address pylint issues

* Black

* Apply suggestion from code review

* Apply suggestions from code review

* Improve tests
2021-09-16 10:57:15 +02:00
Erik Montnemery d899d15a1e
Add statistics validation ()
* Add statistics validation

* Remove redundant None-check

* Move validate_statistics WS API to recorder

* Apply suggestion from code review
2021-09-13 13:44:22 +02:00
Erik Montnemery d2a9f7904a
Include end time of statistics data points in API response ()
* Include end time of statistics data points in API response

* Correct typing

* Update tests
2021-09-13 10:02:24 +02:00
Erik Montnemery 80fd330479
Add sum_decrease and sum_increase statistics () 2021-09-08 23:35:53 -07:00
Erik Montnemery 27764e9985
Fix handling of imperial units in long term statistics () 2021-09-08 08:08:48 -07:00
Erik Montnemery 22e6ddf8df
Do not let one bad statistic spoil the bunch () 2021-09-08 07:55:40 -07:00
Erik Montnemery 8877f37da0
Fix statistics for sensors setting last_reset ()
* Re-add state_class total to sensor

* Make energy cost sensor enforce state_class total_increasing

* Drop state_class total

* Only report energy sensor issues once
2021-08-24 17:02:34 +02:00
Erik Montnemery 32e297f4a0
Compile missing statistics () 2021-08-19 22:10:45 -07:00
Erik Montnemery e1926caeb9
Remove STATE_CLASS_TOTAL and last_reset from sensor ()
* Remove STATE_CLASS_TOTAL

* Update mill sensor

* Update tests

* Kill last_reset

* Return ATTR_LAST_RESET to utility_meter

* Update energy cost sensor

* Restore last_reset for backwards compatibility

* Re-add and update deprecation warning

* Update tests

* Fix utility_meter

* Update EnergyCostSensor

* Tweak

* Fix rebase mistake

* Fix test
2021-08-18 10:03:27 +02:00
Paulus Schoutsen 557cc792e9
Fix SQLAlchemy test warnings () 2021-08-08 20:33:47 -07:00
Erik Montnemery e541bcd54d
Update statistics meta data on entity_id change () 2021-07-14 13:23:11 +02:00
Erik Montnemery 11fd9d9525
Avoid duplicated database queries when fetching statistics () 2021-07-02 15:40:54 +02:00
Erik Montnemery 0476c7f9ee
Normalize temperature statistics to °C ()
* Normalize temperature statistics to °C

* Fix tests

* Support temperature conversion to and from K, improve tests

* Fix test

* Add tests, pylint
2021-06-30 14:17:58 +02:00
PeteBa 42c4317628
Avoid drift in recorder purge cut-off () 2021-06-25 11:29:38 -10:00
Paulus Schoutsen 805ef3f90b
Allow fetching multiple statistics () 2021-06-18 21:03:13 +02:00
Erik Montnemery 39c94e8daa
Fix flaky statistics tests ()
* Fix flaky statistics tests

* Tweak
2021-05-28 22:37:17 +02:00
Erik Montnemery b339d73109
Weight sensor average statistics by state durations ()
* Weight sensor average statistics by state durations

* Fix test
2021-05-28 13:16:52 +02:00
PeteBa aa9b99713c
Add purge_entities service call to recorder () 2021-05-22 10:30:05 -05:00
Erik Montnemery e16a8063a5
Compile statistics for energy sensors ()
* Compile statistics for energy sensors

* Update tests

* Rename abs_value to state

* Tweak

* Recreate statistics table

* Pylint

* Try to fix test

* Fix statistics for multiple energy sensors

* Fix energy statistics when last_reset is not set
2021-05-20 13:05:15 +02:00
J. Nick Koston e7f7e61e88
Ensure a wal checkpoint is scheduled nightly () 2021-05-17 16:27:51 -05:00
J. Nick Koston 72288710ca
Increase the sqlite cache size from ~2MiB to 8MiB () 2021-05-17 19:42:12 +02:00
Erik Montnemery 89dd3292ba
Initial draft of statistics () 2021-05-16 10:23:37 -07:00
Erik Montnemery 973f59e423
Refactor history component ()
* Refactor history component

* Update tests

* Address review comments

* Correct deprecated functions
2021-05-11 09:21:57 +02:00
J. Nick Koston bf2d40adfe
Migrate from pytz to python-dateutil ()
Co-authored-by: Paulus Schoutsen <balloob@gmail.com>
2021-05-07 22:46:26 -07:00
J. Nick Koston 1c8d9ca68b
Check exception causes for matching strings during recorder migration () 2021-05-02 20:57:42 -07:00
Paulus Schoutsen 1bd9826684
Handle different entity_id formats () 2021-05-01 20:30:28 -07:00
J. Nick Koston b27e9e376d
Use StaticPool for recorder and NullPool for all other threads with sqlite3 () 2021-04-26 19:20:31 -10:00
jan iversen c351098f04
HomeAssistantType —> HomeAssistant for Integrations p* - s* () 2021-04-22 19:58:02 +02:00
J. Nick Koston c10836fcee
Upgrade to sqlalchemy 1.4.11 () 2021-04-21 20:29:36 -10:00
J. Nick Koston 6d137d2316
Increase recorder test coverage ()
Co-authored-by: Martin Hjelmare <marhje52@gmail.com>
2021-04-19 08:22:38 -07:00
J. Nick Koston e24f5831a2
Force recorder shutdown at final write event ()
* Force recorder shutdown at EVENT_HOMEASSISTANT_FINAL_WRITE

* remove unreachable

* remove unreachable

* simplify

* cancel in async
2021-04-19 11:24:17 +02:00
J. Nick Koston 53853f035d
Prevent calling stop or restart services during db upgrade () 2021-04-12 17:18:38 -07:00
J. Nick Koston 9368891b1b
Live db migrations and recovery ()
Co-authored-by: Paulus Schoutsen <paulus@home-assistant.io>
2021-04-11 20:43:54 -10:00
Laszlo Magyar c7e4857d2c
Let recorder deal with event names longer than 32 chars () 2021-04-08 07:08:49 -10:00
Franck Nijhof 08870690a6
Fix a collection of tests with missing asserts ()
Co-authored-by: Martin Hjelmare <marhje52@gmail.com>
2021-03-20 17:23:55 +01:00
Franck Nijhof fb849b81b5
Rewrite of not a == b occurances () 2021-03-20 01:27:04 +01:00
J. Nick Koston 28c80c1133
Ensure recorder purge tests can handle multiple purge cycle ()
Since a purge can generate another purge task, we now wait for
three recorder queue completions by default.
2021-03-15 11:19:19 -07:00
J. Nick Koston 61a2460c87
Improve error reporting in recorder purge test () 2021-03-14 19:46:21 -07:00
Erik Montnemery 2178e27fb4
Fix unclean shutdown of recorder test () 2021-03-12 14:17:27 -08:00
Marc Mueller 92852b9c10
Add apply_filter attribute to recorder.purge service () 2021-03-11 17:03:30 -10:00