dlarrick / pykumo

Python library to interact with Mitsubishi KumoCloud devices via their local API
MIT License
33 stars 12 forks source link

Fix KumoCloudAccount unit parsing to consistently handle missing fields #47

Closed mt0321 closed 8 months ago

mt0321 commented 8 months ago

Previously, the try block in _parse_unit(raw_unit) was outside of the for loop. That meant that as soon as a missing key was encountered, the function stopped iterating through subsequent keys, leading to a partial unit dict, even if more desired fields were present in the original raw_unit.

Additionally, iteration over the 'fields' set is non-deterministic because Python set iteration is based on a random hash seed.

These two factors combined could lead to unit parsing that sometimes worked and sometimes didn't. (e.g. if 'address' was missing and iterated through first, a completely empty unit dict would be returned).

May fix: https://github.com/dlarrick/hass-kumo/issues/109

dlarrick commented 8 months ago

Thanks! This sounds promising. I'll take a look this weekend.

landonclark commented 8 months ago

FYI, I had the issue described in dlarrick/hass-kumo#109 and patched my local install with the changes in this PR and it worked great.