Commit graph

263 commits

Author SHA1 Message Date
J. Nick Koston
c615b52840
Refactor integration startup time to show wall clock time (#113707)
* Refactor setup time tracking to exclude time waiting on other operations

We now exclude the import time and th time waiting on
base platforms to setup from the setup times

* tweak

* tweak

* tweak

* tweak

* adjust

* fixes

* fixes

* preen

* preen

* tweak

* tweak

* adjust

* tweak

* reduce

* do not count integrtion platforms against their parent integration

* handle legacy tts platforms

* stt as well

* one more wait

* use the same pattern in all the legacy

* fix tts and stt legacy

* fix

* fix

* reduce

* preen

* entity comp does not wait for platforms

* scene blocks as well

* fix test

* test fixes

* coverage

* coverage

* coverage

* fix test

* Update tests/test_setup.py

Co-authored-by: Martin Hjelmare <marhje52@gmail.com>

* Update tests/test_setup.py

Co-authored-by: Martin Hjelmare <marhje52@gmail.com>

* Update homeassistant/setup.py

Co-authored-by: Martin Hjelmare <marhje52@gmail.com>

* strip

* strip WAIT_PLATFORM_INTEGRATION

* strip WAIT_PLATFORM_INTEGRATION

* strip WAIT_PLATFORM_INTEGRATION

* strip WAIT_PLATFORM_INTEGRATION

* remove complexity

* Apply suggestions from code review

* no longer works that way

* fixes

* fixes

* fixes

---------

Co-authored-by: Martin Hjelmare <marhje52@gmail.com>
2024-03-18 21:45:34 -04:00
J. Nick Koston
9be5f3531f
Run websocket shutdown listener with run_immediately (#113727) 2024-03-18 11:59:44 -10:00
Sid
82a60fe8ad
Enable Ruff RSE (#113695) 2024-03-18 00:40:38 +01:00
Sid
6ee273a548
Clean up unneeded ruff noqa directives (#113616) 2024-03-16 09:48:37 -10:00
J. Nick Koston
a66399ad3d
Add Event typing to websocket_api for entity subscriptions (#112786) 2024-03-08 22:29:46 -05:00
Marc Mueller
3db28d46b2
Replace EventType with Event [t-z] (#112742) 2024-03-08 19:37:26 +01:00
Marc Mueller
c773d57d39
Add empty line after module docstring [w-z] (#112706) 2024-03-08 10:35:45 -05:00
Marc Mueller
8ca127df2a
Use KEY_HASS [h-z] (#112610) 2024-03-07 18:03:44 +01:00
J. Nick Koston
c1750f7c3a
Fix circular imports in core integrations (#111875)
* Fix circular imports in core integrations

* fix circular import

* fix more circular imports

* fix more circular imports

* fix more circular imports

* fix more circular imports

* fix more circular imports

* fix more circular imports

* fix more circular imports

* adjust

* fix

* increase timeout

* remove unused logger

* keep up to date

* make sure its reprod
2024-02-29 21:04:41 -05:00
J. Nick Koston
ebdfff4037
Reduce latency to connect websocket writer (#111559)
Reduce latancy to connect websocket writer

Use an eager start task to start the writer
2024-02-26 20:52:53 -05:00
J. Nick Koston
67e356904b
Add support for eager tasks (#111425)
* Add support for eager tasks

python 3.12 supports eager tasks

reading:
https://docs.python.org/3/library/asyncio-task.html#eager-task-factory
https://github.com/python/cpython/issues/97696

There are lots of places were we are unlikely to suspend, but we might
suspend so creating a task makes sense

* reduce

* revert entity

* revert

* coverage

* coverage

* coverage

* coverage

* fix test
2024-02-26 11:36:46 -05:00
J. Nick Koston
def6c5c21c
Refactor integration startup time tracking to reduce overhead (#110136)
* Refactor integration startup time tracking to reduce overhead

- Use monotonic time for watching integration startup time as it avoids incorrect values if time moves backwards because of ntp during startup and reduces many time conversions since we want durations in seconds and not local time

- Use loop scheduling instead of a task

- Moves all the dispatcher logic into the new _WatchPendingSetups

* websocket as well

* tweaks

* simplify logic

* preserve logic

* preserve logic

* lint

* adjust
2024-02-17 21:47:55 -05:00
J. Nick Koston
9cf45882a7
Use bytes join fast path for large states payload (#110694)
b"".join has a fast path for when there are more than two bytes-strings
to combine

f383ca1a6f/Objects/stringlib/join.h (L123)
2024-02-16 07:58:11 +01:00
Marc Mueller
8b0c9d3d18
Use builtin TimeoutError [t-z] (#109683) 2024-02-05 12:20:36 +01:00
J. Nick Koston
2eea658fd8
Convert getting and removing access tokens to normal functions (#108670) 2024-01-22 20:51:33 -10:00
J. Nick Koston
0b3bcca49b
Avoid string decode/encode round trip in websocket_api get_services (#108632)
The cache was converting from bytes to str and when we read
the cache we converted it back to bytes again
2024-01-21 22:53:45 -05:00
J. Nick Koston
dbb5645e63
Significantly reduce websocket api connection auth phase latency (#108564)
* Significantly reduce websocket api connection auth phase latancy

Since the auth phase has exclusive control over the websocket
until ActiveConnection is created, we can bypass the queue and
send messages right away. This reduces the latancy and reconnect
time since we do not have to wait for the background processing
of the queue to send the auth ok message.

* only start the writer queue after auth is successful
2024-01-21 22:33:31 -05:00
J. Nick Koston
b4b041d4bf
Small cleanups to the websocket api handler (#108274) 2024-01-18 08:39:49 +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
6ada825805
Use faster is_admin check for websocket state and event subscriptions (#107621) 2024-01-13 10:42:41 -10:00
J. Nick Koston
71aecab38b
Revert "Restrict Version Disclosure to Authenticated Requests in Home Assistant" (#107904) 2024-01-12 11:06:59 -10:00
Mikail Tunç
46a06bc8cd
Restrict Version Disclosure to Authenticated Requests in Home Assistant (#107458) 2024-01-12 09:34:18 +01:00
J. Nick Koston
d04e2d56da
Add support for JSON fragments (#107213) 2024-01-07 17:36:31 -10:00
J. Nick Koston
03fcb81a59
Small speed up to compressed state diff (#106624) 2023-12-29 08:36:20 +01:00
Ville Skyttä
24b1e01d71
Update Ruff to 0.1.8, avoid linter/formatter conflicts (#106080)
* Disable Ruff rules that may conflict with the formatter

* Upgrade Ruff to 0.1.8

- https://github.com/astral-sh/ruff/releases/tag/v0.1.7
- https://github.com/astral-sh/ruff/releases/tag/v0.1.8

* Format with Ruff 0.1.8
2023-12-20 23:55:09 +01:00
Jan Bouwhuis
47426a3ddc
Remove redundant websocket_api exception handler (#104727) 2023-11-29 16:56:26 +01:00
Jan Bouwhuis
861bb48ab6
Assign specific error code for HomeAssistantError on websocket_api connection exceptions (#104700)
Assign specific error code for HomeAssistantError
2023-11-29 13:07:52 +01:00
Jan Bouwhuis
efd330f182
Send localization info on websocket_api script errors (#104638)
* Send localization info on script errors

* Use connection exception hander

* Keep HomeAssistantError is unknown_error

* Move specific exception handling
2023-11-29 10:47:23 +01:00
Raman Gupta
618b666126
Add support for responses to call_service WS cmd (#98610)
* Add support for responses to call_service WS cmd

* Revert ServiceNotFound removal and add a parameter for return_response

* fix type

* fix tests

* remove exception handling that was added

* Revert unnecessary modifications

* Use kwargs
2023-11-10 21:44:43 +01:00
J. Nick Koston
da1780f9ec
Small cleanups to process_success_login (#103282) 2023-11-07 10:48:34 +01:00
Jan Bouwhuis
54cf7010cd
Add ServiceValidationError and translation support (#102592)
* Add ServiceValidationError

* Add translation support

* Extend translation support to HomeAssistantError

* Add translation support for ServiceNotFound exc

* Frontend translation & translation_key from caller

* Improve fallback message

* Set websocket_api as default translation_domain

* Add MQTT ServiceValidationError exception

* Follow up comments

* Revert removing gueard on translation_key

* Revert test changes to fix CI test

* Follow up comments

* Fix CI test

* Follow up

* Improve language

* Follow up comment
2023-11-06 15:45:04 +01:00
J. Nick Koston
1a6184a9aa
Allow non-admins to subscribe to the issue registry updated event (#103145) 2023-10-31 16:29:22 -05:00
J. Nick Koston
5648dc6cd1
Reduce string copy needed to subscribe to entities (#102870) 2023-10-28 09:18:25 -05:00
J. Nick Koston
009dc91b97
Fix inner callback decorators with partials (#102873) 2023-10-28 08:38:42 -05:00
J. Nick Koston
653da6e31f
Reduce websocket event and state JSON construction overhead (#101974) 2023-10-15 23:39:09 +02:00
J. Nick Koston
93f10cdce8
Move event permissions out of the websocket api into auth (#101975) 2023-10-15 23:14:19 +02:00
J. Nick Koston
547f32818c
Make core States use cached_property (#100312)
Need to validate this is worth removing __slots__
2023-09-13 20:33:25 -04:00
Erik Montnemery
aedd06b9a9
Tweak entity/source WS command handler (#100272) 2023-09-13 11:14:01 +02:00
Ville Skyttä
fa0b999d08
Upgrade ruff to 0.0.289 (#100238) 2023-09-12 22:22:10 +02:00
Erik Montnemery
51576b7214
Improve typing of entity.entity_sources (#99407)
* Improve typing of entity.entity_sources

* Calculate entity info source when generating WS response

* Adjust typing

* Update tests
2023-09-12 20:41:26 +02:00
Erik Montnemery
fabb098ec3
Simplify WS command entity/source (#99439) 2023-09-12 15:39:11 +02:00
J. Nick Koston
ad4619c038
Speed up serializing event messages (#100017) 2023-09-10 08:25:13 -05:00
Erik Montnemery
1654ef7759
Make WS command render_template not give up if initial render raises (#99808) 2023-09-08 21:02:06 +02:00
Erik Montnemery
e5210c5823
Always set severity level flag on render_template error events (#99804) 2023-09-07 12:00:19 +02:00
Erik Montnemery
48f7924e9e
Allow specifying a custom log function for template render (#99572)
* 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 (#99562) 2023-09-04 14:17:30 -04:00
Allen Porter
7b1c0c2df2
Extend template entities with a script section (#96175)
* 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
Ville Skyttä
3094991236
Upgrade ruff to 0.0.285 (#98647) 2023-08-19 08:17:17 -04:00
Marc Mueller
a9ade1f84d
Use asyncio.timeout [core] (#98447) 2023-08-15 08:36:05 -05:00