Esempio n. 1
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)
Esempio n. 2
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)
Esempio n. 3
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)
Esempio n. 4
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
Esempio n. 5
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)
Esempio n. 6
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)
Esempio n. 7
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)