Add options flow for AirVisual (#32634)
* Add options flow for AirVisual * Code review 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:
1 parent
a3c55b5e96
commit
21cff003f8
6 files changed
+132
-21
No files matched your search
@@ -5,7 +5,12 @@ from pyairvisual.errors import InvalidKeyError
|
||||
from homeassistant import data_entry_flow
|
||||
from homeassistant.components.airvisual import CONF_GEOGRAPHIES, DOMAIN
|
||||
from homeassistant.config_entries import SOURCE_IMPORT, SOURCE_USER
|
||||
from homeassistant.const import CONF_API_KEY, CONF_LATITUDE, CONF_LONGITUDE
|
||||
from homeassistant.const import (
|
||||
CONF_API_KEY,
|
||||
CONF_LATITUDE,
|
||||
CONF_LONGITUDE,
|
||||
CONF_SHOW_ON_MAP,
|
||||
)
|
||||
|
||||
from tests.common import MockConfigEntry
|
||||
|
||||
@@ -37,6 +42,34 @@ async def test_invalid_api_key(hass):
|
||||
assert result["errors"] == {CONF_API_KEY: "invalid_api_key"}
|
||||
|
||||
|
||||
async def test_options_flow(hass):
|
||||
"""Test config flow options."""
|
||||
conf = {CONF_API_KEY: "abcde12345"}
|
||||
|
||||
config_entry = MockConfigEntry(
|
||||
domain=DOMAIN,
|
||||
unique_id="abcde12345",
|
||||
data=conf,
|
||||
options={CONF_SHOW_ON_MAP: True},
|
||||
)
|
||||
config_entry.add_to_hass(hass)
|
||||
|
||||
with patch(
|
||||
"homeassistant.components.airvisual.async_setup_entry", return_value=True
|
||||
):
|
||||
result = await hass.config_entries.options.async_init(config_entry.entry_id)
|
||||
|
||||
assert result["type"] == data_entry_flow.RESULT_TYPE_FORM
|
||||
assert result["step_id"] == "init"
|
||||
|
||||
result = await hass.config_entries.options.async_configure(
|
||||
result["flow_id"], user_input={CONF_SHOW_ON_MAP: False}
|
||||
)
|
||||
|
||||
assert result["type"] == data_entry_flow.RESULT_TYPE_CREATE_ENTRY
|
||||
assert config_entry.options == {CONF_SHOW_ON_MAP: False}
|
||||
|
||||
|
||||
async def test_show_form(hass):
|
||||
"""Test that the form is served with no input."""
|
||||
result = await hass.config_entries.flow.async_init(
|
||||
@@ -49,10 +82,13 @@ async def test_show_form(hass):
|
||||
|
||||
async def test_step_import(hass):
|
||||
"""Test that the import step works."""
|
||||
conf = {CONF_API_KEY: "abcde12345"}
|
||||
conf = {
|
||||
CONF_API_KEY: "abcde12345",
|
||||
CONF_GEOGRAPHIES: [{CONF_LATITUDE: 51.528308, CONF_LONGITUDE: -0.3817765}],
|
||||
}
|
||||
|
||||
with patch(
|
||||
"homeassistant.components.wwlln.async_setup_entry", return_value=True
|
||||
"homeassistant.components.airvisual.async_setup_entry", return_value=True
|
||||
), patch("pyairvisual.api.API.nearest_city"):
|
||||
result = await hass.config_entries.flow.async_init(
|
||||
DOMAIN, context={"source": SOURCE_IMPORT}, data=conf
|
||||
@@ -62,7 +98,7 @@ async def test_step_import(hass):
|
||||
assert result["title"] == "Cloud API (API key: abcd...)"
|
||||
assert result["data"] == {
|
||||
CONF_API_KEY: "abcde12345",
|
||||
CONF_GEOGRAPHIES: [{CONF_LATITUDE: 32.87336, CONF_LONGITUDE: -117.22743}],
|
||||
CONF_GEOGRAPHIES: [{CONF_LATITUDE: 51.528308, CONF_LONGITUDE: -0.3817765}],
|
||||
}
|
||||
|
||||
|
||||
@@ -75,7 +111,7 @@ async def test_step_user(hass):
|
||||
}
|
||||
|
||||
with patch(
|
||||
"homeassistant.components.wwlln.async_setup_entry", return_value=True
|
||||
"homeassistant.components.airvisual.async_setup_entry", return_value=True
|
||||
), patch("pyairvisual.api.API.nearest_city"):
|
||||
result = await hass.config_entries.flow.async_init(
|
||||
DOMAIN, context={"source": SOURCE_USER}, data=conf
|
||||
|
||||
Reference in new issue
Block a user