mirror of
https://github.com/home-assistant/core.git
synced 2025-07-09 14:27:07 +00:00
Abort zha usb discovery if deconz is setup (#55245)
* Abort zha usb discovery if deconz is setup * Update tests/components/zha/test_config_flow.py * add deconz domain const * Update homeassistant/components/zha/config_flow.py Co-authored-by: Robert Svensson <Kane610@users.noreply.github.com> Co-authored-by: Robert Svensson <Kane610@users.noreply.github.com>
This commit is contained in:
parent
d4fa625a7f
commit
d59ea5329e
@ -25,6 +25,7 @@ SUPPORTED_PORT_SETTINGS = (
|
||||
CONF_BAUDRATE,
|
||||
CONF_FLOWCONTROL,
|
||||
)
|
||||
DECONZ_DOMAIN = "deconz"
|
||||
|
||||
|
||||
class ZhaFlowHandler(config_entries.ConfigFlow, domain=DOMAIN):
|
||||
@ -120,7 +121,10 @@ class ZhaFlowHandler(config_entries.ConfigFlow, domain=DOMAIN):
|
||||
# we ignore the usb discovery as they probably
|
||||
# want to use it there instead
|
||||
for flow in self.hass.config_entries.flow.async_progress():
|
||||
if flow["handler"] == "deconz":
|
||||
if flow["handler"] == DECONZ_DOMAIN:
|
||||
return self.async_abort(reason="not_zha_device")
|
||||
for entry in self.hass.config_entries.async_entries(DECONZ_DOMAIN):
|
||||
if entry.source != config_entries.SOURCE_IGNORE:
|
||||
return self.async_abort(reason="not_zha_device")
|
||||
|
||||
self._device_path = dev_path
|
||||
|
@ -7,7 +7,7 @@ import serial.tools.list_ports
|
||||
import zigpy.config
|
||||
from zigpy.config import CONF_DEVICE, CONF_DEVICE_PATH
|
||||
|
||||
from homeassistant import setup
|
||||
from homeassistant import config_entries, setup
|
||||
from homeassistant.components.ssdp import (
|
||||
ATTR_SSDP_LOCATION,
|
||||
ATTR_UPNP_MANUFACTURER_URL,
|
||||
@ -271,6 +271,52 @@ async def test_discovery_via_usb_deconz_already_discovered(detect_mock, hass):
|
||||
assert result["reason"] == "not_zha_device"
|
||||
|
||||
|
||||
@patch("zigpy_znp.zigbee.application.ControllerApplication.probe", return_value=True)
|
||||
async def test_discovery_via_usb_deconz_already_setup(detect_mock, hass):
|
||||
"""Test usb flow -- deconz setup."""
|
||||
MockConfigEntry(domain="deconz", data={}).add_to_hass(hass)
|
||||
await hass.async_block_till_done()
|
||||
discovery_info = {
|
||||
"device": "/dev/ttyZIGBEE",
|
||||
"pid": "AAAA",
|
||||
"vid": "AAAA",
|
||||
"serial_number": "1234",
|
||||
"description": "zigbee radio",
|
||||
"manufacturer": "test",
|
||||
}
|
||||
result = await hass.config_entries.flow.async_init(
|
||||
"zha", context={"source": SOURCE_USB}, data=discovery_info
|
||||
)
|
||||
await hass.async_block_till_done()
|
||||
|
||||
assert result["type"] == "abort"
|
||||
assert result["reason"] == "not_zha_device"
|
||||
|
||||
|
||||
@patch("zigpy_znp.zigbee.application.ControllerApplication.probe", return_value=True)
|
||||
async def test_discovery_via_usb_deconz_ignored(detect_mock, hass):
|
||||
"""Test usb flow -- deconz ignored."""
|
||||
MockConfigEntry(
|
||||
domain="deconz", source=config_entries.SOURCE_IGNORE, data={}
|
||||
).add_to_hass(hass)
|
||||
await hass.async_block_till_done()
|
||||
discovery_info = {
|
||||
"device": "/dev/ttyZIGBEE",
|
||||
"pid": "AAAA",
|
||||
"vid": "AAAA",
|
||||
"serial_number": "1234",
|
||||
"description": "zigbee radio",
|
||||
"manufacturer": "test",
|
||||
}
|
||||
result = await hass.config_entries.flow.async_init(
|
||||
"zha", context={"source": SOURCE_USB}, data=discovery_info
|
||||
)
|
||||
await hass.async_block_till_done()
|
||||
|
||||
assert result["type"] == RESULT_TYPE_FORM
|
||||
assert result["step_id"] == "confirm"
|
||||
|
||||
|
||||
@patch("homeassistant.components.zha.async_setup_entry", AsyncMock(return_value=True))
|
||||
@patch("zigpy_znp.zigbee.application.ControllerApplication.probe", return_value=True)
|
||||
async def test_discovery_already_setup(detect_mock, hass):
|
||||
|
Loading…
x
Reference in New Issue
Block a user