diff --git a/homeassistant/components/deconz/gateway.py b/homeassistant/components/deconz/gateway.py index 1199884fb5a..ddb0d47190c 100644 --- a/homeassistant/components/deconz/gateway.py +++ b/homeassistant/components/deconz/gateway.py @@ -4,6 +4,7 @@ import asyncio import async_timeout from pydeconz import DeconzSession, errors, group, light, sensor +from homeassistant.config_entries import SOURCE_HASSIO from homeassistant.const import CONF_API_KEY, CONF_HOST, CONF_PORT from homeassistant.core import callback from homeassistant.exceptions import ConfigEntryAuthFailed, ConfigEntryNotReady @@ -149,8 +150,13 @@ class DeconzGateway: ) # Gateway service + configuration_url = f"http://{self.host}:{self.config_entry.data[CONF_PORT]}" + if self.config_entry.source == SOURCE_HASSIO: + configuration_url = None device_registry.async_get_or_create( config_entry_id=self.config_entry.entry_id, + configuration_url=configuration_url, + entry_type="service", identifiers={(DECONZ_DOMAIN, self.api.config.bridge_id)}, manufacturer="Dresden Elektronik", model=self.api.config.model_id, diff --git a/tests/components/deconz/test_gateway.py b/tests/components/deconz/test_gateway.py index dc57c679fb7..2cb73102bf1 100644 --- a/tests/components/deconz/test_gateway.py +++ b/tests/components/deconz/test_gateway.py @@ -34,7 +34,7 @@ from homeassistant.components.ssdp import ( ATTR_UPNP_UDN, ) from homeassistant.components.switch import DOMAIN as SWITCH_DOMAIN -from homeassistant.config_entries import SOURCE_SSDP, SOURCE_USER +from homeassistant.config_entries import SOURCE_HASSIO, SOURCE_SSDP, SOURCE_USER from homeassistant.const import ( CONF_API_KEY, CONF_HOST, @@ -43,6 +43,7 @@ from homeassistant.const import ( STATE_OFF, STATE_UNAVAILABLE, ) +from homeassistant.helpers import device_registry as dr from tests.common import MockConfigEntry @@ -169,6 +170,33 @@ async def test_gateway_setup(hass, aioclient_mock): assert forward_entry_setup.mock_calls[10][1] == (config_entry, SIREN_DOMAIN) assert forward_entry_setup.mock_calls[11][1] == (config_entry, SWITCH_DOMAIN) + device_registry = dr.async_get(hass) + gateway_entry = device_registry.async_get_device( + identifiers={(DECONZ_DOMAIN, gateway.bridgeid)} + ) + + assert gateway_entry.configuration_url == f"http://{HOST}:{PORT}" + assert gateway_entry.entry_type == "service" + + +async def test_gateway_device_no_configuration_url_when_addon(hass, aioclient_mock): + """Successful setup.""" + with patch( + "homeassistant.config_entries.ConfigEntries.async_forward_entry_setup", + return_value=True, + ): + config_entry = await setup_deconz_integration( + hass, aioclient_mock, source=SOURCE_HASSIO + ) + gateway = get_gateway_from_config_entry(hass, config_entry) + + device_registry = dr.async_get(hass) + gateway_entry = device_registry.async_get_device( + identifiers={(DECONZ_DOMAIN, gateway.bridgeid)} + ) + + assert not gateway_entry.configuration_url + async def test_gateway_retry(hass): """Retry setup."""