From c504ca906dd5f0cc35a532b5679b9bb5c5304a18 Mon Sep 17 00:00:00 2001 From: Jan-Philipp Benecke Date: Sat, 16 Sep 2023 11:18:19 +0200 Subject: [PATCH] Move co2signal exceptions to their own file (#100473) * Move co2signal exceptions to their own file * Add myself as codeowner --- CODEOWNERS | 2 ++ .../components/co2signal/__init__.py | 19 ++----------------- .../components/co2signal/config_flow.py | 3 ++- .../components/co2signal/exceptions.py | 18 ++++++++++++++++++ .../components/co2signal/manifest.json | 2 +- 5 files changed, 25 insertions(+), 19 deletions(-) create mode 100644 homeassistant/components/co2signal/exceptions.py diff --git a/CODEOWNERS b/CODEOWNERS index 7463731e57a..7c96042caa3 100644 --- a/CODEOWNERS +++ b/CODEOWNERS @@ -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 diff --git a/homeassistant/components/co2signal/__init__.py b/homeassistant/components/co2signal/__init__.py index 721a26e147f..943fa13e240 100644 --- a/homeassistant/components/co2signal/__init__.py +++ b/homeassistant/components/co2signal/__init__.py @@ -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: diff --git a/homeassistant/components/co2signal/config_flow.py b/homeassistant/components/co2signal/config_flow.py index 036282cb3e8..2ac3ebc398f 100644 --- a/homeassistant/components/co2signal/config_flow.py +++ b/homeassistant/components/co2signal/config_flow.py @@ -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" diff --git a/homeassistant/components/co2signal/exceptions.py b/homeassistant/components/co2signal/exceptions.py new file mode 100644 index 00000000000..cc8ee709bde --- /dev/null +++ b/homeassistant/components/co2signal/exceptions.py @@ -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.""" diff --git a/homeassistant/components/co2signal/manifest.json b/homeassistant/components/co2signal/manifest.json index a0a3ee71a9c..4ab4607cccc 100644 --- a/homeassistant/components/co2signal/manifest.json +++ b/homeassistant/components/co2signal/manifest.json @@ -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",