Remove the old ZWave controller from the list of migration targets (#145281)

* Remove the old ZWave controller from the list of migration targets

* ensure addon device path is serial/by_id

* Use executor

---------

Co-authored-by: Martin Hjelmare <marhje52@gmail.com>
This commit is contained in:
Petar Petrov 2025-05-20 23:11:03 +03:00 committed by GitHub
parent 73811eac0a
commit ba44986524
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 15 additions and 0 deletions

View File

@ -1163,6 +1163,15 @@ class ZWaveJSConfigFlow(ConfigFlow, domain=DOMAIN):
_LOGGER.error("Failed to get USB ports: %s", err)
return self.async_abort(reason="usb_ports_failed")
addon_info = await self._async_get_addon_info()
addon_config = addon_info.options
old_usb_path = addon_config.get(CONF_ADDON_DEVICE, "")
# Remove the old controller from the ports list.
ports.pop(
await self.hass.async_add_executor_job(usb.get_serial_by_id, old_usb_path),
None,
)
data_schema = vol.Schema(
{
vol.Required(CONF_USB_PATH): vol.In(ports),

View File

@ -13,6 +13,7 @@ from aiohasupervisor.models import AddonsOptions, Discovery
import aiohttp
import pytest
from serial.tools.list_ports_common import ListPortInfo
from voluptuous import InInvalid
from zwave_js_server.exceptions import FailedCommand
from zwave_js_server.version import VersionInfo
@ -3694,6 +3695,7 @@ async def test_reconfigure_migrate_with_addon(
integration,
addon_running,
restart_addon,
addon_options,
set_addon_options,
get_addon_discovery_info,
get_server_version: AsyncMock,
@ -3717,6 +3719,7 @@ async def test_reconfigure_migrate_with_addon(
"usb_path": "/dev/ttyUSB0",
},
)
addon_options["device"] = "/dev/ttyUSB0"
async def mock_backup_nvm_raw():
await asyncio.sleep(0)
@ -3793,6 +3796,9 @@ async def test_reconfigure_migrate_with_addon(
assert result["type"] is FlowResultType.FORM
assert result["step_id"] == "choose_serial_port"
assert result["data_schema"].schema[CONF_USB_PATH]
# Ensure the old usb path is not in the list of options
with pytest.raises(InInvalid):
result["data_schema"].schema[CONF_USB_PATH](addon_options["device"])
# Reset side effect before starting the add-on.
get_server_version.side_effect = None