Commit Graph

347 Commits (832184bacd8e991ecf0b688304f068449cc6de2f)

Author SHA1 Message Date
Paulus Schoutsen 77829e397b
Don't log DB connection string on error (#61927) 2021-12-15 20:54:57 +01:00
Erik Montnemery bceeaec2f8
Remove duplicated statistics rows (#61146)
* Remove duplicated statistics

* Fix misleading docstring

* Pylint knows best

* Correct test

* Oops

* Prevent insertion of duplicated statistics

* Tweak

* pylint

* Add models_schema_23.py

* Tweak
2021-12-13 14:15:36 +01:00
Michael 83989d7b40
Use relative imports [L-R] (#61575) 2021-12-13 00:24:46 +01:00
Erik Montnemery dc5888ab4a
Correct recorder.statistics.get_last_statistics (#61421) 2021-12-10 10:09:29 -08:00
Stefan Agner a13ae85982
Introduce only_supervisor for @websocket_api.ws_require_user() (#61298) 2021-12-08 16:49:35 -08:00
Erik Montnemery f30eb05870
Refactor recorder queue handling (#61161)
* Refactor recorder queue handling

* Address pylint's concerns

* Implement workaround for mypy bug

* Address review comments
2021-12-08 16:54:26 +01:00
Stefan Agner f0006b92be
Allow to lock SQLite database during backup (#60874)
* Allow to set CONF_DB_URL

This is useful for test which need a custom DB path.

* Introduce write_lock_db helper to lock SQLite database

* Introduce Websocket API which allows to lock database during backup

* Fix isort

* Avoid mutable default arguments

* Address pylint issues

* Avoid holding executor thread

* Set unlock event in case timeout occures

This makes sure the database is left unlocked even in case of a race
condition.

* Add more unit tests

* Address new pylint errors

* Lower timeout to speedup tests

* Introduce queue overflow test

* Unlock database if necessary

This makes sure that the test runs through in case locking actually
succeeds (and the test fails).

* Make DB_LOCK_TIMEOUT a global

There is no good reason for this to be an argument. The recorder needs
to pick a sensible value.

* Add Websocket Timeout test

* Test lock_database() return

* Update homeassistant/components/recorder/__init__.py

Co-authored-by: Erik Montnemery <erik@montnemery.com>

* Fix format

Co-authored-by: J. Nick Koston <nick@koston.org>
Co-authored-by: Erik Montnemery <erik@montnemery.com>
2021-12-07 13:16:24 +01:00
Erik Montnemery d980ca7e04
Correct recorder migration._add_columns for PostgreSQL (#60547) 2021-11-29 18:33:25 +01:00
J. Nick Koston 18e822b7b6
Bump sqlalchemy to 1.4.27 (#60383) 2021-11-25 19:55:17 -08:00
Erik Montnemery 4a5238efa5
Add support for calculating daily and monthly fossil energy consumption (#59588) 2021-11-22 09:10:54 -08:00
Erik Montnemery bcd9f3c05f
Correct end time for monthly statistics summary (#59551)
* Correct end time for monthly statistics summary

* Add tests
2021-11-12 15:01:40 +01:00
Erik Montnemery 65b1f0d9eb
Minor refactor of energy validator (#58209) 2021-11-10 22:38:15 -08:00
J. Nick Koston 751098c220
Bump sqlalchemy to 1.4.26 (#59527) 2021-11-10 20:01:59 -08:00
Erik Montnemery 470b01e4ce
Move async_migration_in_progress (#59087) 2021-11-05 10:40:56 +01:00
Erik Montnemery 491e62792b
Correct rescheduling of ExternalStatisticsTask (#59076) 2021-11-04 18:35:43 +01:00
Erik Montnemery 4c5aca93df
Add recorder status WS API (#58989)
* Add recorder status WS API

* Rename recorder/status to recorder/info

* Silence pylint

* Improve tests

* Address review comments

* Tweak

* Try to fix tests

* Try to debug flaky tests

* Try to fix tests

* Revert changes to async_migration_in_progress

* Try to fix tests

* Remove debug prints

* Apply suggestions from code review
2021-11-04 16:46:45 +01:00
Erik Montnemery be4e9f91b6
Change minimum supported SQLite version to 3.31.0 (#59073) 2021-11-04 16:34:35 +01:00
Erik Montnemery 2f3dea30e2
Correct migration to recorder schema 22 (#59048) 2021-11-04 10:29:10 +01:00
Erik Montnemery 34e5596375
Use async_track_utc_time_change to schedule short term statistics (#58903) 2021-11-01 10:49:54 -07:00
Marc Mueller 84618fa831
Use assignment expressions 30 (#58714) 2021-10-30 16:33:42 +02:00
Erik Montnemery dfa50a842a
Simplify recorder PgSQL version checks (#58533) 2021-10-27 16:05:40 +02:00
Erik Montnemery ac5e32d648
Corrections for external statistics (#58469) 2021-10-26 14:05:45 +02:00
Erik Montnemery e9ba5f3b4b
Warn when recorder connects to an unsupported database (#58161) 2021-10-26 13:41:59 +02:00
Erik Montnemery f594bc353b
Add support for external statistics (#56607)
* Support external statistics

* Update tests

* Lint

* Adjust code after rebase

* Separate external statistic_id with :, add name to metadata

* Adjust tests

* Simplify get_metadata_with_session

* Address review comments

* Allow updating external statistics

* Validate input

* Adjust tests after rebase

* Pylint

* Adjust tests

* Improve test coverage
2021-10-26 10:26:50 +02:00
Erik Montnemery ab2ff45726
Warn if state_changed events are excluded from recorder (#58021) 2021-10-22 14:25:36 +02:00
Erik Montnemery b301ab25a3
Purge short term statistics (#58028)
* Purge short term statistics

* Less meep

* Add tests
2021-10-20 16:00:59 +02:00
Erik Montnemery e3534eec87
Report orphaned statistics in statistic validation (#57324) 2021-10-20 15:57:22 +02:00
Erik Montnemery 9a26a8cfd8
Add support for daily and monthly statistics (#57576)
* Add support for daily and monthly statistics

* Remove debug code

* Format code

* Don't use dateutil package

* Remove 2 TODOs

* Remove TODO

* Add comments
2021-10-19 08:29:23 +02:00
Marc Mueller aa7dc78a1e
Use assignment expressions 11 (#57792) 2021-10-17 20:15:48 +02:00
Erik Montnemery 8ef8838801
Correct detection of row_number support for MariaDB (#57663) 2021-10-14 11:19:39 -07:00
Erik Montnemery ee98849360
Always include start point for statistics (#57182) 2021-10-12 10:39:36 -07:00
Erik Montnemery 0139bfa749
Detect if mysql and sqlite support row_number (#57475) 2021-10-11 21:17:18 -07:00
Erik Montnemery be61009030
Correct SQL query generated by get_metadata_with_session (#57225)
Co-authored-by: Franck Nijhof <git@frenck.dev>
2021-10-07 13:23:23 -07:00
Erik Montnemery 947ae23749
Add home-assistant/core as codeowner for recorder (#57224) 2021-10-07 08:56:43 +02:00
Erik Montnemery 8337baa354
Correct migration to recorder schema 18 (#57165) 2021-10-06 13:29:42 +02:00
Erik Montnemery 8567aa9e13
Evict purged states from recorder's old_state cache (#56877)
Co-authored-by: J. Nick Koston <nick@koston.org>
2021-10-04 08:21:40 -07:00
Erik Montnemery dfb3a0c528
Correct database migration to schema version 22 (#56848) 2021-09-30 14:11:00 -07:00
Erik Montnemery 6af1a835e6
Optimize statistics generation (#56821)
* Optimize statistics generation

* pylint
2021-09-30 17:14:36 +02:00
Erik Montnemery a966714032
Minor cleanup of recorder statistics code (#55339) 2021-09-29 11:42:39 -07:00
Erik Montnemery 40ecf22bac
Remove automatic splitting of net meters from statistics (#56772) 2021-09-29 17:20:17 +02:00
Erik Montnemery 00651a4055
Optimize _get_states_with_session (#56734)
* 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
Marc Mueller 565a9fea6b
Import Callable from collections.abc (2) (#56776) 2021-09-29 14:06:51 +02:00
Erik Montnemery 52e9f76f94
Tweak DB migration to schema version 21 (#56767) 2021-09-29 11:25:50 +02:00
Erik Montnemery 552485bb05
Tweak list_statistic_ids (#55845)
Co-authored-by: Paulus Schoutsen <balloob@gmail.com>
2021-09-28 00:05:26 -07:00
Erik Montnemery 8ef123259e
Add WS API for updating unit_of_measurement in statistics metadata (#56184)
* 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 (#55078)
* 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 fe66d6295c
Improve migration to recorder schema version 21 (#56204) 2021-09-27 19:31:40 +02:00
Erik Montnemery 64393b462d
Add migration for 5-minute statistics (#56585)
* Add migration for 5-minute statistics

* Tweaks
2021-09-24 09:19:22 +02:00
Erik Montnemery f0a4a89d21
Add comments to recorder statistics code (#56545)
* Add comments to recorder statistics code

* Revert accidental change of list_statistic_ids
2021-09-23 13:14:45 +02:00
Erik Montnemery 92253f5192
Minor refactoring of periodic statistics (#56492) 2021-09-22 13:31:33 -07:00