Add back Netatmo public weather sensors (#34401)
* Add public weather sensors back in * Remove stale code * Cleanup after before adding entities * Fix pylint complaint * Add test for options flow * Change mode to listbox * Update .coveragerc * Address comments * Don't process empty list * Address comment * Fix mistake * Make signal unique * Make string more unique * Fix merge conflict
This commit is contained in:
parent
af6a4bb6cf
commit
155a5f7c26
9 changed files with 394 additions and 67 deletions
|
@ -2,6 +2,8 @@
|
|||
from homeassistant import config_entries, data_entry_flow, setup
|
||||
from homeassistant.components.netatmo import config_flow
|
||||
from homeassistant.components.netatmo.const import (
|
||||
CONF_NEW_AREA,
|
||||
CONF_WEATHER_AREAS,
|
||||
DOMAIN,
|
||||
OAUTH2_AUTHORIZE,
|
||||
OAUTH2_TOKEN,
|
||||
|
@ -15,6 +17,8 @@ from tests.common import MockConfigEntry
|
|||
CLIENT_ID = "1234"
|
||||
CLIENT_SECRET = "5678"
|
||||
|
||||
VALID_CONFIG = {}
|
||||
|
||||
|
||||
async def test_abort_if_existing_entry(hass):
|
||||
"""Check flow abort when an entry already exist."""
|
||||
|
@ -27,7 +31,7 @@ async def test_abort_if_existing_entry(hass):
|
|||
"netatmo", context={"source": config_entries.SOURCE_USER}
|
||||
)
|
||||
assert result["type"] == data_entry_flow.RESULT_TYPE_ABORT
|
||||
assert result["reason"] == "already_setup"
|
||||
assert result["reason"] == "missing_configuration"
|
||||
|
||||
result = await hass.config_entries.flow.async_init(
|
||||
"netatmo",
|
||||
|
@ -35,7 +39,7 @@ async def test_abort_if_existing_entry(hass):
|
|||
data={"host": "0.0.0.0", "properties": {"id": "aa:bb:cc:dd:ee:ff"}},
|
||||
)
|
||||
assert result["type"] == data_entry_flow.RESULT_TYPE_ABORT
|
||||
assert result["reason"] == "already_setup"
|
||||
assert result["reason"] == "missing_configuration"
|
||||
|
||||
|
||||
async def test_full_flow(hass, aiohttp_client, aioclient_mock):
|
||||
|
@ -98,3 +102,47 @@ async def test_full_flow(hass, aiohttp_client, aioclient_mock):
|
|||
|
||||
assert len(hass.config_entries.async_entries(DOMAIN)) == 1
|
||||
assert len(mock_setup.mock_calls) == 1
|
||||
|
||||
|
||||
async def test_option_flow(hass):
|
||||
"""Test config flow options."""
|
||||
valid_option = {
|
||||
"lat_ne": 32.91336,
|
||||
"lon_sw": -117.26743,
|
||||
"show_on_map": False,
|
||||
"area_name": "Home",
|
||||
"lon_ne": -117.187429,
|
||||
"lat_sw": 32.83336,
|
||||
"mode": "avg",
|
||||
}
|
||||
|
||||
config_entry = MockConfigEntry(
|
||||
domain=DOMAIN, unique_id=DOMAIN, data=VALID_CONFIG, options={},
|
||||
)
|
||||
config_entry.add_to_hass(hass)
|
||||
|
||||
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"] == "public_weather_areas"
|
||||
|
||||
result = await hass.config_entries.options.async_configure(
|
||||
result["flow_id"], user_input={CONF_NEW_AREA: "Home"}
|
||||
)
|
||||
|
||||
assert result["type"] == data_entry_flow.RESULT_TYPE_FORM
|
||||
assert result["step_id"] == "public_weather"
|
||||
|
||||
result = await hass.config_entries.options.async_configure(
|
||||
result["flow_id"], user_input=valid_option
|
||||
)
|
||||
|
||||
assert result["type"] == data_entry_flow.RESULT_TYPE_FORM
|
||||
assert result["step_id"] == "public_weather_areas"
|
||||
|
||||
result = await hass.config_entries.options.async_configure(
|
||||
result["flow_id"], user_input={}
|
||||
)
|
||||
|
||||
assert result["type"] == data_entry_flow.RESULT_TYPE_CREATE_ENTRY
|
||||
assert config_entry.options == {CONF_WEATHER_AREAS: {"Home": valid_option}}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue