Giter VIP home page Giter VIP logo

Comments (9)

tdorssers avatar tdorssers commented on May 25, 2024

You can try to enable retries, so requests will retry after a connection aborted exception:

with teslapy.Tesla(username, retry=3, timeout=20) as tesla:

You can even have TeslaPy retry HTTP exceptions:

retry = teslapy.Retry(total=3, status_forcelist=(500, 502, 503, 504))
with teslapy.Tesla(username, retry=retry, timeout=20) as tesla:

from teslapy.

SylvainGa avatar SylvainGa commented on May 25, 2024

Thanks, I'll give it a try.

from teslapy.

SylvainGa avatar SylvainGa commented on May 25, 2024

No crash today with the addition of the retry and timeout parameters. I'll report back tomorrow and close the issue if all is well, thanks.

from teslapy.

tdorssers avatar tdorssers commented on May 25, 2024

Great. The reason that retries aren't enabled by default, is that if you hammer the API too much, your account can be blocked temporarily. But if you retry a couple of times and back off a while and retry again, then it shouldn't be an issue.

from teslapy.

SylvainGa avatar SylvainGa commented on May 25, 2024

Hi, it crashed again reading the following line:
vehicleData = vehicles[vehicle].get_vehicle_data()
With a 408 exception. The line just before that was
if vehicles[vehicle].available() == True: # Only read if the car isn't asleep
From what I got in your doc for 'available':

checks if the vehicle is online based on cached data or refreshed status when aged out

It looks like the car went offline before the cache aged out.

I'm just starting with Python and not sure I would go about forcing a cache refresh before the 'available()' call or adding a HTTPError 408 exception around that 'get_vehicle_data()' so it acts as if the car is offline when it's thrown.

For now, i'm doing my own 'available' check as such

available = False
vehicles = tesla.vehicle_list()
if vehicles[vehicle]['state'] != 'asleep':
    available = True

Wondering if there is a better way.

Thanks,

from teslapy.

tdorssers avatar tdorssers commented on May 25, 2024

I would catch the 408 exception, because it takes about 30 seconds for the car to actually go to sleep.

from teslapy.

SylvainGa avatar SylvainGa commented on May 25, 2024

Thanks, I've set the retry and connection parameters as such

retry = teslapy.Retry(total=5, status_forcelist=(408, 500, 502, 503, 504, 540))
tesla = teslapy.Tesla(Config.get('Tesla', 'username'), retry=retry, timeout=10)

I'll see how it goes in the following days. Thanks for maintaining this library btw :-)

from teslapy.

SylvainGa avatar SylvainGa commented on May 25, 2024

Has been stable since my last post 5 days ago. I'll go ahead and close this issue. Thanks for your help :-)

I do wish Tesla would implement internally what I'm doing here, which is when rain is detected (it does already), close the windows if the car is parked. Could work similar to cabin overheat protection. It would work everywhere, not just close to my weather station.

from teslapy.

SylvainGa avatar SylvainGa commented on May 25, 2024

Working, thanks for your help.

from teslapy.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.