Disable updating ZHA coordinator path from discovery info (#112415)
* Never update the device path from config flows * Bring coverage up to 100% * Update tests/components/zha/test_config_flow.py Co-authored-by: TheJulianJES <TheJulianJES@users.noreply.github.com> --------- Co-authored-by: TheJulianJES <TheJulianJES@users.noreply.github.com>pull/113250/head
parent
c60f203aab
commit
095aab5f9d
|
@ -491,23 +491,27 @@ class ZhaConfigFlowHandler(BaseZhaFlow, config_entries.ConfigFlow, domain=DOMAIN
|
||||||
|
|
||||||
VERSION = 4
|
VERSION = 4
|
||||||
|
|
||||||
async def _set_unique_id_or_update_path(
|
async def _set_unique_id_and_update_ignored_flow(
|
||||||
self, unique_id: str, device_path: str
|
self, unique_id: str, device_path: str
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Set the flow's unique ID and update the device path if it isn't unique."""
|
"""Set the flow's unique ID and update the device path in an ignored flow."""
|
||||||
current_entry = await self.async_set_unique_id(unique_id)
|
current_entry = await self.async_set_unique_id(unique_id)
|
||||||
|
|
||||||
if not current_entry:
|
if not current_entry:
|
||||||
return
|
return
|
||||||
|
|
||||||
self._abort_if_unique_id_configured(
|
if current_entry.source != SOURCE_IGNORE:
|
||||||
updates={
|
self._abort_if_unique_id_configured()
|
||||||
CONF_DEVICE: {
|
else:
|
||||||
**current_entry.data.get(CONF_DEVICE, {}),
|
# Only update the current entry if it is an ignored discovery
|
||||||
CONF_DEVICE_PATH: device_path,
|
self._abort_if_unique_id_configured(
|
||||||
},
|
updates={
|
||||||
}
|
CONF_DEVICE: {
|
||||||
)
|
**current_entry.data.get(CONF_DEVICE, {}),
|
||||||
|
CONF_DEVICE_PATH: device_path,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
@callback
|
@callback
|
||||||
|
@ -575,7 +579,7 @@ class ZhaConfigFlowHandler(BaseZhaFlow, config_entries.ConfigFlow, domain=DOMAIN
|
||||||
description = discovery_info.description
|
description = discovery_info.description
|
||||||
dev_path = discovery_info.device
|
dev_path = discovery_info.device
|
||||||
|
|
||||||
await self._set_unique_id_or_update_path(
|
await self._set_unique_id_and_update_ignored_flow(
|
||||||
unique_id=f"{vid}:{pid}_{serial_number}_{manufacturer}_{description}",
|
unique_id=f"{vid}:{pid}_{serial_number}_{manufacturer}_{description}",
|
||||||
device_path=dev_path,
|
device_path=dev_path,
|
||||||
)
|
)
|
||||||
|
@ -625,7 +629,7 @@ class ZhaConfigFlowHandler(BaseZhaFlow, config_entries.ConfigFlow, domain=DOMAIN
|
||||||
node_name = local_name.removesuffix(".local")
|
node_name = local_name.removesuffix(".local")
|
||||||
device_path = f"socket://{discovery_info.host}:{port}"
|
device_path = f"socket://{discovery_info.host}:{port}"
|
||||||
|
|
||||||
await self._set_unique_id_or_update_path(
|
await self._set_unique_id_and_update_ignored_flow(
|
||||||
unique_id=node_name,
|
unique_id=node_name,
|
||||||
device_path=device_path,
|
device_path=device_path,
|
||||||
)
|
)
|
||||||
|
@ -650,7 +654,7 @@ class ZhaConfigFlowHandler(BaseZhaFlow, config_entries.ConfigFlow, domain=DOMAIN
|
||||||
device_settings = discovery_data["port"]
|
device_settings = discovery_data["port"]
|
||||||
device_path = device_settings[CONF_DEVICE_PATH]
|
device_path = device_settings[CONF_DEVICE_PATH]
|
||||||
|
|
||||||
await self._set_unique_id_or_update_path(
|
await self._set_unique_id_and_update_ignored_flow(
|
||||||
unique_id=f"{name}_{radio_type.name}_{device_path}",
|
unique_id=f"{name}_{radio_type.name}_{device_path}",
|
||||||
device_path=device_path,
|
device_path=device_path,
|
||||||
)
|
)
|
||||||
|
|
|
@ -293,45 +293,6 @@ async def test_efr32_via_zeroconf(hass: HomeAssistant) -> None:
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@patch("homeassistant.components.zha.async_setup_entry", AsyncMock(return_value=True))
|
|
||||||
@patch(f"zigpy_znp.{PROBE_FUNCTION_PATH}", AsyncMock(return_value=True))
|
|
||||||
async def test_discovery_via_zeroconf_ip_change(hass: HomeAssistant) -> None:
|
|
||||||
"""Test zeroconf flow -- radio detected."""
|
|
||||||
entry = MockConfigEntry(
|
|
||||||
domain=DOMAIN,
|
|
||||||
unique_id="tube_zb_gw_cc2652p2_poe",
|
|
||||||
data={
|
|
||||||
CONF_DEVICE: {
|
|
||||||
CONF_DEVICE_PATH: "socket://192.168.1.5:6638",
|
|
||||||
CONF_BAUDRATE: 115200,
|
|
||||||
CONF_FLOW_CONTROL: None,
|
|
||||||
}
|
|
||||||
},
|
|
||||||
)
|
|
||||||
entry.add_to_hass(hass)
|
|
||||||
|
|
||||||
service_info = zeroconf.ZeroconfServiceInfo(
|
|
||||||
ip_address=ip_address("192.168.1.22"),
|
|
||||||
ip_addresses=[ip_address("192.168.1.22")],
|
|
||||||
hostname="tube_zb_gw_cc2652p2_poe.local.",
|
|
||||||
name="mock_name",
|
|
||||||
port=6053,
|
|
||||||
properties={"address": "tube_zb_gw_cc2652p2_poe.local"},
|
|
||||||
type="mock_type",
|
|
||||||
)
|
|
||||||
result = await hass.config_entries.flow.async_init(
|
|
||||||
DOMAIN, context={"source": SOURCE_ZEROCONF}, data=service_info
|
|
||||||
)
|
|
||||||
|
|
||||||
assert result["type"] == FlowResultType.ABORT
|
|
||||||
assert result["reason"] == "already_configured"
|
|
||||||
assert entry.data[CONF_DEVICE] == {
|
|
||||||
CONF_DEVICE_PATH: "socket://192.168.1.22:6638",
|
|
||||||
CONF_BAUDRATE: 115200,
|
|
||||||
CONF_FLOW_CONTROL: None,
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
@patch("homeassistant.components.zha.async_setup_entry", AsyncMock(return_value=True))
|
@patch("homeassistant.components.zha.async_setup_entry", AsyncMock(return_value=True))
|
||||||
@patch(f"zigpy_znp.{PROBE_FUNCTION_PATH}", AsyncMock(return_value=True))
|
@patch(f"zigpy_znp.{PROBE_FUNCTION_PATH}", AsyncMock(return_value=True))
|
||||||
async def test_discovery_via_zeroconf_ip_change_ignored(hass: HomeAssistant) -> None:
|
async def test_discovery_via_zeroconf_ip_change_ignored(hass: HomeAssistant) -> None:
|
||||||
|
@ -547,8 +508,8 @@ async def test_discovery_via_usb_already_setup(hass: HomeAssistant) -> None:
|
||||||
|
|
||||||
|
|
||||||
@patch("homeassistant.components.zha.async_setup_entry", AsyncMock(return_value=True))
|
@patch("homeassistant.components.zha.async_setup_entry", AsyncMock(return_value=True))
|
||||||
async def test_discovery_via_usb_path_changes(hass: HomeAssistant) -> None:
|
async def test_discovery_via_usb_path_does_not_change(hass: HomeAssistant) -> None:
|
||||||
"""Test usb flow already setup and the path changes."""
|
"""Test usb flow already set up and the path does not change."""
|
||||||
|
|
||||||
entry = MockConfigEntry(
|
entry = MockConfigEntry(
|
||||||
domain=DOMAIN,
|
domain=DOMAIN,
|
||||||
|
@ -579,7 +540,7 @@ async def test_discovery_via_usb_path_changes(hass: HomeAssistant) -> None:
|
||||||
assert result["type"] == FlowResultType.ABORT
|
assert result["type"] == FlowResultType.ABORT
|
||||||
assert result["reason"] == "already_configured"
|
assert result["reason"] == "already_configured"
|
||||||
assert entry.data[CONF_DEVICE] == {
|
assert entry.data[CONF_DEVICE] == {
|
||||||
CONF_DEVICE_PATH: "/dev/ttyZIGBEE",
|
CONF_DEVICE_PATH: "/dev/ttyUSB1",
|
||||||
CONF_BAUDRATE: 115200,
|
CONF_BAUDRATE: 115200,
|
||||||
CONF_FLOW_CONTROL: None,
|
CONF_FLOW_CONTROL: None,
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue