mirror of
https://github.com/home-assistant/core.git
synced 2025-07-20 03:37:07 +00:00
Fix Z-Wave USB discovery to use serial by id path (#144314)
This commit is contained in:
parent
46df29b390
commit
ec4f4a4a1f
@ -461,10 +461,18 @@ class ZWaveJSConfigFlow(ConfigFlow, domain=DOMAIN):
|
||||
if vid == "10C4" and pid == "EA60" and description and "2652" in description:
|
||||
return self.async_abort(reason="not_zwave_device")
|
||||
|
||||
discovery_info.device = await self.hass.async_add_executor_job(
|
||||
usb.get_serial_by_id, discovery_info.device
|
||||
)
|
||||
|
||||
addon_info = await self._async_get_addon_info()
|
||||
if (
|
||||
addon_info.state not in (AddonState.NOT_INSTALLED, AddonState.INSTALLING)
|
||||
and addon_info.options.get(CONF_ADDON_DEVICE) == discovery_info.device
|
||||
and (addon_device := addon_info.options.get(CONF_ADDON_DEVICE)) is not None
|
||||
and await self.hass.async_add_executor_job(
|
||||
usb.get_serial_by_id, addon_device
|
||||
)
|
||||
== discovery_info.device
|
||||
):
|
||||
return self.async_abort(reason="already_configured")
|
||||
|
||||
|
@ -653,6 +653,7 @@ async def test_usb_discovery(
|
||||
install_addon,
|
||||
addon_options,
|
||||
get_addon_discovery_info,
|
||||
mock_usb_serial_by_id: MagicMock,
|
||||
set_addon_options,
|
||||
start_addon,
|
||||
usb_discovery_info: UsbServiceInfo,
|
||||
@ -668,6 +669,7 @@ async def test_usb_discovery(
|
||||
assert result["type"] is FlowResultType.FORM
|
||||
assert result["step_id"] == "usb_confirm"
|
||||
assert result["description_placeholders"] == {"name": discovery_name}
|
||||
assert mock_usb_serial_by_id.call_count == 1
|
||||
|
||||
result = await hass.config_entries.flow.async_configure(result["flow_id"], {})
|
||||
|
||||
@ -765,6 +767,7 @@ async def test_usb_discovery_addon_not_running(
|
||||
supervisor,
|
||||
addon_installed,
|
||||
addon_options,
|
||||
mock_usb_serial_by_id: MagicMock,
|
||||
set_addon_options,
|
||||
start_addon,
|
||||
get_addon_discovery_info,
|
||||
@ -779,6 +782,7 @@ async def test_usb_discovery_addon_not_running(
|
||||
)
|
||||
assert result["type"] is FlowResultType.FORM
|
||||
assert result["step_id"] == "usb_confirm"
|
||||
assert mock_usb_serial_by_id.call_count == 2
|
||||
|
||||
result = await hass.config_entries.flow.async_configure(result["flow_id"], {})
|
||||
|
||||
@ -876,6 +880,7 @@ async def test_usb_discovery_addon_not_running(
|
||||
async def test_usb_discovery_migration(
|
||||
hass: HomeAssistant,
|
||||
addon_options: dict[str, Any],
|
||||
mock_usb_serial_by_id: MagicMock,
|
||||
set_addon_options: AsyncMock,
|
||||
restart_addon: AsyncMock,
|
||||
client: MagicMock,
|
||||
@ -929,6 +934,7 @@ async def test_usb_discovery_migration(
|
||||
)
|
||||
assert result["type"] is FlowResultType.FORM
|
||||
assert result["step_id"] == "usb_confirm"
|
||||
assert mock_usb_serial_by_id.call_count == 2
|
||||
|
||||
result = await hass.config_entries.flow.async_configure(result["flow_id"], {})
|
||||
|
||||
@ -1278,6 +1284,7 @@ async def test_abort_usb_discovery_addon_required(
|
||||
async def test_abort_usb_discovery_confirm_addon_required(
|
||||
hass: HomeAssistant,
|
||||
addon_options: dict[str, Any],
|
||||
mock_usb_serial_by_id: MagicMock,
|
||||
) -> None:
|
||||
"""Test usb discovery confirm aborted when existing entry not using add-on."""
|
||||
addon_options["device"] = "/dev/another_device"
|
||||
@ -1301,6 +1308,7 @@ async def test_abort_usb_discovery_confirm_addon_required(
|
||||
|
||||
assert result["type"] is FlowResultType.FORM
|
||||
assert result["step_id"] == "usb_confirm"
|
||||
assert mock_usb_serial_by_id.call_count == 2
|
||||
|
||||
hass.config_entries.async_update_entry(
|
||||
entry,
|
||||
@ -1331,6 +1339,7 @@ async def test_usb_discovery_requires_supervisor(hass: HomeAssistant) -> None:
|
||||
async def test_usb_discovery_same_device(
|
||||
hass: HomeAssistant,
|
||||
addon_options: dict[str, Any],
|
||||
mock_usb_serial_by_id: MagicMock,
|
||||
) -> None:
|
||||
"""Test usb discovery flow is aborted when the add-on device is discovered."""
|
||||
addon_options["device"] = USB_DISCOVERY_INFO.device
|
||||
@ -1341,6 +1350,7 @@ async def test_usb_discovery_same_device(
|
||||
)
|
||||
assert result["type"] is FlowResultType.ABORT
|
||||
assert result["reason"] == "already_configured"
|
||||
assert mock_usb_serial_by_id.call_count == 2
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
|
Loading…
x
Reference in New Issue
Block a user