Commit graph

96 commits

Author SHA1 Message Date
Erik Montnemery
48f7924e9e
Allow specifying a custom log function for template render ()
* Allow specifying a custom log function for template render

* Bypass template cache when reporting errors + fix tests

* Send errors as events

* Fix logic for creating new TemplateEnvironment

* Add strict mode back

* Only send error events if report_errors is True

* Force test of websocket_api only

* Debug test

* Run pytest with higher verbosity

* Timeout after 1 minute, enable syslog output

* Adjust timeout

* Add debug logs

* Fix unsafe call to WebSocketHandler._send_message

* Remove debug code

* Improve test coverage

* Revert accidental change

* Include severity in error events

* Remove redundant information from error events
2023-09-06 10:03:35 +02:00
Erik Montnemery
7e36da4cc0
Small cleanup of WS command render_template () 2023-09-04 14:17:30 -04:00
Allen Porter
7b1c0c2df2
Extend template entities with a script section ()
* Extend template entities with a script section

This allows making a trigger entity that triggers a few times a day,
and allows collecting data from a service resopnse which can be
fed into a template entity.

The current alternatives are to publish and subscribe to events or to
store data in input entities.

* Make variables set in actions accessible to templates

* Format code

---------

Co-authored-by: Erik <erik@montnemery.com>
2023-09-02 16:19:45 -07:00
Marc Mueller
582499a260
Improve async_track_template_result callback typing () 2023-07-24 12:42:17 +02:00
Erik Montnemery
78880f0c9d
Fix execute device actions with WS execute_script () 2023-07-03 14:21:01 -04:00
J. Nick Koston
2aff138b92
Small improvements to websocket api performance () 2023-07-02 12:33:25 -05:00
Erik Montnemery
e18f7dffb0
Teach validate_config to validate lists of conditions ()
* Teach validate_config to validate lists of conditions

* Update test
2023-06-27 19:44:23 +02:00
Paulus Schoutsen
5f14cdf69d
Allow stopping a script with a response value () 2023-06-27 08:24:22 +02:00
J. Nick Koston
e1b7d68134
Speed up processing subscribe_events and subscribe_entites when user has read all permissions ()
Speed up processing subscribe_events and subscribe_entites when user the read all permissions
2023-05-27 19:59:46 -04:00
J. Nick Koston
b993fe1c9d
Cache generation of the service descriptions () 2023-05-16 21:42:37 -05:00
J. Nick Koston
99265a983a
Speed up reconnects by caching state serialize () 2023-05-16 02:33:12 -05:00
J. Nick Koston
8711735ec0
Improve websocket throughput and reduce latency () 2023-05-13 00:13:57 +09:00
J. Nick Koston
e7e7f603c2
Remove async_response from websocket apis where nothing was being awaited () 2023-03-23 20:53:18 -04:00
J. Nick Koston
48b93e03ee
Cache transient templates compiles provided via api ()
* Cache transient templates compiles provided via api

partially fixes  (there is more going on here)

* add a bit more coverage just to be sure

* switch method

* Revert "switch method"

This reverts commit 0e9e1c8cbe.

* tweak

* hold hass

* empty for github flakey
2023-03-02 21:31:12 -05:00
epenet
ba23816a0c
Inverse json import logic ()
* Fix helpers and util

* Adjust components

* Move back errors

* Add report

* mypy

* mypy

* Assert deprecation messages

* Move test_json_loads_object

* Adjust tests

* Fix rebase

* Adjust pylint plugin

* Fix plugin

* Adjust references

* Adjust backup tests
2023-02-16 11:37:57 +01:00
J. Nick Koston
0f4b17755e
Improve logging and handling when websocket gets behind ()
fixes undefined
2023-01-29 10:49:27 -10:00
Franck Nijhof
e738924780
Enable Ruff SIM105 ()
* Enable Ruff SIM105

* Adjust existing cases
2023-01-26 21:06:22 -05:00
Franck Nijhof
79b52a2b41
Stricter pylint message control () 2023-01-20 13:47:55 +01:00
J. Nick Koston
57239769ba
Only build compressed states once () 2023-01-09 12:07:32 -10:00
Jan Bouwhuis
23bc39b7f4
Add type hints on Template().__init__() () 2022-11-23 20:26:55 +01:00
Franck Nijhof
bb287dd0ed
Integrations v2.1: Virtual integrations () 2022-10-20 23:09:06 -04:00
Charles Garwood
58d531841b
Fix typo SIGNAL_BOOTSTRAP_INTEGRATONS -> SIGNAL_BOOTSTRAP_INTEGRATIONS () 2022-10-09 17:06:28 -10:00
Erik Montnemery
b173ae7f44
Add support for integrations v2 ()
Co-authored-by: Martin Hjelmare <marhje52@gmail.com>
2022-09-28 11:31:48 -04:00
Franck Nijhof
a19a7e64d5
Fix WebSocket condition testing () 2022-09-16 11:18:00 +02:00
Paulus Schoutsen
0e734e629c
Handle missing supported brands () 2022-09-09 07:47:33 +02:00
J. Nick Koston
f6a03625ba
Implement websocket message coalescing ()
Co-authored-by: Paulus Schoutsen <paulus@home-assistant.io>
2022-08-24 22:50:48 -05:00
J. Nick Koston
61cc9f5288
Consolidate executor jobs when loading integration manifests () 2022-07-14 13:06:08 -07:00
Paulus Schoutsen
41ec8cd354
Expose supported brands via API () 2022-07-12 13:49:54 -07:00
J. Nick Koston
8b067e83f7
Initial orjson support take 3 ()
* Initial orjson support take 2

Still need to work out problem building wheels

--

Redux of  /  Now possible since the following is solved:
 (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 ()" ()
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 () 2022-05-31 12:18:11 -07:00
J. Nick Koston
78f0716574
Add support for specifying the integrations manifest/list fetches ()
* Add support for specifying the integrations manifest/list fetches

See https://github.com/home-assistant/core/pull/71979 for
the motovation

* Update homeassistant/components/websocket_api/commands.py

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

Co-authored-by: Paulus Schoutsen <paulus@home-assistant.io>
2022-05-17 01:22:56 -05:00
J. Nick Koston
d612b9e0b4
Reduce event loop overhead for listeners that already queue ()
Co-authored-by: Paulus Schoutsen <paulus@home-assistant.io>
2022-05-05 23:09:10 -04:00
J. Nick Koston
fe6a4bfb1d
Remove EVENT_TIME_CHANGED and EVENT_TIMER_OUT_OF_SYNC ()
Co-authored-by: Martin Hjelmare <marhje52@gmail.com>
2022-04-09 09:05:54 -10:00
J. Nick Koston
ea6da674df
Remove unneeded permissions check from subscribe entities () 2022-03-12 13:30:27 -08:00
J. Nick Koston
0d8f649bd6
Websocket api to subscribe to entities (payloads reduced by ~80%+ vs state_changed events) () 2022-03-11 20:54:49 -08:00
Paulus Schoutsen
7f4faafe38
Add type code that is being ignored () 2022-02-26 13:56:47 -08:00
J. Nick Koston
c9e46d360b
Use compact encoding for JSON websocket messages ()
Co-authored-by: Paulus Schoutsen <balloob@gmail.com>
2022-02-23 22:15:20 -08:00
Paulus Schoutsen
a42547c0e5
Allow get_states to recover () 2022-02-23 21:15:48 -08:00
Paulus Schoutsen
756e711850
Add a new validate config WS command () 2022-02-22 22:28:37 +01:00
Mike Degatano
8ea6cbc257
Support variables in templates with timeout () 2022-02-21 09:56:20 -08:00
Marc Mueller
b2ee7cebc9
Improve setup_time typing () 2022-02-14 14:24:58 +01:00
Erik Montnemery
8d6e2ae354
Import persistent notification part 1 () 2022-01-11 17:24:59 +01:00
Marc Mueller
198ade5e2b
Fix typing TrackTemplateResultListener [helpers.event] () 2022-01-06 13:43:54 -10:00
Nico Müller
cf1df5ff38
Add 'fire_event' command to websocket api ()
Co-authored-by: Paulus Schoutsen <paulus@home-assistant.io>
2022-01-05 12:28:40 -08:00
Michael
90e52cd3ad
Use relative imports [S-Z] () 2021-12-13 09:39:13 +01:00
Erik Montnemery
caf5ee2fab
Remove optional validation when creating conditions () 2021-11-28 14:54:07 +01:00
Marc Mueller
aa7dc78a1e
Use assignment expressions 11 () 2021-10-17 20:15:48 +02:00
Ville Skyttä
470f2dd73f
Upgrade pyupgrade to 2.21.2, apply its changes () 2021-07-19 10:46:09 +02:00
Ruslan Sayfutdinov
42ff687c32
Add missing type hints to websocket_api () 2021-05-21 09:39:18 -07:00