Commit Graph

185 Commits (091199d24a744bd2614e7b8dc115738a2095e563)

Author SHA1 Message Date
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 440212ddce.
2024-02-21 07:11:58 +01:00
Franck Nijhof e0a9dcd996
Add label registry (#110821) 2024-02-19 11:59:08 +01:00
J. Nick Koston 440212ddce
Reduce dict lookups in entity registry indices (#109712) 2024-02-05 17:23:53 -05:00
J. Nick Koston 908cedf981
Avoid linear search of entity registry in async_clear_config_entry (#109724) 2024-02-05 14:12:16 -06:00
J. Nick Koston e9a41e5023
Avoid linear search in entity registry to clear an area (#109735) 2024-02-05 13:53:33 -06:00
J. Nick Koston 458e1f3a5e
Index area_ids in the entity registry (#109660) 2024-02-05 09:01:43 +01:00
J. Nick Koston 9fef1938b4
Make get_entries_for_device_id skip disabled devices by default (#109645) 2024-02-04 23:11:56 +01:00
J. Nick Koston b24b4fc237
Use get_entries_for_config_entry_id helper in async_migrate_entries (#109629) 2024-02-04 21:05:48 +01:00
Franck Nijhof cdf3c07488
Add icon to entity registry list for display (#108313) 2024-01-19 15:11:27 +01:00
J. Nick Koston 19258cb3df
Fix benign typo in entity registry (#108270) 2024-01-18 07:45:44 +01:00
J. Nick Koston 60ab360fe7
Avoid bytes to string to bytes conversion in websocket api (#108139) 2024-01-16 21:37:34 +01:00
J. Nick Koston d7910841ef
Add an index for devices and config entries to the entity registry (#107516)
* Add an index for devices and config entries to the entity registry

* fixes

* tweak

* use a list for now since the tests check order
2024-01-13 14:49:41 -05:00
Marc Mueller 66d1a7f1dd
Update ReadOnlyEntityOptions typing (#103813) 2023-11-11 22:30:55 +01:00
J. Nick Koston 433c022687
Save previous unique id in entity registry when it changes (#102093) 2023-10-16 21:26:19 -10:00
J. Nick Koston 7b2aa3a369
Improve performance of config/entity_registry/get* calls (#101984) 2023-10-14 08:40:16 -10:00
Erik Montnemery 47ecce4873
Allow deleting entity entries from entity_registry.async_migrate_entries (#101094)
* Allow deleting entity entries from entity_registry.async_migrate_entries

* Explicitly return None in tests
2023-09-30 10:23:10 +02:00
J. Nick Koston 877eedf6d7
Use cached_property in entity_registry (#100302) 2023-09-13 14:38:40 -05:00
Erik Montnemery c3d1cdd0e9
Improve UserDict in device and entity registries (#100307) 2023-09-13 11:09:34 -05:00
Erik Montnemery 684b2d4537
Improve type hint in entity_registry (#100278) 2023-09-13 12:42:06 +02:00
Marc Mueller 4d9b73033d
Update python-typing-update to 0.6.0 (#97531) 2023-07-31 17:59:40 +02:00
Marc Mueller 0624345322
Improve `async_track_entity_registry_updated_event` callback typing (#97124) 2023-07-24 09:14:10 +02:00
Marc Mueller 69d7b035e0
Use EventType for more helper methods (#97107) 2023-07-23 23:22:04 +02:00
Franck Nijhof 30058297cf
Migrate backported StrEnum to built-in StrEnum (#97101) 2023-07-23 23:19:24 +02:00
Erik Montnemery 8fda56d2c9
Stable entity registry id when a deleted entity is restored (#77710)
* Stable entity_id and registry id when a deleted entity is restored

* Don't restore area_id

* Don't restore entity_id

* Address review comments
2023-06-26 15:54:35 +02:00
Erik Montnemery 4a8adae146
Teach alarm_control_panel device trigger about entity registry ids (#60977)
* Teach alarm_control_panel device trigger about entity registry ids

* Lint code

* Address review comment
2023-06-20 08:27:31 -04:00
J. Nick Koston a0c023d5cb
Reduce overhead to lookup items in the entity and device registry (#94568) 2023-06-14 20:47:18 +02:00
J. Nick Koston 9f0d3bfce8
Use ReadOnlyDict for entity registry options (#93824)
* Use ReadOnlyDict for entity registry options

While reviewing #93601 it was noticed this was slow at startup
https://github.com/home-assistant/core/pull/93601#issuecomment-1568958280

This is a first pass attempt to improve the performance

* fix tests
2023-05-30 20:11:39 -04:00
Erik Montnemery 0126cfa9d9
Allow exposing any entity to the default conversation agent (#92398)
* Allow exposing any entity to the default conversation agent

* Tweak

* Fix race, update tests

* Update tests
2023-05-03 09:45:54 -04:00
J. Nick Koston fba7c6cacd
Remove deprecated async_get_registry (#91928)
Deprecated in 2021 via #46265, report was added a year ago in #72088
2023-04-23 23:02:21 -04:00
Erik Montnemery 2c9e9d0fde
Allow UI configuration of entities exposed to voice_assistant (#91233)
* Allow UI configuration of entities exposed to voice_assistant

* Invalidate cache when settings change

* Add tests

* Expose entities to conversation by default

* Update tests
2023-04-11 22:39:40 -04:00
Erik Montnemery e22618a555
Write protect entity options (#90185) 2023-03-28 22:56:51 +02:00
Erik Montnemery 1f34fa63ab
Always include platform in `config/entity_registry/list_for_display` (#88601)
Always include platform in config/entity_registry/list_for_display
2023-02-22 17:59:52 +01:00
Erik Montnemery 0c4c95394e
Add WS command config/entity_registry/list_for_display (#87787)
* Add WS command config/entity_registry/list_for_display

* Make more keys in the display dict optional

* Move disabled_by check to ws command handler

* Hide hidden_by if not hidden

* Use send_json_auto_id in the new test

* Don't include entities which have no data needed for display

* Include platform for entries with translation_key
2023-02-21 20:40:39 +01:00
epenet ba23816a0c
Inverse json import logic (#88099)
* Fix helpers and util

* Adjust components

* Move back errors

* Add report

* mypy

* mypy

* Assert deprecation messages

* Move test_json_loads_object

* Adjust tests

* Fix rebase

* Adjust pylint plugin

* Fix plugin

* Adjust references

* Adjust backup tests
2023-02-16 11:37:57 +01:00
Erik Montnemery cc564026fa
Move EntityCategory to homeassistant.const (#87792)
* Move EntityCategory to homeassistant.const

* Fix more imports
2023-02-09 20:15:37 +01:00
Erik Montnemery 93dafefd96
Include entity options in RegistryEntry.as_partial_dict (#87539) 2023-02-08 08:32:46 -05:00
Erik Montnemery 4d4fb2477d
Optionally update sensor units when unit system is changed (#83851) 2023-02-03 16:30:50 +01:00
Erik Montnemery 788edc21fb
Deduplicate some entity registry code (#85541) 2023-01-16 22:06:52 +01:00