Expose deCONZ configuration url from discovered entry (#64519)

This commit is contained in:
Robert Svensson 2022-01-20 13:46:22 +01:00 committed by GitHub
parent 7d66d4c219
commit 3258f66097
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 24 additions and 2 deletions

View File

@ -33,6 +33,7 @@ from .const import (
CONF_BRIDGE_ID,
DEFAULT_PORT,
DOMAIN,
HASSIO_CONFIGURATION_URL,
LOGGER,
)
from .gateway import DeconzGateway, get_gateway_from_config_entry
@ -227,7 +228,12 @@ class DeconzFlowHandler(ConfigFlow, domain=DOMAIN):
updates={CONF_HOST: hostname, CONF_PORT: port}
)
self.context["title_placeholders"] = {"host": hostname}
self.context.update(
{
"title_placeholders": {"host": hostname},
"configuration_url": f"http://{hostname}:{port}",
}
)
self.deconz_config = {CONF_HOST: hostname, CONF_PORT: port}
@ -251,6 +257,8 @@ class DeconzFlowHandler(ConfigFlow, domain=DOMAIN):
}
)
self.context["configuration_url"] = HASSIO_CONFIGURATION_URL
self._hassio_discovery = discovery_info.config
return await self.async_step_hassio_confirm()

View File

@ -7,6 +7,8 @@ LOGGER = logging.getLogger(__package__)
DOMAIN = "deconz"
HASSIO_CONFIGURATION_URL = "homeassistant://hassio/ingress/core_deconz"
CONF_BRIDGE_ID = "bridgeid"
CONF_GROUP_ID_BASE = "group_id_base"

View File

@ -25,6 +25,7 @@ from .const import (
DEFAULT_ALLOW_DECONZ_GROUPS,
DEFAULT_ALLOW_NEW_DEVICES,
DOMAIN as DECONZ_DOMAIN,
HASSIO_CONFIGURATION_URL,
LOGGER,
PLATFORMS,
)
@ -152,7 +153,7 @@ 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 = "homeassistant://hassio/ingress/core_deconz"
configuration_url = HASSIO_CONFIGURATION_URL
device_registry.async_get_or_create(
config_entry_id=self.config_entry.entry_id,
configuration_url=configuration_url,

View File

@ -17,6 +17,7 @@ from homeassistant.components.deconz.const import (
CONF_ALLOW_NEW_DEVICES,
CONF_MASTER_GATEWAY,
DOMAIN as DECONZ_DOMAIN,
HASSIO_CONFIGURATION_URL,
)
from homeassistant.components.hassio import HassioServiceInfo
from homeassistant.components.ssdp import ATTR_UPNP_MANUFACTURER_URL, ATTR_UPNP_SERIAL
@ -425,6 +426,10 @@ async def test_flow_ssdp_discovery(hass, aioclient_mock):
assert result["type"] == RESULT_TYPE_FORM
assert result["step_id"] == "link"
flows = hass.config_entries.flow.async_progress()
assert len(flows) == 1
assert flows[0].get("context", {}).get("configuration_url") == "http://1.2.3.4:80"
aioclient_mock.post(
"http://1.2.3.4:80/api",
json=[{"success": {"username": API_KEY}}],
@ -558,6 +563,12 @@ async def test_flow_hassio_discovery(hass):
assert result["step_id"] == "hassio_confirm"
assert result["description_placeholders"] == {"addon": "Mock Addon"}
flows = hass.config_entries.flow.async_progress()
assert len(flows) == 1
assert (
flows[0].get("context", {}).get("configuration_url") == HASSIO_CONFIGURATION_URL
)
with patch(
"homeassistant.components.deconz.async_setup_entry",
return_value=True,