Giter VIP home page Giter VIP logo

Comments (18)

tdorssers avatar tdorssers commented on May 25, 2024

By using an authenticator function, which is a callback, you get some async functionality. TeslaPy is a synchronous library. Which framework are you planning to use?

from teslapy.

morpheus65535 avatar morpheus65535 commented on May 25, 2024

Currently I'm running some test with Flask and Threading.Event. Looks promising and I'll update this issue when I get it working for the benefit of others.

from teslapy.

tdorssers avatar tdorssers commented on May 25, 2024

I am working on splitting fetch_token() in two methods. If you don't supply an argument to fetch_token, then it will behave the same as before. A new method will generate the auth url and you can supply the redirected url as an argument to fetch_token.
Will that help/make life easier?

from teslapy.

morpheus65535 avatar morpheus65535 commented on May 25, 2024

Will those two method be independant? Is it gonna be possible to call the first method to get the auth_url then, from a different Falsk route, call the fetch_token method with only the auth_url and (let's call it) the code_url as argument? How will the Tesla class will behave on init if there's no token?

from teslapy.

tdorssers avatar tdorssers commented on May 25, 2024

Yes the methods are independent and will behave like you described. On init, the class will try to read the token from the cache file. If there is no token in the cache file or no file at all, then nothing will happen. The first API call that you try to make, will call fetch_token() without arguments automatically, meaning it will use the authenticator function to get the code. So in your Flask app, you need to make sure not to call an API before you are authenticated using the 'two step' way.

from teslapy.

morpheus65535 avatar morpheus65535 commented on May 25, 2024

It sounds really good! I look forward to this new release! :-)

from teslapy.

tdorssers avatar tdorssers commented on May 25, 2024

Please check out 333c114. You can use it like this:

import teslapy

with teslapy.Tesla('[email protected]') as tesla:
    print(tesla.authorization_url())
    tesla.fetch_token(authorization_response=input('URL: '))
    vehicles = tesla.vehicle_list()
    print(vehicles[0])

tesla.authorization_url() will generate the auth url.
you pass the redirected url to fetch_token() using keyword argument authorization_response.

from teslapy.

morpheus65535 avatar morpheus65535 commented on May 25, 2024

Does it need to be call inside a context manager or can I simply instantiate the tesla object and reuse it?

from teslapy.

tdorssers avatar tdorssers commented on May 25, 2024

Context manager is optional. You can instantiate a tesla object and close it when done.

tesla = Tesla('[email protected]')
# do stuff
tesla.close()

authorization_url() and fetch_token() must be called on the same instance. But I can change that, the state and code_verifier are needed between those calls, so I can make authorization_url() provide a 3-tuple with url, state and code_verifier and make fetch_token() take those as keyword arguments.

from teslapy.

morpheus65535 avatar morpheus65535 commented on May 25, 2024

It works perfectly fine the way you did it! Thank you very much! 👍

from teslapy.

morpheus65535 avatar morpheus65535 commented on May 25, 2024

Would it be too much if I ask for a logout method that would set authorized to False and delete the cached token?

from teslapy.

tdorssers avatar tdorssers commented on May 25, 2024

No not really, please give 917f6af a try.

from teslapy.

morpheus65535 avatar morpheus65535 commented on May 25, 2024

@tdorssers as expected, it just works! Any way to show my gratitude? Maybe a beer or other kind of donation?

from teslapy.

tdorssers avatar tdorssers commented on May 25, 2024

Thanks! How are you managing with vehicle wake up and other calls from your web app?

from teslapy.

morpheus65535 avatar morpheus65535 commented on May 25, 2024

Basically my web app is an evolution from my headless shceduled preheating app that was configured using environment variables. I'm refactoring it to use a config file instead and the frontend will be used to generate the token and edit the config file.

So, until the token is valid and teslapy autorized is True, the schedule task isn't able to start. Once the user as authenticated and we have a valid token, the scheduled task will run based on user requirement (ex.: every weekday at 7am). I also have a maximum preheating length that stop the preheating after a specified delay to prevent preheating to be left enabled for 4 hours if not required.

from teslapy.

morpheus65535 avatar morpheus65535 commented on May 25, 2024

@tdorssers any ETA for releasing master to a new version on pypi? For now I'm linking to this repo in my requirements.txt but making it more "official" would be great ;-)

thanks!

from teslapy.

tdorssers avatar tdorssers commented on May 25, 2024

Just released 2.2.0 a few minutes ago!

from teslapy.

morpheus65535 avatar morpheus65535 commented on May 25, 2024

Thank you very much! Really appreciated. :-)

I'll close this issue now.

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.