teslajson icon indicating copy to clipboard operation
teslajson copied to clipboard

Cleanup of http connection?

Open tillhanke opened this issue 3 years ago • 2 comments

Is there a way to close the http connections when the requests and posts are done?

Our vehicle seems to be awake all the time an I have the suspicion that it is because the API is connected all the time...

tillhanke avatar Apr 11 '21 20:04 tillhanke

How are you calling the API? Why not simply delete the Connection and Vehicle objects?

gglockner avatar Apr 11 '21 23:04 gglockner

I am calling the API as explained in the README

c = teslajson.Connection('youremail', 'yourpassword')
v = c.vehicles[0]
v.wake_up()

Because I didn't see a method for closing the session in your code I searched for the OAuth docs and found the part about requests there its explained, that one should always close the sessions with the close method.

Developers SHOULD close a Requests Session when the jobs are done. You can call .close() manually, or use a with context to automatically close the session:

Maybe its a option to just add a method that closes the session within the Connection Class? I fixed my problem by directly calling c.session.close() this way the Tesla didn't seem awake for so long anymore. Sadly there is no gotosleep command within the teslajson api...

tillhanke avatar Apr 15 '21 19:04 tillhanke