diff --git a/custom_components/fpl/fplapi.py b/custom_components/fpl/fplapi.py index 4790cd0..a7849f9 100644 --- a/custom_components/fpl/fplapi.py +++ b/custom_components/fpl/fplapi.py @@ -296,13 +296,15 @@ class FplApi(object): ): dailyUsage.append( { - "usage": daily["kwhUsed"], - "cost": daily["billingCharge"], - "date": daily["date"], - "max_temperature": daily["averageHighTemperature"], - "netDeliveredKwh": daily["netDeliveredKwh"], - "netReceivedKwh": daily["netReceivedKwh"], - "readTime": daily["readTime"], + "usage": daily.get("kwhUsed"), + "cost": daily.get("billingCharge"), + "date": daily.get("date"), + "max_temperature": daily.get( + "averageHighTemperature" + ), + "netDeliveredKwh": daily.get("netDeliveredKwh"), + "netReceivedKwh": daily.get("netReceivedKwh"), + "readTime": daily.get("readTime"), } ) # totalPowerUsage += int(daily["kwhUsed"]) @@ -310,12 +312,12 @@ class FplApi(object): # data["total_power_usage"] = totalPowerUsage data["daily_usage"] = dailyUsage - data["projectedKWH"] = r["CurrentUsage"]["projectedKWH"] - data["dailyAverageKWH"] = r["CurrentUsage"]["dailyAverageKWH"] - data["billToDateKWH"] = r["CurrentUsage"]["billToDateKWH"] - data["recMtrReading"] = r["CurrentUsage"]["recMtrReading"] - data["delMtrReading"] = r["CurrentUsage"]["delMtrReading"] - data["billStartDate"] = r["CurrentUsage"]["billStartDate"] + data["projectedKWH"] = r["CurrentUsage"].get("projectedKWH") + data["dailyAverageKWH"] = r["CurrentUsage"].get("dailyAverageKWH") + data["billToDateKWH"] = r["CurrentUsage"].get("billToDateKWH") + data["recMtrReading"] = r["CurrentUsage"].get("recMtrReading") + data["delMtrReading"] = r["CurrentUsage"].get("delMtrReading") + data["billStartDate"] = r["CurrentUsage"].get("billStartDate") return data async def __getDataFromApplianceUsage(self, account, lastBilledDate) -> dict: diff --git a/custom_components/fpl/sensor_KWHSensor.py b/custom_components/fpl/sensor_KWHSensor.py index 965d541..1a034ab 100644 --- a/custom_components/fpl/sensor_KWHSensor.py +++ b/custom_components/fpl/sensor_KWHSensor.py @@ -29,7 +29,7 @@ class ProjectedKWHSensor(FplEntity): class DailyAverageKWHSensor(FplEntity): def __init__(self, coordinator, config, account): - super().__init__(coordinator, config, account, "Daily Average") + super().__init__(coordinator, config, account, "Daily Average KWH") @property def state(self):