Improve `ovo_energy` generic typing (#84641)
parent
24a34b1739
commit
54ba09ec1c
|
@ -61,7 +61,7 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
||||||
raise ConfigEntryAuthFailed("Not authenticated with OVO Energy")
|
raise ConfigEntryAuthFailed("Not authenticated with OVO Energy")
|
||||||
return await client.get_daily_usage(datetime.utcnow().strftime("%Y-%m"))
|
return await client.get_daily_usage(datetime.utcnow().strftime("%Y-%m"))
|
||||||
|
|
||||||
coordinator = DataUpdateCoordinator(
|
coordinator = DataUpdateCoordinator[OVODailyUsage](
|
||||||
hass,
|
hass,
|
||||||
_LOGGER,
|
_LOGGER,
|
||||||
# Name of the data. For logging purposes.
|
# Name of the data. For logging purposes.
|
||||||
|
@ -96,12 +96,12 @@ async def async_unload_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
||||||
return unload_ok
|
return unload_ok
|
||||||
|
|
||||||
|
|
||||||
class OVOEnergyEntity(CoordinatorEntity):
|
class OVOEnergyEntity(CoordinatorEntity[DataUpdateCoordinator[OVODailyUsage]]):
|
||||||
"""Defines a base OVO Energy entity."""
|
"""Defines a base OVO Energy entity."""
|
||||||
|
|
||||||
def __init__(
|
def __init__(
|
||||||
self,
|
self,
|
||||||
coordinator: DataUpdateCoordinator,
|
coordinator: DataUpdateCoordinator[OVODailyUsage],
|
||||||
client: OVOEnergy,
|
client: OVOEnergy,
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Initialize the OVO Energy entity."""
|
"""Initialize the OVO Energy entity."""
|
||||||
|
|
|
@ -115,9 +115,9 @@ async def async_setup_entry(
|
||||||
hass: HomeAssistant, entry: ConfigEntry, async_add_entities: AddEntitiesCallback
|
hass: HomeAssistant, entry: ConfigEntry, async_add_entities: AddEntitiesCallback
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Set up OVO Energy sensor based on a config entry."""
|
"""Set up OVO Energy sensor based on a config entry."""
|
||||||
coordinator: DataUpdateCoordinator = hass.data[DOMAIN][entry.entry_id][
|
coordinator: DataUpdateCoordinator[OVODailyUsage] = hass.data[DOMAIN][
|
||||||
DATA_COORDINATOR
|
entry.entry_id
|
||||||
]
|
][DATA_COORDINATOR]
|
||||||
client: OVOEnergy = hass.data[DOMAIN][entry.entry_id][DATA_CLIENT]
|
client: OVOEnergy = hass.data[DOMAIN][entry.entry_id][DATA_CLIENT]
|
||||||
|
|
||||||
entities = []
|
entities = []
|
||||||
|
@ -152,25 +152,22 @@ async def async_setup_entry(
|
||||||
class OVOEnergySensor(OVOEnergyDeviceEntity, SensorEntity):
|
class OVOEnergySensor(OVOEnergyDeviceEntity, SensorEntity):
|
||||||
"""Define a OVO Energy sensor."""
|
"""Define a OVO Energy sensor."""
|
||||||
|
|
||||||
coordinator: DataUpdateCoordinator
|
coordinator: DataUpdateCoordinator[DataUpdateCoordinator[OVODailyUsage]]
|
||||||
entity_description: OVOEnergySensorEntityDescription
|
entity_description: OVOEnergySensorEntityDescription
|
||||||
|
|
||||||
def __init__(
|
def __init__(
|
||||||
self,
|
self,
|
||||||
coordinator: DataUpdateCoordinator,
|
coordinator: DataUpdateCoordinator[OVODailyUsage],
|
||||||
description: OVOEnergySensorEntityDescription,
|
description: OVOEnergySensorEntityDescription,
|
||||||
client: OVOEnergy,
|
client: OVOEnergy,
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Initialize."""
|
"""Initialize."""
|
||||||
super().__init__(
|
super().__init__(coordinator, client)
|
||||||
coordinator,
|
|
||||||
client,
|
|
||||||
)
|
|
||||||
self._attr_unique_id = f"{DOMAIN}_{client.account_id}_{description.key}"
|
self._attr_unique_id = f"{DOMAIN}_{client.account_id}_{description.key}"
|
||||||
self.entity_description = description
|
self.entity_description = description
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def native_value(self) -> StateType | datetime:
|
def native_value(self) -> StateType | datetime:
|
||||||
"""Return the state."""
|
"""Return the state."""
|
||||||
usage: OVODailyUsage = self.coordinator.data
|
usage = self.coordinator.data
|
||||||
return self.entity_description.value(usage)
|
return self.entity_description.value(usage)
|
||||||
|
|
Loading…
Reference in New Issue