Add support for device configuration URL to deCONZ gateway (#58184)

This commit is contained in:
Robert Svensson 2021-10-22 19:41:49 +02:00 committed by GitHub
parent 843296c1a3
commit ab7a34fc71
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 35 additions and 1 deletions

View File

@ -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,

View File

@ -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."""