CharlesGillanders / homeassistant-alphaESS

Monitor your energy generation, storage, and usage data using the official API from Alpha ESS.
MIT License
101 stars 22 forks source link

Add safe_get method for certain coordinator data variables #122

Closed Poshy163 closed 3 months ago

Poshy163 commented 3 months ago

This function checks if the dictionary (aka the variable we are trying to access) is None, and if it is, it returns the default value (which is 0 by default, and means it should not be calculated against). If the dictionary is not None, it proceeds to fetch the value using .get() and passes it to process_value.

This should resolve the issue of where we were trying to modify a None value (e.g. _pvpowerdetails itself is None, meaning we were trying to call .get("ppv1") on a NoneType object), which leads to an AttributeError.