diff --git a/intent_schema.json b/intent_schema.json index f97771b..54e61e9 100644 --- a/intent_schema.json +++ b/intent_schema.json @@ -67,6 +67,16 @@ } ] }, + + { + "intent": "StartCar", + "slots": [ + { + "name": "car", + "type": "CAR" + } + ] + }, { "intent": "AMAZON.HelpIntent" }, diff --git a/main.py b/main.py index 511d72b..0571c95 100644 --- a/main.py +++ b/main.py @@ -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": @@ -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" @@ -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 ({ diff --git a/sample_utterances.txt b/sample_utterances.txt index b5235e9..dee9b13 100644 --- a/sample_utterances.txt +++ b/sample_utterances.txt @@ -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