Commit Graph
292 Commits
Author SHA1 Message Date
J. Nick KostonandGitHub 34d17ca458 Move state length validation to StateMachine APIs (#143681)
* Move state length validation to StateMachine async_set method

We call validate_state to make sure we do not allow any states
into the state machine that have a length>255 so we do not break
the recorder. Since async_set_internal already requires callers
to pre-validate the state, we can move the check to async_set
instead of at State object creation time to avoid needing to
check it twice in the hot path (entity write state)

* move check in async_set_internal so it only happens on state change

* no need to check if same_state
2025-04-25 21:15:15 -04:00
epenetandGitHub 364556a7dd Prefer from...import...as over import...as in core tests (#136146) 2025-01-21 09:28:17 +01:00
epenetandGitHub 899fb091fc Simplify access to hass in service calls (#133062) 2024-12-13 09:31:21 +01:00
Robert ReschandGitHub be81fd86d3 Remvove deprecated core constants (#131803) 2024-11-28 11:06:04 +01:00
epenetandGitHub c7485b94d5 Use breaks_in_ha_version in report_usage (#131137)
* Use breaks_in_ha_version in report_usage

* Revert behavior change
2024-11-23 18:58:24 +01:00
epenetandGitHub deeb55ac50 Add ability to set HA breaking version in report_usage (#130858)
* Add ability to set breaking version in report_usage

* Adjust tests

* Adjust test

* Adjust tests

* Rename breaks_in_version => breaks_in_ha_version
2024-11-20 21:41:57 +01:00
Erik MontnemeryandGitHub 1c6ad2fa66 Allow importing homeassistant.core.Config until 2025.11 (#129537) 2024-10-30 22:56:59 +01:00
Erik MontnemeryandGitHub 4b56701152 Move core config class to core_config.py (#129163) 2024-10-26 07:00:31 +02:00
c759512c70 Prevent callback decorator on coroutine functions (#126429)
* Prevent callback decorator on async functions

* Adjust

* Adjust

* Adjust components

* Adjust tests

* Rename

* One more

* Adjust

* Adjust again

* Apply suggestions from code review

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

---------

Co-authored-by: Martin Hjelmare <[email protected]>
2024-09-23 02:55:55 +02:00
epenetandGitHub ad26db7dc8 Replace pylint broad-exception-raised rule with ruff (#123021) 2024-08-02 12:24:03 +02:00
Marc MuellerandGitHub a6068dcdf2 Update import locations in tests (#122216) 2024-07-20 11:16:04 +02:00
Marc MuellerandGitHub 8bca9a3449 Fix return type annotations in tests (#122184) 2024-07-19 16:44:03 +02:00
Franck NijhofandGitHub a9bf12f102 Rename Services to Actions in translation strings (#121777) 2024-07-15 21:19:25 +02:00
J. Nick KostonandGitHub 8a5b201d75 Fix blocking I/O in event loop in core test (#121128) 2024-07-04 07:43:46 +02:00
J. Nick KostonandGitHub 852bb19223 Cleanup db_schema from_event constructors (#120803) 2024-06-29 07:49:16 -05:00
Erik MontnemeryandGitHub d589eaf440 Simplify EVENT_STATE_REPORTED (#120508) 2024-06-26 11:23:26 +02:00
epenetandGitHub f0dc39a903 Improve typing in core tests (#119958)
Add missing return values in core tests
2024-06-19 19:58:07 +02:00
Erik MontnemeryandGitHub 7e61ec96e7 Make the radius of the home zone configurable (#119385) 2024-06-15 13:22:01 +02:00
epenetandGitHub 9f41133bbc Add missing argument type to core tests (#119667) 2024-06-14 08:42:01 +02:00
epenetandGitHub abb8c58b87 Fix consider-using-tuple pylint warnings in core tests (#119463) 2024-06-12 12:35:01 +02:00
epenetandGitHub 2a7e78a80f Ignore broad-exception-raised pylint warnings in tests (#119468) 2024-06-12 12:21:41 +02:00
epenetandGitHub 7388271689 Fix unspecified-encoding warnings in tests (#119405) 2024-06-11 17:58:40 +02:00
SidandGitHub 721b2c2ca8 Enable Ruff PT012 (#113957) 2024-06-08 17:59:08 +02:00
J. Nick KostonandGitHub 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 KostonandGitHub 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 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