Ejemplo n.º 1
0
def send_notification(deviceID, message, priority=0):
  if deviceID == 'all':
    for device in deviceDB.find({"config.subType":"notification"}):
      dID = device.get('id')
      notificationEvent = ffEvent(str(dID), {'notify': {'message' :message}})
  else:
    notificationEvent = ffEvent(deviceID, {'notify': {'message' :message}})
Ejemplo n.º 2
0
  def startup_zwave(self, args={}):
    ffEvent(self._id,{'zwave':'starting_up'})
    zwaveSetup = ZWaveOption(self._port, self._configFile)
    zwaveSetup.set_console_output(False)
    zwaveSetup.lock()
    network = ZWaveNetwork(zwaveSetup, autostart=False)
    network.start()

    stdout.write("Waking up Zwave (This can take up to 5 minutes)")
    for i in xrange(3):
      if network.state >= network.STATE_AWAKED:
        logging.info('Zwave Network Awake')
        break
      else:
        stdout.write(".")
        stdout.flush()
        sleep(1)

    for x in xrange(3):
      if network.state >= network.STATE_READY:
        ffEvent(self._id,{'zwave':'network_ready'})
      else:
        stdout.write(".")
        stdout.flush()
        sleep(.5)

    return network
Ejemplo n.º 3
0
 def noon_handler(self):
   ffNotify('ZachPushover', 'LOCATION: It is noon!')
   ffEvent('location',{'time':'noon'})
   now = self.now()
   noon_time = self._city.sun(date=datetime.now(self._city.tz) + timedelta(days=1), local=True)['noon']
   logging.debug("Noon Time: " + str(noon_time))
   delay_s = (noon_time - now).total_seconds()
   l_scheduler.runInS(delay_s, self.noon_handler, replace=True, uuid='NoonScheduler')
Ejemplo n.º 4
0
 def mode(self, value):
     value = str(value)
     if value in self._modes:
         self._last_mode = self._mode
         self._mode = value
         ffEvent('location', {'mode': self._mode})
         return True
     return False
Ejemplo n.º 5
0
 def dusk_handler(self):
   ffNotify('ZachPushover', 'LOCATION: It is dusk!')
   ffEvent('location',{'time':'dusk'})
   now = self.now()
   dusk_time = self._city.sun(date=datetime.now(self._city.tz) + timedelta(days=1), local=True)['dusk']
   logging.debug("Dusk Time: " + str(dusk_time))
   delay_s = (dusk_time - now).total_seconds()
   l_scheduler.runInS(delay_s, self.dusk_handler, replace=True, uuid='DuskScheduler')
Ejemplo n.º 6
0
 def mode(self, value):
   value = str(value)
   if value in self._modes:
     self._last_mode = self._mode
     self._mode = value
     ffEvent('location',{'mode':self._mode})
     return True
   return False
Ejemplo n.º 7
0
 def sunset_handler(self):
   ffNotify('ZachPushover', 'LOCATION: It is sunset!')
   ffEvent('location',{'time':'sunset'})
   now = self.now()
   sunset_time = self._city.sun(date=datetime.now(self._city.tz) + timedelta(days=1), local=True)['sunset']
   logging.debug("Sunset Time: " + str(sunset_time))
   delay_s = (sunset_time - now).total_seconds()
   l_scheduler.runInS(delay_s, self.sunset_handler, replace=True, uuid='SunsetScheduler')
Ejemplo n.º 8
0
def send_notification(deviceID, message, priority=0):
    if deviceID == 'all':
        for device in deviceDB.find({"config.subType": "notification"}):
            dID = device.get('id')
            notificationEvent = ffEvent(str(dID),
                                        {'notify': {
                                            'message': message
                                        }})
    else:
        notificationEvent = ffEvent(deviceID, {'notify': {'message': message}})
Ejemplo n.º 9
0
 def sunset_handler(self):
     ffNotify('ZachPushover', 'LOCATION: It is sunset!')
     ffEvent('location', {'time': 'sunset'})
     now = self.now()
     sunset_time = self._city.sun(date=datetime.now(self._city.tz) +
                                  timedelta(days=1),
                                  local=True)['sunset']
     logging.debug("Sunset Time: " + str(sunset_time))
     delay_s = (sunset_time - now).total_seconds()
     l_scheduler.runInS(delay_s,
                        self.sunset_handler,
                        replace=True,
                        uuid='SunsetScheduler')
Ejemplo n.º 10
0
 def noon_handler(self):
     ffNotify('ZachPushover', 'LOCATION: It is noon!')
     ffEvent('location', {'time': 'noon'})
     now = self.now()
     noon_time = self._city.sun(date=datetime.now(self._city.tz) +
                                timedelta(days=1),
                                local=True)['noon']
     logging.debug("Noon Time: " + str(noon_time))
     delay_s = (noon_time - now).total_seconds()
     l_scheduler.runInS(delay_s,
                        self.noon_handler,
                        replace=True,
                        uuid='NoonScheduler')
Ejemplo n.º 11
0
 def sendCommand(self, command):
   simpleCommand = None
   logging.debug('Reciving Command in ' + str(metadata.get('module')) + ' ' + str(command))
   if command.deviceID == self._id:
     for item, value in command.command.iteritems():
       if item in self._commands:
         simpleCommand = self._commands[item](value)
   
     ## OPTIONAL - SEND EVENT
     if command.simple:
       ffEvent(command.deviceID, simpleCommand)
     else:
       ffEvent(command.deviceID, command.command)
Ejemplo n.º 12
0
 def dusk_handler(self):
     ffNotify('ZachPushover', 'LOCATION: It is dusk!')
     ffEvent('location', {'time': 'dusk'})
     now = self.now()
     dusk_time = self._city.sun(date=datetime.now(self._city.tz) +
                                timedelta(days=1),
                                local=True)['dusk']
     logging.debug("Dusk Time: " + str(dusk_time))
     delay_s = (dusk_time - now).total_seconds()
     l_scheduler.runInS(delay_s,
                        self.dusk_handler,
                        replace=True,
                        uuid='DuskScheduler')
Ejemplo n.º 13
0
    def sendCommand(self, command):
        simpleCommand = None
        logging.debug('Reciving Command in ' + str(metadata.get('module')) +
                      ' ' + str(command))
        if command.deviceID == self._id:
            for item, value in command.command.iteritems():
                if item in self._commands:
                    simpleCommand = self._commands[item](value)

            ## OPTIONAL - SEND EVENT
            if command.simple:
                ffEvent(command.deviceID, simpleCommand)
            else:
                ffEvent(command.deviceID, command.command)
Ejemplo n.º 14
0
def auto_start():
  with open('config/devices.json') as devices:
    allDevices = json.load(devices)
    for name, device in allDevices.iteritems():
      if device.get('module') == "ffZwave":
        package_full_path = device.get('type') + 's.' + device.get('package') + '.' + device.get('module')
        package = __import__(package_full_path, globals={}, locals={}, fromlist=[device.get('package')], level=-1)
        ff_zwave.zwave = package.Device(device.get('id'), device)
        #ffZwave.refresh_scheduler()

  for device in deviceDB.find({}):
    deviceID = device.get('id')
    ffEvent(deviceID, {'startup': True})

  #ffScheduler.runEveryM(5, auto_refresh, replace=True, uuid='auto-refresh')
  ffScheduler.runEveryM(5, auto_refresh, job_id='auto_refresh')
Ejemplo n.º 15
0
  def sendCommand(self, command):
    simpleCommand = None
    logging.debug('Reciving Command in ' + str(self.metadata.get('module')) + ' ' + str(command))
    if command.deviceID == self._id:
      for item, value in command.command.iteritems():
        if item in self._commands:
          simpleCommand = self._commands[item](value)

      updated_status = self.refreshData()
      if command.send_event:
        if updated_status:
          ffEvent(self.id, updated_status)
        else:
          logging.debug('NO chnage in status')
      else:
        logging.debug('Set to not send event')
Ejemplo n.º 16
0
  def sendCommand(self, command):
    simpleCommand = None
    logging.debug('Reciving Command in ' + str(self.metadata.get('module')) + ' ' + str(command))
    if command.deviceID == self._id:
      for item, value in command.command.iteritems():
        if item in self._commands:
          simpleCommand = self._commands[item](value)

      updated_status = self.refreshData()
      if command.send_event:
        if updated_status:
          ffEvent(self.id, updated_status)
        else:
          logging.debug('NO chnage in status')
      else:
        logging.debug('Set to not send event')
Ejemplo n.º 17
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
Ejemplo n.º 18
0
def auto_start():
    with open('config/devices.json') as devices:
        allDevices = json.load(devices)
        for name, device in allDevices.iteritems():
            if device.get('module') == "ffZwave":
                package_full_path = device.get('type') + 's.' + device.get(
                    'package') + '.' + device.get('module')
                package = __import__(package_full_path,
                                     globals={},
                                     locals={},
                                     fromlist=[device.get('package')],
                                     level=-1)
                ff_zwave.zwave = package.Device(device.get('id'), device)
                #ffZwave.refresh_scheduler()

    for device in deviceDB.find({}):
        deviceID = device.get('id')
        ffEvent(deviceID, {'startup': True})

    #ffScheduler.runEveryM(5, auto_refresh, replace=True, uuid='auto-refresh')
    ffScheduler.runEveryM(5, auto_refresh, job_id='auto_refresh')
Ejemplo n.º 19
0
def send_test_request(request):
  ffEvent('location',{'time':'sunset'})
  return 'EVENT SENT'
Ejemplo n.º 20
0
def send_test_request(request):
    ffEvent('location', {'time': 'sunset'})
    return 'EVENT SENT'