mirror of
https://github.com/home-assistant/core.git
synced 2025-07-17 10:17:09 +00:00
Add support for device configuration URL to deCONZ gateway (#58184)
This commit is contained in:
parent
843296c1a3
commit
ab7a34fc71
@ -4,6 +4,7 @@ import asyncio
|
|||||||
import async_timeout
|
import async_timeout
|
||||||
from pydeconz import DeconzSession, errors, group, light, sensor
|
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.const import CONF_API_KEY, CONF_HOST, CONF_PORT
|
||||||
from homeassistant.core import callback
|
from homeassistant.core import callback
|
||||||
from homeassistant.exceptions import ConfigEntryAuthFailed, ConfigEntryNotReady
|
from homeassistant.exceptions import ConfigEntryAuthFailed, ConfigEntryNotReady
|
||||||
@ -149,8 +150,13 @@ class DeconzGateway:
|
|||||||
)
|
)
|
||||||
|
|
||||||
# Gateway service
|
# 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(
|
device_registry.async_get_or_create(
|
||||||
config_entry_id=self.config_entry.entry_id,
|
config_entry_id=self.config_entry.entry_id,
|
||||||
|
configuration_url=configuration_url,
|
||||||
|
entry_type="service",
|
||||||
identifiers={(DECONZ_DOMAIN, self.api.config.bridge_id)},
|
identifiers={(DECONZ_DOMAIN, self.api.config.bridge_id)},
|
||||||
manufacturer="Dresden Elektronik",
|
manufacturer="Dresden Elektronik",
|
||||||
model=self.api.config.model_id,
|
model=self.api.config.model_id,
|
||||||
|
@ -34,7 +34,7 @@ from homeassistant.components.ssdp import (
|
|||||||
ATTR_UPNP_UDN,
|
ATTR_UPNP_UDN,
|
||||||
)
|
)
|
||||||
from homeassistant.components.switch import DOMAIN as SWITCH_DOMAIN
|
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 (
|
from homeassistant.const import (
|
||||||
CONF_API_KEY,
|
CONF_API_KEY,
|
||||||
CONF_HOST,
|
CONF_HOST,
|
||||||
@ -43,6 +43,7 @@ from homeassistant.const import (
|
|||||||
STATE_OFF,
|
STATE_OFF,
|
||||||
STATE_UNAVAILABLE,
|
STATE_UNAVAILABLE,
|
||||||
)
|
)
|
||||||
|
from homeassistant.helpers import device_registry as dr
|
||||||
|
|
||||||
from tests.common import MockConfigEntry
|
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[10][1] == (config_entry, SIREN_DOMAIN)
|
||||||
assert forward_entry_setup.mock_calls[11][1] == (config_entry, SWITCH_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):
|
async def test_gateway_retry(hass):
|
||||||
"""Retry setup."""
|
"""Retry setup."""
|
||||||
|
Loading…
x
Reference in New Issue
Block a user