示例#1
0
def update_brightness(intent):
    card_title = "Brightness"

    brightness = intent.get('slots',{}).get('Brightness',{}).get('value')

    if brightness:
        brightness = int(brightness)
        if brightness > 0 and brightness <= 100:
            speech_output = "Yes my lord."
            new_value_dict = {"brightness":brightness}
            shadow_updater.update_shadow(new_value_dict)
        elif brightness == 0:
            speech_output = "Yes my lord."
            new_value_dict = {"power_state":"OFF"}
            shadow_updater.update_shadow(new_value_dict)
        else:
            speech_output = "I'm sorry that value is not in the proper range. "\
                "Please give me a number between 0 and 100."
    else:
        speech_output = "I did not understand that. Please repeat your request."

    response = response_builders.build_response(session_attributes,
        response_builders.build_speechlet_response(card_title,
        speech_output, reprompt_text, should_end_session))
    return response
示例#2
0
def update_power_state(intent):
    """
    Updates power state of IoT shadow. Builds a response confirming the update
    or requesting the user repeat the query if state is not "ON" or "OFF".

    Args:
        intent: Python dict of intent
    Returns:
        Python dict of response message
    """
    card_title = "Power"

    power_state = intent.get('slots', {}).get('PowerState', {}).get('value')
    if power_state and (power_state.upper() == 'ON' or \
                        power_state.upper() == 'OFF'):
        speech_output = "OK."
        new_value_dict = {"power_state": power_state.upper()}
        gateway_connection.update_shadow(new_value_dict)
    else:
        speech_output = "I did not understand that. Please repeat your request."

    response = response_builders.build_response(
        session_attributes,
        response_builders.build_speechlet_response(card_title, speech_output,
                                                   reprompt_text,
                                                   should_end_session))
    return response
示例#3
0
def get_help_response():
    card_title = "Welcome"
    speech_output = "Please give a command for your painting lights."

    response = response_builders.build_response(session_attributes,
        response_builders.build_speechlet_response(card_title,
        speech_output, reprompt_text, should_end_session))
    return response
示例#4
0
def handle_session_end_request():
    card_title = 'Session Ended'
    speech_output = 'It will be done, my Lord.'
    reprompt_text = None

    should_end_session = True
    return response_builders.build_response({},
        response_builders.build_speechlet_response(card_title,
        speech_output, reprompt_text, should_end_session))
def link_question(text):
    print('inside link')
    card_title = 'Link this skill with Fitbit.'
    speech_output = text
    reprompt_text = ' Say Next Routine to continue. '
    should_end_session = False
    card_type = 'LinkAccount'
    return json.dumps(build_response(session.attributes, build_speechlet_response_ssml(\
        card_title, speech_output, reprompt_text, should_end_session, card_type)))
示例#6
0
def execute_order_sixty_six(session):
    session_attributes = session.get('attributes', {})
    card_title = "Order66"
    speech_output = "Yes, my lord."
    reprompt_text = None

    should_end_session = False
    return response_builders.build_response(session_attributes,
        response_builders.build_speechlet_response(card_title,
        speech_output, reprompt_text, should_end_session))
示例#7
0
def get_welcome_response(session):
    session_attributes = session.get('attributes', {})
    card_title = "Welcome"
    speech_output = "Welcome to Star Wars commands. " \
                    "Please say a command."

    reprompt_text = "Please tell me a command."
    should_end_session = False
    return response_builders.build_response(session_attributes,
        response_builders.build_speechlet_response(card_title,
        speech_output, reprompt_text, should_end_session))
示例#8
0
def update_power_state(intent):
    card_title = "Power"

    power_state = intent.get('slots',{}).get('PowerState',{}).get('value')
    if power_state and (power_state.upper() == 'ON' or power_state.upper() == 'OFF'):
        speech_output = "Yes my lord."
        new_value_dict = {"power_state":power_state.upper()}
        shadow_updater.update_shadow(new_value_dict)
    else:
        speech_output = "I did not understand that. Please repeat your request."

    response = response_builders.build_response(session_attributes,
        response_builders.build_speechlet_response(card_title,
        speech_output, reprompt_text, should_end_session))
    return response
示例#9
0
def get_help_response():
    """
    Builds a help/welcome response.

    Args:
        None
    Returns:
        Python dict of response message
    """
    card_title = "Welcome"
    speech_output = "Please give a command for your office lights."

    response = response_builders.build_response(
        session_attributes,
        response_builders.build_speechlet_response(card_title, speech_output,
                                                   reprompt_text,
                                                   should_end_session))
    return response
示例#10
0
def handle_session_end_request():
    """
    Builds a response with a blank message and no session data. If using
    session data this function would specifically have session_attributes = {}
    and should_end_session = True.

    Args:
        None
    Returns:
        Python dict of response message
    """
    speech_output = None
    response = response_builders.build_response(
        session_attributes,
        response_builders.build_speechlet_response(card_title, speech_output,
                                                   reprompt_text,
                                                   should_end_session))
    return response
示例#11
0
def get_planet_from_session(intent, session):
    session_attributes = session.get('attributes', {})
    card_title = intent['name']

    if session_attributes.get('planet', {}):
        speech_output = "The plans are on " + session_attributes['planet']

        should_end_session = True
    else:
        speech_output = 'I do not know.'
        should_end_session = False

    reprompt_text = None

    should_end_session = True
    return response_builders.build_response(session_attributes,
        response_builders.build_speechlet_response(card_title,
        speech_output, reprompt_text, should_end_session))
示例#12
0
def update_mode(intent):
    card_title = "Mode"

    mode = intent.get('slots',{}).get('Mode',{}).get('value')

    if mode and mode.upper() in {"STILL", "STATIC", "WAVE"}:
        if mode.upper() == "STILL":
            mode = "STATIC"
        speech_output = "Yes my lord."
        new_value_dict = {"mode":mode.upper()}
        shadow_updater.update_shadow(new_value_dict)
    else:
        speech_output = "I did not understand that. Please repeat your request."

    response = response_builders.build_response(session_attributes,
        response_builders.build_speechlet_response(card_title,
        speech_output, reprompt_text, should_end_session))
    return response
示例#13
0
def store_planet_in_session(intent, session):
    card_title = intent['name']
    session_attributes = session.get('attributes', {})

    if 'Planet' in intent['slots']:
        planet = intent['slots']['Planet']['value']
        session_attributes = {'planet': planet}

        speech_output = "I know where the plans are."
        reprompt_text = None
    else:
        speech_output = "That planet is not in this system, " \
                        "Please try a new planet."
        reprompt_text = "Please try a new planet."

    should_end_session = False

    return response_builders.build_response(session_attributes,
        response_builders.build_speechlet_response(card_title,
        speech_output, reprompt_text, should_end_session))
示例#14
0
def update_brightness(intent):
    """
    Updates brightness of IoT shadow. Builds a response confirming the update
    or requesting the user repeat the query if 0 <= brightness <= 100. If the
    requested brightness is zero, the power state of the shadow will be
    updated to "OFF" and the brightness will not be changed.

    Args:
        intent: Python dict of intent
    Returns:
        Python dict of response message
    """
    card_title = "Brightness"

    brightness = intent.get('slots', {}).get('Brightness', {}).get('value')

    if brightness:
        brightness = int(brightness)
        if brightness > 0 and brightness <= 100:
            speech_output = "Setting brightness to {}.".format(brightness)
            new_value_dict = {"brightness": brightness}
            gateway_connection.update_shadow(new_value_dict)
        elif brightness == 0:
            speech_output = "Turning off."
            new_value_dict = {"power_state": "OFF"}
            gateway_connection.update_shadow(new_value_dict)
        else:
            speech_output = "I'm sorry that value is not in the proper range. "\
                "Please give me a number between 0 and 100."
    else:
        speech_output = "I did not understand that. Please repeat your request."

    response = response_builders.build_response(
        session_attributes,
        response_builders.build_speechlet_response(card_title, speech_output,
                                                   reprompt_text,
                                                   should_end_session))
    return response