Exemplo n.º 1
0
def locativeHandler(request):
  '''
  locativeHandler takes a flask request and updates the
  presence of a device. It retuerns a LocativeMessage.

  The URL of the request has to be:
  https://PUBLIC_ADDRESS/API/locative?ff_device=FF_DEVICE_ID&token=LOCATIVE_TOKEN
  '''
  message = LocativeMessage(request)
  logging.debug('locative: got message from {} presence: {}'.format(message.ffDevice, message.presence))
  if message.presence:
    ffScheduler.cancel(message.jobID)
    ffCommand(message.ffDevice, {'presence': message.presence}, source='Locative Presence API')
  else:
    ffScheduler.runInM(5, delayedUpdatePresence, args=[message], job_id=message.jobID)
  return message
Exemplo n.º 2
0
def apiCommand():
    c = request.get_json(force=True)
    logging.critical(str(c))

    command = c.get("command")
    logging.critical(command)
    device = c.get("device")
    force = c.get("force")
    routine = c.get("routine")
    source = "web: /API/command"

    if routine:
        ffCommand(device, command, routine=routine, force=force, source=source)
    else:
        ffCommand(device, command, source=source)
    # Refresh device views on change on UI
    device_views.refreshViews()
    return "OK"
Exemplo n.º 3
0
def apiCommand():
    c = request.get_json(force=True)
    logging.critical(str(c))

    command = c.get('command')
    logging.critical(command)
    device = c.get('device')
    force = c.get('force')
    routine = c.get('routine')
    source = 'web: /API/command'

    if routine:
        ffCommand(device, command, routine=routine, force=force, source=source)
    else:
        ffCommand(device, command, source=source)
    # Refresh device views on change on UI
    device_views.refreshViews()
    return "OK"
Exemplo n.º 4
0
def echo_change_mode(intent):
  routine_list = getRoutineList()
  mode = intent.get('slots').get('mode').get('value').lower()
  close_matches = difflib.get_close_matches(mode, routine_list)
  
  if len(close_matches) > 0:
    routine = close_matches[0]
    myCommand = ffCommand(routine, None, routine=True, source="Echo command", force=True)
    if myCommand.result:
      return make_response("Changed mode to " + str(routine), "Changed mode to " + str(routine))
  
  return make_response("Error changing mode to " + str(mode), "Error changing mode to " + str(mode), card_title="Firefly Smart Home Error")
Exemplo n.º 5
0
def ifttt_change_mode(request):
    routine_list = getRoutineList()
    mode = request.get('mode').lower()
    if mode is None:
        return False
    close_matches = difflib.get_close_matches(mode, routine_list)
    if len(close_matches) > 0:
        routine = close_matches[0]
        myCommand = ffCommand(routine, None, routine=True,
                              source="IFTTT command", force=True)
        if myCommand.result:
            return True
    return False
Exemplo n.º 6
0
def ifttt_switch(request):
    device_list = getDeviceList()
    device = request.get('device').lower()
    if device is None:
        return False
    state = request.get('state')
    close_matches = difflib.get_close_matches(device, device_list.keys())
    if len(close_matches) > 0:
        device = close_matches[0]
        myCommand = ffCommand(device_list.get(device), {
                              'switch': state}, source="IFTTT command")
        if myCommand.result:
            return True
    return False
Exemplo n.º 7
0
def ifttt_switch(request):
    device_list = getDeviceList()
    device = request.get('device').lower()
    if device is None:
        return False
    state = request.get('state')
    close_matches = difflib.get_close_matches(device, device_list.keys())
    if len(close_matches) > 0:
        device = close_matches[0]
        myCommand = ffCommand(device_list.get(device), {'switch': state},
                              source="IFTTT command")
        if myCommand.result:
            return True
    return False
Exemplo n.º 8
0
def echo_switch(intent):
  device_list = getDeviceList()
  device = intent.get('slots').get('device').get('value').lower()
  state = intent.get('slots').get('state').get('value')
  close_matches = difflib.get_close_matches(device, device_list.keys())
  logging.critical(device_list)
  logging.critical(close_matches)
  if len(close_matches) > 0:
    device = close_matches[0]
    myCommand = ffCommand(device_list.get(device), {'switch':state})
    if myCommand.result:
      return make_response("Turned " + str(device) + " " + str(state), "Turned " + str(device) + " " +  str(state))

  return make_response("Error finding device " + str(device), "Error finding device " + str(device), card_title="Firefly Smart Home Error")
Exemplo n.º 9
0
def echo_dimmer(intent):
  device_list = getDeviceList()
  device = intent.get('slots').get('device').get('value').lower()
  level = int(intent.get('slots').get('level').get('value'))
  close_matches = difflib.get_close_matches(device, device_list.keys())
  if len(close_matches) < 1:
    get_device_list()
    close_matches = difflib.get_close_matches(device, device_list.keys())
  if len(close_matches) > 0:
    device = close_matches[0]
    myCommand = ffCommand(device_list.get(device), {'setLight' : {'level':level}})
    if myCommand.result:
      return make_response("Set " + str(device) + " to " + str(level) + " percent.", "Set " + str(device) + " to " + str(level) + "percent.")

  return make_response("Error finding device " + str(device), "Error finding device " + str(device), card_title="Firefly Smart Home Error")
Exemplo n.º 10
0
def ifttt_change_mode(request):
    routine_list = getRoutineList()
    mode = request.get('mode').lower()
    if mode is None:
        return False
    close_matches = difflib.get_close_matches(mode, routine_list)
    if len(close_matches) > 0:
        routine = close_matches[0]
        myCommand = ffCommand(routine,
                              None,
                              routine=True,
                              source="IFTTT command",
                              force=True)
        if myCommand.result:
            return True
    return False
Exemplo n.º 11
0
def echo_switch(intent):
    device_list = getDeviceList()
    device = intent.get('slots').get('device').get('value').lower()
    state = intent.get('slots').get('state').get('value')
    close_matches = difflib.get_close_matches(device, device_list.keys())
    logging.critical(device_list)
    logging.critical(close_matches)
    if len(close_matches) > 0:
        device = close_matches[0]
        myCommand = ffCommand(device_list.get(device), {'switch': state})
        if myCommand.result:
            return make_response("Turned " + str(device) + " " + str(state),
                                 "Turned " + str(device) + " " + str(state))

    return make_response("Error finding device " + str(device),
                         "Error finding device " + str(device),
                         card_title="Firefly Smart Home Error")
Exemplo n.º 12
0
def echo_change_mode(intent):
    routine_list = getRoutineList()
    mode = intent.get('slots').get('mode').get('value').lower()
    close_matches = difflib.get_close_matches(mode, routine_list)

    if len(close_matches) > 0:
        routine = close_matches[0]
        myCommand = ffCommand(routine,
                              None,
                              routine=True,
                              source="Echo command",
                              force=True)
        if myCommand.result:
            return make_response("Changed mode to " + str(routine),
                                 "Changed mode to " + str(routine))

    return make_response("Error changing mode to " + str(mode),
                         "Error changing mode to " + str(mode),
                         card_title="Firefly Smart Home Error")
Exemplo n.º 13
0
def echo_dimmer(intent):
    device_list = getDeviceList()
    device = intent.get('slots').get('device').get('value').lower()
    level = int(intent.get('slots').get('level').get('value'))
    close_matches = difflib.get_close_matches(device, device_list.keys())
    if len(close_matches) < 1:
        get_device_list()
        close_matches = difflib.get_close_matches(device, device_list.keys())
    if len(close_matches) > 0:
        device = close_matches[0]
        myCommand = ffCommand(device_list.get(device),
                              {'setLight': {
                                  'level': level
                              }})
        if myCommand.result:
            return make_response(
                "Set " + str(device) + " to " + str(level) + " percent.",
                "Set " + str(device) + " to " + str(level) + "percent.")

    return make_response("Error finding device " + str(device),
                         "Error finding device " + str(device),
                         card_title="Firefly Smart Home Error")
Exemplo n.º 14
0
 def send_all(self):
     for device in deviceDB.find({"config.subType": "notification"}):
         dID = device.get('id')
         ffCommand(str(dID), {'notify': {'message': self._message}})
     if config.get_boolean('SPEECH', 'enable'):
         self.send_cast(config.get_item('SPEECH', 'default_device').lower())
Exemplo n.º 15
0
 def send(self):
   notificationEvent = ffCommand(self._deviceID, {'notify': {'message' :self._message}})
Exemplo n.º 16
0
 def send_all(self):
   for device in deviceDB.find({"config.subType":"notification"}):
     dID = device.get('id')
     notificationEvent = ffCommand(str(dID), {'notify': {'message' :self._message}})
Exemplo n.º 17
0
def ha_bridge_off(p_request):
  ffCommand(p_request.get('device'), {'switch': 'off'}, source='HA Bridge')
  return ""
Exemplo n.º 18
0
def ha_bridge_dim(p_request):
  ffCommand(p_request.get('device'), {'setLight' : {'level':p_request.get('level')}}, source='HA Bridge')
  return ""
Exemplo n.º 19
0
 def send(self):
     ffCommand(self._deviceID, {'notify': {'message': self._message}})
Exemplo n.º 20
0
def delayedUpdatePresence(message):
  ffCommand(message.ffDevice, {'presence': message.presence}, source='Locative Presence API')