* Add configuration flow for Buienradar integration * Update buienradar camera tests to work with config flow * Update buienradar weather tests to work with config flow * Update buienradar sensor tests to work with config flow * Remove buienradar config_flow tests to pass tests * Add config flow tests for buienradar integration * Increase test coverage for buienradar config_flow tests * Move data into domain * Remove forecast option * Move data to options * Remove options from config flow * Adjust tests * Adjust string * Fix pylint issues * Rework review comments * Handle import * Change config flow to setup camera or weather * Fix tests * Remove translated file * Fix pylint * Fix flake8 * Fix unload * Minor name changes * Update homeassistant/components/buienradar/config_flow.py Co-authored-by: Ties de Kock <ties@tiesdekock.nl> * Remove asynctest * Add translation * Disable sensors by default * Remove integration name from translations * Remove import method * Drop selection between platforms, disable camera by default * Minor fix in configured_instances * Bugfix in weather * Rework import * Change unique ids of camera * Fix in import * Fix camera tests * Fix sensor test * Fix sensor test 2 * Fix config flow tests * Add option flow * Add tests for option flow * Add import tests * Some cleanups * Apply suggestions from code review Apply code suggestions Co-authored-by: Franck Nijhof <git@frenck.dev> * Fix isort,black,mypy * Small tweaks and added typing to new parts * Fix review comments (1) * Apply suggestions from code review Co-authored-by: Martin Hjelmare <marhje52@gmail.com> * Fix review comments (2) * Fix issues * Fix unique id * Improve tests * Extend tests * Fix issue with unload * Address review comments * Add warning when loading platform * Add load/unload test Co-authored-by: Ties de Kock <ties@tiesdekock.nl> Co-authored-by: Franck Nijhof <git@frenck.dev> Co-authored-by: Martin Hjelmare <marhje52@gmail.com>
131 lines
4 KiB
Python
131 lines
4 KiB
Python
"""Test the buienradar2 config flow."""
|
|
from unittest.mock import patch
|
|
|
|
from homeassistant import config_entries, data_entry_flow
|
|
from homeassistant.components.buienradar.const import DOMAIN
|
|
from homeassistant.const import CONF_LATITUDE, CONF_LONGITUDE
|
|
|
|
from tests.common import MockConfigEntry
|
|
|
|
TEST_LATITUDE = 51.5288504
|
|
TEST_LONGITUDE = 5.4002156
|
|
|
|
|
|
async def test_config_flow_setup_(hass):
|
|
"""Test setup of camera."""
|
|
result = await hass.config_entries.flow.async_init(
|
|
DOMAIN, context={"source": config_entries.SOURCE_USER}
|
|
)
|
|
|
|
assert result["type"] == "form"
|
|
assert result["step_id"] == "user"
|
|
assert result["errors"] == {}
|
|
|
|
with patch(
|
|
"homeassistant.components.buienradar.async_setup_entry", return_value=True
|
|
):
|
|
result = await hass.config_entries.flow.async_configure(
|
|
result["flow_id"],
|
|
{CONF_LATITUDE: TEST_LATITUDE, CONF_LONGITUDE: TEST_LONGITUDE},
|
|
)
|
|
|
|
assert result["type"] == "create_entry"
|
|
assert result["title"] == f"{TEST_LATITUDE},{TEST_LONGITUDE}"
|
|
assert result["data"] == {
|
|
CONF_LATITUDE: TEST_LATITUDE,
|
|
CONF_LONGITUDE: TEST_LONGITUDE,
|
|
}
|
|
|
|
|
|
async def test_config_flow_already_configured_weather(hass):
|
|
"""Test already configured."""
|
|
entry = MockConfigEntry(
|
|
domain=DOMAIN,
|
|
data={
|
|
CONF_LATITUDE: TEST_LATITUDE,
|
|
CONF_LONGITUDE: TEST_LONGITUDE,
|
|
},
|
|
unique_id=f"{TEST_LATITUDE}-{TEST_LONGITUDE}",
|
|
)
|
|
entry.add_to_hass(hass)
|
|
|
|
result = await hass.config_entries.flow.async_init(
|
|
DOMAIN, context={"source": config_entries.SOURCE_USER}
|
|
)
|
|
|
|
assert result["type"] == "form"
|
|
assert result["step_id"] == "user"
|
|
assert result["errors"] == {}
|
|
|
|
result = await hass.config_entries.flow.async_configure(
|
|
result["flow_id"],
|
|
{CONF_LATITUDE: TEST_LATITUDE, CONF_LONGITUDE: TEST_LONGITUDE},
|
|
)
|
|
|
|
assert result["type"] == "abort"
|
|
assert result["reason"] == "already_configured"
|
|
|
|
|
|
async def test_import_camera(hass):
|
|
"""Test import of camera."""
|
|
with patch(
|
|
"homeassistant.components.buienradar.async_setup_entry", return_value=True
|
|
):
|
|
result = await hass.config_entries.flow.async_init(
|
|
DOMAIN,
|
|
context={"source": config_entries.SOURCE_IMPORT},
|
|
data={CONF_LATITUDE: TEST_LATITUDE, CONF_LONGITUDE: TEST_LONGITUDE},
|
|
)
|
|
|
|
assert result["type"] == "create_entry"
|
|
assert result["title"] == f"{TEST_LATITUDE},{TEST_LONGITUDE}"
|
|
assert result["data"] == {
|
|
CONF_LATITUDE: TEST_LATITUDE,
|
|
CONF_LONGITUDE: TEST_LONGITUDE,
|
|
}
|
|
|
|
result = await hass.config_entries.flow.async_init(
|
|
DOMAIN,
|
|
context={"source": config_entries.SOURCE_IMPORT},
|
|
data={CONF_LATITUDE: TEST_LATITUDE, CONF_LONGITUDE: TEST_LONGITUDE},
|
|
)
|
|
|
|
assert result["type"] == "abort"
|
|
assert result["reason"] == "already_configured"
|
|
|
|
|
|
async def test_options_flow(hass):
|
|
"""Test options flow."""
|
|
entry = MockConfigEntry(
|
|
domain=DOMAIN,
|
|
data={
|
|
CONF_LATITUDE: TEST_LATITUDE,
|
|
CONF_LONGITUDE: TEST_LONGITUDE,
|
|
},
|
|
unique_id=DOMAIN,
|
|
)
|
|
entry.add_to_hass(hass)
|
|
|
|
await hass.config_entries.async_setup(entry.entry_id)
|
|
await hass.async_block_till_done()
|
|
|
|
result = await hass.config_entries.options.async_init(entry.entry_id)
|
|
|
|
assert result["type"] == "form"
|
|
assert result["step_id"] == "init"
|
|
|
|
result = await hass.config_entries.options.async_configure(
|
|
result["flow_id"],
|
|
user_input={"country_code": "BE", "delta": 450, "timeframe": 30},
|
|
)
|
|
|
|
with patch(
|
|
"homeassistant.components.buienradar.async_setup_entry", return_value=True
|
|
), patch(
|
|
"homeassistant.components.buienradar.async_unload_entry", return_value=True
|
|
):
|
|
assert result["type"] == data_entry_flow.RESULT_TYPE_CREATE_ENTRY
|
|
|
|
await hass.async_block_till_done()
|
|
|
|
assert entry.options == {"country_code": "BE", "delta": 450, "timeframe": 30}
|