markruys / gw2pvo

GoodWe to PVOutput
MIT License
45 stars 29 forks source link

Retry on connection error to GW API #63

Open valentijnscholten opened 2 years ago

valentijnscholten commented 2 years ago

I regularly have gaps in my pvo graphs due to gw2pvo being unable to get the data for a specific iteration of run_once.

INFO     Normal, 381.0 W now, 13.1 kWh today, 110.7 kWh all time, 233.9 V grid, 333.1 V PV
INFO     Normal, 378.0 W now, 13.1 kWh today, 110.7 kWh all time, 233.1 V grid, 329.2 V PV
INFO     Normal, 360.0 W now, 13.2 kWh today, 110.8 kWh all time, 233.2 V grid, 329.3 V PV
WARNING  HTTPSConnectionPool(host='semsportal.com', port=443): Read timed out. (read timeout=10)
ERROR    Failed to call GoodWe API (code 100002)
INFO     Normal, 314.0 W now, 13.2 kWh today, 110.8 kWh all time, 232.7 V grid, 321.6 V PV
INFO     Normal, 294.0 W now, 13.2 kWh today, 110.8 kWh all time, 232.9 V grid, 326.0 V PV
INFO     Normal, 279.0 W now, 13.3 kWh today, 110.9 kWh all time, 233.3 V grid, 332.2 V PV

I suggest to implement some retries as on subsequent requests the portal works fine.

For example via: https://stackoverflow.com/questions/15431044/can-i-set-max-retries-for-requests-request or https://www.peterbe.com/plog/best-practice-with-retries-with-requests

Workaround:

valentijnscholten commented 2 years ago

hmm looking at the code, there is already some custom retry mechanism with increasing backoff (4 tries with 3s, 6s, 9s, 12s delay).

so I shouldn't have gaps in my graphs, except when it exceeds 4 retries:

INFO     Normal, 117.0 W now, 13.5 kWh today, 111.1 kWh all time, 233.6 V grid, 322.4 V PV
WARNING  HTTPSConnectionPool(host='semsportal.com', port=443): Read timed out. (read timeout=10)
WARNING  HTTPSConnectionPool(host='semsportal.com', port=443): Read timed out. (read timeout=10)
ERROR    Failed to call GoodWe API (too many retries)
INFO     Normal, 115.0 W now, 13.5 kWh today, 111.1 kWh all time, 233.3 V grid, 325.0 V PV