Commit Graph

2765 Commits (d09a274548ef9abb73617fc92781a18becc75766)

Author SHA1 Message Date
J. Nick Koston d48bd9b016
Deprecate async_track_state_change in favor of async_track_state_change_event (#115558) 2024-04-18 10:45:14 -05:00
J. Nick Koston 80d6cdad67
Small cleanups to translation loading (#115583)
- Add missing typing
- Convert a update loop to a set comp
- Save some indent
2024-04-18 10:42:44 -04:00
J. Nick Koston 11931cdb56
Simplify labels and areas template calls (#115673)
The labels and areas are already exposed on the object
2024-04-17 21:28:09 +02:00
J. Nick Koston bd2efffb4a
Reduce duplicate code in the device registry (#115677) 2024-04-17 15:50:39 +02:00
J. Nick Koston 45f025480e
Avoid linear search to remove a label from the entity registry (#115674)
* Avoid linear search to remove a label from the entity registry

* simplify
2024-04-17 15:47:56 +02:00
J. Nick Koston 8cf14c9268
Avoid linear search to clear labels and areas in the device registry (#115676) 2024-04-17 15:46:59 +02:00
J. Nick Koston 9ca24ab2a2
Avoid linear search to remove labels and floors from area registry (#115675)
* Avoid linear search to remove labels and floors from area registry

* simplify
2024-04-17 15:45:40 +02:00
J. Nick Koston cb16465539
Keep track of top level components (#115586)
* Keep track of top level components

Currently we have to do a set comp for icons, translations,
and integration platforms every time to split the top level
components from the platforms. Keep track of the top level
components in a seperate set so avoid having to do the setcomp
every time.

* remove impossible paths

* remove unused code

* preen

* preen

* fix

* coverage and fixes

* Update homeassistant/core.py

* Update homeassistant/core.py

* Update tests/test_core.py
2024-04-17 13:23:20 +02:00
Erik Montnemery 7cd0fe3c5f
Don't reload other automations when saving an automation (#80254)
* Only reload modified automation

* Correct check for existing automation

* Add tests

* Remove the new service, improve ReloadServiceHelper

* Revert unneeded changes

* Update tests

* Address review comments

* Improve test coverage

* Address review comments

* Tweak reloader code + add a targetted test

* Apply suggestions from code review

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

* Explain the tests + add more variations

* Fix copy-paste mistake in test

* Rephrase explanation of expected test outcome

---------

Co-authored-by: Martin Hjelmare <marhje52@gmail.com>
2024-04-16 15:58:57 +02:00
J. Nick Koston dbc5109fd8
Avoid update calls in state writes when attributes are empty (#115624) 2024-04-15 17:42:18 +02:00
J. Nick Koston 3963b3994b
Small cleanups to the rate limit helper (#115621) 2024-04-15 13:42:28 +02:00
J. Nick Koston 33412dd9f6
Remove unused legacy state translations (#112023)
* Remove unused state translations

There have been replaced with entity translations
https://github.com/home-assistant/developers.home-assistant/pull/1557
https://github.com/home-assistant/core/pull/82701

* nothing does merging anymore

* useless dispatch

* remove

* remove platform code from hassfest

* preen

* Update homeassistant/helpers/translation.py

* ruff

* fix merge

* check is impossible now since we already know if translations exist or not

* keep the function for now

* remove unreachable code since we filter out `.` before now

* reduce

* reduce

* fix merge conflict (again)
2024-04-14 07:13:17 -04:00
Sid 3799d20d43
Enable Ruff B905 (#114197) 2024-04-14 00:14:26 -05:00
J. Nick Koston 8da7de1fea
Remove attr usage in event helper (#115554) 2024-04-13 19:46:23 -05:00
J. Nick Koston edd75a9d5f
Fix race in TimestampDataUpdateCoordinator (#115542)
* Fix race in TimestampDataUpdateCoordinator

The last_update_success_time value was being set after the listeners
were fired which could lead to a loop because the listener may
re-trigger an update because it thinks the data is stale

* coverage

* docstring
2024-04-13 16:35:07 -04:00
Marc Mueller 1b24e78dd9
Improve FlowHandler menu_options typing (#115296) 2024-04-11 22:14:37 -04:00
Jan Bouwhuis 10076e6523
Add notify entity component (#110950)
* Add notify entity component

* Device classes, restore state, icons

* Add icons file

* Add tests for kitchen_sink

* Remove notify from no_entity_platforms in hassfest icons, translation link

* ruff

* Remove `data` feature

* Only message support

* Complete initial device classes

* mypy pylint

* Remove device_class implementation

* format

* Follow up comments

* Remove _attr_supported_features

* Use setup_test_component_platform

* User helper at other places

* last comment

* Add entry unload test and non async test

* Avoid default mutable object in constructor
2024-04-11 12:04:08 +02:00
J. Nick Koston f0c8c2a684
Adjust importlib helper to avoid leaking memory on re-raise (#115377) 2024-04-10 15:19:17 -10:00
J. Nick Koston 6bd6adc4f5
Avoid calling valid_entity_id when adding entities if they are already registered (#115388) 2024-04-10 15:18:47 -10:00
J. Nick Koston bbecb98927
Fix type on known_object_ids in _entity_id_available and async_generate_entity_id (#115378) 2024-04-10 11:44:25 -10:00
J. Nick Koston f80894d56f
Stop scripts with eager tasks (#115340) 2024-04-10 08:41:13 -04:00
Sid d61db732da
Enable Ruff SLOT rules (#115043) 2024-04-09 18:57:27 -10:00
Marc Mueller d8c8d1a297
Use dict instead of MutableMapping [extra_state_attributes] (#115319) 2024-04-09 15:06:11 -10:00
J. Nick Koston 11af7d91ff
Optimize _async_track_event for the single key common case (#115242) 2024-04-09 07:04:50 -10:00
J. Nick Koston 95958ac0ef
Increase discovery flow init concurrency limit to 20 (#115230) 2024-04-08 11:05:40 -10:00
J. Nick Koston ca5ed274cb
Deprecate calling async_listen and async_listen_once with run_immediately (#115169) 2024-04-08 10:07:54 -10:00
Sid 9cbed10372
Enable Ruff PYI041 (#115229) 2024-04-08 09:29:05 -10:00
Marc Mueller 4e94f11665
Use EventType for entity_registry_updated (#115187) 2024-04-08 08:44:59 -10:00
Marc Mueller 2fc0d8494d
Use EventType for device_registry_updated (#115188) 2024-04-08 08:25:57 -10:00
Marc Mueller 0d18679c8f
Use EventType for remaining registry events (#115189) 2024-04-08 08:25:39 -10:00
Marc Mueller 6116f11e6c
Use EventType for system events (#115190) 2024-04-08 08:25:34 -10:00
J. Nick Koston 9ef28f83ea
Switch async_track_state_change to use run_immediately (#115164) 2024-04-07 16:38:25 -10:00
J. Nick Koston 89a2c89fe2
Avoid checking for polling if an entity fails to add (#115159)
* Avoid checking for polling if an entity fails to add

* no need to do protected access

* no need to do protected access

* no need to do protected access

* no need to do protected access

* coverage

* fix test

* fix

* broken one must be first
2024-04-07 21:25:55 -04:00
Marc Mueller a0e6fd6ec5
Add improved typing for event fire and listen methods (#114906)
* Add EventType implementation

* Update integrations for EventType

* Change state_changed to EventType

* Fix tests

* Remove runtime impact

* Add tests

* Move to stub file

* Apply pre-commit to stub files

* Fix ruff PYI checks

---------

Co-authored-by: J. Nick Koston <nick@koston.org>
2024-04-07 13:28:24 -10:00
Sid 8e98ba7312
Add first batch of Ruff PYI rules (#115100)
Co-authored-by: Jan Bouwhuis <jbouwh@users.noreply.github.com>
2024-04-07 11:30:50 -10:00
J. Nick Koston 569f54d8e3
Terminate scripts with until and while conditions that execute more than 10000 times (#115110) 2024-04-07 11:02:53 -10:00
Marc Mueller cb9352110c
Improve registry store data typing (#115066) 2024-04-06 14:34:49 -10:00
J. Nick Koston a0936902c2
Use identity checks for EntityPlatformState enum (#115067) 2024-04-07 02:31:23 +02:00
Marc Mueller 8324fd5d1d
Deprecated old backports and typing aliases (#114883) 2024-04-06 13:15:30 -10:00
J. Nick Koston c4b5a7c027
Migrate start helper to use run_immediately (#115055) 2024-04-06 12:35:46 -10:00
Marc Mueller 81d682874f
Update typing extensions to 4.11.0 (#114985) 2024-04-06 14:23:32 +02:00
Sid 0d66d298ec
Enable Ruff RET504 (#114528)
* Enable Ruff RET504

* fix test

* Use noqa instead of cast

* fix sonos RET504

---------

Co-authored-by: Martin Hjelmare <marhje52@gmail.com>
2024-04-06 11:07:37 +02:00
J. Nick Koston f497c461ed
Switch to using the AsyncResolver with aiohttp (#114529)
* Bump aiodns to 3.2.0

changelog: https://github.com/saghul/aiodns/compare/v3.1.1...v3.2.0

* Switch to using the AsyncResolver with aiohttp

This avoids creating executor jobs to do DNS resolution

AsyncResolver was not usable before https://github.com/aio-libs/aiohttp/pull/8270
because it did not fallback to fallback to A records and only returned AAAA records
in most cases when IPv6 was available

This is a backport of https://github.com/aio-libs/aiohttp/pull/8270

* Switch to using the AsyncResolver with aiohttp

This avoids creating executor jobs to do DNS resolution

AsyncResolver was not usable before https://github.com/aio-libs/aiohttp/pull/8270
because it did not fallback to fallback to A records and only returned AAAA records
in most cases when IPv6 was available

This is a backport of https://github.com/aio-libs/aiohttp/pull/8270

* Switch to using the AsyncResolver with aiohttp

This avoids creating executor jobs to do DNS resolution

AsyncResolver was not usable before https://github.com/aio-libs/aiohttp/pull/8270
because it did not fallback to fallback to A records and only returned AAAA records
in most cases when IPv6 was available

This is a backport of https://github.com/aio-libs/aiohttp/pull/8270

* Switch to using the AsyncResolver with aiohttp

This avoids creating executor jobs to do DNS resolution

AsyncResolver was not usable before https://github.com/aio-libs/aiohttp/pull/8270
because it did not fallback to fallback to A records and only returned AAAA records
in most cases when IPv6 was available

This is a backport of https://github.com/aio-libs/aiohttp/pull/8270

* fixes

* fix mocking in next_dns

* fix unmocked calls in blink

* more mocking fixes

* more fixes

* more fixes

* Fix missing mocking in nextdns tests

extracted from #114539

* extract from context
2024-04-05 23:15:51 -04:00
J. Nick Koston fb98a6f026
Make run_immediately the default for core EventBus listeners (#113752)
* DNM: Make run_immediately the default for listeners

This is a test to see how much progress we have made twords this goal

https://github.com/home-assistant/core/pull/113727#issuecomment-2004587947

* fix shutdown

* Revert "fix shutdown"

This reverts commit a8969d7db9.

* set false since it break utility meter tests

* one more

* fix rfxtrx test

* test needs to be explict now

* fix matrix

* fail sooner
2024-04-05 22:14:20 -04:00
J. Nick Koston 00db97a765
Run device_registry stop listener immediately (#114978) 2024-04-05 21:59:27 -04:00
J. Nick Koston d25ac06326
Run storage final write listener immediately (#114976)
This one should not need a call_soon
2024-04-05 21:59:11 -04:00
J. Nick Koston aeaed83578
Start async_schedule_update_ha_state task eagerly (#114704) 2024-04-05 08:14:21 -10:00
J. Nick Koston bfe944f666
Handle ambiguous script actions by using action map order (#114825) 2024-04-05 08:42:57 +02:00
J. Nick Koston d321906342
Always run keyed event trackers immediately (#114709) 2024-04-04 15:30:01 -10:00
Erik Montnemery 7c95ecff20
Validate unique_id in entity registry (#114648)
Co-authored-by: Shay Levy <levyshay1@gmail.com>
Co-authored-by: J. Nick Koston <nick@koston.org>
2024-04-04 09:51:44 -10:00
J. Nick Koston cceea6dac2
Refactor ConfigStore to avoid needing to pass config_dir (#114827)
Co-authored-by: Erik <erik@montnemery.com>
2024-04-04 09:30:10 -10:00
Marc Mueller 56ef9500f7
Use EventStateChangedData type when firing state changed event (#114740) 2024-04-04 09:27:44 -10:00
J. Nick Koston a9d43db315
Avoid linear search to clear a config entry in the device registry (#114802) 2024-04-04 08:35:07 -10:00
Marc Mueller 816ce116bf
Remove unnecessary functools.cached_property backport (#114239) 2024-04-04 11:24:26 +02:00
J. Nick Koston aedfd6c983
Add index for floor/label to the area registry (#114777) 2024-04-03 21:04:26 -10:00
J. Nick Koston 56d0ad27f0
Adjust async_load_platform comment to remove dead lock reference (#114771)
* Adjust async_load_platform comment

Its likely the deadlock here has been fixed for a long time, however
we should still do these in a task because it has to wait for base
components if they are not loaded yet.

* Adjust async_load_platform comment

Its likely the deadlock here has been fixed for a long time, however
we should still do these in a task because it has to wait for base
components if they are not loaded yet.
2024-04-03 22:53:31 -04:00
J. Nick Koston 3f76d1f056
Add index for area/config_entry/label to the device registry (#114776)
* Add index for area/config_entry/label to the device registry

* use it for services

* naming

* naming

* tweak
2024-04-03 22:52:17 -04:00
J. Nick Koston e86fec310b
Improve performance of extracting entities by label (#114720) 2024-04-03 10:24:44 -10:00
Robert Resch 7adced6876
Allow passing area/device/entity IDs to floor_id and floor_name (#114748) 2024-04-03 16:33:58 +02:00
J. Nick Koston 2b9f22f11e
Make creation of capabilities_updated_at deque in Entity lazy (#114711)
Most entities will never update their capabilities so we should
avoid creating the deque as its a large chunk of the entity
creation time
2024-04-03 13:53:17 +02:00
J. Nick Koston adbaed2c6d
Reduce code for registry items with a base class (#114689) 2024-04-03 09:02:32 +02:00
Franck Nijhof 4a93b4a4b4
Add floor selector (#114614) 2024-04-02 10:43:14 +02:00
J. Nick Koston 5856bbc07b
Add missing platforms_exist guard to check_config (#114600)
* Add missing platforms_exist guard to check_config

related issue #112811

When the exception hits, the config will end up being saved in the traceback
so the memory is never released.

This matches the check_config code to homeassistant.config to avoid having
the exception thrown.

* patch

* merge branch
2024-04-01 21:37:30 -04:00
Michael Hansen d23b22b566
Add initial support for floors to intents (#114456)
* Add initial support for floors to intents

* Fix climate intent

* More tests

* No return value

* Add requested changes

* Reuse event handler
2024-03-30 16:59:20 -04:00
Jan-Philipp Benecke 502231b7d2
Avoid call to `hass.helpers.store` in CategoryRegistry (#114485) 2024-03-30 21:15:52 +01:00
Sid 6587ee20db
Enable Ruff TRY300 (#114437)
* Enable Ruff TRY300

* Update validation.py

* Address review comments
2024-03-30 10:37:59 +01:00
Sid a5b609f081
Enable ruff TRY401 (#114395)
* Enable ruff TRY401

* fix tests
2024-03-29 07:20:36 +01:00
Sid f7b7f74d10
Enable Ruff TRY201 (#114269)
* Enable Ruff TRY201

* remove redundant rules
2024-03-28 10:18:07 +01:00
J. Nick Koston f4922edb4b
Fix empty delays in script helper (#114346)
fixes
```
Logger: homeassistant.components.automation.kamermaster_knop_4_acties_licht
Bron: components/automation/__init__.py:726
integratie: Automatisering (documentatie, problemen)
Eerst voorgekomen: 22:17:29 (5 gebeurtenissen)
Laatst gelogd: 22:59:24

While executing automation automation.kamermaster_knop_4_acties_licht
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/components/automation/__init__.py", line 726, in async_trigger
    return await self.action_script.async_run(
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 1645, in async_run
    return await asyncio.shield(create_eager_task(run.async_run()))
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 454, in async_run
    await self._async_step(log_exceptions=False)
  File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 506, in _async_step
    self._handle_exception(
  File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 536, in _handle_exception
    raise exception
  File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 504, in _async_step
    await getattr(self, handler)()
  File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 626, in _async_delay_step
    if timeout_future.done():
       ^^^^^^^^^^^^^^^^^^^
AttributeError: 'NoneType' object has no attribute 'done'
```
2024-03-28 00:29:43 -04:00
Marc Mueller 911a31f860
Use SignalType to improve typing [core] (#114298) 2024-03-27 14:25:02 +01:00
Marc Mueller 1d2c2d2055
Move SignalTypes to util (#114236) 2024-03-27 08:41:44 +01:00
Franck Nijhof 9a32d1bbd5
Add label selector (#111029)
Co-authored-by: Paulus Schoutsen <balloob@gmail.com>
2024-03-26 20:31:06 +01:00
Franck Nijhof 9a1906322b
Allow numeric state trigger/condition against zone entities (#114221) 2024-03-26 19:41:46 +01:00
Franck Nijhof c247534731
Default floor level to None (and allow unsetting it) (#114249) 2024-03-26 18:58:25 +01:00
Marc Mueller eb81a4204e
Allow string formatting for dispatcher SignalType (#114174) 2024-03-26 10:38:29 +01:00
Franck Nijhof 5c69e0d2c6
Add label template functions (#111024) 2024-03-26 10:32:29 +01:00
J. Nick Koston 54a69a2687
Remove async_get_device_class_lookup from entity_registry (#114212)
This function was only ever used in homekit, and since there is
now an index of devices in the entity registry, homekit no longer
uses it.

I searched github code for all references to async_get_device_class_lookup
and the only think I could find using it were forks of core. It seems
unlikely that any custom components are affected by removing this
function
2024-03-26 09:22:53 +01:00
Marc Mueller d0ecad78ac
Revert "Update typing-extensions to 4.11.0rc1 (#114116)" (#114216) 2024-03-25 20:44:57 -10:00
J. Nick Koston cabc4f797a
Preload storage for integrations we know we are going to setup (#114192) 2024-03-25 15:49:54 -10:00
Joost Lekkerkerker 6bb4e7d62c
Bump ruff to 0.3.4 (#112690)
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
Marc Mueller 188dbfbd2a
Update typing-extensions to 4.11.0rc1 (#114116) 2024-03-25 11:27:47 +01:00
J. Nick Koston de831b6e87
Small performance improvement to template expand (#114086)
* Small performance improvement to template expand

- Avoid fetching entity sources each loop
- Skip already found entities
- Avoid startswith in favor of equality check

* unneeded changes
2024-03-24 00:24:52 -04:00
J. Nick Koston 1c1d8d0317
Avoid creating inner function in EntityComponent setup (#114050) 2024-03-23 11:31:23 -10:00
Jan Bouwhuis a4f52cc622
Use a constant to reference `homeassistant` domain (#113889)
* Use CONF_CORE to reference `homeassistant` domain

* Just use DOMAIN

* USE DOMAIN for `homeasistant` domain in config_schema.py

* Use DOMAIN_HA as constant for homeassistant domain

* Rename CONF_CORE to DOMAIN_HA

* Rename DOMAIN_HA to HA_DOMAIN

* Use relative import

* Use direct imports
2024-03-23 19:58:39 +01:00
Marc Mueller efc54971d3
Update empty line formatting after module docstring (#114040) 2024-03-23 00:27:57 +01:00
Paul Chanvin b2cab70cc0
Fix argument name in async_update_ha_state warning message (#113969)
Fixed warning message using async_update_ha_state
2024-03-22 02:26:11 +01:00
J. Nick Koston aebc95b1d2
Reduce overhead to construct and validate entity service schema (#113920) 2024-03-20 16:07:17 -10:00
J. Nick Koston e015fd2440
Use intersection for determine_script_action (#113915) 2024-03-20 16:06:59 -10:00
J. Nick Koston b574220247
Refactor rate limit helper to track time in seconds (#113898)
* Refactor rate limit helper to track time in seconds

Currently we created datetime and timedelta objects to enforce the
rate limit. When the rate limit was being hit hard, this got expensive.

We now use floats everywhere instead as they are much cheaper which
is important when we are running up against a rate limit, which is
by definition a hot path

The rate limit helper is currently only used for templates and
we do not have any code in the code base that directly passes
in a rate limit so the impact to custom components is expected
to be negligible if any

* misesd two
2024-03-20 19:49:37 -04:00
J. Nick Koston e9c1753f3a
Cache parsing the url for the device registry (#113910)
* Cache parsing the url for the device registry

There are lots of hub integrations that use the same url for every
sub-device which results in a lot of url parsing at startup. The
logic can be simplified quite a bit here by only using yarl
for URLs

* fix onvif
2024-03-20 19:35:01 -04:00
J. Nick Koston 267fe3dc34
Fix system_info importing hassio in the event loop (#113903) 2024-03-20 12:06:40 -10:00
Erik Montnemery 426f73b1f4
Add State.last_reported (#113511)
* Add State.last_reported

* Update tests

* Update test snapshots

* Call state_reported listeners when firing state_changed event

* Add tests
2024-03-20 21:05:07 +01:00
Franck Nijhof fc6a83559f
Add floor template functions (#110847) 2024-03-20 11:58:04 +01:00
Erik Montnemery d31124d5d4
Avoid creating unneeded Context and Event objects when firing events (#113798)
* Avoid creating unneeded Context and Event objects when firing events

* Add test

---------

Co-authored-by: J. Nick Koston <nick@koston.org>
2024-03-20 09:40:06 +01:00
Franck Nijhof 670bd97777
Find referenced labels in automations & scripts (#113812) 2024-03-19 16:28:37 +01:00
Franck Nijhof 38d0854b70
Find referenced floors in automations & scripts (#113802) 2024-03-19 14:18:53 +01:00
J. Nick Koston d740e4c3d7
Migrate restore_state shutdown to use run_immediately (#113786) 2024-03-19 08:42:49 +01:00
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
Franck Nijhof 167e66d45c
Add labels to service target (#113753) 2024-03-18 22:32:23 +01:00
Franck Nijhof 51b8ffc69d
Add WebSocket support for handling labels on device registry (#113758) 2024-03-18 21:19:27 +01:00
Sid 82a60fe8ad
Enable Ruff RSE (#113695) 2024-03-18 00:40:38 +01:00
J. Nick Koston 4d75940cd2
Start and stop template cache watcher to run_immediately (#113644) 2024-03-17 08:16:26 -10:00
J. Nick Koston 68320b1278
Migrate registry for labels and categories to run_immediately (#113645) 2024-03-17 08:16:11 -10:00
J. Nick Koston 93497dde8b
Run registry cleanup listeners immediately (#113646) 2024-03-17 08:15:55 -10:00
J. Nick Koston 091199d24a
Run entity registry write_unavailable_states immediately at start (#113647) 2024-03-17 08:15:41 -10:00
Jan-Philipp Benecke 681705394d
Remove deprecated `hass.components` from network helper function (#113615)
* Remove deprecated `hass.components` from network helper function

* Remove deprecated use of `hass.components` in alexa camera tests
2024-03-17 17:42:48 +01:00
J. Nick Koston 91fa612301
Run entity component shutdown immediately (#113635) 2024-03-16 14:42:36 -10:00
Jan Bouwhuis 554aefed42
Generate HomeAssistantError message from English translations (#113305)
* Fetch exception message from translation cache

* Improve tests

* Return translation key without path, cleanup

* Fetch translations when string variant is requested

* Move import

* revert changes ConfigValidationError

* mypy

* Remove _str__ method instead

* Type _message for mqtt template exception classes

* Revert changes made to test_config.py

* Undo changes TemplateError

* Follow up comments and test coverage
2024-03-16 22:56:48 +01:00
J. Nick Koston 86ccb99f4c
Fix race in removing modified devices from the entity registry (#113623) 2024-03-16 11:51:56 -10:00
Sid 6ee273a548
Clean up unneeded ruff noqa directives (#113616) 2024-03-16 09:48:37 -10:00
Sid ccd2e989c3
Enable ruff RUF005 and fix occurrences (#113589) 2024-03-16 07:37:20 -10:00
Franck Nijhof 0e2775667d
Add category registry (#110897)
* Add category registry

* Add entity registry support

* Update homeassistant/components/config/entity_registry.py

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

* Use ulid instead

* Add tests for adding same name in different scopes

* Handle keyerror on update

* Lookup tweak

* Omit categories from entity registry snapshots

* Use base registry

* Update snapshots

* Update snapshots

---------

Co-authored-by: Martin Hjelmare <marhje52@gmail.com>
2024-03-15 13:25:16 +01:00
J. Nick Koston bdede0e0da
Start script runs eagerly (#113190) 2024-03-14 16:53:26 -10:00
J. Nick Koston 3528cc86d7
Fix delayed registry check to only using the short delay at running (#113471) 2024-03-14 15:11:09 -10:00
J. Nick Koston 09934d44c4
Reduce script overhead by avoiding creation of many tasks (#113183)
* Reduce script overhead by avoiding creation of many tasks

* no eager stop

* reduce

* make sure wait being cancelled is handled

* make sure wait being cancelled is handled

* make sure wait being cancelled is handled

* preen

* preen

* result already raises cancelled error, remove redundant code

* no need to raise it into the future

* will never set an exception

* Simplify long action script implementation

* comment

* preen

* dry

* dry

* preen

* dry

* preen

* no need to access protected

* no need to access protected

* dry

* name

* dry

* dry

* dry

* dry

* reduce name changes

* drop one more task

* stale comment

* stale comment
2024-03-14 20:28:27 -04:00
J. Nick Koston 5b80eb4c3d
Reduce overhead to save the larger registries (#113462)
We save the device and entity registry to disk quite often, and
the cost of serializing them to the storage can block the event
loop for >100ms. Add a cache to reduce the change the loop is blocked
at an inopportune time at run time. The first write after startup
will still be a little slow but we do have to serialize the
bulk of it at least once as there is no way to avoid this

```
2024-03-14 11:28:19.765 WARNING (MainThread) [homeassistant.helpers.storage] Writing data with data_func: core.device_registry
2024-03-14 11:28:20.020 WARNING (MainThread) [homeassistant.helpers.storage] Writing data with data_func: core.entity_registry
2024-03-14 11:28:20.178 WARNING (MainThread) [asyncio] Executing <TimerHandle cancelled when=2319925.760294916 Store._async_schedule_callback_delayed_write() created at /Users/bdraco/home-assistant/homeassistant/helpers/storage.py:328> took 0.159 seconds
```
2024-03-14 19:54:43 -04:00
J. Nick Koston 28836be3eb
Construct storage data in the executor to avoid blocking the event loop (#113465)
Construct storage data in the executor

Constructing storage data can be expensive for large files and can block the event
loop. While ideally we optimize the construction of the data, there are some places
we cannot make it any faster. To avoid blocking the loop, the construction of
the data is now done in the executor by running the data_func in the executor.

2024-03-14 11:28:20.178 WARNING (MainThread) [asyncio] Executing <TimerHandle cancelled when=2319925.760294916 Store._async_schedule_callback_delayed_write() created at /Users/bdraco/home-assistant/homeassistant/helpers/storage.py:328> took 0.159 seconds

There is some risk that the data_func is not thread-safe and needs to be run in
the event loop, but I could not find any cases in our existing code where it
would be a problem
2024-03-14 19:53:11 -04:00
Franck Nijhof 2aadd643ed
Add floors to service target (#110850) 2024-03-14 19:02:23 +01:00
Joost Lekkerkerker 05172d8e4d
Improve loops and lists (#113269)
* Enable PERF

* Enable PERF rule

* Enable PERF rule

* Don't enable flag yet
2024-03-14 10:22:20 +01:00
J. Nick Koston cfe14bca8f
Add a helper to import modules from the event loop (#113169)
* Add a helper to import modules in the event loop

Replaces the one used for triggers with a more generic helper
that can be reused and uses a future to avoid importing concurrently

* Add a helper to import modules in the event loop

Replaces the one used for triggers with a more generic helper
that can be reused and uses a future to avoid importing concurrently

* coverage

* make sure we do not retry

* coverage
2024-03-14 00:26:33 -04:00
J. Nick Koston 8bc3286343
Run coordinator shutdown eagerly (#113174) 2024-03-13 17:33:50 +01:00
J. Nick Koston 0ccd813a99
Remove HassJob wrapping from the DataUpdateCoordinator (#113192) 2024-03-13 14:46:45 +01:00
J. Nick Koston 6666f6a8a5
Simplify clearing _attr cached_property in entities (#113136) 2024-03-13 12:04:27 +01:00
J. Nick Koston fb163278a4
Simplify entity _attr cached_property getter implementation (#113195) 2024-03-13 11:59:36 +01:00
J. Nick Koston 120525e94f
Add the ability to create Debouncer tasks as background tasks (#113128)
* Add the ability to Debouncer tasks in the background

This is a more general solution as a followup to
https://github.com/home-assistant/core/pull/112652#discussion_r1517159607

* Add the ability to Debouncer tasks in the background

This is a more general solution as a followup to
https://github.com/home-assistant/core/pull/112652#discussion_r1517159607

* fix
2024-03-12 08:41:12 -04:00
J. Nick Koston b3dedb3efb
Convert sets to list before passing to the JSON serializer in the registries (#113133)
There were a few places we were missing the set to list
conversions in the registries. We do this before its
cached to avoid the JSON serializer having to fallback
to the default method every time since its expensive
to switch back from the native code into python context
for every set.
2024-03-12 08:38:21 -04:00
J. Nick Koston 734a614eb8
Switch the reload helper to use async_get_component (#113126) 2024-03-11 16:17:07 -10:00
J. Nick Koston 3f72fae60b
Migrate remaining call in check_config helper to use async_get_component (#113123) 2024-03-11 15:56:24 -10:00
J. Nick Koston 17b202d8cf
Await discovery_function in the DiscoveryFlowHandler instead of wrapping it in a task (#113115)
Await discovery_function in the DiscoveryFlowHandler instead of wrapping

This function was always a coro so it can be awaited
directly instead of wrapping it in add_job
2024-03-11 21:37:03 -04:00
J. Nick Koston 427de00524
Remove unnecessary use of async_run_job in script helper (#113118)
The function being passed to `async_run` was always a callback
2024-03-11 21:36:18 -04:00
J. Nick Koston 1536a3981f
Use run_immediately for starting discovery at the started event (#113112) 2024-03-11 14:29:39 -10:00
J. Nick Koston b87036eebe
Make restore state started a callback function (#113110) 2024-03-11 14:25:15 -10:00
J. Nick Koston 620433a79d
Run coroutines as eager tasks in async_run_hass_job (#111683)
* Run coroutines as eager tasks in async_run_hass_job

Note that this does not change async_add_hass_job

Do not merge this. For test run only

* Phase out periodic tasks

* false by default or some tests will block forever, will need to fix each one manually

* kwarg works

* kwarg works

* kwarg works

* fixes

* fix more tests

* fix more tests

* fix lifx

* opensky

* pvpc_hourly_pricing

* adjust more

* adjust more

* smarttub

* adjust more

* adjust more

* adjust more

* adjust more

* adjust

* no eager executor

* zha

* qnap_qsw

* fix more

* fix fix

* docs

* its a wrapper now

* add more coverage

* coverage

* cover all combos

* more fixes

* more fixes

* more fixes

* remaining issues are legit bugs in tests

* make tplink test more predictable

* more fixes

* feedreader

* grind out some more

* make test race safe

* limit first scope to triggers

* one more

* Start tasks eagerly in for async_at_start(ed)

A few of these can avoid being scheduled on the loop
during startup

* fix cloud

* Revert "fix cloud"

This reverts commit 5eb3ce695d.

* fix test to do what start does

* flip flag

* flip flag

* Fix here_travel_time creating many refresh requests at startup

- Each entity would try to refresh the coordinator which
  created many tasks. Move the refresh to a single
  async_at_started

- The tests fired the EVENT_HOMEASSISTANT_START event
  but the code used async_at_started which only worked
  because the tests did not set CoreState to not_running

* fix azure

* remove kw

* remove kw

* rip

* cover

* more rips

* more rips

* more rips
2024-03-11 20:05:08 -04:00
J. Nick Koston 324266a4e6
Fix race in script stop that could cause async_stop to hang forever (#113089) 2024-03-11 10:48:11 -10:00
J. Nick Koston 89c24b2f75
Migrate dispatcher to create tasks eagerly (#112845)
There were quite a few of these that never had to suspend.
2024-03-11 14:58:45 -04:00
J. Nick Koston d7cc30fd2b
Start tasks eagerly in for async_at_start(ed) (#112802) 2024-03-11 08:46:11 -10:00
Paulus Schoutsen 145657dc21
Only load services.yaml for integrations that have it (#112732)
Co-authored-by: J. Nick Koston <nick@koston.org>
2024-03-11 19:05:32 +01:00
Joost Lekkerkerker cddce0ce0d
Enable more SIM ruff rules (#113015)
* SIM101 SIM103

* SIM107 SIM109

* SIM110

* SIM112 SIM113

* SIM115

* SIM116

* Fix

* Fix

* Fix
2024-03-10 23:20:37 -04:00
J. Nick Koston a2318c26c9
Run debouncer tasks eagerly to avoid scheduling on the event loop (#112789) 2024-03-10 08:37:10 -10:00
J. Nick Koston 23ebd80285
Schedule coroutines with eager_task from async_track_state_change_event (#112807) 2024-03-09 11:24:54 -10:00
J. Nick Koston 9ba142f4dd
Use eager_start for discovery listeners (#112803)
Many platforms can be loaded without having to suspend or
be scheduled on the event loop
2024-03-09 11:07:15 -05:00
J. Nick Koston b7d9f26cee
Cache the job type for entity service calls (#112793) 2024-03-08 22:49:08 -10:00
J. Nick Koston 9ca9d7f48f
Use eager_start for tasks to register integration platforms (#112800) 2024-03-08 22:10:57 -10:00
J. Nick Koston a50883d975
Run service call tasks eagerly (#112791) 2024-03-08 20:37:21 -10:00
J. Nick Koston 6a7c255b93
Improve entity translation typing (#112788)
* Improve entity translation typing

* Improve entity translation typing
2024-03-08 22:30:13 -05:00
J. Nick Koston 65358c129a
Replace periodic tasks with background tasks (#112726)
* Phase out periodic tasks

* false by default or some tests will block forever, will need to fix each one manually

* kwarg works

* kwarg works

* kwarg works

* fixes

* fix more tests

* fix more tests

* fix lifx

* opensky

* pvpc_hourly_pricing

* adjust more

* adjust more

* smarttub

* adjust more

* adjust more

* adjust more

* adjust more

* adjust

* no eager executor

* zha

* qnap_qsw

* fix more

* fix fix

* docs

* its a wrapper now

* add more coverage

* coverage

* cover all combos

* more fixes

* more fixes

* more fixes

* remaining issues are legit bugs in tests

* make tplink test more predictable

* more fixes

* feedreader

* grind out some more

* make test race safe

* one more
2024-03-08 21:45:10 -05:00
J. Nick Koston 08416974c9
Avoid trying to load translations for integrations that have none (#112683) 2024-03-08 14:21:44 -10:00
Marc Mueller de886d8c49
Update EventBus listen type signatures (#112760) 2024-03-08 21:57:23 +01:00
Marc Mueller cef20506dc
Replace EventType with Event [missing] (#112753) 2024-03-08 21:56:42 +01:00
Marc Mueller b026b5d589
Replace EventType with Event [helpers] (#112743) 2024-03-08 19:41:50 +01:00
Marc Mueller a6b842f818
Add empty line after module docstring (2) [other] (#112738) 2024-03-08 19:16:38 +01:00
Marc Mueller cb8c14496c
Use more f-strings [ruff] (#112695) 2024-03-08 18:44:42 +01:00
Franck Nijhof aa7acb89c5
Remove Python 3.11 from CI (#112626) 2024-03-08 17:42:18 +01:00
Marc Mueller 19ab3d6daf
Add empty line after module docstring [helpers + other] (#112707) 2024-03-08 10:36:11 -05:00
Marc Mueller d7e7dc96cc
Make Event data generic (#111955) 2024-03-08 13:46:16 +01:00
Marc Mueller 2d701d5a7d
Use aiohttp.AppKey for http cors keys (#112658) 2024-03-08 11:51:59 +01:00
Marc Mueller 4893087a7e
Add TypeVar defaults for DataUpdateCoordinator (#111949) 2024-03-08 11:14:16 +01:00
J. Nick Koston caefdc6192
Avoid writing registries to disk during startup (#112662) 2024-03-07 19:14:42 -10:00
J. Nick Koston a6b17dbe68
Schedule polling as periodic tasks (#112640)
* Schedule periodic coordinator updates as background tasks.

Currently, the coordinator's periodic refreshes delay startup because they are not scheduled as background tasks. We will wait if the startup takes long enough for the first planned refresh. Another coordinator's scheduled refresh will be fired on busy systems, further delaying the startup. This chain of events results in the startup taking a long time and hitting the safety timeout because too many coordinators are refreshing.

This case can also happen with scheduled entity refreshes, but it's less common. A future PR will address that case.

* periodic_tasks

* periodic_tasks

* periodic_tasks

* merge

* merge

* merge

* merge

* merge

* fix test that call the sync api from async

* one more place

* cannot chain

* async_run_periodic_hass_job

* sun and pattern time changes from automations also block startup

* Revert "sun and pattern time changes from automations also block startup"

This reverts commit 6de2defa05.

* make sure polling is cancelled when config entry is unloaded

* Revert "Revert "sun and pattern time changes from automations also block startup""

This reverts commit e8f12aad55.

* remove DisabledError from homewizard test as it relies on a race

* fix race

* direct coverage
2024-03-07 23:32:26 -05:00
Erik Montnemery 49d20eedd4
Remove local imports of hass-nabucasa (#112634) 2024-03-07 20:37:35 +01:00
Marc Mueller 8ca127df2a
Use KEY_HASS [h-z] (#112610) 2024-03-07 18:03:44 +01:00
Marc Mueller 531e25cbc6
Change KEY_HASS to be an aiohttp AppKey (#111954) 2024-03-07 13:37:48 +01:00
Erik Montnemery 82efb3d35b
Make FlowResult a generic type (#111952) 2024-03-07 12:41:14 +01:00
J. Nick Koston 1fb9cfe37e
Speed up the frame helper (#112562) 2024-03-06 20:54:09 -10:00
J. Nick Koston a7b4cd3512
Pass job type to event listeners when creating entities (#112551) 2024-03-06 16:10:07 -10:00
J. Nick Koston 84455dbe1d
Avoid having to work out the job type for each entity service at startup (#112557) 2024-03-06 16:09:55 -10:00
Erik Montnemery 8c2c3e0839
Improve integration_entities template function (#111943) 2024-03-06 11:05:06 +01:00
Jan-Philipp Benecke 995d93dd33
Remove deprecated `hass.components` usage in config entry flow (#111880)
* Remove deprecated `hass.components` usage in config entry flow

* Do local import

* Also use local import for webhook
2024-03-06 09:07:09 +01:00
J. Nick Koston f3a9756f81
Avoid waiting for integration platforms in the parent integration (#112467) 2024-03-05 21:16:42 -10:00
J. Nick Koston 8fe80a4766
Migrate remaining get_platform in check_config to async_get_platform (#112470)
These were very likely to be cached so they were low on the
list to migrate, but since they are called in the event loop
its best to be sure we do no blocking I/O
2024-03-05 23:47:41 -05:00
J. Nick Koston 982c8f8f4a
Fix incorrect scope on checking files to load in translations (#112457)
discovered in https://github.com/home-assistant/core/pull/112295#discussion_r1513505710

We only checked if the last language had files to load
instead of all of them. The checks for each language
are the same because the only reason we would skip
a language is a missing/broken integration or the integration
is a single file. Both of these loop conditions are always
the same reguardless of the language so the check worked
2024-03-05 23:46:24 -05:00
J. Nick Koston e568f867d2
Adjust MAX_LOAD_CONCURRENTLY constant to allow 6 storage loaders (#112468) 2024-03-05 16:31:10 -10:00
J. Nick Koston fbabbc8f92
Limit legacy state translations to custom components (#112295)
* Limit legacy state translations to custom components

We were trying to load **thousands** of `*.light.json`, `*.switch.json` files at run time that did not exist.

There have been replaced with entity translations: https://github.com/home-assistant/developers.home-assistant/pull/1557 https://github.com/home-assistant/core/pull/82701

https://github.com/home-assistant/core/pull/112023 will completely remove them, but
for now we will only load them for custom components to reduce the number
of files having to be examined

* reduce

* reduce

* reduce

* reduce

* comment

* coverage

* try to remove empty dict in loaded_translations fallback when missing
2024-03-05 17:27:45 -05:00
Erik Montnemery 3d3e9900c3
Add TypeVar default for FlowResult (#112345)
Co-authored-by: Marc Mueller <30130371+cdce8p@users.noreply.github.com>
2024-03-05 22:52:11 +01:00
J. Nick Koston 390f5822fe
Initialize triggers eagerly (#112294)
Most of these will never suspend and do not need
to be scheduled as tasks on the event loop
2024-03-05 09:58:43 -05:00
J. Nick Koston f3eb292c2d
Remove async_entity_ids and get_entity_ids from entity registry (#112311)
added in #112277 but not used yet.
2024-03-05 14:50:41 +01:00
J. Nick Koston 8b017016b0
Refactor integration platforms to import in the executor (#112168)
Co-authored-by: Paulus Schoutsen <balloob@gmail.com>
2024-03-04 19:21:18 -10:00
J. Nick Koston 1e173e82d0
Add support for preloading platforms in the loader (#112282)
Co-authored-by: Paulus Schoutsen <balloob@gmail.com>
2024-03-04 16:33:12 -10:00
J. Nick Koston 2c179dc5fb
Reduce some linear searches to cleanup the device registry (#112277)
Some of the data we had to search for was already available
in a dict or underlying data structure. Make it available
instead of having to build it every time.

There are more places these can be used, but I only did
the device registry cleanup for now
2024-03-04 20:59:12 -05:00
RoboMagus b381922a20
Issues template function (#95206)
* Add 'issues' template function for listing active issues.

* Add issue template function test

* Add 'issue' template function for getting specific issue by domain and issue_id

* Remove comment

* Fix function description

* Remove reduntant function,
Fix tests

* remove pass_context

* remove issues filter

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

---------

Co-authored-by: Erik Montnemery <erik@montnemery.com>
2024-03-04 14:22:14 +01:00
J. Nick Koston 331989de4c
Migrate condition/state/trigger helper to use async_get_platform (#112144)
Currently these would always load the platform in the loop
if it was not already loaded
2024-03-03 21:20:47 -05:00
J. Nick Koston da6eca7b68
Avoid compiling entity service schema when passed defaults (#112099)
* Avoid compiling entity service schema when passed defaults

* dry
2024-03-03 12:50:04 -05:00
J. Nick Koston a37c82e34c
Add comment to integration platform helper about blocking I/O (#112103) 2024-03-03 07:00:35 -10:00
J. Nick Koston c8cb0ff61d
Avoid trying to import platforms that do not exist (#112028)
* Avoid trying to import platforms that do not exist

* adjust

* fixes

* cleanup

* cleanup

* cleanup

* Apply suggestions from code review

* docs

* fixes

* fixes

* comment

* coverage

* coverage

* coverage

* Switch config to use async_get_component

This was another path where integrations that were marked to load in the executor
would be loaded in the loop

* Switch config to use async_get_component/async_get_platform

This was another path where integrations that were marked to load in the executor
would be loaded in the loop

* merge

* refactor

* refactor

* coverage

* preen

* preen
2024-03-02 22:14:28 -05:00
J. Nick Koston 6421a08ba8
Avoid expensive inspect calls in config validators (#112085)
* Avoid expensive inspect calls in config validators

inspect has a performance problem https://github.com/python/cpython/issues/92041

We now avoid calling inspect unless we are going to log

* remove unused

* reduce

* get_integration_logger
2024-03-02 21:50:35 -05:00
Jan-Philipp Benecke 196089e8b7
Remove deprecated `hass.components.hassio` usage (#111878) 2024-03-02 15:38:31 +01:00
Marc Mueller daf8d1939b
Fix generic HassJob typing (#111973) 2024-03-01 20:51:45 +01:00
G Johansson 9989a63cdf
Add reconfigure step to config flow (#108794)
* Initial commit reconfigure

* test config config_entries

* Fix reconfigure

* test_config_entries

* review comment

* No reconfigure if reauth ongoing

* Fix tests

* Fix tests

* handle source creating flows

* combine

* No black

* Also check reconfigure in reauth flow

* Fix support

* Add entry id

* reset data entry flow

* Mods

* context data

* reset formatting

* Fix config flow platforms

* Fix tests

* Fix step message

* Handling reconfigure step

* Fix more tests

* Config entries tests

* entry_id always means reconfigure

* Mods

* Remove no longer valid exception

* Fixes

* reset silabs test

* dev reg

* resets

* assist pipeline

* Adjust config_entries

* Fix

* Fixes

* docstrings

* Review comment

* docstring
2024-03-01 12:29:35 +01:00
Michael Hansen 0d0b64d351
Move HassSetPosition to homeassistant domain (#111867)
* Move HassSetPosition to homeassistant domain

* Add test for unsupported domain with HassSetPosition

* Split service intent handler

* cleanup

---------

Co-authored-by: Paulus Schoutsen <balloob@gmail.com>
2024-02-29 21:53:52 -05: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
Erik Montnemery a0e558c457
Add generic classes BaseFlowHandler and BaseFlowManager (#111814)
* Add generic classes BaseFlowHandler and BaseFlowManager

* Migrate zwave_js

* Update tests

* Update tests

* Address review comments
2024-02-29 16:52:39 +01:00
Erik Montnemery 3a8b6412ed
Remove areas template filter (#111827) 2024-02-29 10:52:26 -05:00
Jan-Philipp Benecke bc6b4d01c8
Deprecate `hass.components` and log warning if used inside custom component (#111508)
* Deprecate @bind_hass and log error if used inside custom component

* Log also when accessing `hass.components`

* Log warning only when `hass.components` is used

* Change version

* Process code review
2024-02-29 12:25:46 +01:00
Jan-Philipp Benecke f31244bac4
Add normalized name registry items base class (#111666)
* Add normalized name base registry items class

* Add tests
2024-02-29 01:31:33 +01:00
Erik Montnemery b336095239
Allow translating device names (#110711)
* Allow translating device names

* Don't keep a reference to translations in config entry

* Update kitchen_sink tests

* Add tests
2024-02-28 15:59:59 +01:00
J. Nick Koston 913ee90e1a
Use eager tasks when updating entity state after service calls (#111702)
In a multi-entity update case the state update may not need
to suspend and can get executed without scheduling a task
on the event loop
2024-02-28 12:46:32 +01:00
J. Nick Koston 69a1da0a1a
Make entity component platform setup tasks eager (#111698)
Many of these that setup from YAML will never suspend
because they do no I/O
2024-02-28 12:44:23 +01:00
Jan-Philipp Benecke ebfba7258e
Revert "Drop `@bind_hass` use from hassio component (#111522)" (#111705)
This reverts commit 4e4345f04e.
2024-02-28 10:51:37 +01:00
J. Nick Koston 78bb6dbe75
Reduce latency in storage by making the tasks eager (#111500)
* Reduce latancy to load storage by making the task eager

This changes the semantics a bit under the hood because it
can raise sooner which means we do not store the task
as _load_task if it raises right away. That means
concurrent calls that result in failure are likely to try
again now which will be a tiny performance hit for this
case.

* fix

* will now finish in time
2024-02-27 23:27:37 -05:00
Jan-Philipp Benecke 4e4345f04e
Drop `@bind_hass` use from hassio component (#111522)
* Drop `@bind_hass` use from hassio component

* Add comment why we import locally

---------

Co-authored-by: J. Nick Koston <nick@koston.org>
2024-02-28 00:25:46 +01:00
Jan-Philipp Benecke c8b7f098e5
Avoid call to `hass.helpers.store` in FloorRegistry (#111554)
* Avoid call to `hass.helpers.store` in FloorRegistry

* Change type annotation
2024-02-27 23:03:28 +01:00
J. Nick Koston a6f4f6eae8
Use eager task creation to add entities to entity platform (#111553) 2024-02-27 09:54:51 -10:00
Jan-Philipp Benecke 070b411820
Avoid call to `hass.helpers.store` in LabelRegistry (#111555)
* Avoid call to `hass.helpers.store` in LabelRegistry

* Change type annotation
2024-02-27 09:37:45 -05:00
J. Nick Koston 08e0008d31
Use an eager task to setup entity platforms (#111574)
* Use an eager task to setup entity platforms

Ideally we would have awaited this function instead, but we want
to shield it from cancellation so we wrap it in asyncio.shield
which schedules it as a task. Since we have integrations that
never suspend in async_setup_entry, we can avoid scheduling on
the evnet loop with an eager task for this case

* its an executor future

* its an executor future

* fix

* doc string lied
2024-02-27 08:45:45 -05:00
J. Nick Koston ce0fb1e716
Fully fix race in removing entities (#111499)
Full fix race in removing entities

Followup to #110978 now that we can start the task
eagerly it completely closes the race window
2024-02-26 23:55:15 -05:00
J. Nick Koston d5e1934942
Use an eager task in the update coordinator scheduled refresh (#111570)
* Use an eager task in the update coordinator scheduled refresh

We have a lot of places that will not suspend because the refresh function
decides it does not need to update. Currently these have to be scheduled
on the event loop even though they are a noop.

Since _handle_refresh_interval is subclassed in some integrations, I created
a dunder wrapper function to avoid integraions subclassing it

* fix time fires outside of patch
2024-02-26 23:31:08 -05:00
J. Nick Koston f56e4d6a09
Use eager task creation for entity platform polling (#111575)
* Use eager task creation for entity platform polling

We have lots of places where `async_update` does not suspend and
is only a coro because its required to be a coro to run in the
event loop

* try again
2024-02-26 23:16:39 -05:00
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