Move co2signal exceptions to their own file (#100473)

* Move co2signal exceptions to their own file

* Add myself as codeowner
pull/100478/head
Jan-Philipp Benecke 2023-09-16 11:18:19 +02:00 committed by GitHub
parent 9747e0091f
commit c504ca906d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 25 additions and 19 deletions

View File

@ -205,6 +205,8 @@ build.json @home-assistant/supervisor
/tests/components/cloud/ @home-assistant/cloud
/homeassistant/components/cloudflare/ @ludeeus @ctalkington
/tests/components/cloudflare/ @ludeeus @ctalkington
/homeassistant/components/co2signal/ @jpbede
/tests/components/co2signal/ @jpbede
/homeassistant/components/coinbase/ @tombrien
/tests/components/coinbase/ @tombrien
/homeassistant/components/color_extractor/ @GenericStudent

View File

@ -11,10 +11,11 @@ import CO2Signal
from homeassistant.config_entries import ConfigEntry
from homeassistant.const import CONF_API_KEY, CONF_LATITUDE, CONF_LONGITUDE, Platform
from homeassistant.core import HomeAssistant
from homeassistant.exceptions import ConfigEntryAuthFailed, HomeAssistantError
from homeassistant.exceptions import ConfigEntryAuthFailed
from homeassistant.helpers.update_coordinator import DataUpdateCoordinator, UpdateFailed
from .const import CONF_COUNTRY_CODE, DOMAIN
from .exceptions import APIRatelimitExceeded, CO2Error, InvalidAuth, UnknownError
PLATFORMS = [Platform.SENSOR]
_LOGGER = logging.getLogger(__name__)
@ -86,22 +87,6 @@ class CO2SignalCoordinator(DataUpdateCoordinator[CO2SignalResponse]):
return data
class CO2Error(HomeAssistantError):
"""Base error."""
class InvalidAuth(CO2Error):
"""Raised when invalid authentication credentials are provided."""
class APIRatelimitExceeded(CO2Error):
"""Raised when the API rate limit is exceeded."""
class UnknownError(CO2Error):
"""Raised when an unknown error occurs."""
def get_data(hass: HomeAssistant, config: Mapping[str, Any]) -> CO2SignalResponse:
"""Get data from the API."""
if CONF_COUNTRY_CODE in config:

View File

@ -10,8 +10,9 @@ from homeassistant.const import CONF_API_KEY, CONF_LATITUDE, CONF_LONGITUDE
from homeassistant.data_entry_flow import FlowResult
import homeassistant.helpers.config_validation as cv
from . import APIRatelimitExceeded, InvalidAuth, get_data
from . import get_data
from .const import CONF_COUNTRY_CODE, DOMAIN
from .exceptions import APIRatelimitExceeded, InvalidAuth
from .util import get_extra_name
TYPE_USE_HOME = "Use home location"

View File

@ -0,0 +1,18 @@
"""Exceptions to the co2signal integration."""
from homeassistant.exceptions import HomeAssistantError
class CO2Error(HomeAssistantError):
"""Base error."""
class InvalidAuth(CO2Error):
"""Raised when invalid authentication credentials are provided."""
class APIRatelimitExceeded(CO2Error):
"""Raised when the API rate limit is exceeded."""
class UnknownError(CO2Error):
"""Raised when an unknown error occurs."""

View File

@ -1,7 +1,7 @@
{
"domain": "co2signal",
"name": "Electricity Maps",
"codeowners": [],
"codeowners": ["@jpbede"],
"config_flow": true,
"documentation": "https://www.home-assistant.io/integrations/co2signal",
"iot_class": "cloud_polling",