コード例 #1
0
ファイル: device_db.py プロジェクト: RajeshPatadiya/Firefly-4
def getDeviceStatusDict():
    devices = {}
    for d in deviceDB.find({}, {'status': 1, 'id': 1}):
        d_id = d.get('id')
        if (d.get('status')):
            devices[d_id] = d.get('status')
    return devices
コード例 #2
0
ファイル: firefly_api.py プロジェクト: zpriddy/Firefly
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}})
コード例 #3
0
def APIDevicesStatusAll(request):
    deviceViews = {}
    for d in deviceDB.find({}, {'status': 1, 'id': 1}):
        dID = d.get('id')
        if (d.get('status')):
            deviceViews[dID] = d.get('status')

    returnData = {'devices': deviceViews}

    deviceTypeList = []

    for name, d in deviceViews.iteritems():
        if d.get('views'):
            dType = d.get('views').get('type')
            if dType and dType not in deviceTypeList:
                deviceTypeList.append(str(dType))

    deviceTypes = [{'index': 0, "type": 'all', 'title': 'all devices'}]

    deviceIndex = 1
    for d in sorted(deviceTypeList):
        deviceTypes.append({
            'index': deviceIndex,
            'type': str(d),
            'title': str(d)
        })
        deviceIndex += 1

    returnData['types'] = deviceTypes

    return json.dumps(returnData, sort_keys=True)
コード例 #4
0
ファイル: device_db.py プロジェクト: zpriddy/Firefly
def getDeviceStatusDict():
    devices = {}
    for d in deviceDB.find({}, {"status": 1, "id": 1}):
        d_id = d.get("id")
        if d.get("status"):
            devices[d_id] = d.get("status")
    return devices
コード例 #5
0
ファイル: firefly_api.py プロジェクト: zpriddy/Firefly
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
ファイル: device_db.py プロジェクト: RajeshPatadiya/Firefly-4
def getDeviceList(lower=True):
    device_list = {}
    for d in deviceDB.find({}, {"config.name": 1, "id": 1}):
        if d.get('config').get('name') is not None:
            if lower:
                device_list[d.get('config').get('name').lower()] = d.get('id')
            else:
                device_list[d.get('config').get('name')] = d.get('id')
    return device_list
コード例 #7
0
ファイル: command.py プロジェクト: zpriddy/Firefly
def sendDeviceCommand(command):
  success = False
  for d in deviceDB.find({'id':command.deviceID}):
    s = pickle.loads(d.get('ffObject'))
    s.sendCommand(command)
    d = pickle.dumps(s)
    deviceDB.update_one({'id':command.deviceID},{'$set': {'ffObject':d}, '$currentDate': {'lastModified': True}})
    success = True
  return success
コード例 #8
0
ファイル: device_db.py プロジェクト: zpriddy/Firefly
def getDeviceList(lower=True):
    device_list = {}
    for d in deviceDB.find({}, {"config.name": 1, "id": 1}):
        if d.get("config").get("name") is not None:
            if lower:
                device_list[d.get("config").get("name").lower()] = d.get("id")
            else:
                device_list[d.get("config").get("name")] = d.get("id")
    return device_list
コード例 #9
0
ファイル: device_db.py プロジェクト: RajeshPatadiya/Firefly-4
def getDeviceViewsList(filters=['hgrp-']):
    devices = []
    for d in deviceDB.find({}, {'status.views': 1, 'id': 1}):
        if (d.get('status').get('views')):
            for f in filters:
                if d.get('status').get('views').get('name').find(f) != -1:
                    continue
                devices.append(d.get('status').get('views'))
    return devices
コード例 #10
0
def get_device_list(lower=True):
    logging.critical("GET DEVICE LIST")
    global device_list
    device_list = {}
    for d in deviceDB.find({}, {"config.name": 1, "id": 1}):
        if d.get('config').get('name') is not None:
            if lower:
                device_list[d.get('config').get('name').lower()] = d.get('id')
            else:
                device_list[d.get('config').get('name')] = d.get('id')
コード例 #11
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}})
コード例 #12
0
ファイル: firefly_api.py プロジェクト: zpriddy/Firefly
def get_device_list(lower=True):
  logging.critical("GET DEVICE LIST")
  global device_list
  device_list = {}
  for d in deviceDB.find({},{"config.name":1,"id":1}):
    if d.get('config').get('name') is not None:
      if lower:
        device_list[d.get('config').get('name').lower()] = d.get('id')
      else:
        device_list[d.get('config').get('name')] = d.get('id')
コード例 #13
0
def sendEventToDevice(event):
    for d in deviceDB.find({'id': event.deviceID}):
        s = pickle.loads(d.get('ffObject'))
        s.sendEvent(event)
        d = pickle.dumps(s)
        deviceDB.update_one({'id': event.deviceID}, {
            '$set': {
                'ffObject': d
            },
            '$currentDate': {
                'lastModified': True
            }
        })
コード例 #14
0
ファイル: firefly_api.py プロジェクト: zpriddy/Firefly
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')
コード例 #15
0
ファイル: command.py プロジェクト: RajeshPatadiya/Firefly-4
def sendDeviceCommand(command):
    success = False
    for d in deviceDB.find({'id': command.deviceID}):
        s = pickle.loads(d.get('ffObject'))
        s.sendCommand(command)
        d = pickle.dumps(s)
        deviceDB.update_one({'id': command.deviceID}, {
            '$set': {
                'ffObject': d
            },
            '$currentDate': {
                'lastModified': True
            }
        })
        success = True
    return success
コード例 #16
0
ファイル: device_db.py プロジェクト: RajeshPatadiya/Firefly-4
def getDeviceInfo(filters=None):
    devices = {}
    for d in deviceDB.find({}):
        if not d.get('config').get('name'):
            continue
        if d.get('config').get('name') is not None:
            if filters:
                if d.get('type') not in filters:
                    continue
            devices[d.get('config').get('name')] = {
                'name': d.get('config').get('name'),
                'type': d.get('type'),
                'subtype': d.get('config').get('subtype'),
                'commands': d.get('commands'),
                'id': d.get('id')
            }
    return devices
コード例 #17
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')
コード例 #18
0
ファイル: firefly_api.py プロジェクト: zpriddy/Firefly
def APIDevicesStatusAll(request):
  deviceViews = {}
  for d in deviceDB.find({},{'status':1, 'id':1}):
    dID = d.get('id')
    if (d.get('status')):
      deviceViews[dID] = d.get('status')

  returnData = {'devices': deviceViews}

  deviceTypeList = []

  for name, d in deviceViews.iteritems():
    if d.get('views'):
      dType = d.get('views').get('type')
      if dType and dType not in deviceTypeList:
        deviceTypeList.append(str(dType))

  deviceTypes = [
    {
      'index': 0,
      "type": 'all',
      'title': 'all devices'
    }
  ]

  deviceIndex = 1
  for d in sorted(deviceTypeList):
    deviceTypes.append({
        'index': deviceIndex,
        'type': str(d),
        'title': str(d)
      })
    deviceIndex+=1

  returnData['types'] = deviceTypes

  return json.dumps(returnData, sort_keys=True)
コード例 #19
0
ファイル: device_db.py プロジェクト: zpriddy/Firefly
def getDeviceViewsList():
    devices = []
    for d in deviceDB.find({}, {"status.views": 1, "id": 1}):
        if d.get("status").get("views"):
            devices.append(d.get("status").get("views"))
    return devices
コード例 #20
0
ファイル: event.py プロジェクト: zpriddy/Firefly
def sendEventToDevice(event):
  for d in deviceDB.find({'id':event.deviceID}):
    s = pickle.loads(d.get('ffObject'))
    s.sendEvent(event)
    d = pickle.dumps(s)
    deviceDB.update_one({'id':event.deviceID},{'$set': {'ffObject':d}, '$currentDate': {'lastModified': True}})
コード例 #21
0
ファイル: notify.py プロジェクト: zpriddy/Firefly
 def send_all(self):
   for device in deviceDB.find({"config.subType":"notification"}):
     dID = device.get('id')
     notificationEvent = ffCommand(str(dID), {'notify': {'message' :self._message}})
コード例 #22
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)
コード例 #23
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())