Exemple #1
0
 def set_sched_disabled_op():
     try:
         sched_disabled_op = request.forms.get('op')
         dispatch(op=DispatchOptions.SCHED_DISABLED_OP,
                  state=state,
                  body=sched_disabled_op)
     except:
         abort(
             400,
             'Invalid sched_disabled_op setting. Expecting wakeup or gotosleep'
         )
Exemple #2
0
 def post_settemp():
     try:
         return dispatch(op=DispatchOptions.SETTEMP,
                         state=state,
                         body=float(request.forms.get('settemp')))
     except:
         abort(400, 'Invalid number for set temp.')
Exemple #3
0
 def set_sleep():
     sleep = request.forms.get('sleep')
     weekday_or_weekend = "weekday" if request.forms.get(
         'weekday') == "True" else "weekend"
     try:
         return dispatch(op=DispatchOptions.SET_SLEEP,
                         state=state,
                         body=[sleep, weekday_or_weekend])
     except:
         abort(400, 'Invalid time format.')
Exemple #4
0
 def set_wake():
     wake = request.forms.get('wake')
     weekday_or_weekend = "weekday" if request.forms.get(
         'weekday') == "True" else "weekend"
     try:
         return dispatch(op=DispatchOptions.SET_WAKE,
                         state=state,
                         body=[wake, weekday_or_weekend])
     except:
         abort(400, 'Invalid time format.')
Exemple #5
0
def get_response_for(message, state, client, conversation_id):
    message_split = message.split(' ')
    message = message.lower()
    if re.match(DispatchOptions.NO_OP.value, message):
        return dispatch(op=DispatchOptions.NO_OP, state=state)
    elif re.match(DispatchOptions.CURR_TEMP.value, message):
        currtemp = dispatch(op=DispatchOptions.CURR_TEMP, state=state)
        return "The current temperature is {} F".format(currtemp)
    elif re.match(DispatchOptions.GET_SETTEMP.value, message):
        settemp = dispatch(op=DispatchOptions.GET_SETTEMP, state=state)
        return "The current target temperature is {} F".format(settemp)
    elif re.match(DispatchOptions.SETTEMP.value, message):
        oldtemp = state['settemp']
        settemp = message_split[1]
        dispatch(op=DispatchOptions.SETTEMP, state=state, body=settemp)
        return "Changed target temp {} -> {} F".format(oldtemp, settemp)
    elif re.match(DispatchOptions.IS_AWAKE.value, message):
        isawake = dispatch(op=DispatchOptions.IS_AWAKE, state=state)
        return "The machine is {}awake".format("" if isawake ==
                                               "True" else "not ")
    elif re.match(DispatchOptions.SCHEDULE.value, message):
        sched_enabled = dispatch(op=DispatchOptions.SCHEDULE,
                                 state=state,
                                 body=message_split[1])
        return "Schedule is now {}abled".format(
            "en" if sched_enabled else "dis")
    elif re.match(DispatchOptions.SCHED_DISABLED_OP.value, message):
        prev_sched_op = state['sched_disabled_op']
        sched_op = dispatch(op=DispatchOptions.SCHED_DISABLED_OP,
                            state=state,
                            body=message_split[1])
        return "Schedule disabled op {} -> {}".format(prev_sched_op, sched_op)
    elif re.match(DispatchOptions.SET_WAKE.value, message):
        wake = message_split[1]
        weekday_or_weekend = message_split[2]
        oldwake = state["{}_wake_time".format(weekday_or_weekend)]
        dispatch(op=DispatchOptions.SET_WAKE,
                 state=state,
                 body=message_split[1:])
        return "{} wake changed {} -> {}".format(weekday_or_weekend, oldwake,
                                                 wake)
    elif re.match(DispatchOptions.SET_SLEEP.value, message):
        sleep_req = message_split[1]
        weekday_or_weekend = message_split[2]
        oldsleep = state["{}_sleep_time".format(weekday_or_weekend)]
        dispatch(op=DispatchOptions.SET_SLEEP,
                 state=state,
                 body=message_split[1:])
        return "{} sleep changed {} -> {}".format(weekday_or_weekend, oldsleep,
                                                  sleep_req)
    elif re.match(DispatchOptions.ALLSTATS.value, message):
        allstats = dispatch(op=DispatchOptions.ALLSTATS, state=state)
        return "All stats: ```{}```".format(allstats)
    elif re.match(DispatchOptions.REBOOT.value, message):
        answer = "Rebooting..."
        response = send_message(message=answer,
                                client=client,
                                conversation_id=conversation_id)
        dispatch(op=DispatchOptions.REBOOT, state=state)
        return
    elif re.match(DispatchOptions.SHUTDOWN.value, message):
        answer = "Shutting down..."
        response = send_message(message=answer,
                                client=client,
                                conversation_id=conversation_id)
        dispatch(op=DispatchOptions.SHUTDOWN, state=state)
        return
    elif re.match(DispatchOptions.HC.value, message):
        ok = dispatch(op=DispatchOptions.HC, state=state)
        return "Everything is {}".format(ok)
    else:
        options = dispatch(op=DispatchOptions.LIST, state=state)
        return "The possible commands are: ```{}```".format(options)
Exemple #6
0
 def healthcheck():
     return dispatch(op=DispatchOptions.HC, state=state)
Exemple #7
0
 def shutdown():
     return dispatch(op=DispatchOptions.SHUTDOWN, state=state)
Exemple #8
0
 def restart():
     return dispatch(op=DispatchOptions.REBOOT, state=state)
Exemple #9
0
 def allstats():
     return dispatch(op=DispatchOptions.ALLSTATS, state=state)
Exemple #10
0
 def set_sched():
     try:
         sched = request.forms.get('scheduler')
         dispatch(op=DispatchOptions.SCHEDULE, state=state, body=sched)
     except:
         abort(400, 'Invalid scheduler setting. Expecting True or False')
Exemple #11
0
 def get_is_awake():
     return dispatch(op=DispatchOptions.IS_AWAKE, state=state)
Exemple #12
0
 def settemp():
     return dispatch(op=DispatchOptions.GET_SETTEMP, state=state)
Exemple #13
0
 def curtemp():
     return dispatch(op=DispatchOptions.CURR_TEMP, state=state)