本文整理汇总了Python中domogik.common.database.DbHelper.list_sensor_history_between方法的典型用法代码示例。如果您正苦于以下问题:Python DbHelper.list_sensor_history_between方法的具体用法?Python DbHelper.list_sensor_history_between怎么用?Python DbHelper.list_sensor_history_between使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类domogik.common.database.DbHelper
的用法示例。
在下文中一共展示了DbHelper.list_sensor_history_between方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: DBConnector
# 需要导入模块: from domogik.common.database import DbHelper [as 别名]
# 或者: from domogik.common.database.DbHelper import list_sensor_history_between [as 别名]
#.........这里部分代码省略.........
### 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
if 'mode' in msg_data:
if msg_data['mode'] == "last":
mode = "last"
elif msg_data['mode'] == "period":
mode = "period"
else:
reason = "ERROR when getting sensor history. No valid type (last, from) declared in the message"
self.log.error(reason)
status = False
mode = None
else:
reason = "ERROR when getting sensor history. No type (last, from) declared in the message"
self.log.error(reason)
status = False
sensor_id = None
values = None
### last N values
if mode == "last":
if 'number' in msg_data:
number = msg_data['number']
else:
number = 1
try:
history = self._db.list_sensor_history(sensor_id, number)
if len(history) == 0:
#values = None
values = self._db.get_last_sensor_value(sensor_id)
else:
values = self._db.list_sensor_history(sensor_id, number)
except:
self.log.error("ERROR when getting sensor history for id = {0} : {1}".format(sensor_id, traceback.format_exc()))
reason = "ERROR : {0}".format(traceback.format_exc())
status = False
### period
elif mode == "period":
if 'from' in msg_data:
frm = msg_data['from']
else:
reason = "ERROR when getting sensor history. No key 'from' defined for mode = 'period'!"
self.log.error(reason)
status = False
frm = None
if 'to' in msg_data:
to = msg_data['to']
else:
to = None
if frm != None and to == None:
values = self._db.list_sensor_history_between(sensor_id, frm)
print(values)
else:
# TODO
values = "TODO"
msg.add_data('status', status)
msg.add_data('reason', reason)
msg.add_data('sensor_id', sensor_id)
msg.add_data('mode', mode)
msg.add_data('values', values)
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"})