Comments (18)
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.
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.
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.
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.
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.
It sounds really good! I look forward to this new release! :-)
from teslapy.
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.
Does it need to be call inside a context manager or can I simply instantiate the tesla object and reuse it?
from teslapy.
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.
It works perfectly fine the way you did it! Thank you very much! 👍
from teslapy.
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.
No not really, please give 917f6af a try.
from teslapy.
@tdorssers as expected, it just works! Any way to show my gratitude? Maybe a beer or other kind of donation?
from teslapy.
Thanks! How are you managing with vehicle wake up and other calls from your web app?
from teslapy.
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.
@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.
Just released 2.2.0 a few minutes ago!
from teslapy.
Thank you very much! Really appreciated. :-)
I'll close this issue now.
from teslapy.
Related Issues (20)
- minutes to full charge = 0 HOT 3
- Unlock charge port HOT 2
- Security issue with cache.json HOT 1
- May be an issue with CHANGE_CLIMATE_TEMPERATURE_SETTING command HOT 2
- Calling api() returns 404 error HOT 1
- Unable to edit wpa_supplicant.conf HOT 1
- WebSocket does not terminate in streaming HOT 1
- 'drive_state' Data Sometimes Not Provided Following 'get_vehicle_data'? HOT 6
- sync_wake_up Works Fine With One Car But Sometimes Times Out On Another HOT 3
- TypeError: unsupported format string passed to NoneType.__format__ HOT 9
- last_seen() raises HOT 9
- Charging stops HOT 1
- How to call `mobile-app/*` endpoints?
- Error 404 in every endpoint HOT 2
- (missing_token) Missing access token parameter. HOT 14
- Powerwall - cannot retrieve the mode HOT 3
- 429 on every sync_wake_up() call HOT 3
- last_seen() raises "Timestamp is in the future" error HOT 3
- No longer able to set Powerwall to self_consumption mode HOT 6
- Percentage Charged not updating on get_battery_data()
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from teslapy.