本文整理汇总了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,