Z-Wave to support migrating from USB to socket with same home ID (#153522)

This commit is contained in:
Paulus Schoutsen
2025-10-03 10:46:12 -04:00
committed by GitHub
parent 4ff5462cc4
commit d595ec8a07
2 changed files with 130 additions and 3 deletions
+116 -1
View File
@@ -1303,7 +1303,11 @@ async def test_esphome_discovery_already_configured(
entry = MockConfigEntry(
entry_id="mock-entry-id",
domain=DOMAIN,
data={CONF_SOCKET_PATH: "esphome://existing-device:6053"},
data={
CONF_SOCKET_PATH: "esphome://existing-device:6053",
"use_addon": True,
"integration_created_addon": True,
},
title=TITLE,
unique_id="1234",
)
@@ -1333,6 +1337,117 @@ async def test_esphome_discovery_already_configured(
)
@pytest.mark.usefixtures("supervisor", "addon_not_installed", "addon_info")
async def test_esphome_discovery_usb_same_home_id(
hass: HomeAssistant,
install_addon: AsyncMock,
set_addon_options: AsyncMock,
start_addon: AsyncMock,
) -> None:
"""Test ESPHome discovery works if USB stick with same home ID is configured."""
entry = MockConfigEntry(
entry_id="mock-entry-id",
domain=DOMAIN,
data={
CONF_USB_PATH: "/dev/ttyUSB0",
"use_addon": True,
"integration_created_addon": True,
},
title=TITLE,
unique_id="1234",
)
entry.add_to_hass(hass)
result = await hass.config_entries.flow.async_init(
DOMAIN,
context={"source": config_entries.SOURCE_ESPHOME},
data=ESPHOME_DISCOVERY_INFO,
)
assert result["type"] is FlowResultType.MENU
assert result["step_id"] == "installation_type"
assert result["menu_options"] == ["intent_recommended", "intent_custom"]
result = await hass.config_entries.flow.async_configure(
result["flow_id"], {"next_step_id": "intent_custom"}
)
assert result["step_id"] == "install_addon"
assert result["type"] is FlowResultType.SHOW_PROGRESS
# Make sure the flow continues when the progress task is done.
await hass.async_block_till_done()
result = await hass.config_entries.flow.async_configure(result["flow_id"])
assert install_addon.call_args == call("core_zwave_js")
assert result["type"] is FlowResultType.FORM
assert result["step_id"] == "network_type"
result = await hass.config_entries.flow.async_configure(
result["flow_id"],
{
"network_type": "existing",
},
)
assert result["type"] is FlowResultType.FORM
assert result["step_id"] == "configure_security_keys"
result = await hass.config_entries.flow.async_configure(
result["flow_id"],
{
"s0_legacy_key": "new123",
"s2_access_control_key": "new456",
"s2_authenticated_key": "new789",
"s2_unauthenticated_key": "new987",
"lr_s2_access_control_key": "new654",
"lr_s2_authenticated_key": "new321",
},
)
assert set_addon_options.call_args == call(
"core_zwave_js",
AddonsOptions(
config={
"socket": "esphome://192.168.1.100:6053",
"s0_legacy_key": "new123",
"s2_access_control_key": "new456",
"s2_authenticated_key": "new789",
"s2_unauthenticated_key": "new987",
"lr_s2_access_control_key": "new654",
"lr_s2_authenticated_key": "new321",
}
),
)
assert result["type"] is FlowResultType.SHOW_PROGRESS
assert result["step_id"] == "start_addon"
await hass.async_block_till_done()
result = await hass.config_entries.flow.async_configure(result["flow_id"])
await hass.async_block_till_done()
assert start_addon.call_args == call("core_zwave_js")
assert result["type"] is FlowResultType.ABORT
assert result["reason"] == "migration_successful"
assert entry.data == {
"url": "ws://host1:3001",
"usb_path": None,
"socket_path": "esphome://192.168.1.100:6053",
"s0_legacy_key": "new123",
"s2_access_control_key": "new456",
"s2_authenticated_key": "new789",
"s2_unauthenticated_key": "new987",
"lr_s2_access_control_key": "new654",
"lr_s2_authenticated_key": "new321",
"use_addon": True,
"integration_created_addon": True,
}
@pytest.mark.usefixtures("supervisor", "addon_installed")
async def test_discovery_addon_not_running(
hass: HomeAssistant,