Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

'drive_state' Data Sometimes Not Provided Following 'get_vehicle_data'? #116

Open
Haselmaier opened this issue Jan 1, 2023 · 6 comments

Comments

@Haselmaier
Copy link

Haselmaier commented Jan 1, 2023

It appears that sometimes the 'drive_state' dataset is not provided with a get_vehicle_data call.

Could that be possible.....or maybe there's an issue on my end? My code will run for quite a while - checking some fields in that drive_state section. Then I'll get the following and aborts:

Traceback (most recent call last):
File "/home/pi/Desktop/Tesla/Suncatcherv5.3.py", line 292, in
at_home, tpi,odometer_short = tesla_plugged_in()
File "/home/pi/Desktop/Tesla/Suncatcherv5.3.py", line 16, in tesla_plugged_in
lat_raw = cardata['drive_state']['latitude']
File "/home/pi/.local/lib/python3.9/site-packages/teslapy/init.py", line 610, in missing

The errors/exceptions are pretty lengthy.....but this is the beginning. I've created a test program to only get the data and print it out. Sometimes that section is there....and sometimes it's not.

Thoughts?

Thanks!

@Haselmaier Haselmaier changed the title 'drive_state' Data Sometimes Not Provide Following 'get_vehicle_data'? 'drive_state' Data Sometimes Not Provided Following 'get_vehicle_data'? Jan 1, 2023
@tdorssers
Copy link
Owner

This happens when the vehicle is asleep, because the owner API returns cached data when you make this call. If you call sync_wake_up() before get_vehicle_data(), then this should not happen.

@Haselmaier
Copy link
Author

Haselmaier commented Jan 1, 2023

Thank you Tim!

Have you seen this happen even when a sync_wake_up() is done?

I'll see how things do today. But I seemed to have an occurrence of this yesterday when the car had been woken up.

Thank you again.

Jim

@Haselmaier
Copy link
Author

Haselmaier commented Jan 2, 2023

Additional info:

My code crashed this morning....after running for 18+ hours. The overall context: This program adjusts car charging based on solar panel output and home consumption. The design case is for it to run 24x7....and if car is below certain charge at night charge at night just to a basic minimum we need. My point: It's pinging the car periodically for status. During daylight it's pinging it about every 10 minutes. It had been running quite a long time - with many successful car polls - when this had occurred.

Any ideas?

Thanks so much!

2023-01-02 11_45_53-Desktop

@tdorssers
Copy link
Owner

This exception is common if you access the TeslaPy object outside of a context handler. Here is an example without context handler: https://github.com/tdorssers/TeslaPy#alternative
It is also possible that the connection has dropped to the server. You can enable automatic retries like this: https://github.com/tdorssers/TeslaPy#robustness
Hope this helps.

@Haselmaier
Copy link
Author

Thanks!

@jeffh0821
Copy link

Just to add on to this a bit...

I have also observed some inconsistent behavior with the return of 'drive_state' data after the call of the get_vehicle_data() method on a Vehicle object. I concur with Tim that I think it has to do with the vehicle being 'asleep', but I can also verify that the top-level 'state' is 'online'. In fact, I have not seen a state other than 'online' since I've started working on my project.

I really do not think this is an issue with the library - more of an API nuance. Is there any way for us to reliably establish the case in which a get_vehicle_data() call will NOT return 'drive_state' data?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants