diff --git a/homeassistant/components/unifi/__init__.py b/homeassistant/components/unifi/__init__.py index e7364e6665f..b935a7d01da 100644 --- a/homeassistant/components/unifi/__init__.py +++ b/homeassistant/components/unifi/__init__.py @@ -61,6 +61,7 @@ async def async_setup_entry(hass, config_entry): device_registry = dr.async_get(hass) device_registry.async_get_or_create( config_entry_id=config_entry.entry_id, + configuration_url=controller.api.url, connections={(CONNECTION_NETWORK_MAC, controller.mac)}, default_manufacturer=ATTR_MANUFACTURER, default_model="UniFi Controller", diff --git a/tests/components/unifi/test_controller.py b/tests/components/unifi/test_controller.py index 02745dd60fb..869d33037bb 100644 --- a/tests/components/unifi/test_controller.py +++ b/tests/components/unifi/test_controller.py @@ -40,6 +40,8 @@ from homeassistant.const import ( CONF_VERIFY_SSL, CONTENT_TYPE_JSON, ) +from homeassistant.helpers import device_registry as dr +from homeassistant.helpers.device_registry import CONNECTION_NETWORK_MAC from homeassistant.helpers.dispatcher import async_dispatcher_connect from homeassistant.setup import async_setup_component import homeassistant.util.dt as dt_util @@ -256,6 +258,14 @@ async def test_controller_mac(hass, aioclient_mock): controller = hass.data[UNIFI_DOMAIN][config_entry.entry_id] assert controller.mac == CONTROLLER_HOST["mac"] + device_registry = dr.async_get(hass) + device_entry = device_registry.async_get_or_create( + config_entry_id=config_entry.entry_id, + connections={(CONNECTION_NETWORK_MAC, controller.mac)}, + ) + + assert device_entry.configuration_url == controller.api.url + async def test_controller_not_accessible(hass): """Retry to login gets scheduled when connection fails.""" diff --git a/tests/components/unifi/test_init.py b/tests/components/unifi/test_init.py index 591165dabf2..1d1fcad9cbe 100644 --- a/tests/components/unifi/test_init.py +++ b/tests/components/unifi/test_init.py @@ -48,6 +48,7 @@ async def test_controller_mac(hass): with patch("homeassistant.components.unifi.UniFiController") as mock_controller: mock_controller.return_value.async_setup = AsyncMock(return_value=True) mock_controller.return_value.mac = "mac1" + mock_controller.return_value.api.url = "https://123:443" assert await unifi.async_setup_entry(hass, entry) is True assert len(mock_controller.mock_calls) == 2 @@ -56,6 +57,7 @@ async def test_controller_mac(hass): device = device_registry.async_get_or_create( config_entry_id=entry.entry_id, connections={(CONNECTION_NETWORK_MAC, "mac1")} ) + assert device.configuration_url == "https://123:443" assert device.manufacturer == "Ubiquiti Networks" assert device.model == "UniFi Controller" assert device.name == "UniFi Controller"