mirror of
https://github.com/home-assistant/core.git
synced 2025-07-15 17:27:10 +00:00
Small cleanups to the device registry (#141773)
Remove some calls to internal functions that are now available directly on the devices and deleted_devices objects Remove internal functions that are no longer used
This commit is contained in:
parent
ea5cf3d854
commit
c8d3fa6768
@ -581,8 +581,8 @@ class DeviceRegistryItems[_EntryTypeT: (DeviceEntry, DeletedDeviceEntry)](
|
|||||||
|
|
||||||
def get_entry(
|
def get_entry(
|
||||||
self,
|
self,
|
||||||
identifiers: set[tuple[str, str]] | None,
|
identifiers: set[tuple[str, str]] | None = None,
|
||||||
connections: set[tuple[str, str]] | None,
|
connections: set[tuple[str, str]] | None = None,
|
||||||
) -> _EntryTypeT | None:
|
) -> _EntryTypeT | None:
|
||||||
"""Get entry from identifiers or connections."""
|
"""Get entry from identifiers or connections."""
|
||||||
if identifiers:
|
if identifiers:
|
||||||
@ -709,22 +709,6 @@ class DeviceRegistry(BaseRegistry[dict[str, list[dict[str, Any]]]]):
|
|||||||
"""Check if device is registered."""
|
"""Check if device is registered."""
|
||||||
return self.devices.get_entry(identifiers, connections)
|
return self.devices.get_entry(identifiers, connections)
|
||||||
|
|
||||||
def _async_get_deleted_device(
|
|
||||||
self,
|
|
||||||
identifiers: set[tuple[str, str]],
|
|
||||||
connections: set[tuple[str, str]],
|
|
||||||
) -> DeletedDeviceEntry | None:
|
|
||||||
"""Check if device is deleted."""
|
|
||||||
return self.deleted_devices.get_entry(identifiers, connections)
|
|
||||||
|
|
||||||
def _async_get_deleted_devices(
|
|
||||||
self,
|
|
||||||
identifiers: set[tuple[str, str]] | None = None,
|
|
||||||
connections: set[tuple[str, str]] | None = None,
|
|
||||||
) -> Iterable[DeletedDeviceEntry]:
|
|
||||||
"""List devices that are deleted."""
|
|
||||||
return self.deleted_devices.get_entries(identifiers, connections)
|
|
||||||
|
|
||||||
def _substitute_name_placeholders(
|
def _substitute_name_placeholders(
|
||||||
self,
|
self,
|
||||||
domain: str,
|
domain: str,
|
||||||
@ -839,10 +823,12 @@ class DeviceRegistry(BaseRegistry[dict[str, list[dict[str, Any]]]]):
|
|||||||
else:
|
else:
|
||||||
connections = _normalize_connections(connections)
|
connections = _normalize_connections(connections)
|
||||||
|
|
||||||
device = self.async_get_device(identifiers=identifiers, connections=connections)
|
device = self.devices.get_entry(
|
||||||
|
identifiers=identifiers, connections=connections
|
||||||
|
)
|
||||||
|
|
||||||
if device is None:
|
if device is None:
|
||||||
deleted_device = self._async_get_deleted_device(identifiers, connections)
|
deleted_device = self.deleted_devices.get_entry(identifiers, connections)
|
||||||
if deleted_device is None:
|
if deleted_device is None:
|
||||||
device = DeviceEntry(is_new=True)
|
device = DeviceEntry(is_new=True)
|
||||||
else:
|
else:
|
||||||
@ -869,7 +855,7 @@ class DeviceRegistry(BaseRegistry[dict[str, list[dict[str, Any]]]]):
|
|||||||
name = default_name
|
name = default_name
|
||||||
|
|
||||||
if via_device is not None and via_device is not UNDEFINED:
|
if via_device is not None and via_device is not UNDEFINED:
|
||||||
if (via := self.async_get_device(identifiers={via_device})) is None:
|
if (via := self.devices.get_entry(identifiers={via_device})) is None:
|
||||||
report_usage(
|
report_usage(
|
||||||
"calls `device_registry.async_get_or_create` referencing a "
|
"calls `device_registry.async_get_or_create` referencing a "
|
||||||
f"non existing `via_device` {via_device}, "
|
f"non existing `via_device` {via_device}, "
|
||||||
@ -1172,7 +1158,7 @@ class DeviceRegistry(BaseRegistry[dict[str, list[dict[str, Any]]]]):
|
|||||||
# NOTE: Once we solve the broader issue of duplicated devices, we might
|
# NOTE: Once we solve the broader issue of duplicated devices, we might
|
||||||
# want to revisit it. Instead of simply removing the duplicated deleted device,
|
# want to revisit it. Instead of simply removing the duplicated deleted device,
|
||||||
# we might want to merge the information from it into the non-deleted device.
|
# we might want to merge the information from it into the non-deleted device.
|
||||||
for deleted_device in self._async_get_deleted_devices(
|
for deleted_device in self.deleted_devices.get_entries(
|
||||||
added_identifiers, added_connections
|
added_identifiers, added_connections
|
||||||
):
|
):
|
||||||
del self.deleted_devices[deleted_device.id]
|
del self.deleted_devices[deleted_device.id]
|
||||||
@ -1214,7 +1200,7 @@ class DeviceRegistry(BaseRegistry[dict[str, list[dict[str, Any]]]]):
|
|||||||
# conflict, the index will only see the last one and we will not
|
# conflict, the index will only see the last one and we will not
|
||||||
# be able to tell which one caused the conflict
|
# be able to tell which one caused the conflict
|
||||||
if (
|
if (
|
||||||
existing_device := self.async_get_device(connections={connection})
|
existing_device := self.devices.get_entry(connections={connection})
|
||||||
) and existing_device.id != device_id:
|
) and existing_device.id != device_id:
|
||||||
raise DeviceConnectionCollisionError(
|
raise DeviceConnectionCollisionError(
|
||||||
normalized_connections, existing_device
|
normalized_connections, existing_device
|
||||||
@ -1238,7 +1224,7 @@ class DeviceRegistry(BaseRegistry[dict[str, list[dict[str, Any]]]]):
|
|||||||
# conflict, the index will only see the last one and we will not
|
# conflict, the index will only see the last one and we will not
|
||||||
# be able to tell which one caused the conflict
|
# be able to tell which one caused the conflict
|
||||||
if (
|
if (
|
||||||
existing_device := self.async_get_device(identifiers={identifier})
|
existing_device := self.devices.get_entry(identifiers={identifier})
|
||||||
) and existing_device.id != device_id:
|
) and existing_device.id != device_id:
|
||||||
raise DeviceIdentifierCollisionError(identifiers, existing_device)
|
raise DeviceIdentifierCollisionError(identifiers, existing_device)
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user