コード例 #1
0
ファイル: loaders.py プロジェクト: Nico0084/domoweb
    def loadDevices(cls, develop):
        logger.info(u"MQ: Loading Devices info")
        Device.clean()
        msg = MQMessage()
        msg.set_action('client.list.get')
        res = cli.request('manager', msg.get(), timeout=10)
        if res is not None:
            _datac = res.get_data()
        else:
            _datac = {}
        session = Session()
        for client in _datac.itervalues(): 
            # for each plugin client, we request the list of devices
            if client["type"] == "plugin":
                msg = MQMessage()
                msg.set_action('device.get')
                msg.add_data('type', 'plugin')
                msg.add_data('name', client["name"])
                msg.add_data('host', client["host"])
                logger.info(u"MQ: Get devices list for client {0}-{1}.{2}".format("plugin", client["name"], client["host"]))
                res = cli.request('dbmgr', msg.get(), timeout=10)
                if res is not None:
                    _datad = res.get_data()
                else:
                    _datad = {}
                if 'devices' in _datad:
                    for device in _datad["devices"]:
                        logger.info(u"- {0}".format(device["name"]))
                        d = Device(id=device["id"], name=device["name"], type=device["device_type_id"], reference=device["reference"])
                        session.add(d)
                        if "commands" in device:
                            for ref, command  in device["commands"].iteritems():
                                c = Command(id=command["id"], name=command["name"], device_id=device["id"], reference=ref, return_confirmation=command["return_confirmation"])
                                session.add(c)
                                c.datatypes = ""
                                for param in command["parameters"]:
                                    p = CommandParam(command_id=c.id, key=param["key"], datatype_id=param["data_type"])
                                    session.add(p)
                                    c.datatypes += param["data_type"]
                                session.add(c)
                        if "sensors" in device:
                            for ref, sensor in device["sensors"].iteritems():
                                s = Sensor(id=sensor["id"], name=sensor["name"], device_id=device["id"], reference=ref, datatype_id=sensor["data_type"], last_value=sensor["last_value"], last_received=sensor["last_received"], timeout=sensor["timeout"])
                                session.add(s)

        session.commit()
        session.flush()
コード例 #2
0
ファイル: forms.py プロジェクト: ka2er/domoweb
 def addField(cls, option):
     types = json.loads(option.types)
     datatypes = []
     for t in types:
         args = ()
         for d in t:
             l = [d]
             l += DataType.getChilds(id=d)
             args += (l,)
             for p in itertools.product(*args):
                 datatypes.append(''.join(p))
     commands = Command.getTypesFilter(types=datatypes)
     cls.addGroupedModelChoiceField(key=option.key, label=option.name, required=option.required, queryset=commands, group_by_field='device_id', empty_label="--Select Command--", help_text=option.description)
コード例 #3
0
 def addField(cls, option):
     types = json.loads(option.types)
     datatypes = []
     for t in types:
         args = ()
         for d in t:
             l = [d]
             l += DataType.getChilds(id=d)
             args += (l,)
             for p in itertools.product(*args):
                 datatypes.append(''.join(p))
     commands = Command.getTypesFilter(types=datatypes)
     cls.addModelChoiceField(key=option.key, label=option.name, required=option.required, queryset=commands, group_by_field='device_id', empty_label="--Select Command--", help_text=option.description)
コード例 #4
0
ファイル: loaders.py プロジェクト: overload08/domoweb
    def loadDevices(cls, develop):
        logger.info(u"MQ: Loading Devices info")
        Device.clean()
        msg = MQMessage()
        msg.set_action('client.list.get')
        res = cli.request('manager', msg.get(), timeout=10)
        if res is not None:
            _datac = res.get_data()
        else:
            _datac = {}
        session = Session()
        for client in _datac.itervalues():
            # for each plugin client, we request the list of devices
            if client["type"] == "plugin":
                msg = MQMessage()
                msg.set_action('device.get')
                msg.add_data('type', 'plugin')
                msg.add_data('name', client["name"])
                msg.add_data('host', client["host"])
                logger.info(
                    u"MQ: Get devices list for client {0}-{1}.{2}".format(
                        "plugin", client["name"], client["host"]))
                res = cli.request('dbmgr', msg.get(), timeout=10)
                if res is not None:
                    _datad = res.get_data()
                else:
                    _datad = {}
                if 'devices' in _datad:
                    for device in _datad["devices"]:
                        logger.info(u"- {0}".format(device["name"]))
                        d = Device(id=device["id"],
                                   name=device["name"],
                                   type=device["device_type_id"],
                                   reference=device["reference"])
                        session.add(d)
                        if "commands" in device:
                            for ref, command in device["commands"].iteritems():
                                c = Command(id=command["id"],
                                            name=command["name"],
                                            device_id=device["id"],
                                            reference=ref,
                                            return_confirmation=command[
                                                "return_confirmation"])
                                session.add(c)
                                c.datatypes = ""
                                for param in command["parameters"]:
                                    p = CommandParam(
                                        command_id=c.id,
                                        key=param["key"],
                                        datatype_id=param["data_type"])
                                    session.add(p)
                                    c.datatypes += param["data_type"]
                                session.add(c)
                        if "sensors" in device:
                            for ref, sensor in device["sensors"].iteritems():
                                s = Sensor(
                                    id=sensor["id"],
                                    name=sensor["name"],
                                    device_id=device["id"],
                                    reference=ref,
                                    datatype_id=sensor["data_type"],
                                    last_value=sensor["last_value"],
                                    last_received=sensor["last_received"],
                                    timeout=sensor["timeout"])
                                session.add(s)

        session.commit()
        session.flush()