1
0
mirror of https://github.com/home-assistant/core.git synced 2025-12-24 21:06:19 +00:00

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>
This commit is contained in:
epenet
2024-05-31 21:31:44 +02:00
committed by GitHub
parent bae96e7d36
commit 41e852a01b
2 changed files with 117 additions and 1 deletions

View File

@@ -798,6 +798,7 @@ class DeviceRegistry(BaseRegistry[dict[str, list[dict[str, Any]]]]):
model: str | None | UndefinedType = UNDEFINED,
name_by_user: str | None | UndefinedType = UNDEFINED,
name: str | None | UndefinedType = UNDEFINED,
new_connections: set[tuple[str, str]] | UndefinedType = UNDEFINED,
new_identifiers: set[tuple[str, str]] | UndefinedType = UNDEFINED,
remove_config_entry_id: str | UndefinedType = UNDEFINED,
serial_number: str | None | UndefinedType = UNDEFINED,
@@ -813,6 +814,9 @@ class DeviceRegistry(BaseRegistry[dict[str, list[dict[str, Any]]]]):
config_entries = old.config_entries
if merge_connections is not UNDEFINED and new_connections is not UNDEFINED:
raise HomeAssistantError("Cannot define both merge_connections and new_connections")
if merge_identifiers is not UNDEFINED and new_identifiers is not UNDEFINED:
raise HomeAssistantError
@@ -873,6 +877,10 @@ class DeviceRegistry(BaseRegistry[dict[str, list[dict[str, Any]]]]):
new_values[attr_name] = old_value | setvalue
old_values[attr_name] = old_value
if new_connections is not UNDEFINED:
new_values["connections"] = _normalize_connections(new_connections)
old_values["connections"] = old.connections
if new_identifiers is not UNDEFINED:
new_values["identifiers"] = new_identifiers
old_values["identifiers"] = old.identifiers