parent
774c892ee6
commit
a745134128
|
@ -3,13 +3,23 @@ import asyncio
|
||||||
|
|
||||||
import pydeconz
|
import pydeconz
|
||||||
|
|
||||||
|
from homeassistant import data_entry_flow
|
||||||
from homeassistant.components import ssdp
|
from homeassistant.components import ssdp
|
||||||
from homeassistant.components.deconz import config_flow
|
from homeassistant.components.deconz import config_flow
|
||||||
|
from homeassistant.components.deconz.config_flow import (
|
||||||
|
CONF_SERIAL,
|
||||||
|
DECONZ_MANUFACTURERURL,
|
||||||
|
)
|
||||||
|
from homeassistant.components.deconz.const import (
|
||||||
|
CONF_ALLOW_CLIP_SENSOR,
|
||||||
|
CONF_ALLOW_DECONZ_GROUPS,
|
||||||
|
CONF_MASTER_GATEWAY,
|
||||||
|
DOMAIN,
|
||||||
|
)
|
||||||
|
from homeassistant.const import CONF_API_KEY, CONF_HOST, CONF_PORT
|
||||||
|
|
||||||
from .test_gateway import API_KEY, BRIDGEID, setup_deconz_integration
|
from .test_gateway import API_KEY, BRIDGEID, setup_deconz_integration
|
||||||
|
|
||||||
from tests.common import MockConfigEntry
|
|
||||||
|
|
||||||
|
|
||||||
async def test_flow_1_discovered_bridge(hass, aioclient_mock):
|
async def test_flow_1_discovered_bridge(hass, aioclient_mock):
|
||||||
"""Test that config flow for one discovered bridge works."""
|
"""Test that config flow for one discovered bridge works."""
|
||||||
|
@ -20,10 +30,10 @@ async def test_flow_1_discovered_bridge(hass, aioclient_mock):
|
||||||
)
|
)
|
||||||
|
|
||||||
result = await hass.config_entries.flow.async_init(
|
result = await hass.config_entries.flow.async_init(
|
||||||
config_flow.DOMAIN, context={"source": "user"}
|
DOMAIN, context={"source": "user"}
|
||||||
)
|
)
|
||||||
|
|
||||||
assert result["type"] == "form"
|
assert result["type"] == data_entry_flow.RESULT_TYPE_FORM
|
||||||
assert result["step_id"] == "link"
|
assert result["step_id"] == "link"
|
||||||
|
|
||||||
aioclient_mock.post(
|
aioclient_mock.post(
|
||||||
|
@ -36,12 +46,12 @@ async def test_flow_1_discovered_bridge(hass, aioclient_mock):
|
||||||
result["flow_id"], user_input={}
|
result["flow_id"], user_input={}
|
||||||
)
|
)
|
||||||
|
|
||||||
assert result["type"] == "create_entry"
|
assert result["type"] == data_entry_flow.RESULT_TYPE_CREATE_ENTRY
|
||||||
assert result["title"] == BRIDGEID
|
assert result["title"] == BRIDGEID
|
||||||
assert result["data"] == {
|
assert result["data"] == {
|
||||||
config_flow.CONF_HOST: "1.2.3.4",
|
CONF_HOST: "1.2.3.4",
|
||||||
config_flow.CONF_PORT: 80,
|
CONF_PORT: 80,
|
||||||
config_flow.CONF_API_KEY: API_KEY,
|
CONF_API_KEY: API_KEY,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -57,17 +67,17 @@ async def test_flow_2_discovered_bridges(hass, aioclient_mock):
|
||||||
)
|
)
|
||||||
|
|
||||||
result = await hass.config_entries.flow.async_init(
|
result = await hass.config_entries.flow.async_init(
|
||||||
config_flow.DOMAIN, context={"source": "user"}
|
DOMAIN, context={"source": "user"}
|
||||||
)
|
)
|
||||||
|
|
||||||
assert result["type"] == "form"
|
assert result["type"] == data_entry_flow.RESULT_TYPE_FORM
|
||||||
assert result["step_id"] == "init"
|
assert result["step_id"] == "init"
|
||||||
|
|
||||||
result = await hass.config_entries.flow.async_configure(
|
result = await hass.config_entries.flow.async_configure(
|
||||||
result["flow_id"], user_input={config_flow.CONF_HOST: "1.2.3.4"}
|
result["flow_id"], user_input={CONF_HOST: "1.2.3.4"}
|
||||||
)
|
)
|
||||||
|
|
||||||
assert result["type"] == "form"
|
assert result["type"] == data_entry_flow.RESULT_TYPE_FORM
|
||||||
assert result["step_id"] == "link"
|
assert result["step_id"] == "link"
|
||||||
|
|
||||||
aioclient_mock.post(
|
aioclient_mock.post(
|
||||||
|
@ -80,12 +90,12 @@ async def test_flow_2_discovered_bridges(hass, aioclient_mock):
|
||||||
result["flow_id"], user_input={}
|
result["flow_id"], user_input={}
|
||||||
)
|
)
|
||||||
|
|
||||||
assert result["type"] == "create_entry"
|
assert result["type"] == data_entry_flow.RESULT_TYPE_CREATE_ENTRY
|
||||||
assert result["title"] == BRIDGEID
|
assert result["title"] == BRIDGEID
|
||||||
assert result["data"] == {
|
assert result["data"] == {
|
||||||
config_flow.CONF_HOST: "1.2.3.4",
|
CONF_HOST: "1.2.3.4",
|
||||||
config_flow.CONF_PORT: 80,
|
CONF_PORT: 80,
|
||||||
config_flow.CONF_API_KEY: API_KEY,
|
CONF_API_KEY: API_KEY,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -98,18 +108,17 @@ async def test_flow_manual_configuration(hass, aioclient_mock):
|
||||||
)
|
)
|
||||||
|
|
||||||
result = await hass.config_entries.flow.async_init(
|
result = await hass.config_entries.flow.async_init(
|
||||||
config_flow.DOMAIN, context={"source": "user"}
|
DOMAIN, context={"source": "user"}
|
||||||
)
|
)
|
||||||
|
|
||||||
assert result["type"] == "form"
|
assert result["type"] == data_entry_flow.RESULT_TYPE_FORM
|
||||||
assert result["step_id"] == "init"
|
assert result["step_id"] == "init"
|
||||||
|
|
||||||
result = await hass.config_entries.flow.async_configure(
|
result = await hass.config_entries.flow.async_configure(
|
||||||
result["flow_id"],
|
result["flow_id"], user_input={CONF_HOST: "1.2.3.4", CONF_PORT: 80},
|
||||||
user_input={config_flow.CONF_HOST: "1.2.3.4", config_flow.CONF_PORT: 80},
|
|
||||||
)
|
)
|
||||||
|
|
||||||
assert result["type"] == "form"
|
assert result["type"] == data_entry_flow.RESULT_TYPE_FORM
|
||||||
assert result["step_id"] == "link"
|
assert result["step_id"] == "link"
|
||||||
|
|
||||||
aioclient_mock.post(
|
aioclient_mock.post(
|
||||||
|
@ -128,12 +137,12 @@ async def test_flow_manual_configuration(hass, aioclient_mock):
|
||||||
result["flow_id"], user_input={}
|
result["flow_id"], user_input={}
|
||||||
)
|
)
|
||||||
|
|
||||||
assert result["type"] == "create_entry"
|
assert result["type"] == data_entry_flow.RESULT_TYPE_CREATE_ENTRY
|
||||||
assert result["title"] == BRIDGEID
|
assert result["title"] == BRIDGEID
|
||||||
assert result["data"] == {
|
assert result["data"] == {
|
||||||
config_flow.CONF_HOST: "1.2.3.4",
|
CONF_HOST: "1.2.3.4",
|
||||||
config_flow.CONF_PORT: 80,
|
CONF_PORT: 80,
|
||||||
config_flow.CONF_API_KEY: API_KEY,
|
CONF_API_KEY: API_KEY,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -142,10 +151,10 @@ async def test_manual_configuration_after_discovery_timeout(hass, aioclient_mock
|
||||||
aioclient_mock.get(pydeconz.utils.URL_DISCOVER, exc=asyncio.TimeoutError)
|
aioclient_mock.get(pydeconz.utils.URL_DISCOVER, exc=asyncio.TimeoutError)
|
||||||
|
|
||||||
result = await hass.config_entries.flow.async_init(
|
result = await hass.config_entries.flow.async_init(
|
||||||
config_flow.DOMAIN, context={"source": "user"}
|
DOMAIN, context={"source": "user"}
|
||||||
)
|
)
|
||||||
|
|
||||||
assert result["type"] == "form"
|
assert result["type"] == data_entry_flow.RESULT_TYPE_FORM
|
||||||
assert result["step_id"] == "init"
|
assert result["step_id"] == "init"
|
||||||
assert not hass.config_entries.flow._progress[result["flow_id"]].bridges
|
assert not hass.config_entries.flow._progress[result["flow_id"]].bridges
|
||||||
|
|
||||||
|
@ -155,10 +164,10 @@ async def test_manual_configuration_after_discovery_ResponseError(hass, aioclien
|
||||||
aioclient_mock.get(pydeconz.utils.URL_DISCOVER, exc=config_flow.ResponseError)
|
aioclient_mock.get(pydeconz.utils.URL_DISCOVER, exc=config_flow.ResponseError)
|
||||||
|
|
||||||
result = await hass.config_entries.flow.async_init(
|
result = await hass.config_entries.flow.async_init(
|
||||||
config_flow.DOMAIN, context={"source": "user"}
|
DOMAIN, context={"source": "user"}
|
||||||
)
|
)
|
||||||
|
|
||||||
assert result["type"] == "form"
|
assert result["type"] == data_entry_flow.RESULT_TYPE_FORM
|
||||||
assert result["step_id"] == "init"
|
assert result["step_id"] == "init"
|
||||||
assert not hass.config_entries.flow._progress[result["flow_id"]].bridges
|
assert not hass.config_entries.flow._progress[result["flow_id"]].bridges
|
||||||
|
|
||||||
|
@ -174,18 +183,17 @@ async def test_manual_configuration_update_configuration(hass, aioclient_mock):
|
||||||
)
|
)
|
||||||
|
|
||||||
result = await hass.config_entries.flow.async_init(
|
result = await hass.config_entries.flow.async_init(
|
||||||
config_flow.DOMAIN, context={"source": "user"}
|
DOMAIN, context={"source": "user"}
|
||||||
)
|
)
|
||||||
|
|
||||||
assert result["type"] == "form"
|
assert result["type"] == data_entry_flow.RESULT_TYPE_FORM
|
||||||
assert result["step_id"] == "init"
|
assert result["step_id"] == "init"
|
||||||
|
|
||||||
result = await hass.config_entries.flow.async_configure(
|
result = await hass.config_entries.flow.async_configure(
|
||||||
result["flow_id"],
|
result["flow_id"], user_input={CONF_HOST: "2.3.4.5", CONF_PORT: 80},
|
||||||
user_input={config_flow.CONF_HOST: "2.3.4.5", config_flow.CONF_PORT: 80},
|
|
||||||
)
|
)
|
||||||
|
|
||||||
assert result["type"] == "form"
|
assert result["type"] == data_entry_flow.RESULT_TYPE_FORM
|
||||||
assert result["step_id"] == "link"
|
assert result["step_id"] == "link"
|
||||||
|
|
||||||
aioclient_mock.post(
|
aioclient_mock.post(
|
||||||
|
@ -204,9 +212,9 @@ async def test_manual_configuration_update_configuration(hass, aioclient_mock):
|
||||||
result["flow_id"], user_input={}
|
result["flow_id"], user_input={}
|
||||||
)
|
)
|
||||||
|
|
||||||
assert result["type"] == "abort"
|
assert result["type"] == data_entry_flow.RESULT_TYPE_ABORT
|
||||||
assert result["reason"] == "already_configured"
|
assert result["reason"] == "already_configured"
|
||||||
assert gateway.config_entry.data[config_flow.CONF_HOST] == "2.3.4.5"
|
assert gateway.config_entry.data[CONF_HOST] == "2.3.4.5"
|
||||||
|
|
||||||
|
|
||||||
async def test_manual_configuration_dont_update_configuration(hass, aioclient_mock):
|
async def test_manual_configuration_dont_update_configuration(hass, aioclient_mock):
|
||||||
|
@ -220,18 +228,17 @@ async def test_manual_configuration_dont_update_configuration(hass, aioclient_mo
|
||||||
)
|
)
|
||||||
|
|
||||||
result = await hass.config_entries.flow.async_init(
|
result = await hass.config_entries.flow.async_init(
|
||||||
config_flow.DOMAIN, context={"source": "user"}
|
DOMAIN, context={"source": "user"}
|
||||||
)
|
)
|
||||||
|
|
||||||
assert result["type"] == "form"
|
assert result["type"] == data_entry_flow.RESULT_TYPE_FORM
|
||||||
assert result["step_id"] == "init"
|
assert result["step_id"] == "init"
|
||||||
|
|
||||||
result = await hass.config_entries.flow.async_configure(
|
result = await hass.config_entries.flow.async_configure(
|
||||||
result["flow_id"],
|
result["flow_id"], user_input={CONF_HOST: "1.2.3.4", CONF_PORT: 80},
|
||||||
user_input={config_flow.CONF_HOST: "1.2.3.4", config_flow.CONF_PORT: 80},
|
|
||||||
)
|
)
|
||||||
|
|
||||||
assert result["type"] == "form"
|
assert result["type"] == data_entry_flow.RESULT_TYPE_FORM
|
||||||
assert result["step_id"] == "link"
|
assert result["step_id"] == "link"
|
||||||
|
|
||||||
aioclient_mock.post(
|
aioclient_mock.post(
|
||||||
|
@ -250,7 +257,7 @@ async def test_manual_configuration_dont_update_configuration(hass, aioclient_mo
|
||||||
result["flow_id"], user_input={}
|
result["flow_id"], user_input={}
|
||||||
)
|
)
|
||||||
|
|
||||||
assert result["type"] == "abort"
|
assert result["type"] == data_entry_flow.RESULT_TYPE_ABORT
|
||||||
assert result["reason"] == "already_configured"
|
assert result["reason"] == "already_configured"
|
||||||
|
|
||||||
|
|
||||||
|
@ -263,18 +270,17 @@ async def test_manual_configuration_timeout_get_bridge(hass, aioclient_mock):
|
||||||
)
|
)
|
||||||
|
|
||||||
result = await hass.config_entries.flow.async_init(
|
result = await hass.config_entries.flow.async_init(
|
||||||
config_flow.DOMAIN, context={"source": "user"}
|
DOMAIN, context={"source": "user"}
|
||||||
)
|
)
|
||||||
|
|
||||||
assert result["type"] == "form"
|
assert result["type"] == data_entry_flow.RESULT_TYPE_FORM
|
||||||
assert result["step_id"] == "init"
|
assert result["step_id"] == "init"
|
||||||
|
|
||||||
result = await hass.config_entries.flow.async_configure(
|
result = await hass.config_entries.flow.async_configure(
|
||||||
result["flow_id"],
|
result["flow_id"], user_input={CONF_HOST: "1.2.3.4", CONF_PORT: 80},
|
||||||
user_input={config_flow.CONF_HOST: "1.2.3.4", config_flow.CONF_PORT: 80},
|
|
||||||
)
|
)
|
||||||
|
|
||||||
assert result["type"] == "form"
|
assert result["type"] == data_entry_flow.RESULT_TYPE_FORM
|
||||||
assert result["step_id"] == "link"
|
assert result["step_id"] == "link"
|
||||||
|
|
||||||
aioclient_mock.post(
|
aioclient_mock.post(
|
||||||
|
@ -291,7 +297,7 @@ async def test_manual_configuration_timeout_get_bridge(hass, aioclient_mock):
|
||||||
result["flow_id"], user_input={}
|
result["flow_id"], user_input={}
|
||||||
)
|
)
|
||||||
|
|
||||||
assert result["type"] == "abort"
|
assert result["type"] == data_entry_flow.RESULT_TYPE_ABORT
|
||||||
assert result["reason"] == "no_bridges"
|
assert result["reason"] == "no_bridges"
|
||||||
|
|
||||||
|
|
||||||
|
@ -304,10 +310,10 @@ async def test_link_get_api_key_ResponseError(hass, aioclient_mock):
|
||||||
)
|
)
|
||||||
|
|
||||||
result = await hass.config_entries.flow.async_init(
|
result = await hass.config_entries.flow.async_init(
|
||||||
config_flow.DOMAIN, context={"source": "user"}
|
DOMAIN, context={"source": "user"}
|
||||||
)
|
)
|
||||||
|
|
||||||
assert result["type"] == "form"
|
assert result["type"] == data_entry_flow.RESULT_TYPE_FORM
|
||||||
assert result["step_id"] == "link"
|
assert result["step_id"] == "link"
|
||||||
|
|
||||||
aioclient_mock.post("http://1.2.3.4:80/api", exc=pydeconz.errors.ResponseError)
|
aioclient_mock.post("http://1.2.3.4:80/api", exc=pydeconz.errors.ResponseError)
|
||||||
|
@ -316,7 +322,7 @@ async def test_link_get_api_key_ResponseError(hass, aioclient_mock):
|
||||||
result["flow_id"], user_input={}
|
result["flow_id"], user_input={}
|
||||||
)
|
)
|
||||||
|
|
||||||
assert result["type"] == "form"
|
assert result["type"] == data_entry_flow.RESULT_TYPE_FORM
|
||||||
assert result["step_id"] == "link"
|
assert result["step_id"] == "link"
|
||||||
assert result["errors"] == {"base": "no_key"}
|
assert result["errors"] == {"base": "no_key"}
|
||||||
|
|
||||||
|
@ -324,16 +330,16 @@ async def test_link_get_api_key_ResponseError(hass, aioclient_mock):
|
||||||
async def test_flow_ssdp_discovery(hass, aioclient_mock):
|
async def test_flow_ssdp_discovery(hass, aioclient_mock):
|
||||||
"""Test that config flow for one discovered bridge works."""
|
"""Test that config flow for one discovered bridge works."""
|
||||||
result = await hass.config_entries.flow.async_init(
|
result = await hass.config_entries.flow.async_init(
|
||||||
config_flow.DOMAIN,
|
DOMAIN,
|
||||||
data={
|
data={
|
||||||
ssdp.ATTR_SSDP_LOCATION: "http://1.2.3.4:80/",
|
ssdp.ATTR_SSDP_LOCATION: "http://1.2.3.4:80/",
|
||||||
ssdp.ATTR_UPNP_MANUFACTURER_URL: config_flow.DECONZ_MANUFACTURERURL,
|
ssdp.ATTR_UPNP_MANUFACTURER_URL: DECONZ_MANUFACTURERURL,
|
||||||
ssdp.ATTR_UPNP_SERIAL: BRIDGEID,
|
ssdp.ATTR_UPNP_SERIAL: BRIDGEID,
|
||||||
},
|
},
|
||||||
context={"source": "ssdp"},
|
context={"source": "ssdp"},
|
||||||
)
|
)
|
||||||
|
|
||||||
assert result["type"] == "form"
|
assert result["type"] == data_entry_flow.RESULT_TYPE_FORM
|
||||||
assert result["step_id"] == "link"
|
assert result["step_id"] == "link"
|
||||||
|
|
||||||
aioclient_mock.post(
|
aioclient_mock.post(
|
||||||
|
@ -346,24 +352,24 @@ async def test_flow_ssdp_discovery(hass, aioclient_mock):
|
||||||
result["flow_id"], user_input={}
|
result["flow_id"], user_input={}
|
||||||
)
|
)
|
||||||
|
|
||||||
assert result["type"] == "create_entry"
|
assert result["type"] == data_entry_flow.RESULT_TYPE_CREATE_ENTRY
|
||||||
assert result["title"] == BRIDGEID
|
assert result["title"] == BRIDGEID
|
||||||
assert result["data"] == {
|
assert result["data"] == {
|
||||||
config_flow.CONF_HOST: "1.2.3.4",
|
CONF_HOST: "1.2.3.4",
|
||||||
config_flow.CONF_PORT: 80,
|
CONF_PORT: 80,
|
||||||
config_flow.CONF_API_KEY: API_KEY,
|
CONF_API_KEY: API_KEY,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
async def test_ssdp_discovery_not_deconz_bridge(hass):
|
async def test_ssdp_discovery_not_deconz_bridge(hass):
|
||||||
"""Test a non deconz bridge being discovered over ssdp."""
|
"""Test a non deconz bridge being discovered over ssdp."""
|
||||||
result = await hass.config_entries.flow.async_init(
|
result = await hass.config_entries.flow.async_init(
|
||||||
config_flow.DOMAIN,
|
DOMAIN,
|
||||||
data={ssdp.ATTR_UPNP_MANUFACTURER_URL: "not deconz bridge"},
|
data={ssdp.ATTR_UPNP_MANUFACTURER_URL: "not deconz bridge"},
|
||||||
context={"source": "ssdp"},
|
context={"source": "ssdp"},
|
||||||
)
|
)
|
||||||
|
|
||||||
assert result["type"] == "abort"
|
assert result["type"] == data_entry_flow.RESULT_TYPE_ABORT
|
||||||
assert result["reason"] == "not_deconz_bridge"
|
assert result["reason"] == "not_deconz_bridge"
|
||||||
|
|
||||||
|
|
||||||
|
@ -372,18 +378,18 @@ async def test_ssdp_discovery_update_configuration(hass):
|
||||||
gateway = await setup_deconz_integration(hass)
|
gateway = await setup_deconz_integration(hass)
|
||||||
|
|
||||||
result = await hass.config_entries.flow.async_init(
|
result = await hass.config_entries.flow.async_init(
|
||||||
config_flow.DOMAIN,
|
DOMAIN,
|
||||||
data={
|
data={
|
||||||
ssdp.ATTR_SSDP_LOCATION: "http://2.3.4.5:80/",
|
ssdp.ATTR_SSDP_LOCATION: "http://2.3.4.5:80/",
|
||||||
ssdp.ATTR_UPNP_MANUFACTURER_URL: config_flow.DECONZ_MANUFACTURERURL,
|
ssdp.ATTR_UPNP_MANUFACTURER_URL: DECONZ_MANUFACTURERURL,
|
||||||
ssdp.ATTR_UPNP_SERIAL: BRIDGEID,
|
ssdp.ATTR_UPNP_SERIAL: BRIDGEID,
|
||||||
},
|
},
|
||||||
context={"source": "ssdp"},
|
context={"source": "ssdp"},
|
||||||
)
|
)
|
||||||
|
|
||||||
assert result["type"] == "abort"
|
assert result["type"] == data_entry_flow.RESULT_TYPE_ABORT
|
||||||
assert result["reason"] == "already_configured"
|
assert result["reason"] == "already_configured"
|
||||||
assert gateway.config_entry.data[config_flow.CONF_HOST] == "2.3.4.5"
|
assert gateway.config_entry.data[CONF_HOST] == "2.3.4.5"
|
||||||
|
|
||||||
|
|
||||||
async def test_ssdp_discovery_dont_update_configuration(hass):
|
async def test_ssdp_discovery_dont_update_configuration(hass):
|
||||||
|
@ -391,18 +397,18 @@ async def test_ssdp_discovery_dont_update_configuration(hass):
|
||||||
gateway = await setup_deconz_integration(hass)
|
gateway = await setup_deconz_integration(hass)
|
||||||
|
|
||||||
result = await hass.config_entries.flow.async_init(
|
result = await hass.config_entries.flow.async_init(
|
||||||
config_flow.DOMAIN,
|
DOMAIN,
|
||||||
data={
|
data={
|
||||||
ssdp.ATTR_SSDP_LOCATION: "http://1.2.3.4:80/",
|
ssdp.ATTR_SSDP_LOCATION: "http://1.2.3.4:80/",
|
||||||
ssdp.ATTR_UPNP_MANUFACTURER_URL: config_flow.DECONZ_MANUFACTURERURL,
|
ssdp.ATTR_UPNP_MANUFACTURER_URL: DECONZ_MANUFACTURERURL,
|
||||||
ssdp.ATTR_UPNP_SERIAL: BRIDGEID,
|
ssdp.ATTR_UPNP_SERIAL: BRIDGEID,
|
||||||
},
|
},
|
||||||
context={"source": "ssdp"},
|
context={"source": "ssdp"},
|
||||||
)
|
)
|
||||||
|
|
||||||
assert result["type"] == "abort"
|
assert result["type"] == data_entry_flow.RESULT_TYPE_ABORT
|
||||||
assert result["reason"] == "already_configured"
|
assert result["reason"] == "already_configured"
|
||||||
assert gateway.config_entry.data[config_flow.CONF_HOST] == "1.2.3.4"
|
assert gateway.config_entry.data[CONF_HOST] == "1.2.3.4"
|
||||||
|
|
||||||
|
|
||||||
async def test_ssdp_discovery_dont_update_existing_hassio_configuration(hass):
|
async def test_ssdp_discovery_dont_update_existing_hassio_configuration(hass):
|
||||||
|
@ -410,34 +416,34 @@ async def test_ssdp_discovery_dont_update_existing_hassio_configuration(hass):
|
||||||
gateway = await setup_deconz_integration(hass, source="hassio")
|
gateway = await setup_deconz_integration(hass, source="hassio")
|
||||||
|
|
||||||
result = await hass.config_entries.flow.async_init(
|
result = await hass.config_entries.flow.async_init(
|
||||||
config_flow.DOMAIN,
|
DOMAIN,
|
||||||
data={
|
data={
|
||||||
ssdp.ATTR_SSDP_LOCATION: "http://1.2.3.4:80/",
|
ssdp.ATTR_SSDP_LOCATION: "http://1.2.3.4:80/",
|
||||||
ssdp.ATTR_UPNP_MANUFACTURER_URL: config_flow.DECONZ_MANUFACTURERURL,
|
ssdp.ATTR_UPNP_MANUFACTURER_URL: DECONZ_MANUFACTURERURL,
|
||||||
ssdp.ATTR_UPNP_SERIAL: BRIDGEID,
|
ssdp.ATTR_UPNP_SERIAL: BRIDGEID,
|
||||||
},
|
},
|
||||||
context={"source": "ssdp"},
|
context={"source": "ssdp"},
|
||||||
)
|
)
|
||||||
|
|
||||||
assert result["type"] == "abort"
|
assert result["type"] == data_entry_flow.RESULT_TYPE_ABORT
|
||||||
assert result["reason"] == "already_configured"
|
assert result["reason"] == "already_configured"
|
||||||
assert gateway.config_entry.data[config_flow.CONF_HOST] == "1.2.3.4"
|
assert gateway.config_entry.data[CONF_HOST] == "1.2.3.4"
|
||||||
|
|
||||||
|
|
||||||
async def test_flow_hassio_discovery(hass):
|
async def test_flow_hassio_discovery(hass):
|
||||||
"""Test hassio discovery flow works."""
|
"""Test hassio discovery flow works."""
|
||||||
result = await hass.config_entries.flow.async_init(
|
result = await hass.config_entries.flow.async_init(
|
||||||
config_flow.DOMAIN,
|
DOMAIN,
|
||||||
data={
|
data={
|
||||||
"addon": "Mock Addon",
|
"addon": "Mock Addon",
|
||||||
config_flow.CONF_HOST: "mock-deconz",
|
CONF_HOST: "mock-deconz",
|
||||||
config_flow.CONF_PORT: 80,
|
CONF_PORT: 80,
|
||||||
config_flow.CONF_SERIAL: BRIDGEID,
|
CONF_SERIAL: BRIDGEID,
|
||||||
config_flow.CONF_API_KEY: API_KEY,
|
CONF_API_KEY: API_KEY,
|
||||||
},
|
},
|
||||||
context={"source": "hassio"},
|
context={"source": "hassio"},
|
||||||
)
|
)
|
||||||
assert result["type"] == "form"
|
assert result["type"] == data_entry_flow.RESULT_TYPE_FORM
|
||||||
assert result["step_id"] == "hassio_confirm"
|
assert result["step_id"] == "hassio_confirm"
|
||||||
assert result["description_placeholders"] == {"addon": "Mock Addon"}
|
assert result["description_placeholders"] == {"addon": "Mock Addon"}
|
||||||
|
|
||||||
|
@ -445,11 +451,11 @@ async def test_flow_hassio_discovery(hass):
|
||||||
result["flow_id"], user_input={}
|
result["flow_id"], user_input={}
|
||||||
)
|
)
|
||||||
|
|
||||||
assert result["type"] == "create_entry"
|
assert result["type"] == data_entry_flow.RESULT_TYPE_CREATE_ENTRY
|
||||||
assert result["result"].data == {
|
assert result["result"].data == {
|
||||||
config_flow.CONF_HOST: "mock-deconz",
|
CONF_HOST: "mock-deconz",
|
||||||
config_flow.CONF_PORT: 80,
|
CONF_PORT: 80,
|
||||||
config_flow.CONF_API_KEY: API_KEY,
|
CONF_API_KEY: API_KEY,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -458,21 +464,21 @@ async def test_hassio_discovery_update_configuration(hass):
|
||||||
gateway = await setup_deconz_integration(hass)
|
gateway = await setup_deconz_integration(hass)
|
||||||
|
|
||||||
result = await hass.config_entries.flow.async_init(
|
result = await hass.config_entries.flow.async_init(
|
||||||
config_flow.DOMAIN,
|
DOMAIN,
|
||||||
data={
|
data={
|
||||||
config_flow.CONF_HOST: "2.3.4.5",
|
CONF_HOST: "2.3.4.5",
|
||||||
config_flow.CONF_PORT: 8080,
|
CONF_PORT: 8080,
|
||||||
config_flow.CONF_API_KEY: "updated",
|
CONF_API_KEY: "updated",
|
||||||
config_flow.CONF_SERIAL: BRIDGEID,
|
CONF_SERIAL: BRIDGEID,
|
||||||
},
|
},
|
||||||
context={"source": "hassio"},
|
context={"source": "hassio"},
|
||||||
)
|
)
|
||||||
|
|
||||||
assert result["type"] == "abort"
|
assert result["type"] == data_entry_flow.RESULT_TYPE_ABORT
|
||||||
assert result["reason"] == "already_configured"
|
assert result["reason"] == "already_configured"
|
||||||
assert gateway.config_entry.data[config_flow.CONF_HOST] == "2.3.4.5"
|
assert gateway.config_entry.data[CONF_HOST] == "2.3.4.5"
|
||||||
assert gateway.config_entry.data[config_flow.CONF_PORT] == 8080
|
assert gateway.config_entry.data[CONF_PORT] == 8080
|
||||||
assert gateway.config_entry.data[config_flow.CONF_API_KEY] == "updated"
|
assert gateway.config_entry.data[CONF_API_KEY] == "updated"
|
||||||
|
|
||||||
|
|
||||||
async def test_hassio_discovery_dont_update_configuration(hass):
|
async def test_hassio_discovery_dont_update_configuration(hass):
|
||||||
|
@ -480,41 +486,37 @@ async def test_hassio_discovery_dont_update_configuration(hass):
|
||||||
await setup_deconz_integration(hass)
|
await setup_deconz_integration(hass)
|
||||||
|
|
||||||
result = await hass.config_entries.flow.async_init(
|
result = await hass.config_entries.flow.async_init(
|
||||||
config_flow.DOMAIN,
|
DOMAIN,
|
||||||
data={
|
data={
|
||||||
config_flow.CONF_HOST: "1.2.3.4",
|
CONF_HOST: "1.2.3.4",
|
||||||
config_flow.CONF_PORT: 80,
|
CONF_PORT: 80,
|
||||||
config_flow.CONF_API_KEY: API_KEY,
|
CONF_API_KEY: API_KEY,
|
||||||
config_flow.CONF_SERIAL: BRIDGEID,
|
CONF_SERIAL: BRIDGEID,
|
||||||
},
|
},
|
||||||
context={"source": "hassio"},
|
context={"source": "hassio"},
|
||||||
)
|
)
|
||||||
|
|
||||||
assert result["type"] == "abort"
|
assert result["type"] == data_entry_flow.RESULT_TYPE_ABORT
|
||||||
assert result["reason"] == "already_configured"
|
assert result["reason"] == "already_configured"
|
||||||
|
|
||||||
|
|
||||||
async def test_option_flow(hass):
|
async def test_option_flow(hass):
|
||||||
"""Test config flow options."""
|
"""Test config flow options."""
|
||||||
entry = MockConfigEntry(domain=config_flow.DOMAIN, data={}, options=None)
|
gateway = await setup_deconz_integration(hass)
|
||||||
hass.config_entries._entries.append(entry)
|
|
||||||
|
|
||||||
flow = await hass.config_entries.options.async_create_flow(
|
result = await hass.config_entries.options.async_init(gateway.config_entry.entry_id)
|
||||||
entry.entry_id, context={"source": "test"}, data=None
|
|
||||||
)
|
|
||||||
|
|
||||||
result = await flow.async_step_init()
|
assert result["type"] == data_entry_flow.RESULT_TYPE_FORM
|
||||||
assert result["type"] == "form"
|
|
||||||
assert result["step_id"] == "deconz_devices"
|
assert result["step_id"] == "deconz_devices"
|
||||||
|
|
||||||
result = await flow.async_step_deconz_devices(
|
result = await hass.config_entries.options.async_configure(
|
||||||
user_input={
|
result["flow_id"],
|
||||||
config_flow.CONF_ALLOW_CLIP_SENSOR: False,
|
user_input={CONF_ALLOW_CLIP_SENSOR: False, CONF_ALLOW_DECONZ_GROUPS: False},
|
||||||
config_flow.CONF_ALLOW_DECONZ_GROUPS: False,
|
|
||||||
}
|
|
||||||
)
|
)
|
||||||
assert result["type"] == "create_entry"
|
|
||||||
|
assert result["type"] == data_entry_flow.RESULT_TYPE_CREATE_ENTRY
|
||||||
assert result["data"] == {
|
assert result["data"] == {
|
||||||
config_flow.CONF_ALLOW_CLIP_SENSOR: False,
|
CONF_ALLOW_CLIP_SENSOR: False,
|
||||||
config_flow.CONF_ALLOW_DECONZ_GROUPS: False,
|
CONF_ALLOW_DECONZ_GROUPS: False,
|
||||||
|
CONF_MASTER_GATEWAY: True,
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue