本文整理汇总了Python中domogik.common.database.DbHelper.get_device_by_technology_and_address方法的典型用法代码示例。如果您正苦于以下问题:Python DbHelper.get_device_by_technology_and_address方法的具体用法?Python DbHelper.get_device_by_technology_and_address怎么用?Python DbHelper.get_device_by_technology_and_address使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类domogik.common.database.DbHelper
的用法示例。
在下文中一共展示了DbHelper.get_device_by_technology_and_address方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _callback
# 需要导入模块: from domogik.common.database import DbHelper [as 别名]
# 或者: from domogik.common.database.DbHelper import get_device_by_technology_and_address [as 别名]
def _callback(self, message):
""" Callback for the xpl message
@param message : the Xpl message received
"""
### we put data in database
my_db = DbHelper()
self._log_stats.debug("message catcher : %s" % message)
try:
if self._res["device"] != None:
try:
device = message.data[self._res["device"]]
except KeyError:
# key error means that we are trying to get some key from a xpl where there is no such key
# there may be an issue in the xml file!
self._log_stats.error("Key error : %s in the message : %s" % (self._res["device"], message))
return
my_device = my_db.get_device_by_technology_and_address(self._technology, \
message.data[self._res["device"]])
if my_device != None:
d_id = my_device.id
else:
raise AttributeError
#d_id = my_db.get_device_by_technology_and_address(self._technology, \
# message.data[self._res["device"]]).id
device = message.data[self._res["device"]]
elif self._res["static_device"] != None:
d_id = my_db.get_device_by_technology_and_address(self._technology, \
self._res["static_device"]).id
device = self._res["static_device"]
elif self._res["device_type"] != None:
# device id equals 0 for a notification
if self._res["device_type"] == "notification":
d_id = 0
device = "notification"
else: # oups... something wrong in xml file ?
self._log_stats.error("Device has no name... is there a problem in xml file ?")
raise AttributeError
#print("Stat for techno '%s' / adress '%s' / id '%s'" % (self._technology, message.data[self._res["device"]], d_id))
#print("Stat for techno '%s' / adress '%s' / id '%s'" % (self._technology, device, d_id))
except AttributeError:
if self._res["device"] != None:
self._log_stats_unknown.debug("Received a stat for an unreferenced device : %s - %s" \
% (self._technology, message.data[self._res["device"]]))
else:
self._log_stats_unknown.debug("Received a stat for an unreferenced device : %s - %s" \
% (self._technology, self._res["static_device"]))
print("=> unknown device")
del(my_db)
return
#self._log_stats.debug("Stat received for %s - %s." \
# % (self._technology, message.data[self._res["device"]]))
self._log_stats.debug("Stat received for %s - %s." \
% (self._technology, device))
current_date = calendar.timegm(time.gmtime())
device_data = []
### mapping processing
for my_map in self._res["mapping"]:
# first : get value and default key
key = my_map["name"]
history_size = my_map["history_size"]
try:
value = message.data[my_map["name"]].lower()
if my_map["filter_key"] == None:
key = my_map["name"]
device_data.append({"key" : key, "value" : value})
# we don't insert notifications
if d_id != 0:
my_db.add_device_stat(current_date, key, value, \
d_id, \
history_size)
else:
if my_map["filter_value"] != None and \
my_map["filter_value"].lower() == message.data[my_map["filter_key"]].lower():
key = my_map["new_name"]
device_data.append({"key" : key, "value" : value})
# we don't insert notifications
if d_id != 0:
my_db.add_device_stat(current_date, key, \
value, \
d_id, history_size)
else:
if my_map["filter_value"] == None:
self._log_stats.warning ("Stats : no filter_value defined in map : %s" % str(my_map))
except KeyError:
# no value in message for key
# example : a x10 command = ON has no level value
print("No param value in message for key")
except:
error = "Error when processing stat : %s" % traceback.format_exc()
print("==== Error in Stats ====")
print(error)
print("========================")
self._log_stats.error(error)
# Put data in events queues
self._event_requests.add_in_queues(d_id,
{"timestamp" : current_date, "device_id" : d_id, "data" : device_data})
del(my_db)