Commit Graph
551 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 e12d23bd48 Speed up async_get_loaded_integrations (#117851)
* Speed up async_get_loaded_integrations

Use a setcomp and difference to find the components to split
to avoid the loop. A setcomp is inlined in python3.12 so its
much faster

* Speed up async_get_loaded_integrations

Use a setcomp and difference to find the components to split
to avoid the loop. A setcomp is inlined in python3.12 so its
much faster

* simplify

* fix compat

* bootstrap

* fix tests
2024-05-21 09:08:49 -04:00
J. Nick KostonandGitHub e8fc4e0f19 Small speed up to adding event bus listeners (#117849) 2024-05-21 13:52:44 +02:00
Marc MuellerandGitHub 7998f874c0 Use PEP 695 for function annotations with scoping (#117787) 2024-05-20 12:43:39 +02:00
Marc MuellerandGitHub f50973c76c Use PEP 695 misc (#117788) 2024-05-20 12:01:49 +02: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
Marc MuellerandGitHub 0293315b23 Use PEP 695 for covariant class annotations (#117780) 2024-05-20 10:55:44 +02:00
Marc MuellerandGitHub 4cf0a3f154 Use PEP 695 for function annotations (3) (#117660) 2024-05-18 11:43:32 +02:00
Marc MuellerandGitHub 87bb7ced79 Use PEP 695 for simple type aliases (#117633) 2024-05-17 14:42:21 +02:00
Marc MuellerandGitHub 4edee94a81 Update mypy-dev to 1.11.0a2 (#117630) 2024-05-17 13:32:20 +02:00
Marc MuellerandGitHub 4300ff6b60 Mark HassJob target as Final (#117578) 2024-05-17 00:01:07 +02:00
Marc MuellerandGitHub 53da59a454 Replace meaningless TypeVar usage (#117553) 2024-05-16 12:48:02 +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
ac54cdcdb4 Enable Ruff RUF010 (#115371)
Co-authored-by: J. Nick Koston <[email protected]>
2024-05-08 23:54:49 +02:00
SidandGitHub 2cc916db6d Replace pylint broad-except with Ruff BLE001 (#116250) 2024-05-07 14:00:27 +02:00
Marc MuellerandGitHub 3d700e2b71 Add HassDict implementation (#103844) 2024-05-07 10:53:13 +02:00
SidandGitHub b456d97e65 Replace pylint protected-access with Ruff SLF001 (#115735) 2024-05-06 20:33:26 +02:00
J. Nick KostonandGitHub 0b08ae7e44 Reduce timestamp function call overhead in core states (#116517)
* Reduce timestamp function call overhead in core states

The recorder or the websocket_api will always call the timestamps, so we will set the timestamp values when creating the State to avoid the function call overhead in the property we know will always be called.

* Reduce timestamp function call overhead in core states

The recorder or the websocket_api will always call the timestamps, so we will set the timestamp values when creating the State to avoid the function call overhead in the property we know will always be called.

* reduce scope of change since last_reported is not called in websocket_api

* reduce scope of change since last_reported is not called in websocket_api
2024-05-01 11:04:20 -05:00
J. Nick KostonandGitHub f1e5bbcbca Fix grammar in internal function comments (#116387)
https://github.com/home-assistant/core/pull/116339#discussion_r1582610474
2024-04-29 17:01:15 +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 5d59b4cddd Remove unneeded TYPE_CHECKING guard in core async_set (#116311) 2024-04-27 19:34:17 -05:00
J. Nick KostonandGitHub 50405fae5f Add a cache to _verify_event_type_length_or_raise (#116312)
Most of the time the events being fired are the same so we can
skip the python code in this function
2024-04-27 18:42:29 -05:00
J. Nick KostonandGitHub cbcfd71f3d Reduce number of time calls needed to write state (#116297) 2024-04-27 13:17:31 -05:00
Erik MontnemeryandGitHub aa65f21be7 Fix flapping recorder tests (#116239) 2024-04-26 09:05:23 -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
J. Nick KostonandGitHub a22c221722 Rename bus._async_fire to bus.async_fire_internal (#116027) 2024-04-23 22:28:31 +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 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
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 <[email protected]>
2024-04-07 13:28:24 -10:00
8e98ba7312 Add first batch of Ruff PYI rules (#115100)
Co-authored-by: Jan Bouwhuis <[email protected]>
2024-04-07 11:30:50 -10:00
J. Nick KostonandGitHub 166910f587 Make eager_start default to True for async_create_background_task (#114996) 2024-04-06 09:53:50 -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
J. Nick KostonandGitHub 0e2fe3b728 Avoid timestamp conversion in core State when equal to last_updated (#114911) 2024-04-05 08:27:27 +02: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
Marc MuellerandGitHub 56ef9500f7 Use EventStateChangedData type when firing state changed event (#114740) 2024-04-04 09:27:44 -10:00
Marc MuellerandGitHub 816ce116bf Remove unnecessary functools.cached_property backport (#114239) 2024-04-04 11:24:26 +02:00
J. Nick KostonandGitHub cf4c02b9fa Simplify core state cache clear (#114694)
same as #113136 but for core
2024-04-03 12:20:32 +02:00
J. Nick KostonandGitHub 5038a035bd Detect blocking module imports in the event loop (#114488) 2024-03-30 19:51:31 -10:00
SidandGitHub 6587ee20db Enable Ruff TRY300 (#114437)
* Enable Ruff TRY300

* Update validation.py

* Address review comments
2024-03-30 10:37:59 +01: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