1 """Provides useful helpers for handling devices."""
5 from .
import device_registry
as dr, entity_registry
as er
11 entity_id_or_uuid: str,
13 """Resolve the device id to the entity id or entity uuid."""
15 ent_reg = er.async_get(hass)
17 entity_id = er.async_validate_entity_id(ent_reg, entity_id_or_uuid)
18 if (entity := ent_reg.async_get(entity_id))
is None:
21 return entity.device_id
27 entity_id_or_uuid: str,
28 ) -> dr.DeviceInfo |
None:
29 """DeviceInfo with information to link a device from an entity.
31 DeviceInfo will only return information to categorize as a link.
43 device_id: str |
None,
44 ) -> dr.DeviceInfo |
None:
45 """DeviceInfo with information to link a device from a device id.
47 DeviceInfo will only return information to categorize as a link.
50 dev_reg = dr.async_get(hass)
52 if device_id
is None or (device := dev_reg.async_get(device_id=device_id))
is None:
56 identifiers=device.identifiers,
57 connections=device.connections,
65 source_entity_id_or_uuid: str,
67 """Remove the link between stale devices and a configuration entry.
69 Only the device passed in the source_entity_id_or_uuid parameter
70 linked to the configuration entry will be maintained.
84 current_device_id: str |
None,
86 """Remove the link between stale devices and a configuration entry.
88 Only the device passed in the current_device_id parameter linked to
89 the configuration entry will be maintained.
92 dev_reg = dr.async_get(hass)
94 for device
in dev_reg.devices.get_devices_for_config_entry_id(entry_id):
95 if device.id == current_device_id:
97 dev_reg.async_update_device(device.id, remove_config_entry_id=entry_id)
dr.DeviceInfo|None async_device_info_to_link_from_entity(HomeAssistant hass, str entity_id_or_uuid)
None async_remove_stale_devices_links_keep_current_device(HomeAssistant hass, str entry_id, str|None current_device_id)
None async_remove_stale_devices_links_keep_entity_device(HomeAssistant hass, str entry_id, str source_entity_id_or_uuid)
dr.DeviceInfo|None async_device_info_to_link_from_device_id(HomeAssistant hass, str|None device_id)
str|None async_entity_id_to_device_id(HomeAssistant hass, str entity_id_or_uuid)