fsantini / python-e3dc

Python API for querying E3/DC systems through the manufacturer's portal
MIT License
71 stars 23 forks source link

Added robustness to get_powermeter_data and get_powermeters_data #79

Closed bullitt186 closed 10 months ago

bullitt186 commented 11 months ago

get_powermeters_data() respective get_powermeter_data() crashes when called with an invalid index of an powermeter. Without in-depth knowledge of the system, it is hard to know which powermeters with which index are installed. there is no other function in the library to retrieve the number of installed powermeters.

As a simple mitigation to crashes, i added "None"-Handling to get_powermeter_data() & get_powermeter_data(), so that it simply returns the powermeter data when data is available and omits the other ones if no data is returned. By that, you can safely call get_powermeters_data() with index 1 ... 4 and see in the results for which ones data is returned.

This function would help greatly, to integrate additional powermeters in this extension https://github.com/torbennehmer/hacs-e3dc by @torbennehmer

bullitt186 commented 10 months ago

Hi, is there any perspective if / by when this PR will be integrated?

vchrisb commented 10 months ago

I don't think it is the right approach to handle the problem, that a user doesn't know the indexes. What about adding a function to scan for powermeters and return a list of the indexes, that can then be used in the configuration object? In your library you could look for the powermeters key in the configuration object at startup and if it is not present issue a scan?

torbennehmer commented 10 months ago

Scanning the available powermeters was one thing I have been pondering in the HA integration. I actually don't want the user to have to fiddle around with the details. That would be the best way, auto-configuration is always preferable.

bullitt186 commented 10 months ago

As we have now merged https://github.com/fsantini/python-e3dc/pull/80, i this PR can be closed from my end.