Add more Z-Wave USB discovery (#142460)

This commit is contained in:
Martin Hjelmare 2025-04-08 08:30:43 +02:00 committed by GitHub
parent cb07e64b47
commit dacc4c230d
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 57 additions and 14 deletions

View File

@ -420,17 +420,20 @@ class ZWaveJSConfigFlow(BaseZwaveJSFlow, ConfigFlow, domain=DOMAIN):
self._abort_if_unique_id_configured()
dev_path = discovery_info.device
self.usb_path = dev_path
self._title = usb.human_readable_device_name(
dev_path,
serial_number,
manufacturer,
description,
vid,
pid,
)
self.context["title_placeholders"] = {
CONF_NAME: self._title.split(" - ")[0].strip()
}
if manufacturer == "Nabu Casa" and description == "ZWA-2 - Nabu Casa ZWA-2":
title = "Home Assistant Connect ZWA-2"
else:
human_name = usb.human_readable_device_name(
dev_path,
serial_number,
manufacturer,
description,
vid,
pid,
)
title = human_name.split(" - ")[0].strip()
self.context["title_placeholders"] = {CONF_NAME: title}
self._title = title
return await self.async_step_usb_confirm()
async def async_step_usb_confirm(

View File

@ -21,6 +21,13 @@
"pid": "8A2A",
"description": "*z-wave*",
"known_devices": ["Nortek HUSBZB-1"]
},
{
"vid": "303A",
"pid": "4001",
"description": "*nabu casa zwa-2*",
"manufacturer": "nabu casa",
"known_devices": ["Nabu Casa Connect ZWA-2"]
}
],
"zeroconf": ["_zwave-js-server._tcp.local."]

View File

@ -148,4 +148,11 @@ USB = [
"pid": "8A2A",
"vid": "10C4",
},
{
"description": "*nabu casa zwa-2*",
"domain": "zwave_js",
"manufacturer": "nabu casa",
"pid": "4001",
"vid": "303A",
},
]

View File

@ -556,6 +556,28 @@ async def test_abort_hassio_discovery_for_other_addon(
assert result2["reason"] == "not_zwave_js_addon"
@pytest.mark.parametrize(
("usb_discovery_info", "device", "discovery_name"),
[
(
USB_DISCOVERY_INFO,
USB_DISCOVERY_INFO.device,
"zwave radio",
),
(
UsbServiceInfo(
device="/dev/zwa2",
pid="303A",
vid="4001",
serial_number="1234",
description="ZWA-2 - Nabu Casa ZWA-2",
manufacturer="Nabu Casa",
),
"/dev/zwa2",
"Home Assistant Connect ZWA-2",
),
],
)
@pytest.mark.parametrize(
"discovery_info",
[
@ -578,15 +600,19 @@ async def test_usb_discovery(
get_addon_discovery_info,
set_addon_options,
start_addon,
usb_discovery_info: UsbServiceInfo,
device: str,
discovery_name: str,
) -> None:
"""Test usb discovery success path."""
result = await hass.config_entries.flow.async_init(
DOMAIN,
context={"source": config_entries.SOURCE_USB},
data=USB_DISCOVERY_INFO,
data=usb_discovery_info,
)
assert result["type"] is FlowResultType.FORM
assert result["step_id"] == "usb_confirm"
assert result["description_placeholders"] == {"name": discovery_name}
result = await hass.config_entries.flow.async_configure(result["flow_id"], {})
@ -619,7 +645,7 @@ async def test_usb_discovery(
"core_zwave_js",
AddonsOptions(
config={
"device": USB_DISCOVERY_INFO.device,
"device": device,
"s0_legacy_key": "new123",
"s2_access_control_key": "new456",
"s2_authenticated_key": "new789",
@ -652,7 +678,7 @@ async def test_usb_discovery(
assert result["title"] == TITLE
assert result["data"] == {
"url": "ws://host1:3001",
"usb_path": USB_DISCOVERY_INFO.device,
"usb_path": device,
"s0_legacy_key": "new123",
"s2_access_control_key": "new456",
"s2_authenticated_key": "new789",