Update ZHA config entry radio detection (#55128)

This commit is contained in:
Alexei Chetroi 2021-08-24 16:25:31 -04:00 committed by GitHub
parent 6cf312f3c8
commit 289734c748
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 38 additions and 2 deletions

View File

@ -238,7 +238,10 @@ async def detect_radios(dev_path: str) -> dict[str, Any] | None:
"""Probe all radio types on the device port."""
for radio in RadioType:
dev_config = radio.controller.SCHEMA_DEVICE({CONF_DEVICE_PATH: dev_path})
if await radio.controller.probe(dev_config):
probe_result = await radio.controller.probe(dev_config)
if probe_result:
if isinstance(probe_result, dict):
return {CONF_RADIO_TYPE: radio.name, CONF_DEVICE: probe_result}
return {CONF_RADIO_TYPE: radio.name, CONF_DEVICE: dev_config}
return None

View File

@ -1,6 +1,6 @@
"""Tests for ZHA config flow."""
from unittest.mock import AsyncMock, MagicMock, patch
from unittest.mock import AsyncMock, MagicMock, patch, sentinel
import pytest
import serial.tools.list_ports
@ -446,6 +446,39 @@ async def test_probe_radios(xbee_probe, zigate_probe, deconz_probe, cc_probe, ha
assert cc_probe.await_count == 1
@patch("zigpy_cc.zigbee.application.ControllerApplication.probe", return_value=False)
@patch(
"zigpy_deconz.zigbee.application.ControllerApplication.probe", return_value=False
)
@patch(
"zigpy_zigate.zigbee.application.ControllerApplication.probe", return_value=False
)
@patch("zigpy_xbee.zigbee.application.ControllerApplication.probe", return_value=False)
async def test_probe_new_ezsp(xbee_probe, zigate_probe, deconz_probe, cc_probe, hass):
"""Test detect radios."""
app_ctrl_cls = MagicMock()
app_ctrl_cls.SCHEMA_DEVICE = zigpy.config.SCHEMA_DEVICE
app_ctrl_cls.probe = AsyncMock(side_efferct=(True, False))
p1 = patch(
"bellows.zigbee.application.ControllerApplication.probe",
return_value={
zigpy.config.CONF_DEVICE_PATH: sentinel.usb_port,
"baudrate": 33840,
},
)
with p1 as probe_mock:
res = await config_flow.detect_radios("/dev/null")
assert probe_mock.await_count == 1
assert res[CONF_RADIO_TYPE] == "ezsp"
assert zigpy.config.CONF_DEVICE in res
assert (
res[zigpy.config.CONF_DEVICE][zigpy.config.CONF_DEVICE_PATH]
is sentinel.usb_port
)
assert res[zigpy.config.CONF_DEVICE]["baudrate"] == 33840
@patch("bellows.zigbee.application.ControllerApplication.probe", return_value=False)
async def test_user_port_config_fail(probe_mock, hass):
"""Test port config flow."""