Commit Graph

2358 Commits (1e02260bbe29d48021b603872d31b2c856baf03f)

Author SHA1 Message Date
J. Nick Koston fb4e8a4f3b
Start the debouncer task eagerly (#111569) 2024-02-26 16:29:46 -10:00
J. Nick Koston ae2ce99cbd
Create tasks eagerly in the discovery flow helper (#111557)
The likely outcome from most discoveries is an near immediate abort
so we run them eagerly to avoid having to schedule on the event loop
for the common case
2024-02-26 20:52:04 -05:00
J. Nick Koston b75277cc24
Use an eager task to update multiple entities (#111556)
If there are multiple entities on the same platform its likely
that only one of them will suspend in the update so schedule
them eagerly
2024-02-26 20:49:09 -05:00
J. Nick Koston dd80157dc7
Load translations at setup time if they were not loaded at bootstrap (#110921) 2024-02-24 11:31:25 -10:00
J. Nick Koston 5b8591ec7e
Avoid reschedule churn in Storage.async_delay_save (#111091)
* Avoid circular import in Storage.async_delay_save

We call Storage.async_delay_save for every entity being added or removed
from the registry. The late import took more time than everything else
in the function.

* Avoid reschedule churn in Storage.async_delay_save

When we are adding or removing entities we will call async_delay_save
quite often which has to add and remove a TimerHandle on the event loop
which can add up when there are a lot of registry items changing.

If the timer handle still has 80% of the time remaining on it
we will avoid resceduling and let it fire at the time the
original async_delay_save call was made. This ensures we
do not force the event loop to rebuild its heapq because
too many timer handlers were cancelled at once

* div0

* add coverage for 0 since we had none

* fix bad conflict

* tweaks

* tweaks

* tweaks

* tweaks

* tweaks

* tweaks

* more test fixes

* mqtt tests rely on event loop overhead
2024-02-24 08:46:00 +01:00
J. Nick Koston ff0e0b3e77
Convert debouncer async_shutdown to be a normal function (#111257)
* Convert debouncer async_shutdown to be a normal function

nothing was being awaited here and the shutdown call was only used
in integrations marked internal and other internals. Its possible
that a custom component might have been using the method but it
seemed uncommon enough that it did not warrent marking as a breaking
change. The update coordinator is no longer awaiting anything in
async_shutdown either now but it seemed likely that this use
would get subclassed.

* fix
2024-02-24 08:37:33 +01:00
J. Nick Koston d9addc45f9
Avoid scheduling a task to add each entity when not using update_before_add (#110951)
Co-authored-by: Paulus Schoutsen <balloob@gmail.com>
2024-02-23 10:49:26 -10:00
J. Nick Koston 125de17a09
Avoid linear search to remove from the entity registry index (#111138)
Avoid linear search to remove from entity registry index

Because the entity registry index needs to preserve insertion order
for backwards compat, a list was used for the index. Because some
config entries/devices/areas have a large amount of entities, removing
the entities, the O(n) time complexity of removing from a list can
slow down reloads. As python has no orderedset in stdlib, use
a dict since it preserves insertion order has O(1) add/remove
time complexity for the average case
2024-02-23 13:57:59 -05:00
J. Nick Koston b5a2df1951
Refactor keyed event trackers to reduce future refactoring risk (#111150)
* Refactor keyed event trackers to avoid refactoring risk

Follow to https://github.com/home-assistant/core/pull/110978#discussion_r1496771106

I had to do some type ignores because of the EventType vs Event
which is hopefully not going to be needed after the next mypy

* delete constants only used one in other const

* no field

* fixes

* less refactoring later

* less refactoring later

* keep const
2024-02-23 13:55:02 -05:00
J. Nick Koston 5e16602595
Refactor storage collections to reduce tasks during startup (#111182)
* Make adding entities in storage collection a normal function

Nothing is awaited when adding

* cleanup

* cleanup

* cleanup

* cleanup

* reduce

* reduce

* reduce

* reduce

* tweak
2024-02-23 13:50:25 -05:00
J. Nick Koston 3877a56d23
Avoid creating tasks for automation and script validation (#111181)
These functions created tasks to run small validators, and the cost of
creating all the tasks was more expensive than running the validators
themselves. Since the code is unlikely to suspend its more efficient to
await them in series.
2024-02-23 13:41:36 -05:00
Joost Lekkerkerker 730d805876
Enable SIM114 ruff rule (#111125) 2024-02-23 13:21:59 +01:00
J. Nick Koston 5bf8086a2b
Cache formatting of mac addresses (#111140) 2024-02-22 07:09:56 -10:00
J. Nick Koston 1de83140ab
Avoid circular import in Storage.async_delay_save (#111086) 2024-02-21 12:45:59 -06:00
J. Nick Koston 7bf0fb9e48
Avoid late import of area registry in device registry if its not used (#111081) 2024-02-21 12:45:00 -06:00
J. Nick Koston 776a9b8691
Make device registry cleanup a callback function (#111052)
* Add async_schedule_call to the Debouncer

async_schedule_call allows the Debouncer to schedule a call
from a callback without having to create tasks to run
async_call

* Update homeassistant/helpers/debounce.py

* Make device registry cleanup all callback function

* fix typing, code supported callback functions, but typing did not

* fixes

* fixes

* fix

* we had no coverage for other job types

* we had no coverage for other job types
2024-02-21 09:34:49 +01:00
J. Nick Koston 5b73adba20
Revert "Reduce dict lookups in entity registry indices" (#111055)
Revert "Reduce dict lookups in entity registry indices (#109712)"

This reverts commit 440212ddce.
2024-02-21 07:11:58 +01:00
J. Nick Koston 490c03d248
Add async_schedule_call to the Debouncer (#111051) 2024-02-21 00:09:45 -06:00
J. Nick Koston 1a02330bd9
Avoid creating tasks to remove entities (#110967) 2024-02-20 21:32:36 -06:00
J. Nick Koston 9ce1ec414e
Reduce overhead to load multiple languages in translations (#111028)
* Reduce overhead to load multiple languages in translations

Instead of loading in a task, we now group everything
to be loaded into a single executor job

* fixes

* fixes

* fixes

* fixes

* fixes

* update tests

* add missing coverage (was existing)
2024-02-20 21:52:28 -05:00
J. Nick Koston 9c145b5faa
Fix race in removing entities from the registry (#110978) 2024-02-20 20:48:31 -06:00
J. Nick Koston dc4008c518
Avoid creating tasks to shutdown entity platforms (#111026)
* Avoid creating tasks to shutdown entity platforms

Nothing needed to be awaited here

* fix mocking

* missed one test
2024-02-20 21:10:25 -05:00
Michael Hansen ec4bd9a421
Add new intents for cover, valve, vacuum, and media player (#110757)
* Add valve to HassTurnOn/Off

* Add set position for valves

* Add set position to covers

* Add HassTurnOn/Off for vacuums

* Add media player intents

* Split out vacuum intents

* Address comments

* Extra test
2024-02-19 22:28:42 -05:00
Franck Nijhof e0a9dcd996
Add label registry (#110821) 2024-02-19 11:59:08 +01:00
J. Nick Koston c74958dd36
Reduce one iteration of pending flows in the discovery flow helper (#110918) 2024-02-19 09:57:39 +01:00
Marc Mueller 72ccc40c43
Add better HassJob typing for IntegrationPlatform process_job (#110896) 2024-02-18 16:46:48 -06:00
Franck Nijhof 67ac60d042
Add hex color validator (#110846) 2024-02-18 16:03:21 +01:00
Franck Nijhof 70d1bbb20d
Improve floor registry event typing (#110844) 2024-02-18 14:57:15 +01:00
J. Nick Koston 16653ff5d0
Group loading of translations for integrations to reduce executor jobs at startup (#110674) 2024-02-17 21:08:55 -06:00
J. Nick Koston 9bc130c131
Ensure translations for other integrations can be loaded if one integration fails (#110748)
* load failure

* merge
2024-02-17 21:01:36 -05:00
J. Nick Koston 0d4c82b54d
Convert Integration platforms processors where nothing is awaited to callbacks (#110825)
Convert Integration platforms processors where nothing is awaited callbacks
2024-02-17 20:49:47 -05:00
J. Nick Koston 165d79b553
Add typing of EVENT_COMPONENT_LOADED to integration_platform helper (#110826) 2024-02-17 20:48:46 -05:00
J. Nick Koston 33ff6b5b6e
Avoid creating tasks for checking integrations platforms (#110795)
* Avoid creating tasks for checking integrations platforms

This is a followup to #110743 to avoid creating a task to check
if the integration platform exists. We created tasks because
we needed to await async_get_integrations but since its always
called from EVENT_COMPONENT_LOADED firing, we can use the
async_get_loaded_integration version which does not need
to be awaited. This eliminates one task for every loaded
component

* there is no more race risk

* reduce

* coro or callback

* reduce

* tweak

* race safe

* fix type

* fixes

* use built-in helper to make it smaller

* use built-in helper to make it smaller

* use built-in helper to make it smaller

* add coverage to ensure exceptions are logged

* improve readability a bit

* platforms
2024-02-18 01:07:18 +01:00
Franck Nijhof 4570eed6f6
Add floor registry (#110741)
Co-authored-by: Paulus Schoutsen <balloob@gmail.com>
Co-authored-by: Martin Hjelmare <marhje52@gmail.com>
2024-02-17 21:21:15 +01:00
J. Nick Koston 664285b9d4
Small performance improvement in tracking template results (#110622)
- Avoid inner function creation each refresh
- remove extra unneeded checks from ratelimit
2024-02-17 18:08:24 +01:00
J. Nick Koston 42cf081582
Avoid creating tasks to load integration platforms that do not exist (#110743) 2024-02-17 07:02:51 -06:00
J. Nick Koston 2cb0249f0a
Add filter to translation event listeners to avoid creating tasks (#110732) 2024-02-16 12:13:23 -06:00
J. Nick Koston 53062a81cc
Simplify loading of icons (#110687) 2024-02-16 16:51:14 +01:00
G Johansson cb776593cf
Make context in data entry flow possible to modify for subclasses (#110561)
* Make context in data entry flow possible to modify for subclasses

* mypy

* Make get_context

* base view

* Review comments

* Remove context from options flow
2024-02-16 15:51:51 +01:00
J. Nick Koston dd1cf2c593
Remove unneeded list copy in icon helper (#110680) 2024-02-15 16:33:24 -06:00
deosrc e38cb01d81
Add missing log message for error resolving OAuth token (#107606) 2024-02-11 13:07:54 +00:00
chammp a5cc0ae890
Improve package schema validation (#108125)
* Add failing tests for package config validation error wrapping

* Wrap package schema validation errors in HomeAssistantError

* Fix yamllint errors

* Rework package merge validation

Ignore invalid package definitions instead of failing startup.
Output error messages with locations if possible when a package
definition has errors.

* Ruff format

* Fix linter errors

* Move package_definition_schema to module scope

* Move inner function to module level

* Merge exception handlers

Merge exception handlers for config schema validation and package merge
to avoid untested code branches

* Fix long lines and doc strings

* More minor changes to exception handler

---------

Co-authored-by: Erik Montnemery <erik@montnemery.com>
2024-02-10 20:16:20 +01:00
Piotr Machowski a2f4e99994
Add state_translated function to jinja templates (#96906)
* Add state_translated jinja function

* Add tests for load_state_translations_to_cache and get_cached_translations

* Cleanup state_translated template

* Add tests for state_translated jinja function

* Apply black formatting

* Improve code quality

* Apply suggestions from code review

Co-authored-by: Erik Montnemery <erik@montnemery.com>

* Apply suggestions from code review

* Prevent invalid components from loading translations

* Refactor loading translations to cache

* Adjust code issues

* Update homeassistant/helpers/translation.py

Co-authored-by: Erik Montnemery <erik@montnemery.com>

* Refactor listeners that trigger translation loading

* Apply suggestions from code review

Co-authored-by: Erik Montnemery <erik@montnemery.com>

* Apply suggestions from code review

* Adjust invalid function calls, fix code styling

* Adjust code quality

* Extract async_translate_state function

* Apply suggestions from code review

Co-authored-by: Erik Montnemery <erik@montnemery.com>

* Apply suggestions from code review

* Fix tests

* Fix tests

---------

Co-authored-by: Piotr Machowski <PiotrMachowski@users.noreply.github.com>
Co-authored-by: Erik Montnemery <erik@montnemery.com>
2024-02-10 10:47:56 +01:00
J. Nick Koston 9689cb448d
Avoid linear search of entity registry in async_extract_referenced_entity_ids (#109667)
* Index area_ids in the entity registry

I missed that these are used in _resolve_area in search.

Eventually we can make async_extract_referenced_entity_ids
a bit faster with this as well

* Avoid linear search of entity registry in async_extract_referenced_entity_ids

needs https://github.com/home-assistant/core/pull/109660
2024-02-09 09:42:30 -05:00
Michael d049928be7
Log error and continue on parsing issues of translated strings (#110046) 2024-02-09 08:35:12 +01:00
Michael Hansen 2681dae60c
Matching duplicate named entities is now an error in Assist (#110050)
* Matching duplicate named entities is now an error

* Update snapshot

* Only use area id
2024-02-08 19:38:03 -06:00
Michael Hansen 1750f54da4
Assist fixes (#109889)
* Don't pass entity ids in hassil slot lists

* Use first completed response

* Add more tests
2024-02-07 15:13:42 -06:00
Joost Lekkerkerker 59e9010b65
Show domain in oauth2 error log (#109708)
* Show token url in oauth2 error log

* Fix tests

* Use domain
2024-02-06 23:03:35 +01:00
J. Nick Koston 09c609459d
Fix entity services targeting entities outside the platform when using areas/devices (#109810) 2024-02-06 12:41:57 -06:00
J. Nick Koston 440212ddce
Reduce dict lookups in entity registry indices (#109712) 2024-02-05 17:23:53 -05:00