Commit Graph

404 Commits (607aaa0efe95017c8a54205339c513b431ed7c9f)

Author SHA1 Message Date
epenet bb0b01e4a9
Add error message to snapshot_platform helper (#117974) 2024-05-24 10:38:23 +02:00
J. Nick Koston 5a609c34bb
Fix blocking I/O in the event loop when loading timezones (#117721) 2024-05-20 11:06:03 +02:00
Marc Mueller 8f0fb4db3e
Use PEP 695 for class annotations (4) (#117778) 2024-05-20 10:44:52 +02:00
Robert Svensson fa815234be
Make UniFi use runtime data (#117457) 2024-05-14 21:04:26 +02:00
J. Nick Koston 9381462877
Migrate restore_state to use the singleton helper (#117385) 2024-05-14 09:13:44 +09:00
Erik Montnemery d1525b1edf
Sort parameters to MockConfigEntry (#117239) 2024-05-11 14:16:29 -04:00
J. Nick Koston ead69af27c
Avoid creating a task to clear the hass instance at test teardown (#117103) 2024-05-08 23:39:45 +02:00
J. Nick Koston 26cc1cd3db
Use singleton helper for registries (#117027) 2024-05-07 21:04:01 +02:00
J. Nick Koston 164403de20
Add thread safety checks to async_create_task (#116339)
* Add thread safety checks to async_create_task

Calling async_create_task from a thread almost always results in an
fast crash. Since most internals are using async_create_background_task
or other task APIs, and this is the one integrations seem to get wrong
the most, add a thread safety check here

* Add thread safety checks to async_create_task

Calling async_create_task from a thread almost always results in an
fast crash. Since most internals are using async_create_background_task
or other task APIs, and this is the one integrations seem to get wrong
the most, add a thread safety check here

* missed one

* Update homeassistant/core.py

* fix mocks

* one more internal

* more places where internal can be used

* more places where internal can be used

* more places where internal can be used

* internal one more place since this is high volume and was already eager_start
2024-04-28 18:29:00 -04:00
Jan Bouwhuis 372c6c7874
Use existing monotonic timestamp on mqtt messages for debugging (#116196) 2024-04-25 19:09:54 -05:00
J. Nick Koston 423544401e
Convert MQTT to use asyncio (#115910) 2024-04-21 22:33:58 +02:00
Joost Lekkerkerker 16e31d8f74
Add test helper to snapshot a platform (#115880)
* Add test helper to snapshot a platform

* Add test helper to snapshot a platform
2024-04-20 14:49:57 +02:00
J. Nick Koston ee535ee611
Ensure test async_create_task eager start behavior matches production (#115517) 2024-04-13 15:58:52 -05: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
Marc Mueller a52a80f806
Always include old_state in EventStateChangedData [tests] (#115098) 2024-04-08 08:25:22 -10:00
J. Nick Koston 3daecc7a31
Remove remaining run_immediately=False from tests (#115168) 2024-04-07 16:47:41 -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
Marc Mueller 8324fd5d1d
Deprecated old backports and typing aliases (#114883) 2024-04-06 13:15:30 -10: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 aedfd6c983
Add index for floor/label to the area registry (#114777) 2024-04-03 21:04:26 -10: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
Jan-Philipp Benecke 22b14d83e8
Use `setup_test_component_platform` helper for sensor entity component tests instead of `hass.components` (#114316)
* Use `setup_test_component_platform` helper for sensor entity component tests instead of `hass.components`

* Missing file

* Fix import

* Remove invalid device class
2024-03-28 12:07:55 +01:00
Marc Mueller 1120745d4e
Update SignalType imports (#114287) 2024-03-27 19:41:11 +01:00
Jan-Philipp Benecke 5c97049f2e
Do not override state property in `MockEntity` (#114231)
Do not override state in `MockEntity`
2024-03-27 11:36:00 +01:00
Jan-Philipp Benecke e80d73783c
Do not late import config_entry in `setup_test_component_platform` test helper (#114260) 2024-03-26 21:54:09 +01:00
Marc Mueller eb81a4204e
Allow string formatting for dispatcher SignalType (#114174) 2024-03-26 10:38:29 +01: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
Jan-Philipp Benecke 9b682388f5
Add generic test component platform setup function (#114016)
* Add generic entity platform setup fixture

* rename fixture

* No need for passing hass

* Make function instead of fixture

* Improve typing

* Use Sequence instead

* Migrate flux to use the new helper

* Use list instead

* Use Sequence instead
2024-03-25 21:36:17 +01: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 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