magico13 / PyEmVue

Python Library for the Emporia Vue Energy Monitor
MIT License
185 stars 36 forks source link

Add support for setting timeouts #36

Closed DRuggeri closed 1 year ago

DRuggeri commented 2 years ago

I have noticed several cases in the past few weeks where pyemvue seems to either hang up or wait far too long for API responses. It's not clear if this is caused by an issue on my network or with the Emporia API hanging, but I realized this library does not support setting timeouts.

It is suggested in the Python requests module docs that all requests should have a timeout set, so this PR sets a default connect timeout of 6 seconds and a read timeout of 10 seconds. In my experience, this is more than enough even for very slow Internet connections.

I've tested this with and without the connect/read timeout set on the PyEmVue object as well as setting a very short timeout to confirm everything seems to work fine.