Commit graph

113 commits

Author SHA1 Message Date
epenet
2c210e4b58
Use root import for websocket_api (#125834) 2024-09-12 19:31:57 +02:00
Marc Mueller
2decf6c023
Use dict instead of MutableMapping [recorder] (#115318) 2024-04-09 15:08:31 -10:00
Marc Mueller
3c5089bc3f
Update import for EventStateChangedData [a-h] (#114899) 2024-04-04 11:48:36 -10:00
J. Nick Koston
1e54595084
Use faster time compare in history and live logbook (#113897) 2024-03-20 19:40:23 -04:00
J. Nick Koston
e74791083e
Fix duplicate events in live history (#113896) 2024-03-20 20:14:17 +01:00
J. Nick Koston
8b9a8a33f4
Start live history/logbook with eager tasks (#113779) 2024-03-18 21:00:51 -10:00
Marc Mueller
8f1e2f1a7b
Replace EventType with Event [h-i] (#112740) 2024-03-08 19:35:47 +01:00
Marc Mueller
8809d3aa88
Add empty line after module docstring [g-i] (#112699) 2024-03-08 08:52:48 -05:00
Marc Mueller
d7e7dc96cc
Make Event data generic (#111955) 2024-03-08 13:46:16 +01:00
Marc Mueller
8ca127df2a
Use KEY_HASS [h-z] (#112610) 2024-03-07 18:03:44 +01:00
J. Nick Koston
f73431ac06
Switch utc_to_timestamp to .timestamp() where possible (#109729)
* Switch utc_to_timestamp to .timestamp()

.timestamp() is faster now in newer cpython

```
from homeassistant.util.dt import utc_to_timestamp, utcnow
import timeit
now = utcnow()
print(timeit.timeit('utc_to_timestamp(now)',globals={"now":now,"utc_to_timestamp":utc_to_timestamp}))
print(timeit.timeit('now.timestamp()',globals={"now":now}))
```

utc_to_timestamp = 0.18721245788037777
timestamp = 0.11421508435159922

* compat

* revert

* revert

* revert

* revert

* revert
2024-02-05 23:04:52 +01:00
J. Nick Koston
60ab360fe7
Avoid bytes to string to bytes conversion in websocket api (#108139) 2024-01-16 21:37:34 +01:00
J. Nick Koston
3d595fff13
Avoid duplicate timestamp conversions for websocket api and recorder (#108144)
* Avoid duplicate timestamp conversions for websocket api and recorder

We convert the time from datetime to timestamps one per
open websocket connection and the recorder for every
state update. Only do the conversion once since its
~30% of the cost of building the state diff

* more

* two more

* two more in live history
2024-01-16 14:05:01 +01:00
J. Nick Koston
50f2c41145
Avoid db hit and executor job for impossible history queries (#104724) 2023-11-29 11:20:22 -07:00
Marc Mueller
2618bfc073
Use EventType for state changed [core] (#97115) 2023-07-23 18:10:03 -05:00
Franck Nijhof
acc4b001cd
Fix history YAML deprecation (#92238) 2023-04-29 08:02:34 -04:00
Harvey
bf4559719a
History API entity_id validation (#90067)
Co-authored-by: J. Nick Koston <nick@koston.org>
2023-04-14 09:41:54 -10:00
rlippmann
f5911bcad6
Add slots to dataclasses in default_config (#91410)
* add dataclass slots to default config items

* remove slots from sun mixing
2023-04-14 14:22:39 -04:00
J. Nick Koston
d0d4ab6056
Require a list of entity ids when fetching history (#90992) 2023-04-08 16:14:44 -10:00
J. Nick Koston
85ca94e9d4
Mark database sessions that do not write data as read_only (#89600)
* Mark sessions that do not write data as read_only

* Mark sessions that do not write data as read_only
2023-03-12 21:33:28 -04:00
J. Nick Koston
977a07de13
Generate large history responses in the executor (#89606) 2023-03-12 21:32:26 -04:00
Erik Montnemery
899adef590
Sort manifests 4 (#87025) 2023-02-08 20:27:05 +01:00
J. Nick Koston
0b0e977ce9
Remove history use_include_order configuration option (#86365) 2023-01-22 17:43:05 +01:00
J. Nick Koston
5ff0479c16
Split history websocket API into its own file (#86364) 2023-01-21 18:45:00 -10:00
J. Nick Koston
8227c84e05
Add support for streaming (push) history (#85892)
* Add support for streaming (push) history

Currently we poll for history data, like logbook we can stream
this data to avoid database overhead

* Update homeassistant/components/history/__init__.py

* merge filter

* expose new api

* expose new api

* expose new api

* expose new api

* coverage

* tests

* fixes

* tweak

* tweak

* tweak

* DRY

* leaky

* test for specific entities

* test for specific entities

* test for specific entities

* test for specific entities

* test for specific entities

* cover

* cover

* more cover

* tweak

* make sure it works before history starts

* fix test

* cover

* tweak

* make sure we unsub on overflow

* Update homeassistant/components/history/__init__.py

* Update homeassistant/components/history/__init__.py

* fix race in test

* fix db executor access

* relo above task creation
2023-01-21 22:03:41 -05:00
Erik Montnemery
1582d88957
Remove deprecated history WS API (#82136) 2022-11-16 12:54:03 +01:00
epenet
5442d6af01
Improve msg type hint in websocket commands (#80530) 2022-10-18 16:41:17 +02:00
Franck Nijhof
2b27cfdabb
Set system & entity integration types (#79593) 2022-10-04 10:36:42 -04:00
Erik Montnemery
7937bfeedb
Deprecate history integration's statistics API (#78056) 2022-09-08 16:03:43 -04:00
J. Nick Koston
8b067e83f7
Initial orjson support take 3 (#73849)
* Initial orjson support take 2

Still need to work out problem building wheels

--

Redux of #72754 / #32153 Now possible since the following is solved:
ijl/orjson#220 (comment)

This implements orjson where we use our default encoder.  This does not implement orjson where `ExtendedJSONEncoder` is used as these areas tend to be called far less frequently.  If its desired, this could be done in a followup, but it seemed like a case of diminishing returns (except maybe for large diagnostics files, or traces, but those are not expected to be downloaded frequently).

Areas where this makes a perceptible difference:
- Anything that subscribes to entities (Initial subscribe_entities payload)
- Initial download of registries on first connection / restore
- History queries
- Saving states to the database
- Large logbook queries
- Anything that subscribes to events (appdaemon)

Cavets:
orjson supports serializing dataclasses natively (and much faster) which
eliminates the need to implement `as_dict` in many places
when the data is already in a dataclass. This works
well as long as all the data in the dataclass can also
be serialized. I audited all places where we have an `as_dict`
for a dataclass and found only backups needs to be adjusted (support for `Path` needed to be added for backups).  I was a little bit worried about `SensorExtraStoredData` with `Decimal` but it all seems to work out from since it converts it before it gets to the json encoding cc @dgomes

If it turns out to be a problem we can disable this
with option |= [orjson.OPT_PASSTHROUGH_DATACLASS](https://github.com/ijl/orjson#opt_passthrough_dataclass) and it
will fallback to `as_dict`

Its quite impressive for history queries
<img width="1271" alt="Screen_Shot_2022-05-30_at_23_46_30" src="https://user-images.githubusercontent.com/663432/171145699-661ad9db-d91d-4b2d-9c1a-9d7866c03a73.png">

* use for views as well

* handle UnicodeEncodeError

* tweak

* DRY

* DRY

* not needed

* fix tests

* Update tests/components/http/test_view.py

* Update tests/components/http/test_view.py

* black

* templates
2022-06-22 21:59:51 +02:00
J. Nick Koston
c365454afb
Revert "Initial orjson support (#72754)" (#72789)
This was causing the wheels to fail to build. We need
to workout why when we don't have release pressure

This reverts commit d9d22a9556.
2022-05-31 13:51:55 -07:00
J. Nick Koston
d9d22a9556
Initial orjson support (#72754) 2022-05-31 12:18:11 -07:00
J. Nick Koston
1f753ecd88
Relocate sqlalchemy filter builder to recorder/filters.py (#71883) 2022-05-14 23:04:23 -07:00
J. Nick Koston
68632cb267
Implement use_include_order in the history websocket api (#71839) 2022-05-14 12:37:35 -07:00
J. Nick Koston
e06ea5e03e
Remove deprecated history function entry points (#71815) 2022-05-13 16:19:26 -04:00
J. Nick Koston
9bd508c0bf
Generate json for history and logbook websocket responses in the executor (#71813) 2022-05-13 13:17:54 -04:00
J. Nick Koston
e2cef55162
Add history/history_during_period websocket endpoint (#71688) 2022-05-11 17:52:22 -05:00
J. Nick Koston
195811843b
Remove get_state and get_states history api calls (#70830) 2022-04-26 16:05:43 -07:00
Pawel
bcb8c7ec3c
Add API endpoint get_statistics_metadata (#68471)
Co-authored-by: Erik Montnemery <erik@montnemery.com>
2022-03-21 21:14:47 -07:00
J. Nick Koston
3150915cb7
Convert unindexed domain queries to entity_id queries (#68404) 2022-03-20 01:28:17 -10:00
J. Nick Koston
816695cc96
Avoid selecting attributes in the history api when no_attributes is passed (#68352) 2022-03-19 23:47:22 -10:00
J. Nick Koston
bc862e97ed
Use a dedicated executor pool for database operations (#68105)
Co-authored-by: Erik Montnemery <erik@montnemery.com>
Co-authored-by: Franck Nijhof <git@frenck.dev>
2022-03-17 23:09:01 -10:00
epenet
946238fb02
Import frontend (#64104)
Co-authored-by: epenet <epenet@users.noreply.github.com>
2022-01-14 10:01:12 +01:00
Erik Montnemery
3b7448bb1c
Import websocket_api (part 2) (#63906) 2022-01-11 17:26:25 +01:00
epenet
533c377bd1
Add setup type hints to history (#63441)
Co-authored-by: epenet <epenet@users.noreply.github.com>
2022-01-05 12:16:56 +01:00
Bram Kragten
6e7712da3c
Add periods to statistics_during_period ws (#59425) 2021-11-09 17:29:39 +01:00
Marc Mueller
b1d49b3b66
Use assignment expressions 29 (#58713) 2021-10-30 16:31:43 +02:00
Marc Mueller
aa7dc78a1e
Use assignment expressions 11 (#57792) 2021-10-17 20:15:48 +02:00
Erik Montnemery
6af1a835e6
Optimize statistics generation (#56821)
* Optimize statistics generation

* pylint
2021-09-30 17:14:36 +02:00
Ville Skyttä
d8d34fdd3b
Prefer HTTPStatus over int in HA view JSON functions (#56504)
* Prefer HTTPStatus over int in HA view JSON functions

* Update zwave tests to not expect a fixed typo
2021-09-22 21:59:52 +03:00