dotKrad / hass-fpl

FPL Component for Home Assistant
MIT License
40 stars 20 forks source link

fix(attributes): handle missing attributes and duplicate key #26

Closed admoya closed 2 years ago

admoya commented 2 years ago

First, thanks for the great custom component! I was so relieved this already existed.

I was having some issues logging in, like I see a few others are, because of the finicky FPL API sometimes not returning all the data and then the code throwing a keyError. This was happening to me in the daily attributes as well as in the currentUsage attributes (sometimes). I replaced the bracket notation with .get, which will default the value to None if it is not present. Home Assistant will just handle that as an Unknown value. I figured this was preferable to defaulting to 0, since 0 could be mistaken for a valid measurement.

Also, the DailyAverageKWHSensor was being ignored by Home Assistant because it was registering its name as just "Daily Average", which was already registered by the FplAverageDailySensor, so I tweaked the name there to "Daily Average KWH".

admoya commented 2 years ago

Also, I know this is partially redundant with #24, but I handled the missing values differently so I figured it was worth a new PR so you could decide which you like better.