Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import os
- import sys
- import teslajson
- TESLA_EMAIL = os.environ['TESLA_EMAIL']
- TESLA_PASSWORD = os.environ['TESLA_PASSWORD']
- if len(sys.argv) !=2 or sys.argv[1] not in ("start", "stop"):
- sys.exit("Usage: %s start|stop" % sys.argv[0])
- startstop = sys.argv[1]
- connection = teslajson.Connection(TESLA_EMAIL, TESLA_PASSWORD)
- vehicle = connection.vehicles[0]
- wake_up = vehicle.wake_up()["response"]
- if "state" not in wake_up:
- sys.exit("Could not wake up car.")
- if wake_up["state"] != "online":
- sys.exit("Car not online.")
- print startstop, "charging."
- charge = vehicle.command("charge_" + startstop)
- if "response" not in charge or "result" not in charge["response"]:
- sys.exit("Car did not respond.")
- if charge["response"]["result"]:
- print "OK."
- else:
- sys.exit("Car did not %s charging." % startstop)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement