Environment Canada config_flow fix (#59029)
This commit is contained in:
parent
e57c60bb2f
commit
ca00551e4f
2 changed files with 24 additions and 7 deletions
|
@ -20,13 +20,12 @@ async def validate_input(data):
|
|||
lat = data.get(CONF_LATITUDE)
|
||||
lon = data.get(CONF_LONGITUDE)
|
||||
station = data.get(CONF_STATION)
|
||||
lang = data.get(CONF_LANGUAGE)
|
||||
lang = data.get(CONF_LANGUAGE).lower()
|
||||
|
||||
weather_data = ECWeather(
|
||||
station_id=station,
|
||||
coordinates=(lat, lon),
|
||||
language=lang.lower(),
|
||||
)
|
||||
if station:
|
||||
weather_data = ECWeather(station_id=station, language=lang)
|
||||
else:
|
||||
weather_data = ECWeather(coordinates=(lat, lon), language=lang)
|
||||
await weather_data.update()
|
||||
|
||||
if lat is None or lon is None:
|
||||
|
|
|
@ -123,7 +123,24 @@ async def test_exception_handling(hass, error):
|
|||
assert result["errors"] == {"base": base_error}
|
||||
|
||||
|
||||
async def test_lat_or_lon_not_specified(hass):
|
||||
async def test_import_station_not_specified(hass):
|
||||
"""Test that the import step works."""
|
||||
with mocked_ec(), patch(
|
||||
"homeassistant.components.environment_canada.async_setup_entry",
|
||||
return_value=True,
|
||||
):
|
||||
fake_config = dict(FAKE_CONFIG)
|
||||
del fake_config[CONF_STATION]
|
||||
result = await hass.config_entries.flow.async_init(
|
||||
DOMAIN, context={"source": SOURCE_IMPORT}, data=fake_config
|
||||
)
|
||||
await hass.async_block_till_done()
|
||||
assert result["type"] == data_entry_flow.RESULT_TYPE_CREATE_ENTRY
|
||||
assert result["data"] == FAKE_CONFIG
|
||||
assert result["title"] == FAKE_TITLE
|
||||
|
||||
|
||||
async def test_import_lat_lon_not_specified(hass):
|
||||
"""Test that the import step works."""
|
||||
with mocked_ec(), patch(
|
||||
"homeassistant.components.environment_canada.async_setup_entry",
|
||||
|
@ -131,6 +148,7 @@ async def test_lat_or_lon_not_specified(hass):
|
|||
):
|
||||
fake_config = dict(FAKE_CONFIG)
|
||||
del fake_config[CONF_LATITUDE]
|
||||
del fake_config[CONF_LONGITUDE]
|
||||
result = await hass.config_entries.flow.async_init(
|
||||
DOMAIN, context={"source": SOURCE_IMPORT}, data=fake_config
|
||||
)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue