Commit Graph
267 Commits
Author SHA1 Message Date
J. Nick KostonandGitHub e663d4f602 Refactor state_reported listener setup to avoid merge in async_fire_internal (#117953)
* Refactor state_reported listener setup to avoid merge in async_fire_internal

Instead of merging the listeners in async_fire_internal, setup the listener for
state_changed at the same time so async_fire_internal can avoid having to copy
another list

* Refactor state_reported listener setup to avoid merge in async_fire_internal

Instead of merging the listeners in async_fire_internal, setup the listener for
state_changed at the same time so async_fire_internal can avoid having to copy
another list

* tweak

* tweak

* tweak

* tweak

* tweak
2024-05-22 23:14:50 -04:00
J. Nick KostonandGitHub 5a609c34bb Fix blocking I/O in the event loop when loading timezones (#117721) 2024-05-20 11:06:03 +02:00
d29084d6fc Improve thread safety check messages to better convey impact (#117467)
Co-authored-by: Paulus Schoutsen <[email protected]>
2024-05-15 13:49:57 +09:00
J. Nick KostonandGitHub 7871e9279b Adjust thread safety check messages to point to developer docs (#117392) 2024-05-14 15:20:31 +02:00
J. Nick KostonandGitHub 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
J. Nick KostonandGitHub e215270c05 Remove eager_start argument from internal _async_add_hass_job function (#116310) 2024-04-28 16:30:19 -05:00
J. Nick KostonandGitHub e0b58c3f45 Move thread safety check in async_register/async_remove (#116077) 2024-04-24 10:41:11 +02:00
J. Nick KostonandGitHub 4a59ee978c Always do thread safety checks when calling async_fire (#116055) 2024-04-24 06:41:55 +02:00
J. Nick KostonandGitHub 53a179088f Add debug mode to catch unsafe thread operations using core helpers (#115390)
* adjust

* adjust

* fixes

* one more

* test

* debug

* move to config

* cover

* Update homeassistant/core.py

* set debug from RuntimeConfig

* reduce

* fix message

* raise

* Update homeassistant/core.py

* Update homeassistant/core.py

* no flood check for raise

* cover
2024-04-24 03:36:05 +02:00
SidandGitHub 895f73d8e4 Enable Ruff A001 (#115654) 2024-04-21 23:25:27 +02:00
b592225a87 Improve service validation exception test and translation key (#115843)
* Small improvement to service validation exception test and translation key

* Apply suggestions from code review

Co-authored-by: Martin Hjelmare <[email protected]>

* Refactor string assertion

---------

Co-authored-by: Martin Hjelmare <[email protected]>
2024-04-21 08:54:23 +02:00
Alberto MontesandGitHub c94b0a82ca Make release channel a hardcoded enum rather than a free form string (#115595)
* Make release channel a hardcoded enum rather than a free form string

* Update enum comparison to remove equality and us identity comparison

* Fix comparison condition to match the previous implementation

* Update tests to use Enum instead of string
2024-04-20 20:01:49 +02:00
3299bc5ddc Translate service validation errors (#115024)
* Move service validation error message to translation cache

* Fix test

* Revert unrelated change

* Address review comments

* Improve error message

---------

Co-authored-by: J. Nick Koston <[email protected]>
2024-04-18 14:36:03 +02:00
J. Nick KostonandGitHub 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
J. Nick KostonandGitHub b70edb89bf Fix missing Home in listener deprecation message (#115559) 2024-04-13 20:44:07 -05:00
J. Nick KostonandGitHub ee535ee611 Ensure test async_create_task eager start behavior matches production (#115517) 2024-04-13 15:58:52 -05:00
J. Nick KostonandGitHub ca5ed274cb Deprecate calling async_listen and async_listen_once with run_immediately (#115169) 2024-04-08 10:07:54 -10:00
J. Nick KostonandGitHub 6b4457043d Deprecate async_add_hass_job (#115061) 2024-04-07 14:08:25 -10:00
J. Nick KostonandGitHub c33a234048 Make eager_start default to True for async_create_task (#114995) 2024-04-06 09:15:40 -10:00
J. Nick KostonandGitHub 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
cceea6dac2 Refactor ConfigStore to avoid needing to pass config_dir (#114827)
Co-authored-by: Erik <[email protected]>
2024-04-04 09:30:10 -10:00
J. Nick KostonandGitHub 9a79320861 Mark executor jobs as background unless created from a tracked task (#114450)
* Mark executor jobs as background unless created from a tracked task

If the current task is not tracked the executor job should not
be a background task to avoid delaying startup and shutdown.

Currently any executor job created in a untracked task or
background task would end up being tracked and delaying
startup/shutdown

* import exec has the same issue

* Avoid tracking import executor jobs

There is no reason to track these jobs as they are always awaited
and we do not want to support fire and forget import executor jobs

* fix xiaomi_miio

* lots of fire time changed without background await

* revert changes moved to other PR

* more

* more

* more

* m

* m

* p

* fix fire and forget tests

* scrape

* sonos

* system

* more

* capture callback before block

* coverage

* more

* more races

* more races

* more

* missed some

* more fixes

* missed some more

* fix

* remove unneeded

* one more race

* two
2024-03-30 00:16:53 -04:00
Marc MuellerandGitHub c8260a5966 Remove test cases for task eager_start <3.12 (#114243) 2024-03-26 15:52:38 +01:00
Erik MontnemeryandGitHub dd43947ca0 Add test to ensure non callback event filter is rejected (#114182) 2024-03-26 10:36:08 +01:00
J. Nick KostonandGitHub cabc4f797a Preload storage for integrations we know we are going to setup (#114192) 2024-03-25 15:49:54 -10:00
6bb4e7d62c Bump ruff to 0.3.4 (#112690)
Co-authored-by: Sid <[email protected]>
Co-authored-by: Marc Mueller <[email protected]>
Co-authored-by: J. Nick Koston <[email protected]>
2024-03-26 00:02:16 +01:00
e2ee623d23 Add restrictions for listening to event_reported events (#114183)
* Add restrictions for listening to event_reported events

* Update homeassistant/core.py

Co-authored-by: Martin Hjelmare <[email protected]>

---------

Co-authored-by: Martin Hjelmare <[email protected]>
2024-03-25 19:16:50 +01:00
Jan BouwhuisandGitHub 67ab49b825 Fetch ServiceNotFound message from translation cache and fix super (#114084)
* Fetch ServiceNotFound message from translation cache and fix super

* Fix tests trace component

* Fix script errors
2024-03-24 07:41:13 -10:00
Jan BouwhuisandGitHub dc38d152df Fetch ServiceNotFound message from translation cache (#113893) 2024-03-21 06:54:29 +01:00
8edbf88da1 Fetch MaxLengthExceeded exception mesage from the translation cache (#113904)
* Fetch MaxLengthExceeded exception mesage from the translation cache

* Update homeassistant/components/homeassistant/strings.json

Co-authored-by: J. Nick Koston <[email protected]>

* Add case without homeassistant integration

* Fix test

---------

Co-authored-by: J. Nick Koston <[email protected]>
2024-03-21 06:53:26 +01:00
Erik MontnemeryandGitHub 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
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 <[email protected]>
2024-03-20 09:40:06 +01:00
00ec7f11f0 Enable Ruff rule PT007 (#113764)
Co-authored-by: Franck Nijhof <[email protected]>
2024-03-19 09:01:07 +01:00
6113b99ddd Replace pylint pointless-statement with ruff B018 (#113582)
* Replace pylint pointless-statement with ruff B018

* fix occurrences of B018

* disable pylint expression-not-assigned as well

---------

Co-authored-by: J. Nick Koston <[email protected]>
2024-03-17 10:58:14 +01:00
SidandGitHub 0b9c9aff62 Add ruff rules PIE790, PIE794, PIE807, PIE810 (#113617) 2024-03-16 11:04:58 -10:00
J. Nick KostonandGitHub 5512e8b789 Deprecate async_run_job and async_add_job (#113260) 2024-03-14 09:06:55 -10:00
J. Nick KostonandGitHub d6f1405874 Migrate one time listeners to use async_run_hass_job (#113179) 2024-03-13 11:06:30 +01:00
J. Nick KostonandGitHub 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 KostonandGitHub 53c3e27ed9 Add support for run_immediately to async_listen_once (#113020) 2024-03-11 13:51:03 -10:00
J. Nick KostonandGitHub 77cdecf0f1 Migrate async_run_job to use eager_start for tasks (#113011) 2024-03-11 11:30:46 -10:00
J. Nick KostonandGitHub 3387892f59 Schedule tasks eagerly when called from hass.add_job (#113014) 2024-03-10 21:19:49 -10:00
J. Nick KostonandGitHub 60bddc2861 Schedule coroutine functions eagerly when async_listen uses run_immediately (#112846)
We have a few places where we call async_listen with a callback so we can schedule
the coro eagerly. We can drop these in favor of setting run_immediately now.
2024-03-09 23:04:25 -05:00
J. Nick KostonandGitHub 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
Marc MuellerandGitHub 19ab3d6daf Add empty line after module docstring [helpers + other] (#112707) 2024-03-08 10:36:11 -05:00
J. Nick KostonandGitHub 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
J. Nick KostonandGitHub e12e129065 Make HassJob job_type lookup lazy (#112563) 2024-03-06 17:03:27 -10:00
J. Nick KostonandGitHub 25510fc13c Limit executor imports to a single thread (#111898)
* Limit executor imports to a single thread

* test for import executor

* test for import executor

* test for import executor

* fixes

* better fix
2024-02-29 21:02:13 -05:00
J. Nick KostonandGitHub 044ace0a6a Make core tests that should run in the event loop coros (#111605) 2024-02-26 23:18:22 -10:00
J. Nick KostonandGitHub 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 KostonandGitHub b5afdf34f4 Improve ability to debug one time listeners blocking the event loop (#110064) 2024-02-09 08:44:14 +01:00