当前位置: 首页>>代码示例>>Python>>正文


Python DbHelper.list_devices_by_plugin方法代码示例

本文整理汇总了Python中domogik.common.database.DbHelper.list_devices_by_plugin方法的典型用法代码示例。如果您正苦于以下问题:Python DbHelper.list_devices_by_plugin方法的具体用法?Python DbHelper.list_devices_by_plugin怎么用?Python DbHelper.list_devices_by_plugin使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在domogik.common.database.DbHelper的用法示例。


在下文中一共展示了DbHelper.list_devices_by_plugin方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: DBConnector

# 需要导入模块: from domogik.common.database import DbHelper [as 别名]
# 或者: from domogik.common.database.DbHelper import list_devices_by_plugin [as 别名]

#.........这里部分代码省略.........
        for cmdn in pjson['device_types'][dev_type_id]['commands']:
            cmd = pjson['commands'][cmdn]
            if 'xpl_command'in cmd:
                xcmdn = cmd['xpl_command']
                xcmd = pjson['xpl_commands'][xcmdn]
                result['xpl_commands'][xcmdn] = []
                stats.append( xcmd['xplstat_name'] )
                for param in xcmd['parameters']['device']:
                    result['xpl_commands'][xcmdn].append(param)
        # find the xplStats
        sensors = pjson['device_types'][dev_type_id]['sensors']
        for xstatn in pjson['xpl_stats']:
            xstat = pjson['xpl_stats'][xstatn]
            if xstat['parameters']['dynamic'] in sensors:
                stats.append(xstatn)
        result['xpl_stats'] = {}
        for xstatn in stats:
            xtat = pjson['xpl_stats'][xstatn]
            result['xpl_stats'][xstatn] = []
            for param in xstat['parameters']['device']:
                result['xpl_stats'][xstatn].append(param)
        # return the data
        msg.add_data('result', result)
        self.log.debug(msg.get())
        self.reply(msg.get())

    def _mdp_reply_devices_result(self, data):
        """ Reply to device.get MQ req
            @param data : MQ req message
        """
        msg = MQMessage()
        msg.set_action('device.result')
        status = True

        msg_data = data.get_data()
        if 'type' not in msg_data:
            status = False
            reason = "Devices request : missing 'type' field : {0}".format(data)

        if 'name' not in msg_data:
            status = False
            reason = "Devices request : missing 'name' field : {0}".format(data)

        if 'host' not in msg_data:
            status = False
            reason = "Devices request : missing 'host' field : {0}".format(data)

        if status == False:
            self.log.error(reason)
        else:
            reason = ""
            type = msg_data['type']
            #if type == "plugin":
            #    type = DMG_VENDOR_ID
            name = msg_data['name']
            host = msg_data['host']
            dev_list = self._db.list_devices_by_plugin("{0}-{1}.{2}".format(type, name, host))
            #dev_json = json.dumps(dev_list, cls=domogik_encoder(), check_circular=False),
            dev_json = dev_list
            print(dev_json)
            msg.add_data('status', status)
            msg.add_data('reason', reason)
            msg.add_data('type', type)
            msg.add_data('name', name)
            msg.add_data('host', host)
            msg.add_data('devices', dev_json)

        self.reply(msg.get())


    def convert(self, data):
        """ Do some conversions on data
        """
        if data == "True":
            data = True
        if data == "False":
            data = False
        return data

    def publish_config_updated(self, type, name, host):
        """ Publish over the MQ a message to inform that a plugin configuration has been updated
            @param type : package type (plugin)
            @param name : package name
            @param host : host
        """
        self.log.debug("Publish configuration update notification for {0}-{1}.{2}".format(type, name, host))
        self._pub.send_event('plugin.configuration',
                             {"type" : type,
                              "name" : name,
                              "host" : host,
                              "event" : "updated"})

    def reload_stats(self):
        self.log.debug(u"=============== reload stats")                                                                                                                              
        req = MQSyncReq(self.zmq)
        msg = MQMessage()
        msg.set_action( 'reload' )
        resp = req.request('xplgw', msg.get(), 100)
        self.log.debug(u"Reply from xplgw: {0}".format(resp))
        self.log.debug(u"=============== reload stats END")
开发者ID:anuraagkapoor,项目名称:domogik,代码行数:104,代码来源:dbmgr.py

示例2: DBConnector

# 需要导入模块: from domogik.common.database import DbHelper [as 别名]
# 或者: from domogik.common.database.DbHelper import list_devices_by_plugin [as 别名]

#.........这里部分代码省略.........
            msg.add_data('status', status)
            msg.add_data('reason', reason)
            msg.add_data('devices', dev_json)
        elif 'timestamp'in msg_data:
        # request for all devices that changed after timestamp
            reason = ""
            status = True
            dev_list = self._db.list_devices_by_timestamp(msg_data['timestamp'])
            dev_json = dev_list
            msg.add_data('status', status)
            msg.add_data('reason', reason)
            msg.add_data('devices', dev_json)
        else:
        # request for all devices of one client
            if 'type' not in msg_data:
                status = False
                reason = "Devices request : missing 'type' field : {0}".format(data)

            if 'name' not in msg_data:
                status = False
                reason = "Devices request : missing 'name' field : {0}".format(data)

            if 'host' not in msg_data:
                status = False
                reason = "Devices request : missing 'host' field : {0}".format(data)

            if status == False:
                self.log.error(reason)
            else:
                reason = ""
                type = msg_data['type']
                name = msg_data['name']
                host = msg_data['host']
                dev_list = self._db.list_devices_by_plugin("{0}-{1}.{2}".format(type, name, host))

            #dev_json = json.dumps(dev_list, cls=domogik_encoder(), check_circular=False),
            dev_json = dev_list
            msg.add_data('status', status)
            msg.add_data('reason', reason)
            msg.add_data('type', type)
            msg.add_data('name', name)
            msg.add_data('host', host)
            msg.add_data('devices', dev_json)

        self.reply(msg.get())

    def _mdp_reply_sensor_history(self, data):
        """ Reply to sensor_history.get MQ req
            @param data : MQ req message

            If no other param than the sensor id, return the last value
        """
        msg = MQMessage()
        msg.set_action('sensor_history.result')
        status = True
        reason = ""

        ### process parameters
        msg_data = data.get_data()
        if 'sensor_id' in msg_data:
            sensor_id = msg_data['sensor_id']
        else:
            reason = "ERROR when getting sensor history. No sensor_id declared in the message"
            self.log.error(reason)
            status = False
            sensor_id = None
开发者ID:domogik,项目名称:domogik,代码行数:70,代码来源:dbmgr.py

示例3: DBConnector

# 需要导入模块: from domogik.common.database import DbHelper [as 别名]
# 或者: from domogik.common.database.DbHelper import list_devices_by_plugin [as 别名]

#.........这里部分代码省略.........


    def _fetch_techno_config(self, name, host, key):
        '''
        Fetch a plugin global config value in the database
        @param name : the plugin of the element
        @param host : hostname
        @param key : the key of the config tuple to fetch
        '''
        try:
            try:
                result = self._db.get_plugin_config(name, host, key)
                # tricky loop as workaround for a (sqlalchemy?) bug :
                # sometimes the given result is for another plugin/key
                # so while we don't get the good data, we loop
                # This bug happens rarely
                while result.id != name or \
                   result.hostname != host or \
                   result.key != key:
                    self.log.debug(u"Bad result : {0}/{1} != {2}/{3}".format(result.id, result.key, plugin, key))
                    result = self._db.get_plugin_config(name, host, key)
                val = result.value
                if val == '':
                    val = "None"
                return val
            except AttributeError:
                # if no result is found
                #self.log.error(u"Attribute error : {0}".format(traceback.format_exc()))
                return "None"
        except:
            msg = "No config found host={0}, plugin={1}, key={2}".format(host, name, key)
            self.log.warn(msg)
            return "None"


    def _mdp_reply_devices_result(self, data):
        """ Reply to device.get MQ req
            @param data : MQ req message
        """
        msg = MQMessage()
        msg.set_action('device.result')
        status = True

        msg_data = data.get_data()
        if 'type' not in msg_data:
            status = False
            reason = "Devices request : missing 'type' field : {0}".format(data)

        if 'name' not in msg_data:
            status = False
            reason = "Devices request : missing 'name' field : {0}".format(data)

        if 'host' not in msg_data:
            status = False
            reason = "Devices request : missing 'host' field : {0}".format(data)

        if status == False:
            self.log.error(reason)
        else:
            reason = ""
            type = msg_data['type']
            #if type == "plugin":
            #    type = DMG_VENDOR_ID
            name = msg_data['name']
            host = msg_data['host']
            dev_list = self._db.list_devices_by_plugin("{0}-{1}.{2}".format(type, name, host))
            #dev_json = json.dumps(dev_list, cls=domogik_encoder(), check_circular=False),
            dev_json = dev_list
            print(dev_json)
            msg.add_data('status', status)
            msg.add_data('reason', reason)
            msg.add_data('type', type)
            msg.add_data('name', name)
            msg.add_data('host', host)
            msg.add_data('devices', dev_json)

        self.reply(msg.get())


    def convert(self, data):
        """ Do some conversions on data
        """
        if data == "True":
            data = True
        if data == "False":
            data = False
        return data

    def publish_config_updated(self, type, name, host):
        """ Publish over the MQ a message to inform that a plugin configuration has been updated
            @param type : package type (plugin)
            @param name : package name
            @param host : host
        """
        self.log.debug("Publish configuration update notification for {0}-{1}.{2}".format(type, name, host))
        self._pub.send_event('plugin.configuration',
                             {"type" : type,
                              "name" : name,
                              "host" : host,
                              "event" : "updated"})
开发者ID:Basilic,项目名称:domogik,代码行数:104,代码来源:dbmgr.py


注:本文中的domogik.common.database.DbHelper.list_devices_by_plugin方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。