2018-11-27 20:21:25 +00:00
|
|
|
"""Tests for ZHA config flow."""
|
|
|
|
from asynctest import patch
|
2019-10-21 23:30:56 +00:00
|
|
|
|
2018-11-27 20:21:25 +00:00
|
|
|
from homeassistant.components.zha import config_flow
|
2019-06-23 17:43:19 +00:00
|
|
|
from homeassistant.components.zha.core.const import DOMAIN
|
2019-10-21 23:30:56 +00:00
|
|
|
|
2018-11-27 20:21:25 +00:00
|
|
|
from tests.common import MockConfigEntry
|
|
|
|
|
|
|
|
|
|
|
|
async def test_user_flow(hass):
|
|
|
|
"""Test that config flow works."""
|
|
|
|
flow = config_flow.ZhaFlowHandler()
|
|
|
|
flow.hass = hass
|
|
|
|
|
2019-07-31 19:25:30 +00:00
|
|
|
with patch(
|
|
|
|
"homeassistant.components.zha.config_flow" ".check_zigpy_connection",
|
|
|
|
return_value=False,
|
|
|
|
):
|
2018-11-27 20:21:25 +00:00
|
|
|
result = await flow.async_step_user(
|
2019-07-31 19:25:30 +00:00
|
|
|
user_input={"usb_path": "/dev/ttyUSB1", "radio_type": "ezsp"}
|
|
|
|
)
|
2018-11-27 20:21:25 +00:00
|
|
|
|
2019-07-31 19:25:30 +00:00
|
|
|
assert result["errors"] == {"base": "cannot_connect"}
|
2018-11-27 20:21:25 +00:00
|
|
|
|
2019-07-31 19:25:30 +00:00
|
|
|
with patch(
|
|
|
|
"homeassistant.components.zha.config_flow" ".check_zigpy_connection",
|
|
|
|
return_value=True,
|
|
|
|
):
|
2018-11-27 20:21:25 +00:00
|
|
|
result = await flow.async_step_user(
|
2019-07-31 19:25:30 +00:00
|
|
|
user_input={"usb_path": "/dev/ttyUSB1", "radio_type": "ezsp"}
|
|
|
|
)
|
2018-11-27 20:21:25 +00:00
|
|
|
|
2019-07-31 19:25:30 +00:00
|
|
|
assert result["type"] == "create_entry"
|
|
|
|
assert result["title"] == "/dev/ttyUSB1"
|
|
|
|
assert result["data"] == {"usb_path": "/dev/ttyUSB1", "radio_type": "ezsp"}
|
2018-11-27 20:21:25 +00:00
|
|
|
|
|
|
|
|
|
|
|
async def test_user_flow_existing_config_entry(hass):
|
|
|
|
"""Test if config entry already exists."""
|
2019-07-31 19:25:30 +00:00
|
|
|
MockConfigEntry(domain=DOMAIN, data={"usb_path": "/dev/ttyUSB1"}).add_to_hass(hass)
|
2018-11-27 20:21:25 +00:00
|
|
|
flow = config_flow.ZhaFlowHandler()
|
|
|
|
flow.hass = hass
|
|
|
|
|
|
|
|
result = await flow.async_step_user()
|
|
|
|
|
2019-07-31 19:25:30 +00:00
|
|
|
assert result["type"] == "abort"
|
2018-11-27 20:21:25 +00:00
|
|
|
|
|
|
|
|
|
|
|
async def test_import_flow(hass):
|
|
|
|
"""Test import from configuration.yaml ."""
|
|
|
|
flow = config_flow.ZhaFlowHandler()
|
|
|
|
flow.hass = hass
|
|
|
|
|
2019-07-31 19:25:30 +00:00
|
|
|
result = await flow.async_step_import(
|
|
|
|
{"usb_path": "/dev/ttyUSB1", "radio_type": "xbee"}
|
|
|
|
)
|
2018-11-27 20:21:25 +00:00
|
|
|
|
2019-07-31 19:25:30 +00:00
|
|
|
assert result["type"] == "create_entry"
|
|
|
|
assert result["title"] == "/dev/ttyUSB1"
|
|
|
|
assert result["data"] == {"usb_path": "/dev/ttyUSB1", "radio_type": "xbee"}
|
2018-11-27 20:21:25 +00:00
|
|
|
|
|
|
|
|
|
|
|
async def test_import_flow_existing_config_entry(hass):
|
|
|
|
"""Test import from configuration.yaml ."""
|
2019-07-31 19:25:30 +00:00
|
|
|
MockConfigEntry(domain=DOMAIN, data={"usb_path": "/dev/ttyUSB1"}).add_to_hass(hass)
|
2018-11-27 20:21:25 +00:00
|
|
|
flow = config_flow.ZhaFlowHandler()
|
|
|
|
flow.hass = hass
|
|
|
|
|
2019-07-31 19:25:30 +00:00
|
|
|
result = await flow.async_step_import(
|
|
|
|
{"usb_path": "/dev/ttyUSB1", "radio_type": "xbee"}
|
|
|
|
)
|
2018-11-27 20:21:25 +00:00
|
|
|
|
2019-07-31 19:25:30 +00:00
|
|
|
assert result["type"] == "abort"
|