Fix OVO Energy Sensors (#38849)
parent
f4f614a0bc
commit
47d1920f8a
|
@ -40,7 +40,14 @@ async def async_setup_entry(hass: HomeAssistantType, entry: ConfigEntry) -> bool
|
|||
"""Fetch data from OVO Energy."""
|
||||
now = datetime.utcnow()
|
||||
async with async_timeout.timeout(10):
|
||||
try:
|
||||
await client.authenticate(
|
||||
entry.data[CONF_USERNAME], entry.data[CONF_PASSWORD]
|
||||
)
|
||||
return await client.get_daily_usage(now.strftime("%Y-%m"))
|
||||
except aiohttp.ClientError as exception:
|
||||
_LOGGER.warning(exception)
|
||||
return None
|
||||
|
||||
coordinator = DataUpdateCoordinator(
|
||||
hass,
|
||||
|
|
|
@ -29,15 +29,29 @@ async def async_setup_entry(
|
|||
|
||||
entities = []
|
||||
|
||||
if coordinator.data:
|
||||
if coordinator.data.electricity:
|
||||
currency = coordinator.data.electricity[
|
||||
len(coordinator.data.electricity) - 1
|
||||
].cost.currency_unit
|
||||
entities.append(OVOEnergyLastElectricityReading(coordinator, client))
|
||||
entities.append(OVOEnergyLastElectricityCost(coordinator, client, currency))
|
||||
entities.append(
|
||||
OVOEnergyLastElectricityCost(
|
||||
coordinator,
|
||||
client,
|
||||
coordinator.data.electricity[
|
||||
len(coordinator.data.electricity) - 1
|
||||
].cost.currency_unit,
|
||||
)
|
||||
)
|
||||
if coordinator.data.gas:
|
||||
entities.append(OVOEnergyLastGasReading(coordinator, client))
|
||||
entities.append(OVOEnergyLastGasCost(coordinator, client, currency))
|
||||
entities.append(
|
||||
OVOEnergyLastGasCost(
|
||||
coordinator,
|
||||
client,
|
||||
coordinator.data.gas[
|
||||
len(coordinator.data.gas) - 1
|
||||
].cost.currency_unit,
|
||||
)
|
||||
)
|
||||
|
||||
async_add_entities(
|
||||
entities, True,
|
||||
|
|
Loading…
Reference in New Issue