mlowijs / tesla_api

Lightweight Python API client for the Tesla API.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

How to get charge state?

RecognitionDesigns opened this issue · comments

Hi, total noob here, I'm trying to work out how to get the current charge level of the car to be shown in the terminal window, same as the display_name, vin, etc.
Thanks in advance!

Untested, but in the example, if you replace v.vin with await v.charge.get_state(), I'd expect that to work.

Great! That worked! It was that easy! Thank you!

Sorry, quick question,

so now I get the charge state which is a big list of everything, eg.

{'battery_heater_on': False, 'battery_level': 51, ....

how do I parse this data to get just the 'battery_level' value only?

Thanks again.

It's a dictionary, so just index it, e.g.

state = await v.charge.get_state()
print(state["battery_level"])

If you want to learn more about Python programming, I'd recommend O'Reilly's Learning Python book, to gain a thorough understanding of the language. Or, there's many free courses online for a briefer overview of programming in Python.

If you're tripping up over the await syntax (which is a relatively new thing), just know that you need to put it before any function calls which are marked as async. When you get into some more advanced programming, it will allow you to write asynchronous code, such as being able to have an application respond to user input while in the middle of fetching API data, or being able to make several different API requests at the same time.

Awesome! Thank you! Now I can continue with my little project!
And I promise no more questions, i'll buy that book you mentioned! Cheers!