本文整理汇总了Python中domogik.common.database.DbHelper.detach方法的典型用法代码示例。如果您正苦于以下问题:Python DbHelper.detach方法的具体用法?Python DbHelper.detach怎么用?Python DbHelper.detach使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类domogik.common.database.DbHelper
的用法示例。
在下文中一共展示了DbHelper.detach方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: XplManager
# 需要导入模块: from domogik.common.database import DbHelper [as 别名]
# 或者: from domogik.common.database.DbHelper import detach [as 别名]
#.........这里部分代码省略.........
if xplstat is not None:
# get the device from the db
dev = self._db.get_device(int(cmd.device_id))
msg = XplMessage()
if not dev['client_id'] in self.client_xpl_map.keys():
self._load_client_to_xpl_target()
if not dev['client_id'] in self.client_xpl_map.keys():
failed = "Can not fincd xpl source for {0} client_id".format(dev['client_id'])
else:
msg.set_target(self.client_xpl_map[dev['client_id']])
msg.set_source(self.myxpl.get_source())
msg.set_type("xpl-cmnd")
msg.set_schema(xplcmd.schema)
# static paramsw
for par in xplcmd.params:
msg.add_data({par.key : par.value})
# dynamic params
for par in cmd.params:
if par.key in request['cmdparams']:
value = request['cmdparams'][par.key]
# chieck if we need a conversion
if par.conversion is not None and par.conversion != '':
if dev['client_id'] in self.client_conversion_map:
if par.conversion in self.client_conversion_map[dev['client_id']]:
exec(self.client_conversion_map[dev['client_id']][par.conversion])
value = locals()[par.conversion](value)
msg.add_data({par.key : value})
else:
failed = "Parameter ({0}) for device command msg is not provided in the mq message".format(par.key)
if not failed:
# send out the msg
self.log.debug(u"Sending xplmessage: {0}".format(msg))
self.myxpl.send(msg)
xplstat = self._db.detach(xplstat)
# generate an uuid for the matching answer published messages
if xplstat != None:
resp_uuid = uuid4()
self._cmd_lock_d.acquire()
self._cmd_dict[str(resp_uuid)] = xplstat
self._cmd_lock_d.release()
else:
resp_uuid = None
# send the response
reply_msg = MQMessage()
reply_msg.set_action('cmd.send.result')
reply_msg.add_data('uuid', str(resp_uuid))
reply_msg.add_data('status', True)
reply_msg.add_data('reason', None)
self.log.debug(u"mq reply (success) : {0}".format(reply_msg.get()))
self.reply(reply_msg.get())
if failed:
self.log.error(failed)
reply_msg = MQMessage()
reply_msg.set_action('cmd.send.result')
reply_msg.add_data('uuid', None)
reply_msg.add_data('status', False)
reply_msg.add_data('reason', failed)
self.log.debug(u"mq reply (failed) : {0}".format(reply_msg.get()))
self.reply(reply_msg.get())
def _create_xpl_trigger(self):
""" Create a listener to catch
all xpl-stats and xpl-trig messages
"""
Listener(self._xpl_callback, self.myxpl, {'xpltype': 'xpl-trig'})