Commit graph

175 commits

Author SHA1 Message Date
J. Nick Koston
0e0ac3efe5
Remove uneeded isoformat calls in registry as_storage_fragment properties (#126440) 2024-09-23 14:23:43 +02:00
J. Nick Koston
e1e64be3c9
Remigrate device_registry created_at/modified_at (#122490)
* Remigrate device_registry created_at/modified_at

Nightly current does not boot up because the device registry
will have KeyError: created_at if the previous nightly was
installed.

* reduce

* split migration per discord comments
2024-07-23 15:47:27 -05:00
Erik Montnemery
d3df903d1e
Make device registry migration unconditional (#122414) 2024-07-22 21:37:47 +02:00
Robert Resch
4c853803f1
Add created_at/modified_at to device registry (#122369) 2024-07-22 19:15:23 +02:00
Joost Lekkerkerker
f8ba4d41ba
Add support for adding model_id in device info (#121989) 2024-07-16 15:12:25 +02:00
Erik Montnemery
3e9b57cc07
Don't allow updating a device to have no connections or identifiers (#120603)
* Don't allow updating a device to have no connections or identifiers

* Move check to the top of the function
2024-06-27 09:26:31 +02:00
Erik Montnemery
9bbeb5d608
Add primary_config_entry attribute to device registry entries (#119959)
Co-authored-by: Franck Nijhof <git@frenck.dev>
Co-authored-by: Robert Resch <robert@resch.dev>
2024-06-26 12:26:24 +02:00
Erik Montnemery
d4e93dd01d
Validate new device identifiers and connections (#120413) 2024-06-25 19:17:54 +02:00
Paulus Schoutsen
eb89ce47ea
Inline primary integration (#119860) 2024-06-18 08:08:08 +02:00
Paulus Schoutsen
836abe68c7
Track primary integration (#119741)
* Track primary integration

* Update snapshots

* More snapshots updated

* Uno mas

* Update snapshot
2024-06-16 13:26:06 -04:00
epenet
891f9c9578
Add error message to device registry helper (#118676) 2024-06-03 09:58:02 +02:00
Jan-Philipp Benecke
32b51b8792
Run ruff format for device registry (#118582) 2024-05-31 22:22:48 +02:00
epenet
41e852a01b
Add ability to replace connections in DeviceRegistry (#118555)
* Add ability to replace connections in DeviceRegistry

* Add more tests

* Improve coverage

* Apply suggestion

Co-authored-by: Paulus Schoutsen <paulus@home-assistant.io>

---------

Co-authored-by: Paulus Schoutsen <paulus@home-assistant.io>
2024-05-31 15:31:44 -04: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
8f0fb4db3e
Use PEP 695 for class annotations (4) (#117778) 2024-05-20 10:44:52 +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
eac4aaef10
Use a dictcomp to reconstruct DeviceInfo in the device_registry (#117286)
Use a dictcomp to reconstruct DeviceInfo

a dictcomp is faster than many sets on the dict by at least
25%

We call this for nearly every device in the registry at
startup
2024-05-12 08:07:12 +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
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
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
bd2efffb4a
Reduce duplicate code in the device registry (#115677) 2024-04-17 15:50:39 +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
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
Marc Mueller
cb9352110c
Improve registry store data typing (#115066) 2024-04-06 14:34:49 -10:00
J. Nick Koston
00db97a765
Run device_registry stop listener immediately (#114978) 2024-04-05 21:59:27 -04: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
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
J. Nick Koston
adbaed2c6d
Reduce code for registry items with a base class (#114689) 2024-04-03 09:02:32 +02:00
J. Nick Koston
e9c1753f3a
Cache parsing the url for the device registry (#113910)
* Cache parsing the url for the device registry

There are lots of hub integrations that use the same url for every
sub-device which results in a lot of url parsing at startup. The
logic can be simplified quite a bit here by only using yarl
for URLs

* fix onvif
2024-03-20 19:35:01 -04: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
Franck Nijhof
51b8ffc69d
Add WebSocket support for handling labels on device registry (#113758) 2024-03-18 21:19:27 +01:00
Sid
82a60fe8ad
Enable Ruff RSE (#113695) 2024-03-18 00:40:38 +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
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
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
Erik Montnemery
b336095239
Allow translating device names (#110711)
* Allow translating device names

* Don't keep a reference to translations in config entry

* Update kitchen_sink tests

* Add tests
2024-02-28 15:59:59 +01:00
J. Nick Koston
5bf8086a2b
Cache formatting of mac addresses (#111140) 2024-02-22 07:09:56 -10:00
J. Nick Koston
7bf0fb9e48
Avoid late import of area registry in device registry if its not used (#111081) 2024-02-21 12:45:00 -06:00
J. Nick Koston
776a9b8691
Make device registry cleanup a callback function (#111052)
* Add async_schedule_call to the Debouncer

async_schedule_call allows the Debouncer to schedule a call
from a callback without having to create tasks to run
async_call

* Update homeassistant/helpers/debounce.py

* Make device registry cleanup all callback function

* fix typing, code supported callback functions, but typing did not

* fixes

* fixes

* fix

* we had no coverage for other job types

* we had no coverage for other job types
2024-02-21 09:34:49 +01:00