當前位置: 首頁>>代碼示例>>Python>>正文


Python DbHelper.get_all_command方法代碼示例

本文整理匯總了Python中domogik.common.database.DbHelper.get_all_command方法的典型用法代碼示例。如果您正苦於以下問題:Python DbHelper.get_all_command方法的具體用法?Python DbHelper.get_all_command怎麽用?Python DbHelper.get_all_command使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在domogik.common.database.DbHelper的用法示例。


在下文中一共展示了DbHelper.get_all_command方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: XplManager

# 需要導入模塊: from domogik.common.database import DbHelper [as 別名]
# 或者: from domogik.common.database.DbHelper import get_all_command [as 別名]

#.........這裏部分代碼省略.........
        """ 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' : []
                                            }

                for param in cmd.params:
                    self.all_commands[str(cmd.id)]['params'].append({
                                                                   'data_type' : param.data_type,
                                                                   'conversion' : param.conversion,
                                                                   'cmd_id' : param.cmd_id,
                                                                   'key' : param.key
                                                               })

                #print(cmd.xpl_command)
                #<XplCommand: name='Switch', stat_id='82', cmd_id='6', json_id='switch_lighting2', device_id='21', id='6', schema='ac.basic'>
                if cmd.xpl_command != None:
                    xpl_command = {
                                    'name' : cmd.xpl_command.name,
                                    'stat_id' : cmd.xpl_command.stat_id,
                                    'cmd_id' : cmd.xpl_command.cmd_id,
                                    'json_id' : cmd.xpl_command.json_id,
                                    'device_id' : cmd.xpl_command.device_id,
開發者ID:domogik,項目名稱:domogik,代碼行數:70,代碼來源:xplgw.py


注:本文中的domogik.common.database.DbHelper.get_all_command方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。