Skip to content

Commit

Permalink
Merge pull request #26 from admoya/master
Browse files Browse the repository at this point in the history
fix(attributes): handle missing attributes and duplicate key
  • Loading branch information
dotKrad committed May 18, 2022
2 parents 8e36810 + cfeb6a4 commit 7baac81
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 14 deletions.
28 changes: 15 additions & 13 deletions custom_components/fpl/fplapi.py
Original file line number Diff line number Diff line change
Expand Up @@ -296,26 +296,28 @@ async def __getDataFromEnergyService(
):
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"])

# 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:
Expand Down
2 changes: 1 addition & 1 deletion custom_components/fpl/sensor_KWHSensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ def defineAttributes(self):

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):
Expand Down

0 comments on commit 7baac81

Please sign in to comment.