221 Commits

Author SHA1 Message Date
Erik Montnemery
4b34d1bbb5
Merge config subentry feature branch to dev (#136121)
* Reapply "Add support for subentries to config entries" (#133470) (#136061)

* Reapply "Add support for subentries to config entries" (#133470)

This reverts commit ecb3bf79f32a2e25d141ff467e5958826ed9fc3a.

* Update test snapshot

* Add config subentry support to device registry (#128157)

* Add config subentry support to device registry

* Apply suggestions from code review

* Update syrupy serializer

* Update snapshots

* Address review comments

* Allow a device to be connected to no or a single subentry of a config entry

* Update snapshots

* Revert "Allow a device to be connected to no or a single subentry of a config entry"

This reverts commit ec6f613151cb4a806b7961033c004b71b76510c2.

* Update test snapshots

* Bump release version in comments

* Rename config_subentries to config_entries_subentries

* Add config subentry support to entity registry (#128155)

* Add config subentry support to entity registry

* Update syrupy serializer

* Update snapshots

* Update snapshots

* Accept suggested changes

* Clean registries when removing subentry (#136671)

* Clean up registries when removing subentry

* Update tests

* Clean up subentries from deleted devices when removing config entry (#136669)

* Clean up subentries from deleted devices when removing config entry

* Move

* Add config subentry support to entity platform (#128161)

* Add config subentry support to entity platform

* Rename subentry_id to config_subentry_id

* Store subentry type in subentry (#136687)

* Add reconfigure support to config subentries (#133353)

* Add reconfigure support to config subentries

* Update test

* Minor adjustment

* Rename supported_subentry_flows to supported_subentry_types

* Address review comments

* Add subentry support to kitchen sink (#136755)

* Add subentry support to kitchen sink

* Add subentry reconfigure support to kitchen_sink

* Update kitchen_sink tests with subentry type stored in config entry

* Update kitchen_sink

* Update kitchen_sink

* Adjust kitchen sink tests

* Fix hassfest

* Apply suggestions from code review

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

* Improve docstrings and strings.json

---------

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

* Update snapshots

* Update snapshots

* Update snapshots

* Update snapshots

* Update snapshots

* Update snapshots

* Update snapshots

---------

Co-authored-by: Martin Hjelmare <marhje52@gmail.com>
2025-02-10 16:40:07 +01:00
Marc Mueller
a4fe0cbe7a
Update mypy-dev to 1.16.0a2 (#137542) 2025-02-06 13:43:53 +01:00
Ville Skyttä
40eb8b91cc
Adjust to recommended propcache.api import paths (#136150) 2025-01-21 10:58:22 +01:00
Erik Montnemery
235fda55fe
Validate config entry when adding or updating entity registry entry (#135067) 2025-01-17 19:18:13 +01:00
epenet
5df7092f41
Improve formatting in core files (#135256)
* Adjust core files formatting

* Adjust translations script
2025-01-10 09:08:37 +01:00
Erik Montnemery
5888b83f22
Validate device id when adding or updating entity registry entry (#134982) 2025-01-07 16:10:51 +00:00
J. Nick Koston
24fbc366a6
Restore __slots__ to registry entries (#127481) 2024-10-05 12:16:52 +02:00
J. Nick Koston
0f29fd3e10
Switch to using fast cached_property implementation in propcache (#127339) 2024-10-03 13:11:02 -05:00
J. Nick Koston
0e0ac3efe5
Remove uneeded isoformat calls in registry as_storage_fragment properties (#126440) 2024-09-23 14:23:43 +02:00
Paul Bottein
b471a6e519
Add has_entity_name to entity display dict and fix name (#125832)
* Add has_entity_name to entity display dict and fix name

* Fix tests
2024-09-19 11:35:44 +02:00
Robert Resch
e00f159ebe
Fix loading created_at/modified_at from entity registry store (#122486) 2024-07-23 21:15:12 +02:00
Robert Resch
0d765a27c9
Add created_at/modified_at to entity registry (#122444) 2024-07-23 13:12:29 +02:00
Erik Montnemery
7abffd7cc8
Don't report entities with invalid unique id when loading the entity registry (#118290) 2024-05-29 08:32:39 +02:00
J. Nick Koston
6113b58e9c
Speed up registry indices (#117897)
* Use defaultdict for registry indices

defaultdict is faster and does not have to create an empty
dict that gets throw away when the key is already present

* Use defaultdict for registry indices

defaultdict is faster and does not have to create an empty
dict that gets throw away when the key is already present
2024-05-22 14:07:39 -04:00
Marc Mueller
900b6211ef
Use PEP 695 for function annotations (2) (#117659) 2024-05-18 11:44:39 +02:00
Marc Mueller
87bb7ced79
Use PEP 695 for simple type aliases (#117633) 2024-05-17 14:42:21 +02:00
J. Nick Koston
7871e9279b
Adjust thread safety check messages to point to developer docs (#117392) 2024-05-14 15:20:31 +02:00
J. Nick Koston
26cc1cd3db
Use singleton helper for registries (#117027) 2024-05-07 21:04:01 +02:00
Marc Mueller
fd5885ec83
Use HassKey for registries (#117000) 2024-05-07 18:03:14 +02:00
G Johansson
822646749d
Remove entity category "system" check from entity registry (#116412) 2024-04-30 04:01:12 +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
Erik Montnemery
623d34e1e0
Remove early return when validating entity registry items (#116160) 2024-04-26 08:38:24 +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
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
ca5ed274cb
Deprecate calling async_listen and async_listen_once with run_immediately (#115169) 2024-04-08 10:07:54 -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
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
Marc Mueller
816ce116bf
Remove unnecessary functools.cached_property backport (#114239) 2024-04-04 11:24:26 +02:00
J. Nick Koston
e86fec310b
Improve performance of extracting entities by label (#114720) 2024-04-03 10:24:44 -10:00
J. Nick Koston
adbaed2c6d
Reduce code for registry items with a base class (#114689) 2024-04-03 09:02:32 +02:00
Sid
6587ee20db
Enable Ruff TRY300 (#114437)
* Enable Ruff TRY300

* Update validation.py

* Address review comments
2024-03-30 10:37:59 +01:00
J. Nick Koston
54a69a2687
Remove async_get_device_class_lookup from entity_registry (#114212)
This function was only ever used in homekit, and since there is
now an index of devices in the entity registry, homekit no longer
uses it.

I searched github code for all references to async_get_device_class_lookup
and the only think I could find using it were forks of core. It seems
unlikely that any custom components are affected by removing this
function
2024-03-26 09:22:53 +01:00
Erik Montnemery
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 <nick@koston.org>
2024-03-20 09:40:06 +01:00
J. Nick Koston
68320b1278
Migrate registry for labels and categories to run_immediately (#113645) 2024-03-17 08:16:11 -10:00
J. Nick Koston
93497dde8b
Run registry cleanup listeners immediately (#113646) 2024-03-17 08:15:55 -10:00
J. Nick Koston
091199d24a
Run entity registry write_unavailable_states immediately at start (#113647) 2024-03-17 08:15:41 -10:00
J. Nick Koston
86ccb99f4c
Fix race in removing modified devices from the entity registry (#113623) 2024-03-16 11:51:56 -10:00
Franck Nijhof
0e2775667d
Add category registry (#110897)
* Add category registry

* Add entity registry support

* Update homeassistant/components/config/entity_registry.py

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

* Use ulid instead

* Add tests for adding same name in different scopes

* Handle keyerror on update

* Lookup tweak

* Omit categories from entity registry snapshots

* Use base registry

* Update snapshots

* Update snapshots

---------

Co-authored-by: Martin Hjelmare <marhje52@gmail.com>
2024-03-15 13:25:16 +01:00
J. Nick Koston
5b80eb4c3d
Reduce overhead to save the larger registries (#113462)
We save the device and entity registry to disk quite often, and
the cost of serializing them to the storage can block the event
loop for >100ms. Add a cache to reduce the change the loop is blocked
at an inopportune time at run time. The first write after startup
will still be a little slow but we do have to serialize the
bulk of it at least once as there is no way to avoid this

```
2024-03-14 11:28:19.765 WARNING (MainThread) [homeassistant.helpers.storage] Writing data with data_func: core.device_registry
2024-03-14 11:28:20.020 WARNING (MainThread) [homeassistant.helpers.storage] Writing data with data_func: core.entity_registry
2024-03-14 11:28:20.178 WARNING (MainThread) [asyncio] Executing <TimerHandle cancelled when=2319925.760294916 Store._async_schedule_callback_delayed_write() created at /Users/bdraco/home-assistant/homeassistant/helpers/storage.py:328> took 0.159 seconds
```
2024-03-14 19:54:43 -04:00
J. Nick Koston
b3dedb3efb
Convert sets to list before passing to the JSON serializer in the registries (#113133)
There were a few places we were missing the set to list
conversions in the registries. We do this before its
cached to avoid the JSON serializer having to fallback
to the default method every time since its expensive
to switch back from the native code into python context
for every set.
2024-03-12 08:38:21 -04:00
Marc Mueller
de886d8c49
Update EventBus listen type signatures (#112760) 2024-03-08 21:57:23 +01:00
Marc Mueller
19ab3d6daf
Add empty line after module docstring [helpers + other] (#112707) 2024-03-08 10:36:11 -05:00
J. Nick Koston
caefdc6192
Avoid writing registries to disk during startup (#112662) 2024-03-07 19:14:42 -10:00
J. Nick Koston
f3eb292c2d
Remove async_entity_ids and get_entity_ids from entity registry (#112311)
added in #112277 but not used yet.
2024-03-05 14:50:41 +01:00
J. Nick Koston
2c179dc5fb
Reduce some linear searches to cleanup the device registry (#112277)
Some of the data we had to search for was already available
in a dict or underlying data structure. Make it available
instead of having to build it every time.

There are more places these can be used, but I only did
the device registry cleanup for now
2024-03-04 20:59:12 -05:00
J. Nick Koston
125de17a09
Avoid linear search to remove from the entity registry index (#111138)
Avoid linear search to remove from entity registry index

Because the entity registry index needs to preserve insertion order
for backwards compat, a list was used for the index. Because some
config entries/devices/areas have a large amount of entities, removing
the entities, the O(n) time complexity of removing from a list can
slow down reloads. As python has no orderedset in stdlib, use
a dict since it preserves insertion order has O(1) add/remove
time complexity for the average case
2024-02-23 13:57:59 -05:00
Joost Lekkerkerker
730d805876
Enable SIM114 ruff rule (#111125) 2024-02-23 13:21:59 +01:00
J. Nick Koston
5b73adba20
Revert "Reduce dict lookups in entity registry indices" (#111055)
Revert "Reduce dict lookups in entity registry indices (#109712)"

This reverts commit 440212ddcee21ed82a81242f7aa8556fd2b217d1.
2024-02-21 07:11:58 +01:00
Franck Nijhof
e0a9dcd996
Add label registry (#110821) 2024-02-19 11:59:08 +01:00