From 617ab48fa93f204cabee8e80ded28ef4163a18b7 Mon Sep 17 00:00:00 2001 From: dougiteixeira <31328123+dougiteixeira@users.noreply.github.com> Date: Thu, 27 Jun 2024 03:50:20 -0300 Subject: [PATCH] Address device helper review comments (#120615) * Address review comments from #119761 * Address review comments from #119761 * Address review comments from #119761 * Remove reference from config entry --- homeassistant/helpers/device.py | 21 ++++++++++++++++----- tests/helpers/test_device.py | 4 ++-- 2 files changed, 18 insertions(+), 7 deletions(-) diff --git a/homeassistant/helpers/device.py b/homeassistant/helpers/device.py index e1b9ded5723..16212422236 100644 --- a/homeassistant/helpers/device.py +++ b/homeassistant/helpers/device.py @@ -26,7 +26,10 @@ def async_device_info_to_link_from_entity( hass: HomeAssistant, entity_id_or_uuid: str, ) -> dr.DeviceInfo | None: - """DeviceInfo with information to link a device to a configuration entry in the link category from a entity id or entity uuid.""" + """DeviceInfo with information to link a device from an entity. + + DeviceInfo will only return information to categorize as a link. + """ return async_device_info_to_link_from_device_id( hass, @@ -39,7 +42,10 @@ def async_device_info_to_link_from_device_id( hass: HomeAssistant, device_id: str | None, ) -> dr.DeviceInfo | None: - """DeviceInfo with information to link a device to a configuration entry in the link category from a device id.""" + """DeviceInfo with information to link a device from a device id. + + DeviceInfo will only return information to categorize as a link. + """ dev_reg = dr.async_get(hass) @@ -58,7 +64,11 @@ def async_remove_stale_devices_links_keep_entity_device( entry_id: str, source_entity_id_or_uuid: str, ) -> None: - """Remove the link between stales devices and a configuration entry, keeping only the device that the informed entity is linked to.""" + """Remove the link between stale devices and a configuration entry. + + Only the device passed in the source_entity_id_or_uuid parameter + linked to the configuration entry will be maintained. + """ async_remove_stale_devices_links_keep_current_device( hass=hass, @@ -73,9 +83,10 @@ def async_remove_stale_devices_links_keep_current_device( entry_id: str, current_device_id: str | None, ) -> None: - """Remove the link between stales devices and a configuration entry, keeping only the device informed. + """Remove the link between stale devices and a configuration entry. - Device passed in the current_device_id parameter will be kept linked to the configuration entry. + Only the device passed in the current_device_id parameter linked to + the configuration entry will be maintained. """ dev_reg = dr.async_get(hass) diff --git a/tests/helpers/test_device.py b/tests/helpers/test_device.py index 72c602bec48..852d418da23 100644 --- a/tests/helpers/test_device.py +++ b/tests/helpers/test_device.py @@ -169,7 +169,7 @@ async def test_remove_stale_device_links_keep_entity_device( config_entry.entry_id ) - # After cleanup, only one device is expected to be linked to the configuration entry if at least source_entity_id_or_uuid or device_id was given, else zero + # After cleanup, only one device is expected to be linked to the config entry assert len(devices_config_entry) == 1 assert current_device in devices_config_entry @@ -220,7 +220,7 @@ async def test_remove_stale_devices_links_keep_current_device( config_entry.entry_id ) - # After cleanup, only one device is expected to be linked to the configuration entry + # After cleanup, only one device is expected to be linked to the config entry assert len(devices_config_entry) == 1 assert current_device in devices_config_entry