Modernize Ambient PWS config flow (#32164)

* Modernize Ambient PWS config flow

* Linting
This commit is contained in:
Aaron Bach authored and GitHub committed 2020-02-24 21:37:38 -08:00
1 parent c97b1c60b0
commit ba4cc373c8
8 files changed
+41 -33

No files matched your search

@@ -7,6 +7,7 @@ import pytest
from homeassistant import data_entry_flow
from homeassistant.components.ambient_station import CONF_APP_KEY, DOMAIN, config_flow
from homeassistant.config_entries import SOURCE_USER
from homeassistant.const import CONF_API_KEY
from tests.common import MockConfigEntry, load_fixture, mock_coro
@@ -30,12 +31,16 @@ async def test_duplicate_error(hass):
"""Test that errors are shown when duplicates are added."""
conf = {CONF_API_KEY: "12345abcde12345abcde", CONF_APP_KEY: "67890fghij67890fghij"}
MockConfigEntry(domain=DOMAIN, data=conf).add_to_hass(hass)
flow = config_flow.AmbientStationFlowHandler()
flow.hass = hass
MockConfigEntry(
domain=DOMAIN, unique_id="67890fghij67890fghij", data=conf
).add_to_hass(hass)
result = await flow.async_step_user(user_input=conf)
assert result["errors"] == {CONF_APP_KEY: "identifier_exists"}
result = await hass.config_entries.flow.async_init(
DOMAIN, context={"source": SOURCE_USER}, data=conf
)
assert result["type"] == data_entry_flow.RESULT_TYPE_ABORT
assert result["reason"] == "already_configured"
@pytest.mark.parametrize(
@@ -47,6 +52,7 @@ async def test_invalid_api_key(hass, mock_aioambient):
flow = config_flow.AmbientStationFlowHandler()
flow.hass = hass
flow.context = {"source": SOURCE_USER}
result = await flow.async_step_user(user_input=conf)
assert result["errors"] == {"base": "invalid_key"}
@@ -59,6 +65,7 @@ async def test_no_devices(hass, mock_aioambient):
flow = config_flow.AmbientStationFlowHandler()
flow.hass = hass
flow.context = {"source": SOURCE_USER}
result = await flow.async_step_user(user_input=conf)
assert result["errors"] == {"base": "no_devices"}
@@ -68,6 +75,7 @@ async def test_show_form(hass):
"""Test that the form is served with no input."""
flow = config_flow.AmbientStationFlowHandler()
flow.hass = hass
flow.context = {"source": SOURCE_USER}
result = await flow.async_step_user(user_input=None)
@@ -85,6 +93,7 @@ async def test_step_import(hass, mock_aioambient):
flow = config_flow.AmbientStationFlowHandler()
flow.hass = hass
flow.context = {"source": SOURCE_USER}
result = await flow.async_step_import(import_config=conf)
assert result["type"] == data_entry_flow.RESULT_TYPE_CREATE_ENTRY
@@ -105,6 +114,7 @@ async def test_step_user(hass, mock_aioambient):
flow = config_flow.AmbientStationFlowHandler()
flow.hass = hass
flow.context = {"source": SOURCE_USER}
result = await flow.async_step_user(user_input=conf)
assert result["type"] == data_entry_flow.RESULT_TYPE_CREATE_ENTRY