Improve AirNow Configuration Error Handling (#97267)
* Fix config flow error handling when no data is returned by AirNow API * Add test for PyAirNow EmptyResponseError * Typo Fixpull/97293/head
parent
fd3c2c2811
commit
7113db8da4
|
@ -2,7 +2,7 @@
|
|||
import logging
|
||||
|
||||
from pyairnow import WebServiceAPI
|
||||
from pyairnow.errors import AirNowError, InvalidKeyError
|
||||
from pyairnow.errors import AirNowError, EmptyResponseError, InvalidKeyError
|
||||
import voluptuous as vol
|
||||
|
||||
from homeassistant import config_entries, core, exceptions
|
||||
|
@ -35,6 +35,8 @@ async def validate_input(hass: core.HomeAssistant, data):
|
|||
raise InvalidAuth from exc
|
||||
except AirNowError as exc:
|
||||
raise CannotConnect from exc
|
||||
except EmptyResponseError as exc:
|
||||
raise InvalidLocation from exc
|
||||
|
||||
if not test_data:
|
||||
raise InvalidLocation
|
||||
|
|
|
@ -14,7 +14,7 @@
|
|||
"error": {
|
||||
"cannot_connect": "[%key:common::config_flow::error::cannot_connect%]",
|
||||
"invalid_auth": "[%key:common::config_flow::error::invalid_auth%]",
|
||||
"invalid_location": "No results found for that location",
|
||||
"invalid_location": "No results found for that location, try changing the location or station radius.",
|
||||
"unknown": "[%key:common::config_flow::error::unknown%]"
|
||||
},
|
||||
"abort": {
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
"""Test the AirNow config flow."""
|
||||
from unittest.mock import AsyncMock
|
||||
|
||||
from pyairnow.errors import AirNowError, InvalidKeyError
|
||||
from pyairnow.errors import AirNowError, EmptyResponseError, InvalidKeyError
|
||||
import pytest
|
||||
|
||||
from homeassistant import config_entries, data_entry_flow
|
||||
|
@ -55,6 +55,17 @@ async def test_form_cannot_connect(hass: HomeAssistant, config, setup_airnow) ->
|
|||
assert result2["errors"] == {"base": "cannot_connect"}
|
||||
|
||||
|
||||
@pytest.mark.parametrize("mock_api_get", [AsyncMock(side_effect=EmptyResponseError)])
|
||||
async def test_form_empty_result(hass: HomeAssistant, config, setup_airnow) -> None:
|
||||
"""Test we handle empty response error."""
|
||||
result = await hass.config_entries.flow.async_init(
|
||||
DOMAIN, context={"source": config_entries.SOURCE_USER}
|
||||
)
|
||||
result2 = await hass.config_entries.flow.async_configure(result["flow_id"], config)
|
||||
assert result2["type"] == "form"
|
||||
assert result2["errors"] == {"base": "invalid_location"}
|
||||
|
||||
|
||||
@pytest.mark.parametrize("mock_api_get", [AsyncMock(side_effect=RuntimeError)])
|
||||
async def test_form_unexpected(hass: HomeAssistant, config, setup_airnow) -> None:
|
||||
"""Test we handle an unexpected error."""
|
||||
|
|
Loading…
Reference in New Issue