本文整理汇总了Python中domogik.common.database.DbHelper.add_full_device方法的典型用法代码示例。如果您正苦于以下问题:Python DbHelper.add_full_device方法的具体用法?Python DbHelper.add_full_device怎么用?Python DbHelper.add_full_device使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类domogik.common.database.DbHelper
的用法示例。
在下文中一共展示了DbHelper.add_full_device方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: DBConnector
# 需要导入模块: from domogik.common.database import DbHelper [as 别名]
# 或者: from domogik.common.database.DbHelper import add_full_device [as 别名]
#.........这里部分代码省略.........
# send the pub message
if status and res:
self._pub.send_event('device.update',
{"device_id" : res.id,
"client_id" : res.client_id})
def _mdp_reply_devices_create_result(self, data):
status = True
reason = False
result = False
# get the filled package json
params = data.get_data()['data']
# get the json
cli = MQSyncReq(self.zmq)
msg = MQMessage()
msg.set_action('device_types.get')
msg.add_data('device_type', params['device_type'])
res = cli.request('manager', msg.get(), timeout=10)
del cli
if res is None:
status = False
reason = "Manager is not replying to the mq request"
pjson = res.get_data()
if pjson is None:
status = False
reason = "No data for {0} found by manager".format(params['device_type'])
pjson = pjson[params['device_type']]
if pjson is None:
status = False
reason = "The json for {0} found by manager is empty".format(params['device_type'])
if status:
# call the add device function
res = self._db.add_full_device(params, pjson)
if not res:
status = False
reason = "An error occured while adding the device in database. Please check the file dbmgr.log for more informations"
else:
status = True
reason = False
result = res
msg = MQMessage()
msg.set_action('device.create.result')
if reason:
msg.add_data('reason', reason)
if result:
msg.add_data('result', result)
msg.add_data('status', status)
self.log.debug(msg.get())
self.reply(msg.get())
# send the pub message
if status and res:
self._pub.send_event('device.update',
{"device_id" : res['id'],
"client_id" : res['client_id']})
def _mdp_reply_devices_params_result(self, data):
"""
Reply to device.params mq req
@param data : MQ req message
=> should contain
- device_type
"""
status = True
示例2: DBConnector
# 需要导入模块: from domogik.common.database import DbHelper [as 别名]
# 或者: from domogik.common.database.DbHelper import add_full_device [as 别名]
#.........这里部分代码省略.........
msg.add_data('status', status)
if reason:
msg.add_data('reason', reason)
self.log.debug(msg.get())
self.reply(msg.get())
def _mdp_reply_devices_create_result(self, data):
status = True
reason = False
result = False
# get the filled package json
params = data.get_data()['data']
# get the json
cli = MQSyncReq(self.zmq)
msg = MQMessage()
msg.set_action('device_types.get')
msg.add_data('device_type', params['device_type'])
res = cli.request('manager', msg.get(), timeout=10)
del cli
if res is None:
status = False
reason = "Manager is not replying to the mq request"
pjson = res.get_data()
if pjson is None:
status = False
reason = "No data for {0} found by manager".format(params['device_type'])
pjson = pjson[params['device_type']]
if pjson is None:
status = False
reason = "The json for {0} found by manager is empty".format(params['device_type'])
if status:
# call the add device function
res = self._db.add_full_device(params, pjson)
if not res:
status = False
reason = "An error occured while adding the device in database. Please check the file dbmgr.log for more informations"
else:
status = True
reason = False
result = res
msg = MQMessage()
msg.set_action('device.create.result')
if reason:
msg.add_data('reason', reason)
if result:
msg.add_data('result', result)
msg.add_data('status', status)
self.log.debug(msg.get())
self.reply(msg.get())
def _mdp_reply_devices_params_result(self, data):
"""
Reply to device.params mq req
@param data : MQ req message
=> should contain
- device_type
"""
status = True
# check we have all the needed info
msg_data = data.get_data()
if 'device_type' not in msg_data:
status = False
reason = "Device params request : missing 'cevice_type' field : {0}".format(data)