本文整理汇总了Python中domogik.mq.message.MQMessage.add_data方法的典型用法代码示例。如果您正苦于以下问题:Python MQMessage.add_data方法的具体用法?Python MQMessage.add_data怎么用?Python MQMessage.add_data使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类domogik.mq.message.MQMessage
的用法示例。
在下文中一共展示了MQMessage.add_data方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _mdp_reply_plugin_stop
# 需要导入模块: from domogik.mq.message import MQMessage [as 别名]
# 或者: from domogik.mq.message.MQMessage import add_data [as 别名]
def _mdp_reply_plugin_stop(self, data):
""" Stop the plugin
@param data : MQ req message
First, send the MQ Rep to 'ack' the request
Then, change the plugin status to STATUS_STOP_REQUEST
Then, quit the plugin by calling force_leave(). This should make the plugin send a STATUS_STOPPED if all is ok
Notice that no check is done on the MQ req content : we need nothing in it as it is directly addressed to a plugin
"""
# check if the message is for us
content = data.get_data()
if content['name'] != self._name or content['host'] != self.get_sanitized_hostname():
return
### Send the ack over MQ Rep
msg = MQMessage()
msg.set_action('plugin.stop.result')
status = True
reason = ""
msg.add_data('status', status)
msg.add_data('reason', reason)
self.reply(msg.get())
### Change the plugin status
self._set_status(STATUS_STOP_REQUEST)
### Try to stop the plugin
# if it fails, the manager should try to kill the plugin
self.force_leave()
示例2: _mdp_reply_plugin_start
# 需要导入模块: from domogik.mq.message import MQMessage [as 别名]
# 或者: from domogik.mq.message.MQMessage import add_data [as 别名]
def _mdp_reply_plugin_start(self, data):
""" Reply on the MQ
@param data : msg REQ received
"""
msg = MQMessage()
msg.set_action('plugin.start.result')
if 'name' not in data.get_data().keys():
status = False
reason = "Plugin startup request : missing 'name' field"
self.log.error(reason)
else:
name = data.get_data()['name']
msg.add_data('name', name)
# try to start the plugin
pid = self._plugins[name].start()
if pid != 0:
status = True
reason = ""
else:
status = False
reason = "Plugin '{0}' startup failed".format(name)
msg.add_data('status', status)
msg.add_data('reason', reason)
self.reply(msg.get())
示例3: WSCommandSend
# 需要导入模块: from domogik.mq.message import MQMessage [as 别名]
# 或者: from domogik.mq.message.MQMessage import add_data [as 别名]
def WSCommandSend(self, data):
cli = MQSyncReq(zmq.Context())
msg = MQMessage()
msg.set_action('cmd.send')
msg.add_data('cmdid', data['command_id'])
msg.add_data('cmdparams', data['parameters'])
return cli.request('xplgw', msg.get(), timeout=10).get()
示例4: test_XplCmd
# 需要导入模块: from domogik.mq.message import MQMessage [as 别名]
# 或者: from domogik.mq.message.MQMessage import add_data [as 别名]
def test_XplCmd(self, parameters = {}, statParams = None):
"""Send an Xpl cmd with statics parameters by request, if necessary start testcase listener for ack message and
check if insert in database is ok.
"""
if self.get_return_confirmation() :
schema, data, statResult = self.get_XplStat_fromAck(statParams)
th = threading.Thread(None, self.assert_Xpl_Stat_Ack_Wait, "th_test_0110_xpl-ack_from_{0}".format(self.command_name), (schema, data, statResult))
th.start()
time.sleep(1)
else :
print (u"No ack required for {0}".format(self.command_name))
if self._device and self.command_id :
cli = MQSyncReq(zmq.Context())
msg = MQMessage()
msg.set_action('cmd.send')
msg.add_data('cmdid', self.command_id)
msg.add_data('cmdparams', parameters)
print (u"Send xpl_cmnd {0}".format(self.command_name))
cli.request('xplgw', msg.get(), timeout=10)
# if self.get_return_confirmation() :
# self.assert_get_last_command_in_db(statResult)
# else :
# print (u"No ack required for {0}".format(self.command_name))
return True
else : return False
示例5: _mdp_reply_helper_help
# 需要导入模块: from domogik.mq.message import MQMessage [as 别名]
# 或者: from domogik.mq.message.MQMessage import add_data [as 别名]
def _mdp_reply_helper_help(self, data):
content = data.get_data()
if 'command' in contens.keys():
if content['command'] in self.helpers.keys():
msg = MQMessage()
msg.set_action('helper.help.result')
msg.add_data('help', self.helpers[content['command']]['help'])
self.reply(msg.get())
示例6: _mdp_reply_packages_detail
# 需要导入模块: from domogik.mq.message import MQMessage [as 别名]
# 或者: from domogik.mq.message.MQMessage import add_data [as 别名]
def _mdp_reply_packages_detail(self):
""" Reply on the MQ
"""
msg = MQMessage()
msg.set_action('package.detail.result')
for pkg in self._packages:
msg.add_data(pkg, self._packages[pkg].get_json())
self.reply(msg.get())
示例7: _mdp_reply_helper_list
# 需要导入模块: from domogik.mq.message import MQMessage [as 别名]
# 或者: from domogik.mq.message.MQMessage import add_data [as 别名]
def _mdp_reply_helper_list(self, data):
""" Return a list of supported helpers
@param data : MQ req message
"""
### Send the ack over MQ Rep
msg = MQMessage()
msg.set_action('helper.list.result')
msg.add_data('actions', self.helpers.keys())
self.reply(msg.get())
示例8: _mdp_reply_clients_detail
# 需要导入模块: from domogik.mq.message import MQMessage [as 别名]
# 或者: from domogik.mq.message.MQMessage import add_data [as 别名]
def _mdp_reply_clients_detail(self):
""" Reply on the MQ
"""
msg = MQMessage()
msg.set_action('client.detail.result')
clients = self._clients.get_detail()
for key in clients:
msg.add_data(key, clients[key])
self.reply(msg.get())
示例9: _mdp_reply_device_new_get
# 需要导入模块: from domogik.mq.message import MQMessage [as 别名]
# 或者: from domogik.mq.message.MQMessage import add_data [as 别名]
def _mdp_reply_device_new_get(self, data):
""" Return a list of new devices detected
@param data : MQ req message
"""
### Send the ack over MQ Rep
msg = MQMessage()
msg.set_action('device.new.result')
msg.add_data('devices', self.new_devices)
self.reply(msg.get())
示例10: _mdp_reply
# 需要导入模块: from domogik.mq.message import MQMessage [as 别名]
# 或者: from domogik.mq.message.MQMessage import add_data [as 别名]
def _mdp_reply(self, plugin, hostname, key, value, element=None):
msg = MQMessage()
msg.setaction( 'config.result' )
msg.add_data('plugin', plugin)
msg.add_data('hostname', hostname)
msg.add_data('key', key)
msg.add_data('value', value)
if element:
msg.add_data('element', element)
print msg.get()
self.reply(msg.get())
示例11: device_params
# 需要导入模块: from domogik.mq.message import MQMessage [as 别名]
# 或者: from domogik.mq.message.MQMessage import add_data [as 别名]
def device_params(client_id, dev_type_id):
cli = MQSyncReq(urlHandler.zmq_context)
msg = MQMessage()
msg.set_action('device.params')
msg.add_data('device_type', dev_type_id)
res = cli.request('dbmgr', msg.get(), timeout=10)
result = ""
if res:
res = res.get_data()
result = res['result'];
result["client_id"] = client_id
# return the info
return 200, result
示例12: do_action
# 需要导入模块: from domogik.mq.message import MQMessage [as 别名]
# 或者: from domogik.mq.message.MQMessage import add_data [as 别名]
def do_action(self, condition, tests):
cli = MQSyncReq(zmq.Context())
msg = MQMessage()
msg.set_action('cmd.send')
msg.add_data('cmdid', self._params['cmdid'])
msg.add_data('cmdparams', self._params['cmdparams'])
# do the request
res = cli.request('xplgw', msg.get(), timeout=10)
if res:
data = res.get_data()
if not data['status']:
self._log.error("Command sending to XPL gw failed: {0}".format(res))
else:
self._log.error("XPL gw did not respond")
示例13: loadDevices
# 需要导入模块: from domogik.mq.message import MQMessage [as 别名]
# 或者: from domogik.mq.message.MQMessage import add_data [as 别名]
def loadDevices(cls):
logger.info("MQ: Loading Devices info")
Device.clean()
msg = MQMessage()
msg.set_action('client.list.get')
res = cli.request('manager', msg.get(), timeout=10)
if res is not None:
_datac = res.get_data()
else:
_datac = {}
session = Session()
for client in _datac.itervalues():
# for each plugin client, we request the list of devices
if client["type"] == "plugin":
msg = MQMessage()
msg.set_action('device.get')
msg.add_data('type', 'plugin')
msg.add_data('name', client["name"])
msg.add_data('host', client["host"])
res = cli.request('dbmgr', msg.get(), timeout=10)
if res is not None:
_datad = res.get_data()
else:
_datad = {}
if 'devices' in _datad:
for device in _datad["devices"]:
d = Device(id=device["id"], name=device["name"], type=device["device_type_id"], reference=device["reference"])
session.add(d)
if "commands" in device:
for ref, command in device["commands"].iteritems():
c = Command(id=command["id"], name=command["name"], device_id=device["id"], reference=ref, return_confirmation=command["return_confirmation"])
session.add(c)
c.datatypes = ""
for param in command["parameters"]:
p = CommandParam(command_id=c.id, key=param["key"], datatype_id=param["data_type"])
session.add(p)
c.datatypes += param["data_type"]
session.add(c)
if "sensors" in device:
for ref, sensor in device["sensors"].iteritems():
s = Sensor(id=sensor["id"], name=sensor["name"], device_id=device["id"], reference=ref, datatype_id=sensor["data_type"], last_value=sensor["last_value"], last_received=sensor["last_received"])
session.add(s)
session.commit()
session.flush()
示例14: api_ncommand
# 需要导入模块: from domogik.mq.message import MQMessage [as 别名]
# 或者: from domogik.mq.message.MQMessage import add_data [as 别名]
def api_ncommand(cid):
cli = MQSyncReq(urlHandler.zmq_context)
msg = MQMessage()
msg.set_action('cmd.send')
msg.add_data('cmdid', cid)
# build the commandparams
cmdparams = {}
for param in request.args:
cmdparams[param] = request.args.get(param)
msg.add_data('cmdparams', cmdparams)
# do the request
resp = cli.request('xplgw', msg.get(), timeout=10)
if resp:
response = resp.get_data()
if response['status']:
return 204, None
else:
return 400, {'msg': response['reason']}
else:
return 400, {'msg': "XPL gateway does not respond"}
示例15: delete_configuration
# 需要导入模块: from domogik.mq.message import MQMessage [as 别名]
# 或者: from domogik.mq.message.MQMessage import add_data [as 别名]
def delete_configuration(type, name, host):
cli = MQSyncReq(zmq.Context())
msg = MQMessage()
msg.set_action('config.delete')
msg.add_data('type', type)
msg.add_data('host', host)
msg.add_data('name', name)
result = cli.request('dbmgr', msg.get(), timeout=10)
if result:
data = result.get_data()
if 'status' in data:
if not data['status']:
print(result.get())
raise RuntimeError("DbMgr did not return status true on a config.set for {0}-{1}.{2} : {3} = {4}".format(type, name, host, key, value))
else:
return True
else:
print(result.get())
raise RuntimeError("DbMgr did not return a status on a config.set for {0}-{1}.{2} : {3} = {4}".format(type, name, host, key, value))
else:
raise RuntimeError("Timeout while deleting configuration for {0}-{1}.{2}".format(type, name, host))