mirror of
https://github.com/home-assistant/core.git
synced 2026-08-24 10:13:52 -05:00
Use console name in UniFi Network discovery title (#173931)
This commit is contained in:
@@ -24,6 +24,7 @@ from homeassistant.config_entries import (
|
||||
)
|
||||
from homeassistant.const import (
|
||||
CONF_HOST,
|
||||
CONF_NAME,
|
||||
CONF_PASSWORD,
|
||||
CONF_PORT,
|
||||
CONF_USERNAME,
|
||||
@@ -192,7 +193,7 @@ class UnifiFlowHandler(ConfigFlow, domain=DOMAIN):
|
||||
|
||||
self.context["title_placeholders"] = {
|
||||
CONF_HOST: reauth_entry.data[CONF_HOST],
|
||||
CONF_SITE_ID: reauth_entry.title,
|
||||
CONF_NAME: reauth_entry.title,
|
||||
}
|
||||
|
||||
self.reauth_schema = {
|
||||
@@ -231,8 +232,13 @@ class UnifiFlowHandler(ConfigFlow, domain=DOMAIN):
|
||||
self._abort_if_unique_id_configured(updates=self.config, reload_on_update=False)
|
||||
|
||||
self.context["title_placeholders"] = {
|
||||
CONF_HOST: host,
|
||||
CONF_SITE_ID: DEFAULT_SITE_ID,
|
||||
CONF_NAME: (
|
||||
discovery_info.get("name")
|
||||
or discovery_info.get("hostname")
|
||||
or discovery_info.get("product_name")
|
||||
or "UniFi Network"
|
||||
),
|
||||
CONF_HOST: source_ip,
|
||||
}
|
||||
self.context["configuration_url"] = f"https://{host}"
|
||||
|
||||
|
||||
@@ -11,7 +11,7 @@
|
||||
"service_unavailable": "[%key:common::config_flow::error::cannot_connect%]",
|
||||
"unknown_client_mac": "No client available on that MAC address"
|
||||
},
|
||||
"flow_title": "{site} ({host})",
|
||||
"flow_title": "{name} ({host})",
|
||||
"step": {
|
||||
"site": {
|
||||
"data": {
|
||||
|
||||
@@ -319,6 +319,16 @@ async def test_reauth_flow_update_configuration(
|
||||
assert result["type"] is FlowResultType.FORM
|
||||
assert result["step_id"] == "user"
|
||||
|
||||
context = next(
|
||||
flow["context"]
|
||||
for flow in hass.config_entries.flow.async_progress()
|
||||
if flow["flow_id"] == result["flow_id"]
|
||||
)
|
||||
assert context["title_placeholders"] == {
|
||||
"host": config_entry.data[CONF_HOST],
|
||||
"name": config_entry.title,
|
||||
}
|
||||
|
||||
with patch(
|
||||
"homeassistant.components.unifi.UnifiHub.available", new_callable=PropertyMock
|
||||
) as ws_mock:
|
||||
@@ -439,7 +449,9 @@ async def test_discover_unifi_negative(hass: HomeAssistant) -> None:
|
||||
INTEGRATION_DISCOVERY_INFO = {
|
||||
"source_ip": "10.0.0.1",
|
||||
"hw_addr": "e0:63:da:20:14:a9",
|
||||
"name": "Dream Machine Pro",
|
||||
"hostname": "UniFi-Dream-Machine",
|
||||
"product_name": "UDMPRO",
|
||||
"platform": "UCG-Ultra",
|
||||
"direct_connect_domain": "x.ui.direct",
|
||||
}
|
||||
@@ -461,13 +473,54 @@ async def test_flow_integration_discovery(hass: HomeAssistant) -> None:
|
||||
for flow in hass.config_entries.flow.async_progress()
|
||||
if flow["flow_id"] == result["flow_id"]
|
||||
)
|
||||
assert context["title_placeholders"] == {
|
||||
"host": "x.ui.direct",
|
||||
"site": "default",
|
||||
}
|
||||
assert context["configuration_url"] == "https://x.ui.direct"
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
("extra_info", "expected_name"),
|
||||
[
|
||||
(
|
||||
{
|
||||
"name": "Dream Machine Pro",
|
||||
"hostname": "UniFi-Dream-Machine",
|
||||
"product_name": "UDMPRO",
|
||||
},
|
||||
"Dream Machine Pro",
|
||||
),
|
||||
(
|
||||
{"hostname": "UniFi-Dream-Machine", "product_name": "UDMPRO"},
|
||||
"UniFi-Dream-Machine",
|
||||
),
|
||||
({"product_name": "UDMPRO"}, "UDMPRO"),
|
||||
({}, "UniFi Network"),
|
||||
],
|
||||
ids=["name", "hostname", "product_name", "fallback"],
|
||||
)
|
||||
async def test_flow_integration_discovery_title(
|
||||
hass: HomeAssistant, extra_info: dict[str, str], expected_name: str
|
||||
) -> None:
|
||||
"""Test discovery title priority: name, hostname, product_name, then fallback."""
|
||||
result = await hass.config_entries.flow.async_init(
|
||||
DOMAIN,
|
||||
context={"source": config_entries.SOURCE_INTEGRATION_DISCOVERY},
|
||||
data={
|
||||
"source_ip": "10.0.0.1",
|
||||
"hw_addr": "e0:63:da:20:14:a9",
|
||||
"direct_connect_domain": "x.ui.direct",
|
||||
**extra_info,
|
||||
},
|
||||
)
|
||||
context = next(
|
||||
flow["context"]
|
||||
for flow in hass.config_entries.flow.async_progress()
|
||||
if flow["flow_id"] == result["flow_id"]
|
||||
)
|
||||
assert context["title_placeholders"] == {
|
||||
"host": "10.0.0.1",
|
||||
"name": expected_name,
|
||||
}
|
||||
|
||||
|
||||
@pytest.mark.usefixtures("config_entry")
|
||||
async def test_flow_integration_discovery_aborts_if_host_already_exists(
|
||||
hass: HomeAssistant,
|
||||
@@ -497,16 +550,6 @@ async def test_flow_integration_discovery_uses_direct_connect_domain(
|
||||
assert result["type"] is FlowResultType.FORM
|
||||
assert result["step_id"] == "user"
|
||||
|
||||
context = next(
|
||||
flow["context"]
|
||||
for flow in hass.config_entries.flow.async_progress()
|
||||
if flow["flow_id"] == result["flow_id"]
|
||||
)
|
||||
assert context["title_placeholders"] == {
|
||||
"host": "x.ui.direct",
|
||||
"site": "default",
|
||||
}
|
||||
|
||||
schema_defaults = {
|
||||
marker.schema: marker.default()
|
||||
for marker in result["data_schema"].schema
|
||||
@@ -599,6 +642,6 @@ async def test_flow_integration_discovery_gets_form_with_ignored_entry(
|
||||
if flow["flow_id"] == result["flow_id"]
|
||||
)
|
||||
assert context["title_placeholders"] == {
|
||||
"host": "x.ui.direct",
|
||||
"site": "default",
|
||||
"host": "10.0.0.1",
|
||||
"name": "Dream Machine Pro",
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user