Move co2signal exceptions to their own file (#100473)
* Move co2signal exceptions to their own file * Add myself as codeownerpull/100478/head
parent
9747e0091f
commit
c504ca906d
|
@ -205,6 +205,8 @@ build.json @home-assistant/supervisor
|
||||||
/tests/components/cloud/ @home-assistant/cloud
|
/tests/components/cloud/ @home-assistant/cloud
|
||||||
/homeassistant/components/cloudflare/ @ludeeus @ctalkington
|
/homeassistant/components/cloudflare/ @ludeeus @ctalkington
|
||||||
/tests/components/cloudflare/ @ludeeus @ctalkington
|
/tests/components/cloudflare/ @ludeeus @ctalkington
|
||||||
|
/homeassistant/components/co2signal/ @jpbede
|
||||||
|
/tests/components/co2signal/ @jpbede
|
||||||
/homeassistant/components/coinbase/ @tombrien
|
/homeassistant/components/coinbase/ @tombrien
|
||||||
/tests/components/coinbase/ @tombrien
|
/tests/components/coinbase/ @tombrien
|
||||||
/homeassistant/components/color_extractor/ @GenericStudent
|
/homeassistant/components/color_extractor/ @GenericStudent
|
||||||
|
|
|
@ -11,10 +11,11 @@ import CO2Signal
|
||||||
from homeassistant.config_entries import ConfigEntry
|
from homeassistant.config_entries import ConfigEntry
|
||||||
from homeassistant.const import CONF_API_KEY, CONF_LATITUDE, CONF_LONGITUDE, Platform
|
from homeassistant.const import CONF_API_KEY, CONF_LATITUDE, CONF_LONGITUDE, Platform
|
||||||
from homeassistant.core import HomeAssistant
|
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 homeassistant.helpers.update_coordinator import DataUpdateCoordinator, UpdateFailed
|
||||||
|
|
||||||
from .const import CONF_COUNTRY_CODE, DOMAIN
|
from .const import CONF_COUNTRY_CODE, DOMAIN
|
||||||
|
from .exceptions import APIRatelimitExceeded, CO2Error, InvalidAuth, UnknownError
|
||||||
|
|
||||||
PLATFORMS = [Platform.SENSOR]
|
PLATFORMS = [Platform.SENSOR]
|
||||||
_LOGGER = logging.getLogger(__name__)
|
_LOGGER = logging.getLogger(__name__)
|
||||||
|
@ -86,22 +87,6 @@ class CO2SignalCoordinator(DataUpdateCoordinator[CO2SignalResponse]):
|
||||||
return data
|
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:
|
def get_data(hass: HomeAssistant, config: Mapping[str, Any]) -> CO2SignalResponse:
|
||||||
"""Get data from the API."""
|
"""Get data from the API."""
|
||||||
if CONF_COUNTRY_CODE in config:
|
if CONF_COUNTRY_CODE in config:
|
||||||
|
|
|
@ -10,8 +10,9 @@ from homeassistant.const import CONF_API_KEY, CONF_LATITUDE, CONF_LONGITUDE
|
||||||
from homeassistant.data_entry_flow import FlowResult
|
from homeassistant.data_entry_flow import FlowResult
|
||||||
import homeassistant.helpers.config_validation as cv
|
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 .const import CONF_COUNTRY_CODE, DOMAIN
|
||||||
|
from .exceptions import APIRatelimitExceeded, InvalidAuth
|
||||||
from .util import get_extra_name
|
from .util import get_extra_name
|
||||||
|
|
||||||
TYPE_USE_HOME = "Use home location"
|
TYPE_USE_HOME = "Use home location"
|
||||||
|
|
|
@ -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."""
|
|
@ -1,7 +1,7 @@
|
||||||
{
|
{
|
||||||
"domain": "co2signal",
|
"domain": "co2signal",
|
||||||
"name": "Electricity Maps",
|
"name": "Electricity Maps",
|
||||||
"codeowners": [],
|
"codeowners": ["@jpbede"],
|
||||||
"config_flow": true,
|
"config_flow": true,
|
||||||
"documentation": "https://www.home-assistant.io/integrations/co2signal",
|
"documentation": "https://www.home-assistant.io/integrations/co2signal",
|
||||||
"iot_class": "cloud_polling",
|
"iot_class": "cloud_polling",
|
||||||
|
|
Loading…
Reference in New Issue