Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle no data error in Electricity Maps config flow #110259

Merged
merged 2 commits into from
Feb 12, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 3 additions & 0 deletions homeassistant/components/co2signal/config_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
ElectricityMaps,
ElectricityMapsError,
ElectricityMapsInvalidTokenError,
ElectricityMapsNoDataError,
)
import voluptuous as vol

Expand Down Expand Up @@ -151,6 +152,8 @@ async def _validate_and_create(
await fetch_latest_carbon_intensity(self.hass, em, data)
except ElectricityMapsInvalidTokenError:
errors["base"] = "invalid_auth"
except ElectricityMapsNoDataError:
errors["base"] = "no_data"
except ElectricityMapsError:
errors["base"] = "unknown"
else:
Expand Down
5 changes: 1 addition & 4 deletions homeassistant/components/co2signal/strings.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,9 @@
"error": {
"invalid_auth": "[%key:common::config_flow::error::invalid_auth%]",
"unknown": "[%key:common::config_flow::error::unknown%]",
"api_ratelimit": "API Ratelimit exceeded"
"no_data": "No data is provided for the location you have selected."
jpbede marked this conversation as resolved.
Show resolved Hide resolved
},
"abort": {
"already_configured": "[%key:common::config_flow::abort::already_configured_device%]",
"unknown": "[%key:common::config_flow::error::unknown%]",
"api_ratelimit": "[%key:component::co2signal::config::error::api_ratelimit%]",
"reauth_successful": "[%key:common::config_flow::abort::reauth_successful%]"
}
},
Expand Down
8 changes: 3 additions & 5 deletions tests/components/co2signal/test_config_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
ElectricityMapsConnectionError,
ElectricityMapsError,
ElectricityMapsInvalidTokenError,
ElectricityMapsNoDataError,
)
import pytest

Expand Down Expand Up @@ -139,12 +140,9 @@ async def test_form_country(hass: HomeAssistant) -> None:
),
(ElectricityMapsError("Something else"), "unknown"),
(ElectricityMapsConnectionError("Boom"), "unknown"),
(ElectricityMapsNoDataError("I have no data"), "no_data"),
],
ids=[
"invalid auth",
"generic error",
"json decode error",
],
ids=["invalid auth", "generic error", "json decode error", "no data error"],
)
async def test_form_error_handling(
hass: HomeAssistant,
Expand Down