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