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


Python DbHelper.list_devices方法代码示例

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


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

示例1: DBConnector

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

#.........这里部分代码省略.........
                            #print("ADD") 
                            stats.append(xstatn)
            result['xpl_stats'] = {}
            #print("STATS = {0}".format(stats))
            for xstatn in stats:
                xstat = 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())
        except:
            self.log.error("Error when replying to device.params for data={0}. Error: {1}".format(data, traceback.format_exc()))

    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()

        # request for all devices
        if 'type' not in msg_data and \
           'name' not in msg_data and \
           'host' not in msg_data and \
           'timestamp' not in msg_data:
            reason = ""
            status = True
            dev_list = self._db.list_devices()
            dev_json = dev_list
            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']
开发者ID:domogik,项目名称:domogik,代码行数:70,代码来源:dbmgr.py

示例2: _SensorStoreThread

# 需要导入模块: from domogik.common.database import DbHelper [as 别名]
# 或者: from domogik.common.database.DbHelper import list_devices [as 别名]
    class _SensorStoreThread(threading.Thread):
        """ SensorStoreThread class
        Thread that will handle the sensorStore queue
        every item in this queue should be stored in the db
        - conversion will happend
        - formula applying
        - rounding
        - and eventually storing it in the db
        Its a thread to make sure it does not block anything else
        """
        def __init__(self, queue, log, get_conversion_map, pub):
            threading.Thread.__init__(self)
            self._log = log
            self._db = DbHelper()
            self._conv = get_conversion_map
            self._queue = queue
            self._pub = pub
            # on startup, load the device parameters
            self.on_device_changed()

        def on_device_changed(self):
            """ Function called when a device have been changed to reload the devices parameters
            """
            self._log.info("Event : one device changed. Reloading data for _SensorStoreThread")
            self.all_sensors = {}
            self.all_devices = {}
            with self._db.session_scope():
                for sen in self._db.get_all_sensor():
                    #print(sen)
                    #<Sensor: conversion='', value_min='None', history_round='0.0', reference='adco', data_type='DT_String', history_duplicate='False', last_received='1474968431', incremental='False', id='29', history_expire='0', timeout='180', history_store='True', history_max='0', formula='None', device_id='2', last_value='030928084432', value_max='3.09036843008e+11', name='Electric meter address'>
                    self.all_sensors[str(sen.id)] = { 'id' : sen.id,
                                                 'conversion' : sen.conversion,
                                                 'value_min' : sen.value_min,
                                                 'history_round' : sen.history_round,
                                                 'reference' : sen.reference,
                                                 'data_type' : sen.data_type,
                                                 'history_duplicate' : sen.history_duplicate,
                                                 'last_received' : sen.last_received,
                                                 'incremental' : sen.incremental,
                                                 'history_expire' : sen.history_expire,
                                                 'timeout' : sen.timeout,
                                                 'history_store' : sen.history_store,
                                                 'history_max' : sen.history_max,
                                                 'formula' : sen.formula,
                                                 'device_id' : sen.device_id,
                                                 'last_value' : sen.last_value,
                                                 'value_max' : sen.value_max,
                                                 'name' : sen.name}
                #print(self.all_sensors)


                    
                for dev in self._db.list_devices():
                    #print(dev)
                    #{'xpl_stats': {u'get_total_space': {'json_id': u'get_total_space', 'schema': u'sensor.basic', 'id': 3, 'parameters': {'dynamic': [{'ignore_values': u'', 'sensor_name': u'get_total_space', 'key': u'current'}], 'static': [{'type': u'string', 'value': u'/', 'key': u'device'}, {'type': None, 'value': u'total_space', 'key': u'type'}]}, 'name': u'Total space'}, u'get_free_space': {'json_id': u'get_free_space', 'schema': u'sensor.basic', 'id': 4, 'parameters': {'dynamic': [{'ignore_values': u'', 'sensor_name': u'get_free_space', 'key': u'current'}], 'static': [{'type': u'string', 'value': u'/', 'key': u'device'}, {'type': None, 'value': u'free_space', 'key': u'type'}]}, 'name': u'Free space'}, u'get_used_space': {'json_id': u'get_used_space', 'schema': u'sensor.basic', 'id': 5, 'parameters': {'dynamic': [{'ignore_values': u'', 'sensor_name': u'get_used_space', 'key': u'current'}], 'static': [{'type': u'string', 'value': u'/', 'key': u'device'}, {'type': None, 'value': u'used_space', 'key': u'type'}]}, 'name': u'Used space'}, u'get_percent_used': {'json_id': u'get_percent_used', 'schema': u'sensor.basic', 'id': 6, 'parameters': {'dynamic': [{'ignore_values': u'', 'sensor_name': u'get_percent_used', 'key': u'current'}], 'static': [{'type': u'string', 'value': u'/', 'key': u'device'}, {'type': None, 'value': u'percent_used', 'key': u'type'}]}, 'name': u'Percent used'}}, 'commands': {}, 'description': u'', 'reference': u'', 'sensors': {u'get_total_space': {'value_min': None, 'data_type': u'DT_Byte', 'incremental': False, 'id': 57, 'reference': u'get_total_space', 'conversion': u'', 'name': u'Total Space', 'last_received': 1459192737, 'timeout': 0, 'formula': None, 'last_value': u'14763409408', 'value_max': 14763409408.0}, u'get_free_space': {'value_min': None, 'data_type': u'DT_Byte', 'incremental': False, 'id': 59, 'reference': u'get_free_space', 'conversion': u'', 'name':u'Free Space', 'last_received': 1459192737, 'timeout': 0, 'formula': None, 'last_value': u'1319346176', 'value_max': 8220349952.0}, u'get_used_space': {'value_min': None, 'data_type': u'DT_Byte', 'incremental': False, 'id': 60, 'reference': u'get_used_space', 'conversion': u'', 'name': u'Used Space', 'last_received': 1459192737, 'timeout': 0, 'formula': None, 'last_value': u'13444063232', 'value_max': 14763409408.0}, u'get_percent_used': {'value_min': None, 'data_type':u'DT_Scaling', 'incremental': False, 'id': 58, 'reference': u'get_percent_used', 'conversion': u'', 'name': u'Percent used', 'last_received': 1459192737, 'timeout': 0, 'formula': None, 'last_value': u'91', 'value_max': 100.0}}, 'xpl_commands': {}, 'client_id': u'plugin-diskfree.ambre', 'device_type_id': u'diskfree.disk_usage', 'client_version': u'1.0', 'parameters': {u'interval': {'value': u'5', 'type': u'integer', 'id': 5, 'key': u'interval'}}, 'id': 3, 'name': u'Ambre /'}
                    self.all_devices[str(dev['id'])] = {
                                                    'client_id': dev['client_id'],
                                                    'id': dev['id'],
                                                    'name': dev['name'],
                                                  }
                #print(self.all_devices)
            self._log.info("Event : one device changed. Reloading data for _SensorStoreThread -- finished")

        def run(self):
            while True:
                try:
                    store = True
                    item = self._queue.get()
                    #self._log.debug(u"Getting item from the store queue, current length = {0}".format(self._queue.qsize()))
                    self._log.debug(u"Getting item from the store queue, current length = {0}, item = '{1}'".format(self._queue.qsize(), item))
                    # handle ignore
                    value = item['value']
                    senid = item['sensor_id']
                    current_date = item['time']
                    # get the sensor and dev
                    # TODO : DEBUG - LOG TO REMOVE
                    #self._log.debug(u"DEBUG - BEFORE THE with self._db.session_scope()")
                    with self._db.session_scope():
                        #self._log.debug(u"DEBUG - BEGINNING OF THE with self._db.session_scope()")
                        #sen = self._db.get_sensor(senid)
                        #dev = self._db.get_device(sen.device_id)
                        sen = self.all_sensors[str(senid)]
                        dev = self.all_devices[str(sen['device_id'])]
                        # check if we need a conversion
                        if sen['conversion'] is not None and sen['conversion'] != '':
                            if dev['client_id'] in self._conv() and sen['conversion'] in self._conv()[dev['client_id']]:
                                self._log.debug( \
                                    u"Calling conversion {0}".format(sen['conversion']))
                                exec(self._conv()[dev['client_id']][sen['conversion']])
                                value = locals()[sen['conversion']](value)
                        self._log.info( \
                                u"Storing stat for device '{0}' ({1}) and sensor '{2}' ({3}) with value '{4}' after conversion." \
                                .format(dev['name'], dev['id'], sen['name'], sen['id'], value))
                        try:
                            # do the store
                            value = self._db.add_sensor_history(\
                                    senid, \
                                    sen, \
                                    value, \
                                    current_date)
#.........这里部分代码省略.........
开发者ID:domogik,项目名称:domogik,代码行数:103,代码来源:xplgw.py

示例3: int

# 需要导入模块: from domogik.common.database import DbHelper [as 别名]
# 或者: from domogik.common.database.DbHelper import list_devices [as 别名]
            selk = j + 1
            while selk > j:
                try:
                    selk = int(raw_input('Select Action: '))
                except:
                    print('ERROR: select a number between 0 and {0}. Try again'.format(j))
                    selk = j + 1
            if selk > 0:
                selKey = selDev['keys'][selk-1]
                print("")
                print("Select device '{0}' with key '{1}' to upgrade".format(selDev['name'], selKey))
                print("")

                print ("Select the sensor to copy the data to")
                print("")
                newDev = db.list_devices()
                k = 1
                for nDev in newDev:
                    print("{0}. {1}".format(k, nDev["name"]))
                    k = k +1
                print("0. Exit")
                seln = k + 1
                while seln > k:
                    try:
                        seln = int(raw_input('Select Action: '))
                    except:
                        print('ERROR: select a number between 0 and {0}. Try again'.format(k))
                        seln = k + 1
                if seln > 0:
                    print("")
                    print ("Select the sensor to copy the data to")
开发者ID:Nico0084,项目名称:domogik,代码行数:33,代码来源:statsUpgrade.py

示例4: XplManager

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

#.........这里部分代码省略.........
    def on_message(self, msgid, content):
        """ Method called on a subscribed message
        """
        try:
            XplPlugin.on_message(self, msgid, content)
            if msgid == 'client.conversion':
                self._parse_conversions(content)
            elif msgid == 'client.list':
                self._parse_xpl_target(content)
            elif msgid == 'client.sensor':
                self._handle_mq_sensor(content)
            elif msgid == 'device.update':
                self._handle_mq_device_update(content)
        except Exception as exp:
            self.log.error(traceback.format_exc())

    def _handle_mq_device_update(self, content):
        """ On a device change, a Mq message is received
            So we update all the devices parameters used by xplgw
        """
        self.log.debug(u"New message (from MQ) about some device changes > reload the devices parameters...")
        self._x_thread.on_device_changed()
        self._s_thread.on_device_changed()
        self._reload_devices()
        self._reload_commands()

        
    def _reload_devices(self):
        """ Reload the commands
        """
        self.log.info("Event : one device changed. Reloading data for devices (light data)")
        self.all_devices = {}
        with self._db.session_scope():
            for dev in self._db.list_devices():
                #print(dev)
                #{'xpl_stats': {u'get_total_space': {'json_id': u'get_total_space', 'schema': u'sensor.basic', 'id': 3, 'parameters': {'dynamic': [{'ignore_values': u'', 'sensor_name': u'get_total_space', 'key': u'current'}], 'static': [{'type': u'string', 'value': u'/', 'key': u'device'}, {'type': None, 'value': u'total_space', 'key': u'type'}]}, 'name': u'Total space'}, u'get_free_space': {'json_id': u'get_free_space', 'schema': u'sensor.basic', 'id': 4, 'parameters': {'dynamic': [{'ignore_values': u'', 'sensor_name': u'get_free_space', 'key': u'current'}], 'static': [{'type': u'string', 'value': u'/', 'key': u'device'}, {'type': None, 'value': u'free_space', 'key': u'type'}]}, 'name': u'Free space'}, u'get_used_space': {'json_id': u'get_used_space', 'schema': u'sensor.basic', 'id': 5, 'parameters': {'dynamic': [{'ignore_values': u'', 'sensor_name': u'get_used_space', 'key': u'current'}], 'static': [{'type': u'string', 'value': u'/', 'key': u'device'}, {'type': None, 'value': u'used_space', 'key': u'type'}]}, 'name': u'Used space'}, u'get_percent_used': {'json_id': u'get_percent_used', 'schema': u'sensor.basic', 'id': 6, 'parameters': {'dynamic': [{'ignore_values': u'', 'sensor_name': u'get_percent_used', 'key': u'current'}], 'static': [{'type': u'string', 'value': u'/', 'key': u'device'}, {'type': None, 'value': u'percent_used', 'key': u'type'}]}, 'name': u'Percent used'}}, 'commands': {}, 'description': u'', 'reference': u'', 'sensors': {u'get_total_space': {'value_min': None, 'data_type': u'DT_Byte', 'incremental': False, 'id': 57, 'reference': u'get_total_space', 'conversion': u'', 'name': u'Total Space', 'last_received': 1459192737, 'timeout': 0, 'formula': None, 'last_value': u'14763409408', 'value_max': 14763409408.0}, u'get_free_space': {'value_min': None, 'data_type': u'DT_Byte', 'incremental': False, 'id': 59, 'reference': u'get_free_space', 'conversion': u'', 'name':u'Free Space', 'last_received': 1459192737, 'timeout': 0, 'formula': None, 'last_value': u'1319346176', 'value_max': 8220349952.0}, u'get_used_space': {'value_min': None, 'data_type': u'DT_Byte', 'incremental': False, 'id': 60, 'reference': u'get_used_space', 'conversion': u'', 'name': u'Used Space', 'last_received': 1459192737, 'timeout': 0, 'formula': None, 'last_value': u'13444063232', 'value_max': 14763409408.0}, u'get_percent_used': {'value_min': None, 'data_type':u'DT_Scaling', 'incremental': False, 'id': 58, 'reference': u'get_percent_used', 'conversion': u'', 'name': u'Percent used', 'last_received': 1459192737, 'timeout': 0, 'formula': None, 'last_value': u'91', 'value_max': 100.0}}, 'xpl_commands': {}, 'client_id': u'plugin-diskfree.ambre', 'device_type_id': u'diskfree.disk_usage', 'client_version': u'1.0', 'parameters': {u'interval': {'value': u'5', 'type': u'integer', 'id': 5, 'key': u'interval'}}, 'id': 3, 'name': u'Ambre /'}
                self.all_devices[str(dev['id'])] = {
                                                'client_id': dev['client_id'],
                                                'id': dev['id'],
                                                'name': dev['name'],
                                              }
            #print(self.all_devices)
        self.log.info("Event : one device changed. Reloading data for devices (light data) -- finished")

    def _reload_commands(self):
        """ Reload the commands
        """
        self.log.info("Event : one device changed. Reloading data for commands")
        self.all_commands = {}
        with self._db.session_scope():
            for cmd in self._db.get_all_command():
                #print(cmd)
                #<Command: return_confirmation='True', name='Swith', reference='switch_lighting2', id='6', device_id='21'>
                #print(cmd.params)
                #[<CommandParam: data_type='DT_Trigger', conversion='', cmd_id='16', key='state'>]

                self.all_commands[str(cmd.id)] = {
                                              'return_confirmation' : cmd.return_confirmation,
                                              'name' : cmd.name,
                                              'reference' : cmd.reference,
                                              'id' : cmd.id,
                                              'device_id' : cmd.device_id,
                                              'xpl_command' : None,
                                              'params' : []
                                            }
开发者ID:domogik,项目名称:domogik,代码行数:69,代码来源:xplgw.py


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