Commit Graph

568 Commits

Author SHA1 Message Date
Erik Montnemery
d1264655a0 Fix some typos in core.py (#121189) 2024-07-04 13:04:52 +02:00
J. Nick Koston
48172b0426 Small speed up to writing entity state (#121043) 2024-07-03 12:16:41 -05:00
J. Nick Koston
852bb19223 Cleanup db_schema from_event constructors (#120803) 2024-06-29 07:49:16 -05:00
Erik Montnemery
3895252965 Fix docstring for EventStateEventData (#120662) 2024-06-27 08:00:14 -05:00
Erik Montnemery
a165064e9d Improve typing of state event helpers (#120639) 2024-06-27 06:08:19 -05:00
Erik Montnemery
d589eaf440 Simplify EVENT_STATE_REPORTED (#120508) 2024-06-26 11:23:26 +02:00
Marc Mueller
b4eee166aa Add voluptuous type aliases (#120399) 2024-06-25 11:58:27 +02:00
Erik Montnemery
7e61ec96e7 Make the radius of the home zone configurable (#119385) 2024-06-15 13:22:01 +02:00
Erik Montnemery
904b89df80 Allow importing typing helper in core files (#119377)
* Allow importing typing helper in core files

* Really fix the circular import

* Update test
2024-06-11 13:48:12 +02:00
J. Nick Koston
f9205cd88d Avoid additional timestamp conversion to set state (#118885)
Avoid addtional timestamp conversion to set state

Since we already have the timestamp, we can pass it on to the State
object and avoid the additional timestamp conversion which can be as
much as 30% of the state write runtime.

Since datetime objects are limited to microsecond precision, we need
to adjust some tests to account for the additional precision that we
will now be able to get in the database
2024-06-05 23:43:34 -04:00
J. Nick Koston
475c20d529 Always do thread safety check when writing state (#118886)
* Always do thread safety check when writing state

Refactor the 3 most common places where the thread safety check
for the event loop to be inline to make the check fast enough
that we can keep it long term. While code review catches most
of the thread safety issues in core, some of them still make
it through, and new ones keep getting added. Its not possible
to catch them all with manual code review, so its worth the
tiny overhead to check each time.

Previously the check was limited to custom components
because they were the most common source of thread
safety issues.

* Always do thread safety check when writing state

Refactor the 3 most common places where the thread safety check
for the event loop to be inline to make the check fast enough
that we can keep it long term. While code review catches most
of the thread safety issues in core, some of them still make
it through, and new ones keep getting added. Its not possible
to catch them all with manual code review, so its worth the
tiny overhead to check each time.

Previously the check was limited to custom components
because they were the most common source of thread
safety issues.

* async_fire is more common than expected with ccs

* fix mock

* fix hass mocking
2024-06-05 23:41:55 -04:00
J. Nick Koston
76aa504e36 Fix last_reported_timestamp not being updated when last_reported is changed (#118341)
* Reduce number of calls to last_reported_timestamp

When a state is created, last_update is always the same
as last_reported, and we only update it later if it changes
so we can pre-set the cached property to avoid it being
run when the recorder accesses it later.

* fix cache not being overridden

* coverage
2024-05-28 19:03:19 -10:00
J. Nick Koston
33ff84469a Align max expected entities constant between modules (#118102) 2024-05-27 14:06:16 -10:00
J. Nick Koston
25f199c39c Improve performance of verify_event_loop_thread (#118198) 2024-05-26 17:39:15 -10:00
Paulus Schoutsen
87fc27eeae Teach Context about deepcopy (#118206)
Teach context about deepcopy
2024-05-26 23:14:02 -04:00
J. Nick Koston
56431ef750 Pre-set the HassJob job_type cached_property if its known (#118199) 2024-05-26 16:13:48 -10:00
J. Nick Koston
c368ffffd5 Add async_get_hass_or_none (#118164) 2024-05-26 13:38:46 +02:00
J. Nick Koston
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 Koston
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 Koston
e8fc4e0f19 Small speed up to adding event bus listeners (#117849) 2024-05-21 13:52:44 +02:00
Marc Mueller
7998f874c0 Use PEP 695 for function annotations with scoping (#117787) 2024-05-20 12:43:39 +02:00
Marc Mueller
f50973c76c Use PEP 695 misc (#117788) 2024-05-20 12:01:49 +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
0293315b23 Use PEP 695 for covariant class annotations (#117780) 2024-05-20 10:55:44 +02:00
Marc Mueller
4cf0a3f154 Use PEP 695 for function annotations (3) (#117660) 2024-05-18 11:43:32 +02:00
Marc Mueller
87bb7ced79 Use PEP 695 for simple type aliases (#117633) 2024-05-17 14:42:21 +02:00
Marc Mueller
4edee94a81 Update mypy-dev to 1.11.0a2 (#117630) 2024-05-17 13:32:20 +02:00
Marc Mueller
4300ff6b60 Mark HassJob target as Final (#117578) 2024-05-17 00:01:07 +02:00
Marc Mueller
53da59a454 Replace meaningless TypeVar usage (#117553) 2024-05-16 12:48:02 +02:00
J. Nick Koston
d29084d6fc Improve thread safety check messages to better convey impact (#117467)
Co-authored-by: Paulus Schoutsen <balloob@gmail.com>
2024-05-15 13:49:57 +09:00
J. Nick Koston
7871e9279b Adjust thread safety check messages to point to developer docs (#117392) 2024-05-14 15:20:31 +02:00
Sid
ac54cdcdb4 Enable Ruff RUF010 (#115371)
Co-authored-by: J. Nick Koston <nick@koston.org>
2024-05-08 23:54:49 +02:00
Sid
2cc916db6d Replace pylint broad-except with Ruff BLE001 (#116250) 2024-05-07 14:00:27 +02:00
Marc Mueller
3d700e2b71 Add HassDict implementation (#103844) 2024-05-07 10:53:13 +02:00
Sid
b456d97e65 Replace pylint protected-access with Ruff SLF001 (#115735) 2024-05-06 20:33:26 +02:00
J. Nick Koston
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 Koston
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 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
J. Nick Koston
e215270c05 Remove eager_start argument from internal _async_add_hass_job function (#116310) 2024-04-28 16:30:19 -05:00
J. Nick Koston
5d59b4cddd Remove unneeded TYPE_CHECKING guard in core async_set (#116311) 2024-04-27 19:34:17 -05:00
J. Nick Koston
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 Koston
cbcfd71f3d Reduce number of time calls needed to write state (#116297) 2024-04-27 13:17:31 -05:00
Erik Montnemery
aa65f21be7 Fix flapping recorder tests (#116239) 2024-04-26 09:05:23 -05:00
J. Nick Koston
e0b58c3f45 Move thread safety check in async_register/async_remove (#116077) 2024-04-24 10:41:11 +02:00
J. Nick Koston
4a59ee978c Always do thread safety checks when calling async_fire (#116055) 2024-04-24 06:41:55 +02:00
J. Nick Koston
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 Koston
a22c221722 Rename bus._async_fire to bus.async_fire_internal (#116027) 2024-04-23 22:28:31 +02:00
Jan Bouwhuis
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 <marhje52@gmail.com>

* Refactor string assertion

---------

Co-authored-by: Martin Hjelmare <marhje52@gmail.com>
2024-04-21 08:54:23 +02:00
Alberto Montes
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
Jan Bouwhuis
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 <nick@koston.org>
2024-04-18 14:36:03 +02:00