Skip to content

Commit

Permalink
Added car start feature
Browse files Browse the repository at this point in the history
  • Loading branch information
ishan11 committed Sep 16, 2017
1 parent 84a87a9 commit 3c7f4b6
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 4 deletions.
10 changes: 10 additions & 0 deletions intent_schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,16 @@
}
]
},

{
"intent": "StartCar",
"slots": [
{
"name": "car",
"type": "CAR"
}
]
},
{
"intent": "AMAZON.HelpIntent"
},
Expand Down
27 changes: 23 additions & 4 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,8 @@ def onIntent(intentRequest, session,headers,vehicle_id):
return flashLights(headers, vehicle_id)
elif intentName == "Location":
return getLocation(headers,vehicle_id)
elif intentName == "startCar":
return startCar(headers,vehicle_id)
elif intentName == "AMAZON.HelpIntent":
return getWelcomeResponse()
elif intentName == "AMAZON.StopIntent":
Expand All @@ -100,11 +102,11 @@ def chargingResponse(headers,vehicle_id):
if(res.status_code == 200):
res = res.json()
if res["response"]["charging_state"] == "Complete":
speechOutput = "Your car has completed charging. With a range of " + str(res["response"]["battery_range"]) + "."
cardTitle = "Your car has completed charging. With a range of " + str(res["response"]["battery_range"]) + "."
speechOutput = "Your car has completed charging. With a range of " + str(res["response"]["battery_range"]) + "miles."
cardTitle = "Your car has completed charging. With a range of " + str(res["response"]["battery_range"]) + "miles."
else:
speechOutput = "Your car is " + str(res["response"]["battery_level"]) + " charged. With a range of " + str(res["response"]["battery_range"]) + "."
cardTitle = "Your car is " + str(res["response"]["battery_level"]) + " charged. With a range of " + str(res["response"]["battery_range"]) + "."
speechOutput = "Your car is " + str(res["response"]["battery_level"]) + " percent charged. With a range of " + str(res["response"]["battery_range"]) + "miles."
cardTitle = "Your car is " + str(res["response"]["battery_level"]) + " percent charged. With a range of " + str(res["response"]["battery_range"]) + "miles."
else:
speechOutput = "Error connecting to Tesla Servers. Please try again"
cardTitle = "Error connecting to Tesla Servers. Please try again"
Expand Down Expand Up @@ -227,6 +229,23 @@ def getLocation(headers,vehicle_id):

return(buildSpeechletResponse(cardTitle,speechOutput,repromptText,shouldEndSession))

def startCar(headers,vehicle_id):
params = {"password":PASSWORD}
res = requests.post("https://owner-api.teslamotors.com/api/1/vehicles/"+str(vehicle_id)+"/command/remote_start_drive", params = params, headers = headers)

if(res.status_code == 200):
speechOutput = "Ok, your Tesla has been started"
cardTitle = speechOutput
else:
speechOutput = "Error connecting to Tesla Server. Please try again"
cardTitle = speechOutput

repromptText = "I didnt understand that. Please try again"
shouldEndSession = True

return(buildSpeechletResponse(cardTitle,speechOutput,repromptText,shouldEndSession))


# --------------- Helpers that build all of the responses -----------------------
def buildSpeechletResponse(title, output, repromptText, shouldEndSession):
return ({
Expand Down
2 changes: 2 additions & 0 deletions sample_utterances.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,5 @@ AC_State to turn {power} {conditioning}
FlashLight to flash lights
Location where my {car} is
Location where it is
StartCar to start
StartCar to turn on

0 comments on commit 3c7f4b6

Please sign in to comment.