2018-03-16 20:27:05 -07:00
|
|
|
"""Tests for Philips Hue config flow."""
|
|
|
|
import asyncio
|
2018-03-29 20:15:40 -07:00
|
|
|
from unittest.mock import Mock, patch
|
2018-03-16 20:27:05 -07:00
|
|
|
|
|
|
|
import aiohue
|
|
|
|
import pytest
|
|
|
|
import voluptuous as vol
|
|
|
|
|
2019-12-18 07:41:01 +01:00
|
|
|
from homeassistant import config_entries, data_entry_flow
|
2019-12-19 19:28:03 +02:00
|
|
|
from homeassistant.components import ssdp
|
2019-12-16 19:45:09 +01:00
|
|
|
from homeassistant.components.hue import config_flow, const
|
2018-03-16 20:27:05 -07:00
|
|
|
|
|
|
|
from tests.common import MockConfigEntry, mock_coro
|
|
|
|
|
|
|
|
|
2019-12-16 19:45:09 +01:00
|
|
|
async def test_flow_works(hass):
|
2018-03-16 20:27:05 -07:00
|
|
|
"""Test config flow ."""
|
2019-12-16 19:45:09 +01:00
|
|
|
mock_bridge = Mock()
|
|
|
|
mock_bridge.host = "1.2.3.4"
|
|
|
|
mock_bridge.username = None
|
|
|
|
mock_bridge.config.name = "Mock Bridge"
|
|
|
|
mock_bridge.id = "aabbccddeeff"
|
|
|
|
|
|
|
|
async def mock_create_user(username):
|
|
|
|
mock_bridge.username = username
|
|
|
|
|
|
|
|
mock_bridge.create_user = mock_create_user
|
|
|
|
mock_bridge.initialize.return_value = mock_coro()
|
2018-03-16 20:27:05 -07:00
|
|
|
|
2018-03-29 20:15:40 -07:00
|
|
|
flow = config_flow.HueFlowHandler()
|
2018-03-16 20:27:05 -07:00
|
|
|
flow.hass = hass
|
2019-12-16 12:27:43 +01:00
|
|
|
flow.context = {}
|
2019-07-31 12:25:30 -07:00
|
|
|
|
2019-12-16 19:45:09 +01:00
|
|
|
with patch(
|
|
|
|
"homeassistant.components.hue.config_flow.discover_nupnp",
|
|
|
|
return_value=mock_coro([mock_bridge]),
|
|
|
|
):
|
|
|
|
result = await flow.async_step_init()
|
2018-03-16 20:27:05 -07:00
|
|
|
|
2019-12-16 19:45:09 +01:00
|
|
|
assert result["type"] == "form"
|
|
|
|
assert result["step_id"] == "link"
|
2018-03-16 20:27:05 -07:00
|
|
|
|
2019-12-16 19:45:09 +01:00
|
|
|
assert flow.context["unique_id"] == "aabbccddeeff"
|
2018-03-16 20:27:05 -07:00
|
|
|
|
2019-12-16 19:45:09 +01:00
|
|
|
result = await flow.async_step_link(user_input={})
|
2018-03-16 20:27:05 -07:00
|
|
|
|
2019-07-31 12:25:30 -07:00
|
|
|
assert result["type"] == "create_entry"
|
|
|
|
assert result["title"] == "Mock Bridge"
|
|
|
|
assert result["data"] == {
|
|
|
|
"host": "1.2.3.4",
|
2019-12-16 19:45:09 +01:00
|
|
|
"username": "home-assistant#test-home",
|
2018-03-16 20:27:05 -07:00
|
|
|
}
|
|
|
|
|
2019-12-16 19:45:09 +01:00
|
|
|
assert len(mock_bridge.initialize.mock_calls) == 1
|
|
|
|
|
2018-03-16 20:27:05 -07:00
|
|
|
|
|
|
|
async def test_flow_no_discovered_bridges(hass, aioclient_mock):
|
|
|
|
"""Test config flow discovers no bridges."""
|
2018-03-29 20:15:40 -07:00
|
|
|
aioclient_mock.get(const.API_NUPNP, json=[])
|
|
|
|
flow = config_flow.HueFlowHandler()
|
2018-03-16 20:27:05 -07:00
|
|
|
flow.hass = hass
|
|
|
|
|
|
|
|
result = await flow.async_step_init()
|
2019-07-31 12:25:30 -07:00
|
|
|
assert result["type"] == "abort"
|
2018-03-16 20:27:05 -07:00
|
|
|
|
|
|
|
|
|
|
|
async def test_flow_all_discovered_bridges_exist(hass, aioclient_mock):
|
|
|
|
"""Test config flow discovers only already configured bridges."""
|
2019-07-31 12:25:30 -07:00
|
|
|
aioclient_mock.get(
|
|
|
|
const.API_NUPNP, json=[{"internalipaddress": "1.2.3.4", "id": "bla"}]
|
|
|
|
)
|
2019-12-16 19:45:09 +01:00
|
|
|
MockConfigEntry(
|
|
|
|
domain="hue", unique_id="bla", data={"host": "1.2.3.4"}
|
|
|
|
).add_to_hass(hass)
|
2018-03-29 20:15:40 -07:00
|
|
|
flow = config_flow.HueFlowHandler()
|
2018-03-16 20:27:05 -07:00
|
|
|
flow.hass = hass
|
2019-12-16 19:45:09 +01:00
|
|
|
flow.context = {}
|
2018-03-16 20:27:05 -07:00
|
|
|
|
|
|
|
result = await flow.async_step_init()
|
2019-07-31 12:25:30 -07:00
|
|
|
assert result["type"] == "abort"
|
2018-03-16 20:27:05 -07:00
|
|
|
|
|
|
|
|
|
|
|
async def test_flow_one_bridge_discovered(hass, aioclient_mock):
|
|
|
|
"""Test config flow discovers one bridge."""
|
2019-07-31 12:25:30 -07:00
|
|
|
aioclient_mock.get(
|
|
|
|
const.API_NUPNP, json=[{"internalipaddress": "1.2.3.4", "id": "bla"}]
|
|
|
|
)
|
2018-03-29 20:15:40 -07:00
|
|
|
flow = config_flow.HueFlowHandler()
|
2018-03-16 20:27:05 -07:00
|
|
|
flow.hass = hass
|
2019-12-16 19:45:09 +01:00
|
|
|
flow.context = {}
|
2018-03-16 20:27:05 -07:00
|
|
|
|
|
|
|
result = await flow.async_step_init()
|
2019-07-31 12:25:30 -07:00
|
|
|
assert result["type"] == "form"
|
|
|
|
assert result["step_id"] == "link"
|
2018-03-16 20:27:05 -07:00
|
|
|
|
|
|
|
|
|
|
|
async def test_flow_two_bridges_discovered(hass, aioclient_mock):
|
|
|
|
"""Test config flow discovers two bridges."""
|
2019-12-18 07:41:01 +01:00
|
|
|
# Add ignored config entry. Should still show up as option.
|
|
|
|
MockConfigEntry(
|
|
|
|
domain="hue", source=config_entries.SOURCE_IGNORE, unique_id="bla"
|
|
|
|
).add_to_hass(hass)
|
|
|
|
|
2019-07-31 12:25:30 -07:00
|
|
|
aioclient_mock.get(
|
|
|
|
const.API_NUPNP,
|
|
|
|
json=[
|
|
|
|
{"internalipaddress": "1.2.3.4", "id": "bla"},
|
|
|
|
{"internalipaddress": "5.6.7.8", "id": "beer"},
|
|
|
|
],
|
|
|
|
)
|
2018-03-29 20:15:40 -07:00
|
|
|
flow = config_flow.HueFlowHandler()
|
2018-03-16 20:27:05 -07:00
|
|
|
flow.hass = hass
|
|
|
|
|
|
|
|
result = await flow.async_step_init()
|
2019-07-31 12:25:30 -07:00
|
|
|
assert result["type"] == "form"
|
|
|
|
assert result["step_id"] == "init"
|
2018-03-16 20:27:05 -07:00
|
|
|
|
|
|
|
with pytest.raises(vol.Invalid):
|
2019-12-16 19:45:09 +01:00
|
|
|
assert result["data_schema"]({"id": "not-discovered"})
|
2018-03-16 20:27:05 -07:00
|
|
|
|
2019-12-16 19:45:09 +01:00
|
|
|
result["data_schema"]({"id": "bla"})
|
|
|
|
result["data_schema"]({"id": "beer"})
|
2018-03-16 20:27:05 -07:00
|
|
|
|
|
|
|
|
|
|
|
async def test_flow_two_bridges_discovered_one_new(hass, aioclient_mock):
|
|
|
|
"""Test config flow discovers two bridges."""
|
2019-07-31 12:25:30 -07:00
|
|
|
aioclient_mock.get(
|
|
|
|
const.API_NUPNP,
|
|
|
|
json=[
|
|
|
|
{"internalipaddress": "1.2.3.4", "id": "bla"},
|
|
|
|
{"internalipaddress": "5.6.7.8", "id": "beer"},
|
|
|
|
],
|
|
|
|
)
|
2019-12-16 19:45:09 +01:00
|
|
|
MockConfigEntry(
|
|
|
|
domain="hue", unique_id="bla", data={"host": "1.2.3.4"}
|
|
|
|
).add_to_hass(hass)
|
2018-03-29 20:15:40 -07:00
|
|
|
flow = config_flow.HueFlowHandler()
|
2018-03-16 20:27:05 -07:00
|
|
|
flow.hass = hass
|
2019-12-16 19:45:09 +01:00
|
|
|
flow.context = {}
|
2018-03-16 20:27:05 -07:00
|
|
|
|
|
|
|
result = await flow.async_step_init()
|
2019-07-31 12:25:30 -07:00
|
|
|
assert result["type"] == "form"
|
|
|
|
assert result["step_id"] == "link"
|
2019-12-16 19:45:09 +01:00
|
|
|
assert flow.bridge.host == "5.6.7.8"
|
2018-03-16 20:27:05 -07:00
|
|
|
|
|
|
|
|
|
|
|
async def test_flow_timeout_discovery(hass):
|
|
|
|
"""Test config flow ."""
|
2018-03-29 20:15:40 -07:00
|
|
|
flow = config_flow.HueFlowHandler()
|
2018-03-16 20:27:05 -07:00
|
|
|
flow.hass = hass
|
|
|
|
|
2019-07-31 12:25:30 -07:00
|
|
|
with patch(
|
|
|
|
"homeassistant.components.hue.config_flow.discover_nupnp",
|
|
|
|
side_effect=asyncio.TimeoutError,
|
|
|
|
):
|
2018-03-16 20:27:05 -07:00
|
|
|
result = await flow.async_step_init()
|
|
|
|
|
2019-07-31 12:25:30 -07:00
|
|
|
assert result["type"] == "abort"
|
2018-03-16 20:27:05 -07:00
|
|
|
|
|
|
|
|
|
|
|
async def test_flow_link_timeout(hass):
|
|
|
|
"""Test config flow ."""
|
2018-03-29 20:15:40 -07:00
|
|
|
flow = config_flow.HueFlowHandler()
|
2018-03-16 20:27:05 -07:00
|
|
|
flow.hass = hass
|
2019-12-16 19:45:09 +01:00
|
|
|
flow.bridge = Mock()
|
2018-03-16 20:27:05 -07:00
|
|
|
|
2019-07-31 12:25:30 -07:00
|
|
|
with patch("aiohue.Bridge.create_user", side_effect=asyncio.TimeoutError):
|
2018-03-16 20:27:05 -07:00
|
|
|
result = await flow.async_step_link({})
|
|
|
|
|
2019-07-31 12:25:30 -07:00
|
|
|
assert result["type"] == "form"
|
|
|
|
assert result["step_id"] == "link"
|
|
|
|
assert result["errors"] == {"base": "linking"}
|
2018-03-16 20:27:05 -07:00
|
|
|
|
|
|
|
|
|
|
|
async def test_flow_link_button_not_pressed(hass):
|
|
|
|
"""Test config flow ."""
|
2018-03-29 20:15:40 -07:00
|
|
|
flow = config_flow.HueFlowHandler()
|
2018-03-16 20:27:05 -07:00
|
|
|
flow.hass = hass
|
2019-12-16 19:45:09 +01:00
|
|
|
flow.bridge = Mock(
|
|
|
|
username=None, create_user=Mock(side_effect=aiohue.LinkButtonNotPressed)
|
|
|
|
)
|
2018-03-16 20:27:05 -07:00
|
|
|
|
2019-12-16 19:45:09 +01:00
|
|
|
result = await flow.async_step_link({})
|
2018-03-16 20:27:05 -07:00
|
|
|
|
2019-07-31 12:25:30 -07:00
|
|
|
assert result["type"] == "form"
|
|
|
|
assert result["step_id"] == "link"
|
|
|
|
assert result["errors"] == {"base": "register_failed"}
|
2018-03-16 20:27:05 -07:00
|
|
|
|
|
|
|
|
|
|
|
async def test_flow_link_unknown_host(hass):
|
|
|
|
"""Test config flow ."""
|
2018-03-29 20:15:40 -07:00
|
|
|
flow = config_flow.HueFlowHandler()
|
2018-03-16 20:27:05 -07:00
|
|
|
flow.hass = hass
|
2019-12-16 19:45:09 +01:00
|
|
|
flow.bridge = Mock()
|
2018-03-16 20:27:05 -07:00
|
|
|
|
2019-07-31 12:25:30 -07:00
|
|
|
with patch("aiohue.Bridge.create_user", side_effect=aiohue.RequestError):
|
2018-03-16 20:27:05 -07:00
|
|
|
result = await flow.async_step_link({})
|
|
|
|
|
2019-07-31 12:25:30 -07:00
|
|
|
assert result["type"] == "form"
|
|
|
|
assert result["step_id"] == "link"
|
|
|
|
assert result["errors"] == {"base": "linking"}
|
2018-03-29 20:15:40 -07:00
|
|
|
|
|
|
|
|
2019-05-26 19:48:27 -07:00
|
|
|
async def test_bridge_ssdp(hass):
|
2018-03-29 20:15:40 -07:00
|
|
|
"""Test a bridge being discovered."""
|
|
|
|
flow = config_flow.HueFlowHandler()
|
|
|
|
flow.hass = hass
|
2019-05-26 19:48:27 -07:00
|
|
|
flow.context = {}
|
2018-03-29 20:15:40 -07:00
|
|
|
|
2019-12-16 19:45:09 +01:00
|
|
|
result = await flow.async_step_ssdp(
|
|
|
|
{
|
2019-12-19 19:28:03 +02:00
|
|
|
ssdp.ATTR_SSDP_LOCATION: "http://0.0.0.0/",
|
|
|
|
ssdp.ATTR_UPNP_MANUFACTURER_URL: config_flow.HUE_MANUFACTURERURL,
|
|
|
|
ssdp.ATTR_UPNP_SERIAL: "1234",
|
2019-12-16 19:45:09 +01:00
|
|
|
}
|
|
|
|
)
|
2018-03-29 20:15:40 -07:00
|
|
|
|
2019-07-31 12:25:30 -07:00
|
|
|
assert result["type"] == "form"
|
|
|
|
assert result["step_id"] == "link"
|
2018-03-29 20:15:40 -07:00
|
|
|
|
|
|
|
|
2019-06-03 18:26:01 +02:00
|
|
|
async def test_bridge_ssdp_discover_other_bridge(hass):
|
|
|
|
"""Test that discovery ignores other bridges."""
|
|
|
|
flow = config_flow.HueFlowHandler()
|
|
|
|
flow.hass = hass
|
|
|
|
|
2019-07-31 12:25:30 -07:00
|
|
|
result = await flow.async_step_ssdp(
|
2019-12-19 19:28:03 +02:00
|
|
|
{ssdp.ATTR_UPNP_MANUFACTURER_URL: "http://www.notphilips.com"}
|
2019-07-31 12:25:30 -07:00
|
|
|
)
|
2019-06-03 18:26:01 +02:00
|
|
|
|
2019-07-31 12:25:30 -07:00
|
|
|
assert result["type"] == "abort"
|
2019-06-03 18:26:01 +02:00
|
|
|
|
|
|
|
|
2019-05-26 19:48:27 -07:00
|
|
|
async def test_bridge_ssdp_emulated_hue(hass):
|
2018-03-29 20:15:40 -07:00
|
|
|
"""Test if discovery info is from an emulated hue instance."""
|
|
|
|
flow = config_flow.HueFlowHandler()
|
|
|
|
flow.hass = hass
|
2019-05-26 19:48:27 -07:00
|
|
|
flow.context = {}
|
2018-03-29 20:15:40 -07:00
|
|
|
|
2019-07-31 12:25:30 -07:00
|
|
|
result = await flow.async_step_ssdp(
|
|
|
|
{
|
2019-12-19 19:28:03 +02:00
|
|
|
ssdp.ATTR_SSDP_LOCATION: "http://0.0.0.0/",
|
|
|
|
ssdp.ATTR_UPNP_FRIENDLY_NAME: "HASS Bridge",
|
|
|
|
ssdp.ATTR_UPNP_MANUFACTURER_URL: config_flow.HUE_MANUFACTURERURL,
|
|
|
|
ssdp.ATTR_UPNP_SERIAL: "1234",
|
2019-07-31 12:25:30 -07:00
|
|
|
}
|
|
|
|
)
|
2018-03-29 20:15:40 -07:00
|
|
|
|
2019-07-31 12:25:30 -07:00
|
|
|
assert result["type"] == "abort"
|
2019-12-01 06:28:42 +01:00
|
|
|
assert result["reason"] == "not_hue_bridge"
|
|
|
|
|
|
|
|
|
|
|
|
async def test_bridge_ssdp_espalexa(hass):
|
|
|
|
"""Test if discovery info is from an Espalexa based device."""
|
|
|
|
flow = config_flow.HueFlowHandler()
|
|
|
|
flow.hass = hass
|
|
|
|
flow.context = {}
|
|
|
|
|
|
|
|
result = await flow.async_step_ssdp(
|
|
|
|
{
|
2019-12-19 19:28:03 +02:00
|
|
|
ssdp.ATTR_SSDP_LOCATION: "http://0.0.0.0/",
|
|
|
|
ssdp.ATTR_UPNP_FRIENDLY_NAME: "Espalexa (0.0.0.0)",
|
|
|
|
ssdp.ATTR_UPNP_MANUFACTURER_URL: config_flow.HUE_MANUFACTURERURL,
|
|
|
|
ssdp.ATTR_UPNP_SERIAL: "1234",
|
2019-12-01 06:28:42 +01:00
|
|
|
}
|
|
|
|
)
|
|
|
|
|
|
|
|
assert result["type"] == "abort"
|
|
|
|
assert result["reason"] == "not_hue_bridge"
|
2018-03-29 20:15:40 -07:00
|
|
|
|
|
|
|
|
2019-05-26 19:48:27 -07:00
|
|
|
async def test_bridge_ssdp_already_configured(hass):
|
2018-03-29 20:15:40 -07:00
|
|
|
"""Test if a discovered bridge has already been configured."""
|
2019-12-16 19:45:09 +01:00
|
|
|
MockConfigEntry(
|
|
|
|
domain="hue", unique_id="1234", data={"host": "0.0.0.0"}
|
|
|
|
).add_to_hass(hass)
|
2018-03-29 20:15:40 -07:00
|
|
|
|
|
|
|
flow = config_flow.HueFlowHandler()
|
|
|
|
flow.hass = hass
|
2019-08-16 16:19:00 -07:00
|
|
|
flow.context = {}
|
2018-03-29 20:15:40 -07:00
|
|
|
|
2019-12-16 19:45:09 +01:00
|
|
|
with pytest.raises(data_entry_flow.AbortFlow):
|
|
|
|
await flow.async_step_ssdp(
|
|
|
|
{
|
2019-12-19 19:28:03 +02:00
|
|
|
ssdp.ATTR_SSDP_LOCATION: "http://0.0.0.0/",
|
|
|
|
ssdp.ATTR_UPNP_MANUFACTURER_URL: config_flow.HUE_MANUFACTURERURL,
|
|
|
|
ssdp.ATTR_UPNP_SERIAL: "1234",
|
2019-12-16 19:45:09 +01:00
|
|
|
}
|
|
|
|
)
|
2018-03-29 20:15:40 -07:00
|
|
|
|
|
|
|
|
|
|
|
async def test_import_with_no_config(hass):
|
|
|
|
"""Test importing a host without an existing config file."""
|
|
|
|
flow = config_flow.HueFlowHandler()
|
|
|
|
flow.hass = hass
|
2019-08-16 16:19:00 -07:00
|
|
|
flow.context = {}
|
2018-03-29 20:15:40 -07:00
|
|
|
|
2019-12-16 19:45:09 +01:00
|
|
|
result = await flow.async_step_import({"host": "0.0.0.0"})
|
2018-03-29 20:15:40 -07:00
|
|
|
|
2019-07-31 12:25:30 -07:00
|
|
|
assert result["type"] == "form"
|
|
|
|
assert result["step_id"] == "link"
|
2018-03-29 20:15:40 -07:00
|
|
|
|
|
|
|
|
|
|
|
async def test_creating_entry_removes_entries_for_same_host_or_bridge(hass):
|
|
|
|
"""Test that we clean up entries for same host and bridge.
|
|
|
|
|
|
|
|
An IP can only hold a single bridge and a single bridge can only be
|
|
|
|
accessible via a single IP. So when we create a new entry, we'll remove
|
|
|
|
all existing entries that either have same IP or same bridge_id.
|
|
|
|
"""
|
2019-12-16 12:27:43 +01:00
|
|
|
orig_entry = MockConfigEntry(
|
2019-12-16 19:45:09 +01:00
|
|
|
domain="hue", data={"host": "0.0.0.0", "username": "aaaa"}, unique_id="id-1234",
|
2019-12-16 12:27:43 +01:00
|
|
|
)
|
|
|
|
orig_entry.add_to_hass(hass)
|
2018-03-29 20:15:40 -07:00
|
|
|
|
2019-07-31 12:25:30 -07:00
|
|
|
MockConfigEntry(
|
2019-12-16 19:45:09 +01:00
|
|
|
domain="hue", data={"host": "1.2.3.4", "username": "bbbb"}, unique_id="id-5678",
|
2019-07-31 12:25:30 -07:00
|
|
|
).add_to_hass(hass)
|
2018-03-29 20:15:40 -07:00
|
|
|
|
2019-07-31 12:25:30 -07:00
|
|
|
assert len(hass.config_entries.async_entries("hue")) == 2
|
2018-03-29 20:15:40 -07:00
|
|
|
|
|
|
|
bridge = Mock()
|
2019-07-31 12:25:30 -07:00
|
|
|
bridge.username = "username-abc"
|
|
|
|
bridge.config.name = "Mock Bridge"
|
|
|
|
bridge.host = "0.0.0.0"
|
2019-12-16 19:45:09 +01:00
|
|
|
bridge.id = "id-1234"
|
2019-07-31 12:25:30 -07:00
|
|
|
|
2019-12-16 19:45:09 +01:00
|
|
|
with patch(
|
|
|
|
"aiohue.Bridge", return_value=bridge,
|
|
|
|
):
|
2019-12-16 12:27:43 +01:00
|
|
|
result = await hass.config_entries.flow.async_init(
|
|
|
|
"hue", data={"host": "2.2.2.2"}, context={"source": "import"}
|
|
|
|
)
|
2019-07-31 12:25:30 -07:00
|
|
|
|
2019-12-16 19:45:09 +01:00
|
|
|
assert result["type"] == "form"
|
|
|
|
assert result["step_id"] == "link"
|
|
|
|
|
|
|
|
with patch(
|
|
|
|
"homeassistant.components.hue.config_flow.authenticate_bridge",
|
|
|
|
return_value=mock_coro(),
|
|
|
|
), patch(
|
|
|
|
"homeassistant.components.hue.async_setup_entry",
|
|
|
|
side_effect=lambda _, _2: mock_coro(True),
|
|
|
|
):
|
|
|
|
result = await hass.config_entries.flow.async_configure(result["flow_id"], {})
|
|
|
|
|
2019-07-31 12:25:30 -07:00
|
|
|
assert result["type"] == "create_entry"
|
|
|
|
assert result["title"] == "Mock Bridge"
|
|
|
|
assert result["data"] == {
|
|
|
|
"host": "0.0.0.0",
|
|
|
|
"username": "username-abc",
|
2018-03-16 20:27:05 -07:00
|
|
|
}
|
2019-12-16 12:27:43 +01:00
|
|
|
entries = hass.config_entries.async_entries("hue")
|
|
|
|
assert len(entries) == 2
|
|
|
|
new_entry = entries[-1]
|
|
|
|
assert orig_entry.entry_id != new_entry.entry_id
|
|
|
|
assert new_entry.unique_id == "id-1234"
|
2019-06-07 22:59:51 -07:00
|
|
|
|
|
|
|
|
|
|
|
async def test_bridge_homekit(hass):
|
|
|
|
"""Test a bridge being discovered via HomeKit."""
|
|
|
|
flow = config_flow.HueFlowHandler()
|
|
|
|
flow.hass = hass
|
|
|
|
flow.context = {}
|
|
|
|
|
2019-12-16 19:45:09 +01:00
|
|
|
result = await flow.async_step_homekit(
|
|
|
|
{
|
|
|
|
"host": "0.0.0.0",
|
|
|
|
"serial": "1234",
|
|
|
|
"manufacturerURL": config_flow.HUE_MANUFACTURERURL,
|
|
|
|
"properties": {"id": "aa:bb:cc:dd:ee:ff"},
|
|
|
|
}
|
|
|
|
)
|
2019-06-07 22:59:51 -07:00
|
|
|
|
2019-07-31 12:25:30 -07:00
|
|
|
assert result["type"] == "form"
|
|
|
|
assert result["step_id"] == "link"
|
2019-06-07 22:59:51 -07:00
|
|
|
|
|
|
|
|
|
|
|
async def test_bridge_homekit_already_configured(hass):
|
|
|
|
"""Test if a HomeKit discovered bridge has already been configured."""
|
2019-12-16 19:45:09 +01:00
|
|
|
MockConfigEntry(
|
|
|
|
domain="hue", unique_id="aabbccddeeff", data={"host": "0.0.0.0"}
|
|
|
|
).add_to_hass(hass)
|
2019-06-07 22:59:51 -07:00
|
|
|
|
|
|
|
flow = config_flow.HueFlowHandler()
|
|
|
|
flow.hass = hass
|
|
|
|
flow.context = {}
|
|
|
|
|
2019-12-16 19:45:09 +01:00
|
|
|
with pytest.raises(data_entry_flow.AbortFlow):
|
|
|
|
await flow.async_step_homekit(
|
|
|
|
{"host": "0.0.0.0", "properties": {"id": "aa:bb:cc:dd:ee:ff"}}
|
|
|
|
)
|