예제 #1
0
파일: contact.py 프로젝트: zpriddy/Firefly
  def TurnLightsOff(self):
    from core import ffScheduler
    from core import ffLocation

    if self._disabled:
      logging.critical('Contact Events Disabled')
      return -2

    if self.run_modes:
      if ffLocation.mode not in self.run_modes:
        logging.critical("Not in mode to run")
        return -2

    if self.no_run_modes:
      if ffLocation.mode in self.no_run_modes:
        logging.critical("In no run mode")
        return -2

    if self.lights:
      for light in self.lights:
        ffCommand(light, "off", send_event=self._send_event)

    if self.actions_contact_closed:
      for device, action in self.actions_contact_closed.iteritems():
        ffCommand(device, action, send_event=self._send_event)
        if 'hue' in device:
          sleep(0.5)
예제 #2
0
    def TurnLightsOff(self):
        from core import ffScheduler
        from core import ffLocation

        if self._disabled:
            logging.critical('Switch Events Disabled')
            return -2

        if self.run_modes:
            if ffLocation.mode not in self.run_modes:
                logging.critical("Not in mode to run")
                return -2

        if self.no_run_modes:
            if ffLocation.mode in self.no_run_modes:
                logging.critical("In no run mode")
                return -2

        if self.lights:
            for light in self.lights:
                ffCommand(light, "off", send_event=self._send_event)

        if self.actions_switch_off:
            for device, action in self.actions_switch_off.iteritems():
                ffCommand(device, action, send_event=self._send_event)
                if 'hue' in device:
                    sleep(0.5)
예제 #3
0
 def setOn(self, args={}):
     self._state = True
     ffCommand(self._controller_id,
               {'switch': {
                   'node': self._node,
                   'on': True
               }})
예제 #4
0
  def TurnLightsOff(self):
    if self._disabled:
      logging.critical('Motion Events Disabled')
      return -2

    for light in self.lights:
      ffCommand(light, "off")
예제 #5
0
def manual_command(request):
  device_names = {}
  for d in deviceDB.find({},{"config.name":1,"id":1}):
    device_names[d.get('config').get('name')] = d.get('id')
  
  device_list = ''
  for name, did in device_names.iteritems():
    device_list += str(name) + '  -  ' + str(did) + '<br>'

  form = '''
    <html>
    <h1>Manual Command</h1>
    <br>
    <form action="manual_command" method="POST" id="command">
    <textarea form ="command" name="myCommand" id="myCommand" rows="6" cols="70" wrap="soft"></textarea>
    <input type="submit">
    </form>
    Sample Commands <br>
    <a href='?myCommand={"device":"hue-light-8", "command":{"switch":"on"}}'>{"device":"hue-light-8", "command":{"switch":"on"}}</a> <br>
    <a href='?myCommand={"device":"hue-light-8", "command":{"switch":"off"}}'>{"device":"hue-light-8", "command":{"switch":"off"}}</a> <br>
    <a href='?myCommand={"device":"ZachPushover", "command":{"notify":{"message":"New Test Message"}}}'>{"device":"ZachPushover", "command":{"notify":{"message":"New Test Message"}}}</a> <br>
    <a href='?myCommand={"device":"ZachPresence", "command":{"presence":true}}'>{"device":"ZachPresence", "command":{"presence":true}}</a> <br>
    <a href='?myCommand={"device":"ZachPresence", "command":{"presence":false}}'>{"device":"ZachPresence", "command":{"presence":false}}</a> <br>
    <a href='?myCommand={"device":"hue-group-4", "command":{"setLight":{"preset":"cloudy", "transitiontime":40,"effect":"none","level":100,"alert":"lselect"}}}'>{"device":"hue-group-4", "command":{"setLight":{"preset":"cloudy", "transitiontime":40,"effect":"none","level":100,"alert":"lselect"}}}</a> <br>
    <br>
    <a href='?myCommand={"device":"hue-light-3", "command":{"setLight":{"effect":"colorloop","level":50}}}'>{"device":"hue-light-3", "command":{"setLight":{"effect":"colorloop","level":50}}}</a><br>
    <a href='?myCommand={"device":"hue-light-3", "command":{"setLight":{"effect":"none","level":50}}}'>{"device":"hue-light-3", "command":{"setLight":{"effect":"none","level":50}}}</a><br>
    <a href='?myCommand={"device":"hue-light-3", "command":{"switch":"on"}}'>{"device":"hue-light-3", "command":{"switch":"on"}}</a> <br>
    <a href='?myCommand={"device":"hue-light-3", "command":{"switch":"off"}}'>{"device":"hue-light-3", "command":{"switch":"off"}}</a> <br>
    <a href='?myCommand={"device":"hue-light-3", "command":{"setLight":{"name":"red","level":100}}}'>{"device":"hue-light-3", "command":{"setLight":{"name":"red","level":100}}}</a><br>
    <a href='?myCommand={"device":"hue-light-3", "command":{"setLight":{"name":"blue","level":100}}}'>{"device":"hue-light-3", "command":{"setLight":{"name":"blue","level":100}}}</a><br>
    <a href='?myCommand={"device":"hue-group-4", "command":{"ctfade":{"startK":6500, "endK":2700, "fadeS":900}}}'>{"device":"hue-group-4", "command":{"ctfade":{"startK":6500, "endK":2700, "fadeS":900}}}</a>

    <br>
    <br>
    <a href='?myCommand={"device":"home","routine":true, "force":true}'>{"device":"home","routine":true, "force":true}</a> <br>
    <a href='?myCommand={"device":"home-daylight","routine":true, "force":true}'>{"device":"home-daylight","routine":true, "force":true}</a> <br>
    <a href='?myCommand={"device":"night","routine":true, "force":true}'>{"device":"night","routine":true, "force":true}</a> <br>
    <a href='?myCommand={"device":"away","routine":true, "force":true}'>{"device":"away","routine":true, "force":true}</a> <br>
    <a href='?myCommand={"device":"sexy","routine":true, "force":true}'>{"device":"sexy","routine":true, "force":true}</a> <br>
    <a href='?myCommand={"device":"morning","routine":true, "force":true}'>{"device":"morning","routine":true, "force":true}</a> <br>
    <a href='?myCommand={"device":"sunset","routine":true, "force":true}'>{"device":"sunset","routine":true, "force":true}</a> <br>
    <br>
    <a href="http://www.w3schools.com/colors/colors_hex.asp"> Color Names </a><br>
    <br>
    Devices:<br>''' + device_list + '''
    </html>
    '''
  if request.method == 'POST' or request.args.get('myCommand'):
    try:
      command = json.loads(request.args.get('myCommand')[0])
      if command.get('routine'):
        myCommand = ffCommand(command.get('device'),command.get('command'), routine=command.get('routine'), force=command.get('force'), source='Web: Manual Command').result
      else:
        myCommand = ffCommand(command.get('device'),command.get('command'), source='Web: Manual Command').result
      return form + '<br><br> Last Command: ' + str(request.args.get('myCommand')[0])  + 'Sucessfully sent to device: ' + str(myCommand)
    except ValueError:
      return form + '<br><br>Last Command Failed - INVALID JSON FORMAT ' + str(request.args.get('myCommand')[0])
  else:
    return form + str(request.args)
예제 #6
0
 def runFade(self):
     if self._run:
         if self._startLevel and self._endLevel:
             lightCommand = ffCommand(
                 self._deviceID, {
                     'setLight': {
                         'ct': str(self._currentK) + 'K',
                         'transitiontime': self._delay * 10,
                         'level': self._currnetL,
                         'ctfade': True
                     }
                 })
             self._currnetL += self._lStep
         else:
             lightCommand = ffCommand(
                 self._deviceID, {
                     'setLight': {
                         'ct': str(self._currentK) + 'K',
                         'transitiontime': self._delay * 10,
                         'ctfade': True
                     }
                 })
         if self._timeRemaining > 0:
             ffScheduler.runInS(int(self._delay),
                                self.runFade,
                                replace=True,
                                job_id=self._deviceID)
         self._currentK -= self._step
         self._timeRemaining -= self._delay
예제 #7
0
 def setOff(self, args={}):
     self._state = False
     ffCommand(self._controller_id,
               {'switch': {
                   'node': self._node,
                   'on': False
               }})
    def TurnLightsOff(self):
        if self._disabled:
            logging.critical('Motion Events Disabled')
            return -2

        for light in self.lights:
            ffCommand(light, "off")
예제 #9
0
 def set_light(self, value):
     logging.critical("SET_LIGHT")
     ffCommand(self._bridge, {
         'sendLightCommand': {
             'lightCommand': value,
             'lightID': self._light_id
         }
     })
예제 #10
0
파일: ffHue.py 프로젝트: zpriddy/Firefly
  def refresh_hue(self):
    rawLightData = self._hueBridge.get_lights()
    for light, lightData in rawLightData.iteritems():
      deviceID = 'hue-light-' + str(light)
      updateEvent =ffCommand(deviceID,{'update':lightData})

    rawGroupData = self._hueBridge.get_groups()
    for group, groupData in rawGroupData.iteritems():
      deviceID = 'hue-group-' + str(group)
      updateEvent = ffCommand(deviceID,{'update':groupData})
예제 #11
0
파일: ctFade.py 프로젝트: zpriddy/Firefly
 def runFade(self):
   if self._run:
     if self._startLevel and self._endLevel:
       lightCommand = ffCommand(self._deviceID, {'setLight':{'ct':str(self._currentK)+'K','transitiontime':self._delay*10,'level':self._currnetL, 'ctfade':True}})
       self._currnetL += self._lStep
     else:
       lightCommand = ffCommand(self._deviceID, {'setLight':{'ct':str(self._currentK)+'K','transitiontime':self._delay*10, 'ctfade':True}})
     if self._timeRemaining > 0:
       ffScheduler.runInS(int(self._delay), self.runFade, replace=True, job_id=self._deviceID)
     self._currentK -= self._step
     self._timeRemaining -= self._delay
예제 #12
0
    def sensorHandler(self, event={}):
        from core import ffScheduler
        from core import ffLocation

        logging.critical("ENTERNING LUX HANDELER")

        lux = int(event.event.get('luminance')) if event.event.get(
            'luminance') is not None else None
        if lux is None or lux == '':
            return -2
        logging.critical('LUX: ' + str(lux))
        change_value = self.lux_level

        if self._disabled:
            logging.critical('Lux Events Disabled')
            return -2

        if self.run_modes:
            if ffLocation.mode not in self.run_modes:
                logging.critical("Not in mode to run")
                return -2

        if self.no_run_modes:
            if ffLocation.mode in self.no_run_modes:
                logging.critical("In no run mode")
                return -2

        if self.run_dark is not None:
            if not ffLocation.isDark:
                logging.critical("Not running because is dark")
                retunr - 2

        if self.run_light is not None:
            if not ffLocation.isLight:
                logging.critical("Not running because is light")
                return -2

        if lux <= change_value:
            if self.lights:
                for light in self.lights:
                    ffCommand(light, "on", send_event=self._send_event)
            if self.actions_lux_low:
                for device, action in self.actions_lux_low.iteritems():
                    ffCommand(device, action, send_event=self._send_event)
            ffScheduler.cancel(self._id)

        if lux > change_value:
            if self.delay_time is None:
                self.TurnLightsOff()
            else:
                ffScheduler.runInM(self.delay_time,
                                   self.TurnLightsOff,
                                   replace=True,
                                   job_id=self._id)
예제 #13
0
    def switchHandler(self, event={}):
        from core import ffScheduler
        from core import ffLocation

        if self._disabled:
            logging.critical('Switch Events Disabled')
            return -2

        if self.run_modes:
            if ffLocation.mode not in self.run_modes:
                logging.critical("Not in mode to run")
                return -2

        if self.no_run_modes:
            if ffLocation.mode in self.no_run_modes:
                logging.critical("In no run mode")
                return -2

        if self.run_dark is not None:
            if not ffLocation.isDark:
                logging.critical("Not running because is dark")
                return -2

        if self.run_light is not None:
            if not ffLocation.isLight:
                logging.critical("Not running because is light")
                return -2

        if event.event.get('on'):
            if self.lights:
                for light in self.lights:
                    ffCommand(light, "on", send_event=self._send_event)
            if self.actions_switch_on:
                for device, action in self.actions_switch_on.iteritems():
                    ffCommand(device, action, send_event=self._send_event)
            ffScheduler.cancel(self._id)
            #Hack to be fixed soon
            if self.actions_switch_on_delayed:
                ffScheduler.cancel(self._id + "delayed")
                ffScheduler.runInM(self.delay_time,
                                   self.SwitchOnDelayed,
                                   replace=True,
                                   job_id=self._id + "delayed")

        if not event.event.get('on'):
            if self.delay_time is None:
                self.TurnLightsOff()
            else:
                ffScheduler.runInM(self.delay_time,
                                   self.TurnLightsOff,
                                   replace=True,
                                   job_id=self._id)
예제 #14
0
파일: lux.py 프로젝트: zpriddy/Firefly
  def sensorHandler(self, event={}):
    from core import ffScheduler
    from core import ffLocation

    logging.critical("ENTERNING LUX HANDELER")

    lux = int(event.event.get('luminance')) if event.event.get('luminance') is not None else None
    if lux is None or lux == '':
      return -2
    logging.critical('LUX: ' + str(lux))
    change_value = self.lux_level


    if self._disabled:
      logging.critical('Lux Events Disabled')
      return -2

    if self.run_modes:
      if ffLocation.mode not in self.run_modes:
        logging.critical("Not in mode to run")
        return -2

    if self.no_run_modes:
      if ffLocation.mode in self.no_run_modes:
        logging.critical("In no run mode")
        return -2

    if self.run_dark is not None:
      if not ffLocation.isDark:
        logging.critical("Not running because is dark")
        retunr -2

    if self.run_light is not None:
      if not ffLocation.isLight: 
        logging.critical("Not running because is light")
        return -2 

    if lux <= change_value:
      if self.lights:
        for light in self.lights:
          ffCommand(light,"on", send_event=self._send_event)
      if self.actions_lux_low:
        for device, action in self.actions_lux_low.iteritems():
          ffCommand(device, action, send_event=self._send_event)
      ffScheduler.cancel(self._id)

    if lux > change_value:
      if self.delay_time is None:
        self.TurnLightsOff()
      else:
        ffScheduler.runInM(self.delay_time, self.TurnLightsOff, replace=True, job_id=self._id)
예제 #15
0
def api_control(request):
  request.setHeader('Content-Type', 'application/json')
  body = json.loads(request.content.read())
  device =  body.get('device')
  command = body.get('command')
  result = ffCommand(device,command)
  return json.dumps({'action':'recieved'})
예제 #16
0
def api_control(request):
    request.setHeader('Content-Type', 'application/json')
    body = json.loads(request.content.read())
    device = body.get('device')
    command = body.get('command')
    result = ffCommand(device, command)
    return json.dumps({'action': 'recieved'})
예제 #17
0
 def set_light(self, value):
     light_id = self._light_id
     lightCommand = ffCommand(
         self._bridge,
         {'sendLightRequest': {
             'lightID': light_id,
             'data': value
         }})
예제 #18
0
    def motionHandeler(self, event={}):
        logging.critical('Motion Handeler!!!##')
        from core import ffScheduler
        from core import ffLocation

        logging.critical('Entered Motion Handeler')

        if self._disabled:
            logging.critical('Motion Events Disabled')
            return -2

        if self.run_modes:
            if ffLocation.mode not in self.run_modes:
                logging.critical("Not in mode to run")
                return -2

        if self.no_run_modes:
            if ffLocation.mode in self.no_run_modes:
                logging.critical("In no run mode")
                return -2

        if self.run_dark is not None:
            if not ffLocation.isDark:
                logging.critical("Not running because is dark")
                return -2

        if self.run_light is not None:
            if not ffLocation.isLight:
                logging.critical("Not running because is light")
                return -2

        if event.event.get('motion'):
            for light in self.lights:
                ffCommand(light, "on", send_event=self._send_event)
            for device, action in self.actions_on_motion_active.iteritems():
                ffCommand(device, action, send_event=self._send_event)
            ffScheduler.cancel(self._id)

        if not event.event.get('motion'):
            if self.delay_time is None:
                self.TurnLightsOff()
            else:
                ffScheduler.runInM(self.delay_time,
                                   self.TurnLightsOff,
                                   replace=True,
                                   job_id=self._id)
예제 #19
0
파일: switch.py 프로젝트: zpriddy/Firefly
  def switchHandler(self, event={}):
    from core import ffScheduler
    from core import ffLocation

    if self._disabled:
      logging.critical('Switch Events Disabled')
      return -2

    if self.run_modes:
      if ffLocation.mode not in self.run_modes:
        logging.critical("Not in mode to run")
        return -2

    if self.no_run_modes:
      if ffLocation.mode in self.no_run_modes:
        logging.critical("In no run mode")
        return -2

    if self.run_dark is not None:
      if not ffLocation.isDark:
        logging.critical("Not running because is dark")
        return -2

    if self.run_light is not None:
      if not ffLocation.isLight:
        logging.critical("Not running because is light")
        return -2 

    if event.event.get('on'):
      if self.lights:
        for light in self.lights:
          ffCommand(light,"on", send_event=self._send_event)
      if self.actions_switch_on:
        for device, action in self.actions_switch_on.iteritems():
          ffCommand(device, action, send_event=self._send_event)
      ffScheduler.cancel(self._id)
      #Hack to be fixed soon
      if self.actions_switch_on_delayed:
        ffScheduler.cancel(self._id+"delayed")
        ffScheduler.runInM(self.delay_time, self.SwitchOnDelayed, replace=True, job_id=self._id+"delayed")

    if not event.event.get('on'):
      if self.delay_time is None:
        self.TurnLightsOff()
      else:
        ffScheduler.runInM(self.delay_time, self.TurnLightsOff, replace=True, job_id=self._id)
예제 #20
0
파일: motion.py 프로젝트: zpriddy/Firefly
  def motionHandeler(self, event={}):
    logging.critical('Motion Handeler!!!##')
    from core import ffScheduler
    from core import ffLocation

    logging.critical('Entered Motion Handeler')

    if self._disabled:
      logging.critical('Motion Events Disabled')
      return -2

    if self.run_modes:
      if ffLocation.mode not in self.run_modes:
        logging.critical("Not in mode to run")
        return -2

    if self.no_run_modes:
      if ffLocation.mode in self.no_run_modes:
        logging.critical("In no run mode")
        return -2

    if self.run_dark is not None:
      if not ffLocation.isDark:
        logging.critical("Not running because is dark")
        return -2

    if self.run_light is not None:
      if not ffLocation.isLight:
        logging.critical("Not running because is light")
        return -2 

    if event.event.get('motion'):
      for light in self.lights:
        ffCommand(light,"on", send_event=self._send_event)
      for device, action in self.actions_on_motion_active.iteritems():
        ffCommand(device, action, send_event=self._send_event)
      ffScheduler.cancel(self._id)

    if not event.event.get('motion'):
      if self.delay_time is None:
        self.TurnLightsOff()
      else:
        ffScheduler.runInM(self.delay_time, self.TurnLightsOff, replace=True, job_id=self._id)
예제 #21
0
  def get_all_node_data(self, args={}):
    if self._network is None:
      ffEvent(self._id,{'zwave':'network_not_ready'})
      #logging.critical('Zwave not ready')
      return 1

    returnData = {}
    for node in self._network.nodes:
      nodeData = {}
      nodeData['node'] = node
      nodeData['manufacturer_name'] = self._network.nodes[node].manufacturer_name
      nodeData['product_name'] = self._network.nodes[node].product_name
      nodeData['product_id'] = self._network.nodes[node].product_id
      nodeData['product_type'] = self._network.nodes[node].product_type
      nodeData['device_type'] = self._network.nodes[node].device_type
      nodeData['command_classes_as_string'] = self._network.nodes[node].command_classes_as_string
      nodeData['ready'] = self._network.nodes[node].is_ready
      nodeData['failed'] = self._network.nodes[node].is_failed
      now = time()
      if self._lastNodeUpdate.get(node) is None or int(self._lastNodeUpdate.get(node) - now) > 1:
        for val in self._network.nodes[node].get_switches():
          self._network.nodes[node].refresh_value(val)
          self._lastNodeUpdate[node] = now
          sleep(1)
      dataValues = {}
      for a,b in self._network.nodes[node].values_to_dict().iteritems():
        dataValues[b['label']] = b

      nodeData['data'] = dataValues
      returnData['node-'+str(node)] = nodeData
      
    if self._oldData == returnData:
      logging.debug('Zwave No Change')
    else:
      chnageData = {}
      for oA, oB in self._oldData.iteritems():
        if oB != returnData[oA]:
          chnageData[oA] = returnData[oA]
          #logging.critical(str(returnData[oA]))
          ffCommand('zwave-' + str(oA), {'update' : returnData[oA]}, source='ffZwave')
      self._oldData = returnData
예제 #22
0
def echo_change_mode(intent):
  global routine_list
  mode = intent.get('slots').get('mode').get('value').lower()
  close_matches = difflib.get_close_matches(mode, routine_list)
  if len(close_matches) < 1:
    get_routines_list()
    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")
예제 #23
0
def echo_dimmer(intent):
  global device_list
  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")
예제 #24
0
def ifttt_change_mode(request):
  global routine_list
  mode = request.get('mode').lower()
  if mode is None:
    return False
  close_matches = difflib.get_close_matches(mode, routine_list)
  if len(close_matches) < 1:
    get_routines_list()
    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 True
  return False
예제 #25
0
def echo_switch(intent):
  global device_list
  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) < 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), {'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")
예제 #26
0
def ifttt_switch(request):
  global device_list
  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())
  logging.critical(device_list)
  logging.critical(close_matches)
  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), {'switch':state})
    if myCommand.result:
      return True
  return False
예제 #27
0
def ifttt_switch(request):
    global device_list
    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())
    logging.critical(device_list)
    logging.critical(close_matches)
    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), {'switch': state})
        if myCommand.result:
            return True
    return False
예제 #28
0
def ifttt_change_mode(request):
    global routine_list
    mode = request.get('mode').lower()
    if mode is None:
        return False
    close_matches = difflib.get_close_matches(mode, routine_list)
    if len(close_matches) < 1:
        get_routines_list()
        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 True
    return False
예제 #29
0
def echo_switch(intent):
    global device_list
    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) < 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), {'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")
예제 #30
0
def echo_change_mode(intent):
    global routine_list
    mode = intent.get('slots').get('mode').get('value').lower()
    close_matches = difflib.get_close_matches(mode, routine_list)
    if len(close_matches) < 1:
        get_routines_list()
        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")
예제 #31
0
def echo_dimmer(intent):
    global device_list
    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")
예제 #32
0
 def setOn(self, args={}):
   self._state = True
   ffCommand(self._controller_id,{'switch' : {'node':self._node, 'on':True}})
예제 #33
0
 def set_light(self, value):
   light_id = self._light_id
   lightCommand = ffCommand(self._bridge,{'sendLightRequest' : {'lightID':light_id,'data':value}})
예제 #34
0
 def set_light(self, value):
   logging.critical("SET_LIGHT")
   ffCommand(self._bridge, {'sendLightCommand':{'lightCommand':value,'lightID': self._light_id}})
예제 #35
0
 def setOff(self, args={}):
   self._state = False
   ffCommand(self._controller_id,{'switch' : {'node':self._node, 'on':False}})
예제 #36
0
def manual_command(request):
    device_names = {}
    for d in deviceDB.find({}, {"config.name": 1, "id": 1}):
        device_names[d.get('config').get('name')] = d.get('id')

    device_list = ''
    for name, did in device_names.iteritems():
        device_list += str(name) + '  -  ' + str(did) + '<br>'

    form = '''
    <html>
    <h1>Manual Command</h1>
    <br>
    <form action="manual_command" method="POST" id="command">
    <textarea form ="command" name="myCommand" id="myCommand" rows="6" cols="70" wrap="soft"></textarea>
    <input type="submit">
    </form>
    Sample Commands <br>
    <a href='?myCommand={"device":"hue-light-8", "command":{"switch":"on"}}'>{"device":"hue-light-8", "command":{"switch":"on"}}</a> <br>
    <a href='?myCommand={"device":"hue-light-8", "command":{"switch":"off"}}'>{"device":"hue-light-8", "command":{"switch":"off"}}</a> <br>
    <a href='?myCommand={"device":"ZachPushover", "command":{"notify":{"message":"New Test Message"}}}'>{"device":"ZachPushover", "command":{"notify":{"message":"New Test Message"}}}</a> <br>
    <a href='?myCommand={"device":"ZachPresence", "command":{"presence":true}}'>{"device":"ZachPresence", "command":{"presence":true}}</a> <br>
    <a href='?myCommand={"device":"ZachPresence", "command":{"presence":false}}'>{"device":"ZachPresence", "command":{"presence":false}}</a> <br>
    <a href='?myCommand={"device":"hue-group-4", "command":{"setLight":{"preset":"cloudy", "transitiontime":40,"effect":"none","level":100,"alert":"lselect"}}}'>{"device":"hue-group-4", "command":{"setLight":{"preset":"cloudy", "transitiontime":40,"effect":"none","level":100,"alert":"lselect"}}}</a> <br>
    <br>
    <a href='?myCommand={"device":"hue-light-3", "command":{"setLight":{"effect":"colorloop","level":50}}}'>{"device":"hue-light-3", "command":{"setLight":{"effect":"colorloop","level":50}}}</a><br>
    <a href='?myCommand={"device":"hue-light-3", "command":{"setLight":{"effect":"none","level":50}}}'>{"device":"hue-light-3", "command":{"setLight":{"effect":"none","level":50}}}</a><br>
    <a href='?myCommand={"device":"hue-light-3", "command":{"switch":"on"}}'>{"device":"hue-light-3", "command":{"switch":"on"}}</a> <br>
    <a href='?myCommand={"device":"hue-light-3", "command":{"switch":"off"}}'>{"device":"hue-light-3", "command":{"switch":"off"}}</a> <br>
    <a href='?myCommand={"device":"hue-light-3", "command":{"setLight":{"name":"red","level":100}}}'>{"device":"hue-light-3", "command":{"setLight":{"name":"red","level":100}}}</a><br>
    <a href='?myCommand={"device":"hue-light-3", "command":{"setLight":{"name":"blue","level":100}}}'>{"device":"hue-light-3", "command":{"setLight":{"name":"blue","level":100}}}</a><br>
    <a href='?myCommand={"device":"hue-group-4", "command":{"ctfade":{"startK":6500, "endK":2700, "fadeS":900}}}'>{"device":"hue-group-4", "command":{"ctfade":{"startK":6500, "endK":2700, "fadeS":900}}}</a>

    <br>
    <br>
    <a href='?myCommand={"device":"home","routine":true, "force":true}'>{"device":"home","routine":true, "force":true}</a> <br>
    <a href='?myCommand={"device":"home-daylight","routine":true, "force":true}'>{"device":"home-daylight","routine":true, "force":true}</a> <br>
    <a href='?myCommand={"device":"night","routine":true, "force":true}'>{"device":"night","routine":true, "force":true}</a> <br>
    <a href='?myCommand={"device":"away","routine":true, "force":true}'>{"device":"away","routine":true, "force":true}</a> <br>
    <a href='?myCommand={"device":"sexy","routine":true, "force":true}'>{"device":"sexy","routine":true, "force":true}</a> <br>
    <a href='?myCommand={"device":"morning","routine":true, "force":true}'>{"device":"morning","routine":true, "force":true}</a> <br>
    <a href='?myCommand={"device":"sunset","routine":true, "force":true}'>{"device":"sunset","routine":true, "force":true}</a> <br>
    <br>
    <a href="http://www.w3schools.com/colors/colors_hex.asp"> Color Names </a><br>
    <br>
    Devices:<br>''' + device_list + '''
    </html>
    '''
    if request.method == 'POST' or request.args.get('myCommand'):
        try:
            command = json.loads(request.args.get('myCommand')[0])
            if command.get('routine'):
                myCommand = ffCommand(command.get('device'),
                                      command.get('command'),
                                      routine=command.get('routine'),
                                      force=command.get('force'),
                                      source='Web: Manual Command').result
            else:
                myCommand = ffCommand(command.get('device'),
                                      command.get('command'),
                                      source='Web: Manual Command').result
            return form + '<br><br> Last Command: ' + str(
                request.args.get('myCommand')
                [0]) + 'Sucessfully sent to device: ' + str(myCommand)
        except ValueError:
            return form + '<br><br>Last Command Failed - INVALID JSON FORMAT ' + str(
                request.args.get('myCommand')[0])
    else:
        return form + str(request.args)
예제 #37
0
파일: switch.py 프로젝트: zpriddy/Firefly
 def SwitchOnDelayed(self):
   if self.actions_switch_on_delayed:
     for device, action in self.actions_switch_on_delayed.iteritems():
       ffCommand(device, action, send_event=self._send_event)
       if 'hue' in device:
         sleep(0.5)
예제 #38
0
 def SwitchOnDelayed(self):
     if self.actions_switch_on_delayed:
         for device, action in self.actions_switch_on_delayed.iteritems():
             ffCommand(device, action, send_event=self._send_event)
             if 'hue' in device:
                 sleep(0.5)
예제 #39
0
파일: routine.py 프로젝트: zpriddy/Firefly
  def executeRoutine(self, force=False):
    from time import sleep
    from datetime import datetime, time
    from core import ffLocation
    from core.utils.notify import Notification as ffNotification
    logging.debug("Executing Routine: " + self._name)

    if not force:
      if self._mode_no_run:
        if ffLocation.mode in self._mode_no_run:
          logging.debug(
              'Returning: Set to not execute in mode: ' + ffLocation.mode)
          return

      if self._mode_run:
        if ffLocation.mode not in self._mode_run:
          logging.debug(
              'Returning: Set to not execute in mode: ' + ffLocation.mode)
          return

      if self._run_time_ranges or self._no_run_time_ranges:
        now = datetime.now().time()
        if self._run_time_ranges:
          for timeRange in self._run_time_ranges:
            startH, startM = timeRange.get('start_time').split(':')
            startH = int(startH)
            startM = int(startM)
            endH, endM = timeRange.get('end_time').split(':')
            endH = int(endH)
            endM = int(endM)
            if startH <= endH:
              if not (now >= time(startH, startM) and now <= time(endH, endM)):
                logging.critical("Not in time range to run routine")
                return
            else:
              if not (now >= time(startH, startM) or now <= time(endH, endM)):
                logging.critical("Not in time range to run routine")
                return

        if self._no_run_time_ranges:
          for timeRange in self._no_run_time_ranges:
            startH, startM = timeRange.get('start_time').split(':')
            startH = int(startH)
            startM = int(startM)
            endH, endM = timeRange.get('end_time').split(':')
            endH = int(endH)
            endM = int(endM)
            logging.critical(str(startH) + ' ' + str(endH))
            if startH <= endH:
              if now >= time(startH, startM) and now <= time(endH, endM):
                logging.critical("In time range to not run routine")
                return
            else:
              if now >= time(startH, startM) or now <= time(endH, endM):
                logging.critical("In time range to not run routine")
                return

    for device, commands in self._actions.iteritems():
      ffCommand(device, commands)
      if 'hue' in device:
        sleep(0.5)

    if ffLocation:
      if ffLocation.isLightOffset(sunrise_offset=self._sunrise_offset):
        for device, commands in self._actions_day.iteritems():
          ffCommand(device, commands)
          if 'hue' in device:
            sleep(0.5)

      elif ffLocation.isDark:
        for device, commands in self._actions_night.iteritems():
          ffCommand(device, commands)
          if 'hue' in device:
            sleep(0.5)

    if self._mode:
      ffLocation.mode = self._mode

    if self._notification_devices and self._notification_message:
      for device in self._notification_devices:
        ffNotification(device, self._notification_message)
예제 #40
0
 def set_group(self, value):
   group_id = self._group_id
   groupCommand = ffCommand(self._bridge,{'sendGroupRequest' : {'groupID':group_id,'data':value}})
예제 #41
0
def auto_refresh():
    refresh_command = ffCommand('nest', 'update', source='NEST-UPDATER')
예제 #42
0
def auto_refresh():
  refresh_command = ffCommand('nest', 'update', source='NEST-UPDATER')