Skip to content

Commit

Permalink
updating lambda to version 0.2
Browse files Browse the repository at this point in the history
  • Loading branch information
keatontaylor committed May 9, 2020
1 parent 78aa5fb commit f51306d
Showing 1 changed file with 15 additions and 9 deletions.
24 changes: 15 additions & 9 deletions lambda_function.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
## VERSION 0.1
## VERSION 0.2

import logging
import urllib3
Expand All @@ -18,6 +18,7 @@
# UPDATE THESE VARIABLES WITH YOUR CONFIG
HOME_ASSISTANT_URL = "https://yourhainstall.com" # REPLACE WITH THE URL FOR YOUR HA FRONTEND
VERIFY_SSL = True # SET TO FALSE IF YOU DO NOT HAVE VALID CERTS
TOKEN = "" # ADD YOUR LONG LIVED TOKEN IF NEEDED OTHERWISE LEAVE BLANK

home_assistant_object = None
class HomeAssistant():
Expand All @@ -26,7 +27,8 @@ def __init__(self, handler_input):
self.event_id = ""
self.text = ""
self.handler_input = handler_input
self.token = self._fetch_token(handler_input)

self.token = self._fetch_token(handler_input) if TOKEN == "" else TOKEN

def _fetch_token(self, handler_input):
return ask_utils.get_account_linking_access_token(handler_input)
Expand Down Expand Up @@ -82,7 +84,7 @@ def get_ha_state(self):

return self.text

def post_ha_event(self, response: bool):
def post_ha_event(self, response: str):
"""Send event to HA."""

http = urllib3.PoolManager(
Expand Down Expand Up @@ -140,9 +142,8 @@ def handle(self, handler_input):
if home_assistant_object == None:
home_assistant_object = HomeAssistant(handler_input)
home_assistant_object.get_ha_state()


speak_output = home_assistant_object.post_ha_event(True)
speak_output = home_assistant_object.post_ha_event("ResponseYes")
return (
handler_input.response_builder
.speak(speak_output)
Expand All @@ -159,13 +160,13 @@ def can_handle(self, handler_input):

def handle(self, handler_input):
# type: (HandlerInput) -> Response

global home_assistant_object
if home_assistant_object == None:
home_assistant_object = HomeAssistant(handler_input)
home_assistant_object.get_ha_state()


speak_output = home_assistant_object.post_ha_event(False)
speak_output = home_assistant_object.post_ha_event("ResponseNo")
return (
handler_input.response_builder
.speak(speak_output)
Expand Down Expand Up @@ -223,8 +224,13 @@ def can_handle(self, handler_input):
def handle(self, handler_input):
# type: (HandlerInput) -> Response

print("SessionEndedRequestHandler")
# Any cleanup logic goes here.
global home_assistant_object
if home_assistant_object == None:
home_assistant_object = HomeAssistant(handler_input)
home_assistant_object.get_ha_state()

speak_output = home_assistant_object.post_ha_event("ResponseNone")

return handler_input.response_builder.response


Expand Down

0 comments on commit f51306d

Please sign in to comment.