Commit Graph

375 Commits (ac175a42401c815b40cad34a13a0383c61f90ccc)

Author SHA1 Message Date
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 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
Jan Bouwhuis 3ed7a7166d
Revert "Remove unused test helper mock_area_registry" (#113453) 2024-03-14 22:11:44 +01:00
J. Nick Koston 1cceaaf193
Small improvement to test run time (#113175) 2024-03-12 23:01:39 +01:00
J. Nick Koston 3387892f59
Schedule tasks eagerly when called from hass.add_job (#113014) 2024-03-10 21:19:49 -10:00
Marc Mueller cb8c14496c
Use more f-strings [ruff] (#112695) 2024-03-08 18:44:42 +01:00
Marc Mueller 19ab3d6daf
Add empty line after module docstring [helpers + other] (#112707) 2024-03-08 10:36:11 -05:00
J. Nick Koston 1fb9cfe37e
Speed up the frame helper (#112562) 2024-03-06 20:54:09 -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
Erik Montnemery c58828aac0
Remove unused test helper mock_area_registry (#112172) 2024-03-04 06:09:27 -05:00
J. Nick Koston 9af12a0639
Avoid calling async_get_component twice for each component being setup (#112096)
We already have the component so we can pass it to
async_process_component_config to avoid having to
look it up again
2024-03-03 12:48:07 -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 4bddf32cc4
Avoid the final write of every registry at the end of each test (#111053) 2024-02-21 06:01:19 -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
J. Nick Koston 98d5f2fc01
Reduce registry overhead in tests (#110955)
* Avoid scheduling registry loads as tasks in tests

Since we patch out async_load in Store, these will not yield
to the event loop so it makes sense to await them instead
of creating tasks

This reduced my local test run times ~2.5% on average

* mock out save as well so we do not schedule tasks to save empty data

* tweaks

* fix lingering files

* another one

* too much for one PR, reduce

* fix targets
2024-02-20 21:01:50 -05:00
Franck Nijhof e0a9dcd996
Add label registry (#110821) 2024-02-19 11:59:08 +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
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
Marc Mueller 2ef2172b01
Convert test helpers to get hass instance to contextmanagers (#109990)
* Convert get_test_home_assistant helper to contextmanager

* Convert async_test_home_assistant helper to contextmanager

* Move timezone reset to async_test_home_assistant helper
2024-02-11 21:23:51 +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 f6d4617c7a
Avoid directly changing config entry state in tests (part 2) (#110115)
followup to #110048 for more places
2024-02-10 07:20:15 +01:00
J. Nick Koston 02efe41564
Avoid directly changing config entry state in tests (#110048) 2024-02-08 16:31:17 -06:00
J. Nick Koston c399cab427
Small speed up to checking core state (#107845) 2024-01-18 08:41:32 -10:00
J. Nick Koston 3649cb96de
Refactor config entry storage and index (#107590) 2024-01-13 10:34:15 -10:00
J. Nick Koston b1d0c6a4f1
Refactor User attribute caching to be safer and more efficient (#96723)
* Cache construction of is_admin

This has to be checked for a lot of api calls and the websocket
every time the call is made

* Cache construction of is_admin

This has to be checked for a lot of api calls and the websocket
every time the call is made

* Cache construction of is_admin

This has to be checked for a lot of api calls and the websocket
every time the call is made

* modernize

* coverage

* coverage

* verify caching

* verify caching

* fix type

* fix mocking
2024-01-13 15:10:50 -05:00
Jan Bouwhuis 20610645fb
Pop the mocked config flow, restore the original with mock_config_flow (#107567)
Pop the mocked config flow, restore the original if it existed
2024-01-08 19:01:43 +01:00
J. Nick Koston d04e2d56da
Add support for JSON fragments (#107213) 2024-01-07 17:36:31 -10:00
Jan Bouwhuis d6aaaf1f1a
Only mock config_entries.HANDLERS for the current test in mock_config_flow (#107357) 2024-01-06 11:46:12 +01:00
Erik Montnemery c805ea7b4f
Include deprecated constants in wildcard imports (#107114) 2024-01-05 11:46:45 +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
Robert Resch db985925c4
Deprecate deprecated automation constants (#106067) 2023-12-19 19:22:13 +01:00
Robert Resch 0e0fd39603
Add dir_with_deprecated_constants function to deprecation helper (#106059) 2023-12-19 16:37:21 +01:00
Erik Montnemery 6908497c3d
Add minor version to config entries (#105479) 2023-12-12 08:44:35 +01:00
Erik Montnemery 1edfaed7be
Improve raise contains mocks (#105078)
Co-authored-by: J. Nick Koston <nick@koston.org>
2023-12-05 19:14:35 +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
Aarni Koskela 706add4a57
Switch formatting from black to ruff-format (#102893)
Co-authored-by: Franck Nijhof <git@frenck.dev>
2023-11-27 14:38:59 +01:00
Jan Bouwhuis 19040becd3
Fix hassio mqtt discovery CI test (#104463)
* Fix hassio mqtt discovery CI test

* Avoid mqtt set up before mocking the flow

* Fix mock
2023-11-24 21:54:53 +01:00
Jan Bouwhuis af71c2bb45
Raise and suppress stack trace when reloading yaml fails (#102410)
* Allow async_integration_yaml_config to raise

* Docstr - split check

* Implement as wrapper, return dataclass

* Fix setup error handling

* Fix reload test mock

* Move log_messages to error handler

* Remove unreachable code

* Remove config test helper

* Refactor and ensure notifications during setup

* Remove redundat error, adjust tests notifications

* Fix patch

* Apply suggestions from code review

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

* Follow up comments

* Add call_back decorator

* Split long lines

* Update exception abbreviations

---------

Co-authored-by: Erik Montnemery <erik@montnemery.com>
2023-11-24 17:34:45 +01:00
Erik Montnemery 4536fb3541
Remove mock_entity_platform test helper (#104073) 2023-11-16 16:55:08 +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
Joost Lekkerkerker 8b5bfd8cee
Add test helper for cloud status updates (#100993)
* Add helper for cloud status updates

* Move import
2023-09-27 17:08:51 +02:00
J. Nick Koston a03ad87cfb
Avoid ConfigEntry lookups in hass.config_entries.async_entries for domain index (#100598) 2023-09-20 18:43:15 +02:00
Erik Montnemery 9dac6a2948
Use loop.time in DataUpdateCoordinator (#98937) 2023-08-28 10:16:34 -05:00
Marc Mueller 544d6b05a5
Replace mock_coro with AsyncMock (#99014)
* Replace mock_coro with AsyncMock

* Remove mock_coro test helper function

* Remove redundant AsyncMock
2023-08-25 22:54:55 +02:00
Erik Montnemery 3a71e21d6a
Add and improve comments about staggering of event listeners (#99058) 2023-08-25 19:47:13 +02:00
Ville Skyttä 6399d74c15
Remove unnnecessary pylint configs from core (#98704) 2023-08-22 23:12:12 +02:00
Ville Skyttä 2399cd283a
Python 3.10 support cleanups (#98640) 2023-08-21 19:14:07 +02:00
Erik Montnemery 91faa53843
Don't allow hass.config.config_dir to be None (#98442) 2023-08-16 13:00:14 +02:00
Erik Montnemery 3b9d6f2dde
Add setup function to the component loader (#98148)
* Add setup function to the component loader

* Update test

* Setup the loader in safe mode and in check_config script
2023-08-15 10:59:42 +02:00
J. Nick Koston 790c1bc251
Decrease event loop latency by binding time.monotonic to loop.time directly (#98288)
* Decrease event loop latency by binding time.monotonic to loop.time directly

This is a small improvment to decrease event loop latency. While the goal is
is to reduce Bluetooth connection time latency, everything using asyncio
is a bit more responsive as a result.

* relo per comments

* fix too fast by adding resolution, ensure monotonic time is patchable by freezegun

* fix test that freezes time too late and has a race loop
2023-08-13 20:37:45 -04:00