Commit graph

285 commits

Author SHA1 Message Date
epenet
0bb8c4832d
Enable raise-within-try (TRY301) rule in ruff () 2024-08-12 09:16:33 +02:00
Erik Montnemery
9b2118e556
Remove recorder from websocket_api after dependencies ()
Co-authored-by: J. Nick Koston <nick@koston.org>
2024-07-22 16:50:05 -05:00
Franck Nijhof
a9bf12f102
Rename Services to Actions in translation strings () 2024-07-15 21:19:25 +02:00
Marc Mueller
0e52d149e4
Update voluptuous to 0.15.2 ()
* Update voluptuous to 0.15.1

* Fix typing issues

* Add type ignores for json result type

* Update voluptuous to 0.15.2

---------

Co-authored-by: J. Nick Koston <nick@koston.org>
2024-07-02 12:57:09 -07:00
Marc Mueller
b816fce976
Improve websocket_api schema typing () 2024-06-25 14:08:30 +02:00
epenet
960d1289ef
Avoid references to websocket_api.const in core and other components () 2024-06-10 13:49:44 +02:00
Erik Montnemery
8099ea8817
Improve WS command validate_config ()
Co-authored-by: epenet <6771947+epenet@users.noreply.github.com>
Co-authored-by: Robert Resch <robert@resch.dev>
2024-06-05 18:53:44 +02:00
J. Nick Koston
79bc179ce8
Improve websocket message coalescing to handle thundering herds better ()
* Increase websocket peak messages to match max expected entities

During startup the websocket would frequently disconnect if more than
4096 entities were added back to back. Some MQTT setups will have more
than 10000 entities. Match the websocket peak value to the max expected
entities

* coalesce more

* delay more if the backlog gets large

* wait to send if the queue is building rapidly

* tweak

* tweak for chrome since it works great in firefox but chrome cannot handle it

* Revert "tweak for chrome since it works great in firefox but chrome cannot handle it"

This reverts commit 439e2d76b1.

* adjust for chrome

* lower number

* remove code

* fixes

* fast path for bytes

* compact

* adjust test since we see the close right away now on overload

* simplify check

* reduce loop

* tweak

* handle ready right away
2024-05-28 23:14:06 -04:00
J. Nick Koston
caa65708fb
Collapse websocket_api _state_diff into _state_diff_event () 2024-05-26 16:04:34 +02:00
Marc Mueller
3b4b36a9fd
Fix partial typing () 2024-05-24 10:24:18 +02:00
J. Nick Koston
c5cc9801a6
Cache serialize of manifest for loaded integrations ()
* Cache serialize of manifest for loaded integrations

The manifest/list and manifest/get websocket apis
are called frequently when moving around in the UI.
Since the manifest does not change we can make
the the serialized version a cached property

* reduce

* reduce
2024-05-23 10:52:05 -04:00
Sid
c2b3bf3fb9
Enable Ruff RET502 () 2024-05-21 22:19:33 +02:00
Marc Mueller
87bb7ced79
Use PEP 695 for simple type aliases () 2024-05-17 14:42:21 +02:00
Sid
2cc916db6d
Replace pylint broad-except with Ruff BLE001 () 2024-05-07 14:00:27 +02:00
Sid
b456d97e65
Replace pylint protected-access with Ruff SLF001 () 2024-05-06 20:33:26 +02:00
J. Nick Koston
9995207817
Avoid re-encoding the message id as bytes for every event/state change () 2024-04-30 12:02:28 -05:00
J. Nick Koston
588c260dc5
Skip processing websocket_api schema if it has no arguments ()
* Skip processing websocket_api schema if has no arguments

About 40% of the websocket commands on first connection have
no arguments. We can skip processing the schema for these cases

* cover

* fixes

* allow extra

* Revert "allow extra"

This reverts commit 85d9ec36b3.

* match behavior
2024-04-18 10:41:08 -04:00
J. Nick Koston
2ec588d2a6
Migrate websocket_api sensor to use shorthand attrs () 2024-04-15 20:40:31 +02:00
J. Nick Koston
ca5ed274cb
Deprecate calling async_listen and async_listen_once with run_immediately () 2024-04-08 10:07:54 -10:00
Marc Mueller
0f03079065
Update import for EventStateChangedData [i-z] () 2024-04-04 11:48:29 -10:00
Sid
a5b609f081
Enable ruff TRY401 ()
* Enable ruff TRY401

* fix tests
2024-03-29 07:20:36 +01:00
Joost Lekkerkerker
6bb4e7d62c
Bump ruff to 0.3.4 ()
Co-authored-by: Sid <27780930+autinerd@users.noreply.github.com>
Co-authored-by: Marc Mueller <30130371+cdce8p@users.noreply.github.com>
Co-authored-by: J. Nick Koston <nick@koston.org>
2024-03-26 00:02:16 +01:00
J. Nick Koston
c615b52840
Refactor integration startup time to show wall clock time ()
* 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 () 2024-03-18 11:59:44 -10:00
Sid
82a60fe8ad
Enable Ruff RSE () 2024-03-18 00:40:38 +01:00
Sid
6ee273a548
Clean up unneeded ruff noqa directives () 2024-03-16 09:48:37 -10:00
J. Nick Koston
a66399ad3d
Add Event typing to websocket_api for entity subscriptions () 2024-03-08 22:29:46 -05:00
Marc Mueller
3db28d46b2
Replace EventType with Event [t-z] () 2024-03-08 19:37:26 +01:00
Marc Mueller
c773d57d39
Add empty line after module docstring [w-z] () 2024-03-08 10:35:45 -05:00
Marc Mueller
8ca127df2a
Use KEY_HASS [h-z] () 2024-03-07 18:03:44 +01:00
J. Nick Koston
c1750f7c3a
Fix circular imports in core integrations ()
* 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 ()
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 ()
* 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 ()
* 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 ()
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] () 2024-02-05 12:20:36 +01:00
J. Nick Koston
2eea658fd8
Convert getting and removing access tokens to normal functions () 2024-01-22 20:51:33 -10:00
J. Nick Koston
0b3bcca49b
Avoid string decode/encode round trip in websocket_api get_services ()
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 ()
* 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 () 2024-01-18 08:39:49 +01:00
J. Nick Koston
60ab360fe7
Avoid bytes to string to bytes conversion in websocket api () 2024-01-16 21:37:34 +01:00
J. Nick Koston
3d595fff13
Avoid duplicate timestamp conversions for websocket api and recorder ()
* 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 () 2024-01-13 10:42:41 -10:00
J. Nick Koston
71aecab38b
Revert "Restrict Version Disclosure to Authenticated Requests in Home Assistant" () 2024-01-12 11:06:59 -10:00
Mikail Tunç
46a06bc8cd
Restrict Version Disclosure to Authenticated Requests in Home Assistant () 2024-01-12 09:34:18 +01:00
J. Nick Koston
d04e2d56da
Add support for JSON fragments () 2024-01-07 17:36:31 -10:00
J. Nick Koston
03fcb81a59
Small speed up to compressed state diff () 2023-12-29 08:36:20 +01:00
Ville Skyttä
24b1e01d71
Update Ruff to 0.1.8, avoid linter/formatter conflicts ()
* 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 () 2023-11-29 16:56:26 +01:00
Jan Bouwhuis
861bb48ab6
Assign specific error code for HomeAssistantError on websocket_api connection exceptions ()
Assign specific error code for HomeAssistantError
2023-11-29 13:07:52 +01:00