Commit Graph

2658 Commits (eeeb5b272538a5ecd5bbb44930b361935ae8a7cd)

Author SHA1 Message Date
Marc Mueller 018e7731ae
Add SignificantChangeProtocol to improve platform typing (#117002) 2024-05-07 18:40:57 +02:00
Marc Mueller 2db64c7e6d
Use HassKey for helpers (1) (#117012) 2024-05-07 11:25:16 -05:00
Marc Mueller 8f614fb06d
Use HassKey for helpers (2) (#117013) 2024-05-07 11:24:13 -05:00
Marc Mueller fd5885ec83
Use HassKey for registries (#117000) 2024-05-07 18:03:14 +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 5d5f311898
Move thread safety check in issue_registry sooner (#116899) 2024-05-05 20:32:55 -05:00
J. Nick Koston 91fa8b50cc
Turn on thread safety checks in async_dispatcher_send (#116867)
* Turn on thread safety checks in async_dispatcher_send

We keep seeing issues where async_dispatcher_send is called from
a thread which means we call the callback function on the other
side in the thread as well which usually leads to a crash

* Turn on thread safety checks in async_dispatcher_send

We keep seeing issues where async_dispatcher_send is called from
a thread which means we call the callback function on the other
side in the thread as well which usually leads to a crash

* adjust
2024-05-05 16:29:43 -04:00
J. Nick Koston b41b1bb998
Refactor entity_platform polling to avoid double time fetch (#116877)
* Refactor entity_platform polling to avoid double time fetch

Replace async_track_time_interval with loop.call_later
to avoid the useless time fetch every time the listener
fired since we always throw it away

* fix test
2024-05-05 16:28:01 -04:00
J. Nick Koston 0380116ef6
Improve logging of _TrackPointUTCTime objects (#116711) 2024-05-04 17:35:44 -05:00
Jan Bouwhuis 84308c9e53
Add title feature to notify entity platform (#116426)
* Add title feature to notify entity platform

* Add overload variants

* Remove overloads, update signatures

* Improve test coverage

* Apply suggestions from code review

Co-authored-by: Martin Hjelmare <marhje52@gmail.com>

* Do not use const

* fix typo

---------

Co-authored-by: Martin Hjelmare <marhje52@gmail.com>
2024-05-03 11:17:28 +02:00
J. Nick Koston 2401580b6f
Make a copy of capability_attributes instead of making a new dict (#116477) 2024-04-30 17:54:33 -05:00
G Johansson 822646749d
Remove entity category "system" check from entity registry (#116412) 2024-04-30 04:01:12 +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 ab2ea6100c
Speed up singleton decorator so it can be used more places (#116292) 2024-04-28 12:11:08 -05:00
J. Nick Koston 66e86170b1
Make storage load tasks background tasks to avoid delaying shutdown (#116332) 2024-04-28 08:14:15 -05:00
J. Nick Koston 76639252c9
Make discovery flow tasks background tasks (#116327) 2024-04-28 08:13:37 -05:00
J. Nick Koston cbcfd71f3d
Reduce number of time calls needed to write state (#116297) 2024-04-27 13:17:31 -05:00
J. Nick Koston f295172d07
Add a fast path for _stringify_state when state is already a str (#116295) 2024-04-27 10:48:17 -05:00
J. Nick Koston eea66921bb
Avoid update call in entity state write if there is no customize data (#116296) 2024-04-27 10:48:05 -05:00
J. Nick Koston 7715bee6b0
Fix script in restart mode that is fired from the same trigger (#116247) 2024-04-27 07:08:29 -05:00
J. Nick Koston b403c9f92e
Move thread safety check in area_registry sooner (#116265)
It turns out we have custom components that are writing to the area registry using the async APIs from threads. We now catch it at the point async_fire is called. Instead we should check sooner and use async_fire_internal so we catch the unsafe operation before it can corrupt the registry.
2024-04-27 09:26:35 +02:00
J. Nick Koston 244433aeca
Move thread safety check in entity_registry sooner (#116263)
* Move thread safety check in entity_registry sooner

It turns out we have a lot of custom components that are writing
to the entity registry using the async APIs from threads. We now
catch it at the point async_fire is called. Instread we should check
sooner and use async_fire_internal so we catch the unsafe operation
before it can corrupt the registry.

* coverage

* Apply suggestions from code review
2024-04-27 09:25:19 +02:00
J. Nick Koston 09ebbfa0e1
Move thread safety check in device_registry sooner (#116264)
It turns out we have custom components that are writing to the device registry using the async APIs from threads. We now catch it at the point async_fire is called. Instead we should check sooner and use async_fire_internal so we catch the unsafe operation before it can corrupt the registry.
2024-04-27 09:24:55 +02:00
Sid e662e3b65c
Bump ruff to 0.4.2 (#116201)
* Bump ruff to 0.4.2

* review comments
2024-04-26 08:48:32 +02:00
Erik Montnemery 623d34e1e0
Remove early return when validating entity registry items (#116160) 2024-04-26 08:38:24 +02:00
Jan Bouwhuis 372c6c7874
Use existing monotonic timestamp on mqtt messages for debugging (#116196) 2024-04-25 19:09:54 -05:00
Erik Montnemery 6bff0c384f
Remove deprecation warnings for relative_time (#116144)
* Remove deprecation warnings for relative_time

* Update homeassistant/helpers/template.py

Co-authored-by: Simon <80467011+sorgfresser@users.noreply.github.com>

---------

Co-authored-by: Simon <80467011+sorgfresser@users.noreply.github.com>
2024-04-25 13:02:18 +02:00
Erik Montnemery 2e88ba40ff
Fix lying docstring for relative_time template function (#116146)
* Fix lying docstring for relative_time template function

* Update homeassistant/helpers/template.py

Co-authored-by: Martin Hjelmare <marhje52@gmail.com>

---------

Co-authored-by: Martin Hjelmare <marhje52@gmail.com>
2024-04-25 13:01:41 +02:00
J. Nick Koston df12789e08
Remove duplicate async_write_ha_state thread safety check (#116086) 2024-04-24 12:46:16 +02:00
rlippmann 1120246194
Deprecate relative_time() in favor of time_since() and time_until() (#111177)
* add time_since/time_until.  add deprecation of relative_time

* fix merge conflicts

* Apply suggestions from code review

* Update homeassistant/helpers/template.py

* Update homeassistant/helpers/template.py

* Update homeassistant/helpers/template.py

---------

Co-authored-by: Erik Montnemery <erik@montnemery.com>
2024-04-24 11:13:07 +02:00
J. Nick Koston 79b4889812
Always do thread safety checks when writing state for custom components (#116044) 2024-04-24 10:05:52 +02:00
Robert Resch a4829330f6
Add strict connection for cloud (#115814)
Co-authored-by: Martin Hjelmare <marhje52@gmail.com>
2024-04-24 09:57:38 +02:00
J. Nick Koston b520efb87a
Small speed up to async_track_event (#116083) 2024-04-24 09:56:59 +02:00
Sid b37f7b1ff0
Enable Ruff RUF019 (#115396)
* Enable Ruff RUF019

* fix tado tests

* review comments
2024-04-24 07:23:24 +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
J. Nick Koston 8f1761343e
Only work out job type once when setting up dispatcher (#116030) 2024-04-23 22:24:36 +02:00
Martijn van der Pol e90d76b18d
Don't raise errors when using datetime objects in `as_datetime` Jinja function/filter (#109062)
* add support for datetime objects to as_datetime

* change import of datetime.date

---------

Co-authored-by: Erik Montnemery <erik@montnemery.com>
2024-04-23 09:55:58 +02:00
Sid 895f73d8e4
Enable Ruff A001 (#115654) 2024-04-21 23:25:27 +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
J. Nick Koston 4529268544
Ensure scripts with timeouts of zero timeout immediately (#115830) 2024-04-19 18:24:54 +02:00
J. Nick Koston d48bd9b016
Deprecate async_track_state_change in favor of async_track_state_change_event (#115558) 2024-04-18 10:45:14 -05:00
J. Nick Koston 80d6cdad67
Small cleanups to translation loading (#115583)
- Add missing typing
- Convert a update loop to a set comp
- Save some indent
2024-04-18 10:42:44 -04:00
J. Nick Koston 11931cdb56
Simplify labels and areas template calls (#115673)
The labels and areas are already exposed on the object
2024-04-17 21:28:09 +02:00
J. Nick Koston bd2efffb4a
Reduce duplicate code in the device registry (#115677) 2024-04-17 15:50:39 +02:00
J. Nick Koston 45f025480e
Avoid linear search to remove a label from the entity registry (#115674)
* Avoid linear search to remove a label from the entity registry

* simplify
2024-04-17 15:47:56 +02:00
J. Nick Koston 8cf14c9268
Avoid linear search to clear labels and areas in the device registry (#115676) 2024-04-17 15:46:59 +02:00
J. Nick Koston 9ca24ab2a2
Avoid linear search to remove labels and floors from area registry (#115675)
* Avoid linear search to remove labels and floors from area registry

* simplify
2024-04-17 15:45:40 +02:00
J. Nick Koston 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
Erik Montnemery 7cd0fe3c5f
Don't reload other automations when saving an automation (#80254)
* Only reload modified automation

* Correct check for existing automation

* Add tests

* Remove the new service, improve ReloadServiceHelper

* Revert unneeded changes

* Update tests

* Address review comments

* Improve test coverage

* Address review comments

* Tweak reloader code + add a targetted test

* Apply suggestions from code review

Co-authored-by: Martin Hjelmare <marhje52@gmail.com>

* Explain the tests + add more variations

* Fix copy-paste mistake in test

* Rephrase explanation of expected test outcome

---------

Co-authored-by: Martin Hjelmare <marhje52@gmail.com>
2024-04-16 15:58:57 +02:00
J. Nick Koston dbc5109fd8
Avoid update calls in state writes when attributes are empty (#115624) 2024-04-15 17:42:18 +02:00
J. Nick Koston 3963b3994b
Small cleanups to the rate limit helper (#115621) 2024-04-15 13:42:28 +02:00
J. Nick Koston 33412dd9f6
Remove unused legacy state translations (#112023)
* Remove unused state translations

There have been replaced with entity translations
https://github.com/home-assistant/developers.home-assistant/pull/1557
https://github.com/home-assistant/core/pull/82701

* nothing does merging anymore

* useless dispatch

* remove

* remove platform code from hassfest

* preen

* Update homeassistant/helpers/translation.py

* ruff

* fix merge

* check is impossible now since we already know if translations exist or not

* keep the function for now

* remove unreachable code since we filter out `.` before now

* reduce

* reduce

* fix merge conflict (again)
2024-04-14 07:13:17 -04:00
Sid 3799d20d43
Enable Ruff B905 (#114197) 2024-04-14 00:14:26 -05:00
J. Nick Koston 8da7de1fea
Remove attr usage in event helper (#115554) 2024-04-13 19:46:23 -05:00
J. Nick Koston edd75a9d5f
Fix race in TimestampDataUpdateCoordinator (#115542)
* Fix race in TimestampDataUpdateCoordinator

The last_update_success_time value was being set after the listeners
were fired which could lead to a loop because the listener may
re-trigger an update because it thinks the data is stale

* coverage

* docstring
2024-04-13 16:35:07 -04:00
Marc Mueller 1b24e78dd9
Improve FlowHandler menu_options typing (#115296) 2024-04-11 22:14:37 -04:00
Jan Bouwhuis 10076e6523
Add notify entity component (#110950)
* Add notify entity component

* Device classes, restore state, icons

* Add icons file

* Add tests for kitchen_sink

* Remove notify from no_entity_platforms in hassfest icons, translation link

* ruff

* Remove `data` feature

* Only message support

* Complete initial device classes

* mypy pylint

* Remove device_class implementation

* format

* Follow up comments

* Remove _attr_supported_features

* Use setup_test_component_platform

* User helper at other places

* last comment

* Add entry unload test and non async test

* Avoid default mutable object in constructor
2024-04-11 12:04:08 +02:00
J. Nick Koston f0c8c2a684
Adjust importlib helper to avoid leaking memory on re-raise (#115377) 2024-04-10 15:19:17 -10:00
J. Nick Koston 6bd6adc4f5
Avoid calling valid_entity_id when adding entities if they are already registered (#115388) 2024-04-10 15:18:47 -10:00
J. Nick Koston bbecb98927
Fix type on known_object_ids in _entity_id_available and async_generate_entity_id (#115378) 2024-04-10 11:44:25 -10:00
J. Nick Koston f80894d56f
Stop scripts with eager tasks (#115340) 2024-04-10 08:41:13 -04:00
Sid d61db732da
Enable Ruff SLOT rules (#115043) 2024-04-09 18:57:27 -10:00
Marc Mueller d8c8d1a297
Use dict instead of MutableMapping [extra_state_attributes] (#115319) 2024-04-09 15:06:11 -10:00
J. Nick Koston 11af7d91ff
Optimize _async_track_event for the single key common case (#115242) 2024-04-09 07:04:50 -10:00
J. Nick Koston 95958ac0ef
Increase discovery flow init concurrency limit to 20 (#115230) 2024-04-08 11:05:40 -10: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
Sid 9cbed10372
Enable Ruff PYI041 (#115229) 2024-04-08 09:29:05 -10:00
Marc Mueller 4e94f11665
Use EventType for entity_registry_updated (#115187) 2024-04-08 08:44:59 -10:00
Marc Mueller 2fc0d8494d
Use EventType for device_registry_updated (#115188) 2024-04-08 08:25:57 -10:00
Marc Mueller 0d18679c8f
Use EventType for remaining registry events (#115189) 2024-04-08 08:25:39 -10:00
Marc Mueller 6116f11e6c
Use EventType for system events (#115190) 2024-04-08 08:25:34 -10:00
J. Nick Koston 9ef28f83ea
Switch async_track_state_change to use run_immediately (#115164) 2024-04-07 16:38:25 -10:00
J. Nick Koston 89a2c89fe2
Avoid checking for polling if an entity fails to add (#115159)
* Avoid checking for polling if an entity fails to add

* no need to do protected access

* no need to do protected access

* no need to do protected access

* no need to do protected access

* coverage

* fix test

* fix

* broken one must be first
2024-04-07 21:25:55 -04:00
Marc Mueller 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 <nick@koston.org>
2024-04-07 13:28:24 -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
J. Nick Koston 569f54d8e3
Terminate scripts with until and while conditions that execute more than 10000 times (#115110) 2024-04-07 11:02:53 -10:00
Marc Mueller cb9352110c
Improve registry store data typing (#115066) 2024-04-06 14:34:49 -10:00
J. Nick Koston a0936902c2
Use identity checks for EntityPlatformState enum (#115067) 2024-04-07 02:31:23 +02:00
Marc Mueller 8324fd5d1d
Deprecated old backports and typing aliases (#114883) 2024-04-06 13:15:30 -10:00
J. Nick Koston c4b5a7c027
Migrate start helper to use run_immediately (#115055) 2024-04-06 12:35:46 -10:00
Marc Mueller 81d682874f
Update typing extensions to 4.11.0 (#114985) 2024-04-06 14:23:32 +02:00
Sid 0d66d298ec
Enable Ruff RET504 (#114528)
* Enable Ruff RET504

* fix test

* Use noqa instead of cast

* fix sonos RET504

---------

Co-authored-by: Martin Hjelmare <marhje52@gmail.com>
2024-04-06 11:07:37 +02:00
J. Nick Koston f497c461ed
Switch to using the AsyncResolver with aiohttp (#114529)
* Bump aiodns to 3.2.0

changelog: https://github.com/saghul/aiodns/compare/v3.1.1...v3.2.0

* Switch to using the AsyncResolver with aiohttp

This avoids creating executor jobs to do DNS resolution

AsyncResolver was not usable before https://github.com/aio-libs/aiohttp/pull/8270
because it did not fallback to fallback to A records and only returned AAAA records
in most cases when IPv6 was available

This is a backport of https://github.com/aio-libs/aiohttp/pull/8270

* Switch to using the AsyncResolver with aiohttp

This avoids creating executor jobs to do DNS resolution

AsyncResolver was not usable before https://github.com/aio-libs/aiohttp/pull/8270
because it did not fallback to fallback to A records and only returned AAAA records
in most cases when IPv6 was available

This is a backport of https://github.com/aio-libs/aiohttp/pull/8270

* Switch to using the AsyncResolver with aiohttp

This avoids creating executor jobs to do DNS resolution

AsyncResolver was not usable before https://github.com/aio-libs/aiohttp/pull/8270
because it did not fallback to fallback to A records and only returned AAAA records
in most cases when IPv6 was available

This is a backport of https://github.com/aio-libs/aiohttp/pull/8270

* Switch to using the AsyncResolver with aiohttp

This avoids creating executor jobs to do DNS resolution

AsyncResolver was not usable before https://github.com/aio-libs/aiohttp/pull/8270
because it did not fallback to fallback to A records and only returned AAAA records
in most cases when IPv6 was available

This is a backport of https://github.com/aio-libs/aiohttp/pull/8270

* fixes

* fix mocking in next_dns

* fix unmocked calls in blink

* more mocking fixes

* more fixes

* more fixes

* Fix missing mocking in nextdns tests

extracted from #114539

* extract from context
2024-04-05 23:15:51 -04: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 00db97a765
Run device_registry stop listener immediately (#114978) 2024-04-05 21:59:27 -04:00
J. Nick Koston d25ac06326
Run storage final write listener immediately (#114976)
This one should not need a call_soon
2024-04-05 21:59:11 -04:00
J. Nick Koston aeaed83578
Start async_schedule_update_ha_state task eagerly (#114704) 2024-04-05 08:14:21 -10:00
J. Nick Koston bfe944f666
Handle ambiguous script actions by using action map order (#114825) 2024-04-05 08:42:57 +02:00
J. Nick Koston d321906342
Always run keyed event trackers immediately (#114709) 2024-04-04 15:30:01 -10:00
Erik Montnemery 7c95ecff20
Validate unique_id in entity registry (#114648)
Co-authored-by: Shay Levy <levyshay1@gmail.com>
Co-authored-by: J. Nick Koston <nick@koston.org>
2024-04-04 09:51:44 -10:00
J. Nick Koston cceea6dac2
Refactor ConfigStore to avoid needing to pass config_dir (#114827)
Co-authored-by: Erik <erik@montnemery.com>
2024-04-04 09:30:10 -10:00
Marc Mueller 56ef9500f7
Use EventStateChangedData type when firing state changed event (#114740) 2024-04-04 09:27:44 -10:00
J. Nick Koston a9d43db315
Avoid linear search to clear a config entry in the device registry (#114802) 2024-04-04 08:35:07 -10:00
Marc Mueller 816ce116bf
Remove unnecessary functools.cached_property backport (#114239) 2024-04-04 11:24:26 +02: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 56d0ad27f0
Adjust async_load_platform comment to remove dead lock reference (#114771)
* Adjust async_load_platform comment

Its likely the deadlock here has been fixed for a long time, however
we should still do these in a task because it has to wait for base
components if they are not loaded yet.

* Adjust async_load_platform comment

Its likely the deadlock here has been fixed for a long time, however
we should still do these in a task because it has to wait for base
components if they are not loaded yet.
2024-04-03 22:53:31 -04: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