1
mirror of https://github.com/home-assistant/core synced 2024-07-27 18:58:57 +02:00

Fix OVO Energy NoneType error occurring for some users (#65714)

This commit is contained in:
Aidan Timson 2022-02-05 10:46:52 +00:00 committed by GitHub
parent bf0816d4c6
commit b1bf9b50d8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -121,14 +121,22 @@ async def async_setup_entry(
if coordinator.data:
if coordinator.data.electricity:
for description in SENSOR_TYPES_ELECTRICITY:
if description.key == KEY_LAST_ELECTRICITY_COST:
if (
description.key == KEY_LAST_ELECTRICITY_COST
and coordinator.data.electricity[-1] is not None
and coordinator.data.electricity[-1].cost is not None
):
description.native_unit_of_measurement = (
coordinator.data.electricity[-1].cost.currency_unit
)
entities.append(OVOEnergySensor(coordinator, description, client))
if coordinator.data.gas:
for description in SENSOR_TYPES_GAS:
if description.key == KEY_LAST_GAS_COST:
if (
description.key == KEY_LAST_GAS_COST
and coordinator.data.gas[-1] is not None
and coordinator.data.gas[-1].cost is not None
):
description.native_unit_of_measurement = coordinator.data.gas[
-1
].cost.currency_unit