def action_wrapper(hermes, intentMessage, conf):
    """ Write the body of the function that will be executed once the intent is recognized. 
    In your scope, you have the following objects : 
    - intentMessage : an object that represents the recognized intent
    - hermes : an object with methods to communicate with the MQTT bus following the hermes protocol. 
    - conf : a dictionary that holds the skills parameters you defined 
    Refer to the documentation for further details. 
    """     
    url = conf['global']['url']
    try:
        verbose = conf['global']['verbose']
    except:
        verbose = 'False'
        
    dl, pl = common.readcache()
    if dl == [] or pl == []:
        dl = common.retrieveDeviceList(url)
        pl = common.retrieveProgramList(url)
        common.writecache(dl, pl)
    
    try:
        spoken_name = str(intentMessage.slots.Device.first().value).lower()
        spoken_percent = intentMessage.slots.Prozentwert.first().value/100
        if common.changeDeviceState(url, common.getID(dl, spoken_name), spoken_percent):
            if verbose == 'True' or verbose == 'true':
                result_sentence = "Setze " + spoken_name + " auf " + str(spoken_percent*100) + " Prozent." 
            else:
                result_sentence = "OK"
        else:
            result_sentence = "Ich konnte den Namen des Geräts nicht finden!"
    except:
        result_sentence = "Ich habe es nicht verstanden!"
    
    current_session_id = intentMessage.session_id
    hermes.publish_end_session(current_session_id, result_sentence)
Пример #2
0
def action_wrapper(hermes, intentMessage, conf):
    """ Write the body of the function that will be executed once the intent is recognized. 
    In your scope, you have the following objects : 
    - intentMessage : an object that represents the recognized intent
    - hermes : an object with methods to communicate with the MQTT bus following the hermes protocol. 
    - conf : a dictionary that holds the skills parameters you defined 
    Refer to the documentation for further details. 
    """
    url = conf['global']['url']
    try:
        verbose = conf['global']['verbose']
    except:
        verbose = 'False'

    dl, pl = common.readcache()
    if dl == [] or pl == []:
        dl = common.retrieveDeviceList(url)
        pl = common.retrieveProgramList(url)
        common.writecache(dl, pl)

    try:
        spoken_name = common.simplify(
            str(intentMessage.slots.Device.first().value))
        spoken_word = str(intentMessage.slots.Wert.first().value).lower()

        number = -1
        if spoken_word in [
                'hoch', 'auf', 'an', 'herauf', 'rauf', 'up', '1', 'eins',
                '100%', 'angeschaltet', 'öffne', 'öffnen', 'hochfahren'
        ]:
            number = 1
        if spoken_word in [
                'runter', 'zu', 'aus', 'herunter', 'runter', 'down', '0',
                'null', '0%', 'ausgeschaltet', 'schließe', 'schließen',
                'runterfahren', 'herunterfahren'
        ]:
            number = 0

        if number > -1:
            if common.changeDeviceState(url, common.getID(dl, spoken_name),
                                        number):
                if verbose == 'True' or verbose == 'true':
                    if number == 1:
                        result_sentence = "Schalte " + spoken_name + " ein."
                    else:
                        result_sentence = "Schalte " + spoken_name + " aus."
                else:
                    result_sentence = "OK"
            else:
                result_sentence = "Ich konnte den Namen des Geräts nicht finden!"
    except:
        result_sentence = "Ich habe es nicht verstanden!"

    current_session_id = intentMessage.session_id
    hermes.publish_end_session(current_session_id, result_sentence)