Commit Graph

22 Commits (1bf2c4d976c73841f9c4ba94a4da419dbe3ba4b6)

Author SHA1 Message Date
Franck Nijhof 1c2ebdf307
Upgrade black to 20.8b1 (#39287) 2020-08-27 13:56:20 +02:00
J. Nick Koston f8d547f2d3
Adjust history as all scripts can now be canceled (#37820) 2020-07-14 22:31:34 +02:00
Paulus Schoutsen 8ed1a29c82
Drop white blacklist pt1 (#37816) 2020-07-13 17:43:11 +02:00
J. Nick Koston b64ae55c66
Prebake common history queries (#37496)
* Prebake common history queries

The python overhead of to construct
the queries exceeded the database overhead.  We now
prebake the queries that get frequently polled.

This reduces the time it takes to update history_stats
sensors and can make quite a difference if there
are a lot of them.

When using the mini-graph-card card, all the entities
on the card being graphed are queried every few seconds
for new states. Previously this would tie up the database if there
are lot of these graphs in the UI.

* Update homeassistant/components/history/__init__.py

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

* Update homeassistant/components/history/__init__.py

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

* cache entity_filter in the lambda

* switch to yield

* Revert "switch to yield"

This reverts commit f8386f4940.

* get_states always returns a list

* query wasnt actually reusable so revert part of the breakout

Co-authored-by: Paulus Schoutsen <paulus@home-assistant.io>
2020-07-05 11:03:23 -05:00
J. Nick Koston f4528d0db2
Ensure history states can be copied (#37081)
The filter integration makes a copy of a
state object obtained from history.
2020-06-24 22:43:08 -05:00
J. Nick Koston 5b79c1f9ef
Remove support for deprecated hidden attribute from logbook and history (#37039) 2020-06-23 13:40:39 -07:00
J. Nick Koston e19c97af7c
Fix history api with no constraints (#36979) 2020-06-22 10:32:46 -05:00
J. Nick Koston 9cc20fc6b8
Fix history graphs with mysql/mariadb (#36769) 2020-06-13 21:22:16 -07:00
Paulus Schoutsen c33edbe5bb
Use TestCase.addCleanup (#36560) 2020-06-08 12:26:40 -07:00
J. Nick Koston 0a6deeb49b
Improve history api performance (#35822)
* Improve history api performance

A new option "minimal_response" reduces the amount of data
sent between the first and last history states to only the
"last_changed" and "state" fields.

Calling to_native is now avoided where possible and only
done at the end for rows that will be returned in the response.

When sending the `minimal_response` option, the history
api now returns a json response similar to the following
for an entity

Testing:

History API Response time for 1 day
Average of 10 runs with minimal_response

Before: 19.89s. (content length : 3427428)
After: 8.44s (content length: 592199)

```
[{
	"attributes": {--TRUNCATED--},
	"context": {--TRUNCATED--},
	"entity_id": "binary_sensor.powerwall_status",
	"last_changed": "2020-05-18T23:20:03.213000+00:00",
	"last_updated": "2020-05-18T23:20:03.213000+00:00",
	"state": "on"
},
...
{
	"last_changed": "2020-05-19T00:41:08Z",
	"state": "unavailable"
},
...
{
	"attributes": {--TRUNCATED--},
	"context": {--TRUNCATED--},
	"entity_id": "binary_sensor.powerwall_status",
	"last_changed": "2020-05-19T00:42:08.069698+00:00",
	"last_updated": "2020-05-19T00:42:08.069698+00:00",
	"state": "on"
}]
```

* Remove impossible state check

* Remove another impossible state check

* Update homeassistant/components/history/__init__.py

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

* Reorder to save some indent per review

* Make query response make sense with to_native=False

* Update test for 00:00 to Z change

* Update homeassistant/components/recorder/models.py

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

Co-authored-by: Paulus Schoutsen <paulus@home-assistant.io>
2020-05-26 21:53:56 -05:00
J. Nick Koston ebed1de581
Avoid creating multiple sqlalchemy sessions in a single history call (#35721)
* Avoid a context switch in the history api

The history api was creating a job to fetch the
states and another job to convert the states to
json. This can be done in a single job which
decreases the overhead of the operation.

* Ensure there is only one sqlalchemy session created per history
query.

Most queries created three sqlalchemy sessions which was
especially slow with sqlite since it opens and closes the
database.

In testing the UI is noticeably faster at generating history
graphs for entites.

* Add additional coverage

* pass hass first to _states_to_json and _get_significant_states
2020-05-19 07:52:38 +02:00
Paulus Schoutsen 2af984917e
Use asynctest-mock in most places (#35109)
* Use asynctest-mock in most places

* Fix broken patch in pilight
2020-05-03 11:27:19 -07:00
Franck Nijhof 906385172a
String formatting improvements for tests (#33663) 2020-04-05 00:26:08 +02:00
Santobert 0186ce7896
Filter the history of device_tracker by location attributes (#33356)
* Add include_location_attributes

* Add check for different state

* Fix things

* Drop filter

* significant changes only

* Change default behavior

* Remove trailing commas
2020-03-30 08:13:22 -07:00
J. Nick Koston 2360fd4141
Switch legacy calls to init_recorder_component using async_add… (#33185) 2020-03-23 11:27:45 -07:00
J. Nick Koston 3a680bf7b7
Add a commit interval setting to recorder (#32596)
* Add a commit interval setting to recorder

* Make the default every 1s instead of immediate

* See attached py-spy flamegraphs for why 1s

* This avoids disk thrashing during event storms

* Make Home Assistant significantly more responsive on busy systems

* remove debug

* Add commit forces for tests that expect commits to be immediate

* Add commit forces for tests that expect commits to be immediate

* make sure _trigger_db_commit is in the right place (all effective "wait_recording_done" calls)

* De-duplicate wait_recording_done code
2020-03-09 17:43:26 -07:00
Bas Nijholt 8b39957c56 Sort imports according to PEP8 for components starting with "H" (#29768) 2019-12-09 14:19:48 +01:00
Paulus Schoutsen 3649a1b5e9
Filter out empty results in history API (#25633) 2019-08-01 11:52:57 -07:00
Paulus Schoutsen 93c0db2328 Lint 2019-07-31 12:53:07 -07:00
Paulus Schoutsen 4de97abc3a Black 2019-07-31 12:25:30 -07:00
Thomas Lovén 671cb0d092 Return history for entities in the order they were requested (#25560)
* Return history for entities in the order they were requested

* Fix problems. Add tests

* Update __init__.py
2019-07-31 11:59:25 -07:00
Paulus Schoutsen b8cc547fa3
Move components to folders (#20774)
* Move all components into folders

* Move component tests into folders

* Fix init moving

* Move tests

* Lint

* Update coverage

* Fix service descriptions

* Update CODEOWNERS
2019-02-05 19:31:15 -08:00