mirror of
https://github.com/home-assistant/core.git
synced 2025-07-27 15:17:35 +00:00
Move ovo_energy base entity to separate module (#126507)
This commit is contained in:
parent
f7543cd0ba
commit
d67a1993d0
@ -15,12 +15,7 @@ from homeassistant.const import CONF_PASSWORD, CONF_USERNAME, Platform
|
|||||||
from homeassistant.core import HomeAssistant
|
from homeassistant.core import HomeAssistant
|
||||||
from homeassistant.exceptions import ConfigEntryAuthFailed, ConfigEntryNotReady
|
from homeassistant.exceptions import ConfigEntryAuthFailed, ConfigEntryNotReady
|
||||||
from homeassistant.helpers.aiohttp_client import async_get_clientsession
|
from homeassistant.helpers.aiohttp_client import async_get_clientsession
|
||||||
from homeassistant.helpers.device_registry import DeviceEntryType, DeviceInfo
|
from homeassistant.helpers.update_coordinator import DataUpdateCoordinator, UpdateFailed
|
||||||
from homeassistant.helpers.update_coordinator import (
|
|
||||||
CoordinatorEntity,
|
|
||||||
DataUpdateCoordinator,
|
|
||||||
UpdateFailed,
|
|
||||||
)
|
|
||||||
from homeassistant.util import dt as dt_util
|
from homeassistant.util import dt as dt_util
|
||||||
|
|
||||||
from .const import CONF_ACCOUNT, DATA_CLIENT, DATA_COORDINATOR, DOMAIN
|
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]
|
del hass.data[DOMAIN][entry.entry_id]
|
||||||
|
|
||||||
return unload_ok
|
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,
|
|
||||||
)
|
|
||||||
|
43
homeassistant/components/ovo_energy/entity.py
Normal file
43
homeassistant/components/ovo_energy/entity.py
Normal 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,
|
||||||
|
)
|
@ -24,8 +24,8 @@ from homeassistant.helpers.typing import StateType
|
|||||||
from homeassistant.helpers.update_coordinator import DataUpdateCoordinator
|
from homeassistant.helpers.update_coordinator import DataUpdateCoordinator
|
||||||
from homeassistant.util import dt as dt_util
|
from homeassistant.util import dt as dt_util
|
||||||
|
|
||||||
from . import OVOEnergyDeviceEntity
|
|
||||||
from .const import DATA_CLIENT, DATA_COORDINATOR, DOMAIN
|
from .const import DATA_CLIENT, DATA_COORDINATOR, DOMAIN
|
||||||
|
from .entity import OVOEnergyDeviceEntity
|
||||||
|
|
||||||
SCAN_INTERVAL = timedelta(seconds=300)
|
SCAN_INTERVAL = timedelta(seconds=300)
|
||||||
PARALLEL_UPDATES = 4
|
PARALLEL_UPDATES = 4
|
||||||
|
Loading…
x
Reference in New Issue
Block a user