Move ovo_energy base entity to separate module (#126507)

pull/126520/head
epenet 2024-09-23 12:44:24 +02:00 committed by GitHub
parent f7543cd0ba
commit d67a1993d0
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 45 additions and 36 deletions

View File

@ -15,12 +15,7 @@ from homeassistant.const import CONF_PASSWORD, CONF_USERNAME, Platform
from homeassistant.core import HomeAssistant
from homeassistant.exceptions import ConfigEntryAuthFailed, ConfigEntryNotReady
from homeassistant.helpers.aiohttp_client import async_get_clientsession
from homeassistant.helpers.device_registry import DeviceEntryType, DeviceInfo
from homeassistant.helpers.update_coordinator import (
CoordinatorEntity,
DataUpdateCoordinator,
UpdateFailed,
)
from homeassistant.helpers.update_coordinator import DataUpdateCoordinator, UpdateFailed
from homeassistant.util import dt as dt_util
from .const import CONF_ACCOUNT, DATA_CLIENT, DATA_COORDINATOR, DOMAIN
@ -102,32 +97,3 @@ async def async_unload_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
del hass.data[DOMAIN][entry.entry_id]
return unload_ok
class OVOEnergyEntity(CoordinatorEntity[DataUpdateCoordinator[OVODailyUsage]]):
"""Defines a base OVO Energy entity."""
_attr_has_entity_name = True
def __init__(
self,
coordinator: DataUpdateCoordinator[OVODailyUsage],
client: OVOEnergy,
) -> None:
"""Initialize the OVO Energy entity."""
super().__init__(coordinator)
self._client = client
class OVOEnergyDeviceEntity(OVOEnergyEntity):
"""Defines a OVO Energy device entity."""
@property
def device_info(self) -> DeviceInfo:
"""Return device information about this OVO Energy instance."""
return DeviceInfo(
entry_type=DeviceEntryType.SERVICE,
identifiers={(DOMAIN, self._client.account_id)},
manufacturer="OVO Energy",
name=self._client.username,
)

View File

@ -0,0 +1,43 @@
"""Support for OVO Energy."""
from __future__ import annotations
from ovoenergy import OVOEnergy
from ovoenergy.models import OVODailyUsage
from homeassistant.helpers.device_registry import DeviceEntryType, DeviceInfo
from homeassistant.helpers.update_coordinator import (
CoordinatorEntity,
DataUpdateCoordinator,
)
from .const import DOMAIN
class OVOEnergyEntity(CoordinatorEntity[DataUpdateCoordinator[OVODailyUsage]]):
"""Defines a base OVO Energy entity."""
_attr_has_entity_name = True
def __init__(
self,
coordinator: DataUpdateCoordinator[OVODailyUsage],
client: OVOEnergy,
) -> None:
"""Initialize the OVO Energy entity."""
super().__init__(coordinator)
self._client = client
class OVOEnergyDeviceEntity(OVOEnergyEntity):
"""Defines a OVO Energy device entity."""
@property
def device_info(self) -> DeviceInfo:
"""Return device information about this OVO Energy instance."""
return DeviceInfo(
entry_type=DeviceEntryType.SERVICE,
identifiers={(DOMAIN, self._client.account_id)},
manufacturer="OVO Energy",
name=self._client.username,
)

View File

@ -24,8 +24,8 @@ from homeassistant.helpers.typing import StateType
from homeassistant.helpers.update_coordinator import DataUpdateCoordinator
from homeassistant.util import dt as dt_util
from . import OVOEnergyDeviceEntity
from .const import DATA_CLIENT, DATA_COORDINATOR, DOMAIN
from .entity import OVOEnergyDeviceEntity
SCAN_INTERVAL = timedelta(seconds=300)
PARALLEL_UPDATES = 4