Do not rely on pyserial for port scanning with the CM5 + ZHA (#137585)

Do not rely on pyserial for port scanning with the CM5
This commit is contained in:
puddly 2025-02-07 10:33:40 -05:00 committed by Franck Nijhof
parent bea201f9f6
commit c71ab054f1
No known key found for this signature in database
GPG Key ID: D62583BA8AB11CA3
2 changed files with 19 additions and 5 deletions

View File

@ -113,9 +113,14 @@ async def list_serial_ports(hass: HomeAssistant) -> list[ListPortInfo]:
except HomeAssistantError:
pass
else:
yellow_radio = next(p for p in ports if p.device == "/dev/ttyAMA1")
yellow_radio.description = "Yellow Zigbee module"
yellow_radio.manufacturer = "Nabu Casa"
# PySerial does not properly handle the Yellow's serial port with the CM5
# so we manually include it
port = ListPortInfo(device="/dev/ttyAMA1", skip_link_detection=True)
port.description = "Yellow Zigbee module"
port.manufacturer = "Nabu Casa"
ports = [p for p in ports if not p.device.startswith("/dev/ttyAMA")]
ports.insert(0, port)
if is_hassio(hass):
# Present the multi-PAN addon as a setup option, if it's available

View File

@ -1914,9 +1914,18 @@ async def test_options_flow_migration_reset_old_adapter(
assert result4["step_id"] == "choose_serial_port"
async def test_config_flow_port_yellow_port_name(hass: HomeAssistant) -> None:
@pytest.mark.parametrize(
"device",
[
"/dev/ttyAMA1", # CM4
"/dev/ttyAMA10", # CM5, erroneously detected by pyserial
],
)
async def test_config_flow_port_yellow_port_name(
hass: HomeAssistant, device: str
) -> None:
"""Test config flow serial port name for Yellow Zigbee radio."""
port = com_port(device="/dev/ttyAMA1")
port = com_port(device=device)
port.serial_number = None
port.manufacturer = None
port.description = None