mirror of
https://github.com/jpawlowski/hass.tibber_prices.git
synced 2026-03-29 21:03:40 +00:00
rename functions
This commit is contained in:
parent
8123285489
commit
ef38bf75b5
9 changed files with 52 additions and 52 deletions
|
|
@ -14,15 +14,15 @@ from homeassistant.const import CONF_PASSWORD, CONF_USERNAME, Platform
|
|||
from homeassistant.helpers.aiohttp_client import async_get_clientsession
|
||||
from homeassistant.loader import async_get_loaded_integration
|
||||
|
||||
from .api import IntegrationBlueprintApiClient
|
||||
from .api import TibberPricesApiClient
|
||||
from .const import DOMAIN, LOGGER
|
||||
from .coordinator import BlueprintDataUpdateCoordinator
|
||||
from .data import IntegrationBlueprintData
|
||||
from .data import TibberPricesData
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from homeassistant.core import HomeAssistant
|
||||
|
||||
from .data import IntegrationBlueprintConfigEntry
|
||||
from .data import TibberPricesConfigEntry
|
||||
|
||||
PLATFORMS: list[Platform] = [
|
||||
Platform.SENSOR,
|
||||
|
|
@ -34,7 +34,7 @@ PLATFORMS: list[Platform] = [
|
|||
# https://developers.home-assistant.io/docs/config_entries_index/#setting-up-an-entry
|
||||
async def async_setup_entry(
|
||||
hass: HomeAssistant,
|
||||
entry: IntegrationBlueprintConfigEntry,
|
||||
entry: TibberPricesConfigEntry,
|
||||
) -> bool:
|
||||
"""Set up this integration using UI."""
|
||||
coordinator = BlueprintDataUpdateCoordinator(
|
||||
|
|
@ -43,8 +43,8 @@ async def async_setup_entry(
|
|||
name=DOMAIN,
|
||||
update_interval=timedelta(hours=1),
|
||||
)
|
||||
entry.runtime_data = IntegrationBlueprintData(
|
||||
client=IntegrationBlueprintApiClient(
|
||||
entry.runtime_data = TibberPricesData(
|
||||
client=TibberPricesApiClient(
|
||||
username=entry.data[CONF_USERNAME],
|
||||
password=entry.data[CONF_PASSWORD],
|
||||
session=async_get_clientsession(hass),
|
||||
|
|
@ -64,7 +64,7 @@ async def async_setup_entry(
|
|||
|
||||
async def async_unload_entry(
|
||||
hass: HomeAssistant,
|
||||
entry: IntegrationBlueprintConfigEntry,
|
||||
entry: TibberPricesConfigEntry,
|
||||
) -> bool:
|
||||
"""Handle removal of an entry."""
|
||||
return await hass.config_entries.async_unload_platforms(entry, PLATFORMS)
|
||||
|
|
@ -72,7 +72,7 @@ async def async_unload_entry(
|
|||
|
||||
async def async_reload_entry(
|
||||
hass: HomeAssistant,
|
||||
entry: IntegrationBlueprintConfigEntry,
|
||||
entry: TibberPricesConfigEntry,
|
||||
) -> None:
|
||||
"""Reload config entry."""
|
||||
await async_unload_entry(hass, entry)
|
||||
|
|
|
|||
|
|
@ -9,18 +9,18 @@ import aiohttp
|
|||
import async_timeout
|
||||
|
||||
|
||||
class IntegrationBlueprintApiClientError(Exception):
|
||||
class TibberPricesApiClientError(Exception):
|
||||
"""Exception to indicate a general API error."""
|
||||
|
||||
|
||||
class IntegrationBlueprintApiClientCommunicationError(
|
||||
IntegrationBlueprintApiClientError,
|
||||
class TibberPricesApiClientCommunicationError(
|
||||
TibberPricesApiClientError,
|
||||
):
|
||||
"""Exception to indicate a communication error."""
|
||||
|
||||
|
||||
class IntegrationBlueprintApiClientAuthenticationError(
|
||||
IntegrationBlueprintApiClientError,
|
||||
class TibberPricesApiClientAuthenticationError(
|
||||
TibberPricesApiClientError,
|
||||
):
|
||||
"""Exception to indicate an authentication error."""
|
||||
|
||||
|
|
@ -29,13 +29,13 @@ def _verify_response_or_raise(response: aiohttp.ClientResponse) -> None:
|
|||
"""Verify that the response is valid."""
|
||||
if response.status in (401, 403):
|
||||
msg = "Invalid credentials"
|
||||
raise IntegrationBlueprintApiClientAuthenticationError(
|
||||
raise TibberPricesApiClientAuthenticationError(
|
||||
msg,
|
||||
)
|
||||
response.raise_for_status()
|
||||
|
||||
|
||||
class IntegrationBlueprintApiClient:
|
||||
class TibberPricesApiClient:
|
||||
"""Sample API Client."""
|
||||
|
||||
def __init__(
|
||||
|
|
@ -86,16 +86,16 @@ class IntegrationBlueprintApiClient:
|
|||
|
||||
except TimeoutError as exception:
|
||||
msg = f"Timeout error fetching information - {exception}"
|
||||
raise IntegrationBlueprintApiClientCommunicationError(
|
||||
raise TibberPricesApiClientCommunicationError(
|
||||
msg,
|
||||
) from exception
|
||||
except (aiohttp.ClientError, socket.gaierror) as exception:
|
||||
msg = f"Error fetching information - {exception}"
|
||||
raise IntegrationBlueprintApiClientCommunicationError(
|
||||
raise TibberPricesApiClientCommunicationError(
|
||||
msg,
|
||||
) from exception
|
||||
except Exception as exception: # pylint: disable=broad-except
|
||||
msg = f"Something really wrong happened! - {exception}"
|
||||
raise IntegrationBlueprintApiClientError(
|
||||
raise TibberPricesApiClientError(
|
||||
msg,
|
||||
) from exception
|
||||
|
|
|
|||
|
|
@ -10,14 +10,14 @@ from homeassistant.components.binary_sensor import (
|
|||
BinarySensorEntityDescription,
|
||||
)
|
||||
|
||||
from .entity import IntegrationBlueprintEntity
|
||||
from .entity import TibberPricesEntity
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||
|
||||
from .coordinator import BlueprintDataUpdateCoordinator
|
||||
from .data import IntegrationBlueprintConfigEntry
|
||||
from .data import TibberPricesConfigEntry
|
||||
|
||||
ENTITY_DESCRIPTIONS = (
|
||||
BinarySensorEntityDescription(
|
||||
|
|
@ -30,12 +30,12 @@ ENTITY_DESCRIPTIONS = (
|
|||
|
||||
async def async_setup_entry(
|
||||
hass: HomeAssistant, # noqa: ARG001 Unused function argument: `hass`
|
||||
entry: IntegrationBlueprintConfigEntry,
|
||||
entry: TibberPricesConfigEntry,
|
||||
async_add_entities: AddEntitiesCallback,
|
||||
) -> None:
|
||||
"""Set up the binary_sensor platform."""
|
||||
async_add_entities(
|
||||
IntegrationBlueprintBinarySensor(
|
||||
TibberPricesBinarySensor(
|
||||
coordinator=entry.runtime_data.coordinator,
|
||||
entity_description=entity_description,
|
||||
)
|
||||
|
|
@ -43,7 +43,7 @@ async def async_setup_entry(
|
|||
)
|
||||
|
||||
|
||||
class IntegrationBlueprintBinarySensor(IntegrationBlueprintEntity, BinarySensorEntity):
|
||||
class TibberPricesBinarySensor(TibberPricesEntity, BinarySensorEntity):
|
||||
"""tibber_prices binary_sensor class."""
|
||||
|
||||
def __init__(
|
||||
|
|
|
|||
|
|
@ -10,10 +10,10 @@ from homeassistant.helpers.aiohttp_client import async_create_clientsession
|
|||
from slugify import slugify
|
||||
|
||||
from .api import (
|
||||
IntegrationBlueprintApiClient,
|
||||
IntegrationBlueprintApiClientAuthenticationError,
|
||||
IntegrationBlueprintApiClientCommunicationError,
|
||||
IntegrationBlueprintApiClientError,
|
||||
TibberPricesApiClient,
|
||||
TibberPricesApiClientAuthenticationError,
|
||||
TibberPricesApiClientCommunicationError,
|
||||
TibberPricesApiClientError,
|
||||
)
|
||||
from .const import DOMAIN, LOGGER
|
||||
|
||||
|
|
@ -35,13 +35,13 @@ class BlueprintFlowHandler(config_entries.ConfigFlow, domain=DOMAIN):
|
|||
username=user_input[CONF_USERNAME],
|
||||
password=user_input[CONF_PASSWORD],
|
||||
)
|
||||
except IntegrationBlueprintApiClientAuthenticationError as exception:
|
||||
except TibberPricesApiClientAuthenticationError as exception:
|
||||
LOGGER.warning(exception)
|
||||
_errors["base"] = "auth"
|
||||
except IntegrationBlueprintApiClientCommunicationError as exception:
|
||||
except TibberPricesApiClientCommunicationError as exception:
|
||||
LOGGER.error(exception)
|
||||
_errors["base"] = "connection"
|
||||
except IntegrationBlueprintApiClientError as exception:
|
||||
except TibberPricesApiClientError as exception:
|
||||
LOGGER.exception(exception)
|
||||
_errors["base"] = "unknown"
|
||||
else:
|
||||
|
|
@ -81,7 +81,7 @@ class BlueprintFlowHandler(config_entries.ConfigFlow, domain=DOMAIN):
|
|||
|
||||
async def _test_credentials(self, username: str, password: str) -> None:
|
||||
"""Validate credentials."""
|
||||
client = IntegrationBlueprintApiClient(
|
||||
client = TibberPricesApiClient(
|
||||
username=username,
|
||||
password=password,
|
||||
session=async_create_clientsession(self.hass),
|
||||
|
|
|
|||
|
|
@ -8,25 +8,25 @@ from homeassistant.exceptions import ConfigEntryAuthFailed
|
|||
from homeassistant.helpers.update_coordinator import DataUpdateCoordinator, UpdateFailed
|
||||
|
||||
from .api import (
|
||||
IntegrationBlueprintApiClientAuthenticationError,
|
||||
IntegrationBlueprintApiClientError,
|
||||
TibberPricesApiClientAuthenticationError,
|
||||
TibberPricesApiClientError,
|
||||
)
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from .data import IntegrationBlueprintConfigEntry
|
||||
from .data import TibberPricesConfigEntry
|
||||
|
||||
|
||||
# https://developers.home-assistant.io/docs/integration_fetching_data#coordinated-single-api-poll-for-data-for-all-entities
|
||||
class BlueprintDataUpdateCoordinator(DataUpdateCoordinator):
|
||||
"""Class to manage fetching data from the API."""
|
||||
|
||||
config_entry: IntegrationBlueprintConfigEntry
|
||||
config_entry: TibberPricesConfigEntry
|
||||
|
||||
async def _async_update_data(self) -> Any:
|
||||
"""Update data via library."""
|
||||
try:
|
||||
return await self.config_entry.runtime_data.client.async_get_data()
|
||||
except IntegrationBlueprintApiClientAuthenticationError as exception:
|
||||
except TibberPricesApiClientAuthenticationError as exception:
|
||||
raise ConfigEntryAuthFailed(exception) from exception
|
||||
except IntegrationBlueprintApiClientError as exception:
|
||||
except TibberPricesApiClientError as exception:
|
||||
raise UpdateFailed(exception) from exception
|
||||
|
|
|
|||
|
|
@ -9,17 +9,17 @@ if TYPE_CHECKING:
|
|||
from homeassistant.config_entries import ConfigEntry
|
||||
from homeassistant.loader import Integration
|
||||
|
||||
from .api import IntegrationBlueprintApiClient
|
||||
from .api import TibberPricesApiClient
|
||||
from .coordinator import BlueprintDataUpdateCoordinator
|
||||
|
||||
|
||||
type IntegrationBlueprintConfigEntry = ConfigEntry[IntegrationBlueprintData]
|
||||
type TibberPricesConfigEntry = ConfigEntry[TibberPricesData]
|
||||
|
||||
|
||||
@dataclass
|
||||
class IntegrationBlueprintData:
|
||||
class TibberPricesData:
|
||||
"""Data for the Blueprint integration."""
|
||||
|
||||
client: IntegrationBlueprintApiClient
|
||||
client: TibberPricesApiClient
|
||||
coordinator: BlueprintDataUpdateCoordinator
|
||||
integration: Integration
|
||||
|
|
|
|||
|
|
@ -9,7 +9,7 @@ from .const import ATTRIBUTION
|
|||
from .coordinator import BlueprintDataUpdateCoordinator
|
||||
|
||||
|
||||
class IntegrationBlueprintEntity(CoordinatorEntity[BlueprintDataUpdateCoordinator]):
|
||||
class TibberPricesEntity(CoordinatorEntity[BlueprintDataUpdateCoordinator]):
|
||||
"""BlueprintEntity class."""
|
||||
|
||||
_attr_attribution = ATTRIBUTION
|
||||
|
|
|
|||
|
|
@ -6,14 +6,14 @@ from typing import TYPE_CHECKING
|
|||
|
||||
from homeassistant.components.sensor import SensorEntity, SensorEntityDescription
|
||||
|
||||
from .entity import IntegrationBlueprintEntity
|
||||
from .entity import TibberPricesEntity
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||
|
||||
from .coordinator import BlueprintDataUpdateCoordinator
|
||||
from .data import IntegrationBlueprintConfigEntry
|
||||
from .data import TibberPricesConfigEntry
|
||||
|
||||
ENTITY_DESCRIPTIONS = (
|
||||
SensorEntityDescription(
|
||||
|
|
@ -26,12 +26,12 @@ ENTITY_DESCRIPTIONS = (
|
|||
|
||||
async def async_setup_entry(
|
||||
hass: HomeAssistant, # noqa: ARG001 Unused function argument: `hass`
|
||||
entry: IntegrationBlueprintConfigEntry,
|
||||
entry: TibberPricesConfigEntry,
|
||||
async_add_entities: AddEntitiesCallback,
|
||||
) -> None:
|
||||
"""Set up the sensor platform."""
|
||||
async_add_entities(
|
||||
IntegrationBlueprintSensor(
|
||||
TibberPricesSensor(
|
||||
coordinator=entry.runtime_data.coordinator,
|
||||
entity_description=entity_description,
|
||||
)
|
||||
|
|
@ -39,7 +39,7 @@ async def async_setup_entry(
|
|||
)
|
||||
|
||||
|
||||
class IntegrationBlueprintSensor(IntegrationBlueprintEntity, SensorEntity):
|
||||
class TibberPricesSensor(TibberPricesEntity, SensorEntity):
|
||||
"""tibber_prices Sensor class."""
|
||||
|
||||
def __init__(
|
||||
|
|
|
|||
|
|
@ -6,14 +6,14 @@ from typing import TYPE_CHECKING, Any
|
|||
|
||||
from homeassistant.components.switch import SwitchEntity, SwitchEntityDescription
|
||||
|
||||
from .entity import IntegrationBlueprintEntity
|
||||
from .entity import TibberPricesEntity
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||
|
||||
from .coordinator import BlueprintDataUpdateCoordinator
|
||||
from .data import IntegrationBlueprintConfigEntry
|
||||
from .data import TibberPricesConfigEntry
|
||||
|
||||
ENTITY_DESCRIPTIONS = (
|
||||
SwitchEntityDescription(
|
||||
|
|
@ -26,12 +26,12 @@ ENTITY_DESCRIPTIONS = (
|
|||
|
||||
async def async_setup_entry(
|
||||
hass: HomeAssistant, # noqa: ARG001 Unused function argument: `hass`
|
||||
entry: IntegrationBlueprintConfigEntry,
|
||||
entry: TibberPricesConfigEntry,
|
||||
async_add_entities: AddEntitiesCallback,
|
||||
) -> None:
|
||||
"""Set up the switch platform."""
|
||||
async_add_entities(
|
||||
IntegrationBlueprintSwitch(
|
||||
TibberPricesSwitch(
|
||||
coordinator=entry.runtime_data.coordinator,
|
||||
entity_description=entity_description,
|
||||
)
|
||||
|
|
@ -39,7 +39,7 @@ async def async_setup_entry(
|
|||
)
|
||||
|
||||
|
||||
class IntegrationBlueprintSwitch(IntegrationBlueprintEntity, SwitchEntity):
|
||||
class TibberPricesSwitch(TibberPricesEntity, SwitchEntity):
|
||||
"""tibber_prices switch class."""
|
||||
|
||||
def __init__(
|
||||
|
|
|
|||
Loading…
Reference in a new issue