Handle json and 2 year certs #53

Merged
bmartin5692 merged 5 commits from ozmo950 into master 2019-10-06 22:48:50 +02:00
2 changed files with 61 additions and 10 deletions
Showing only changes of commit e233fe933e - Show all commits

View file

@ -183,9 +183,16 @@ class MQTTHelperBot:
cmdjson["payloadType"], cmdjson["payloadType"],
) )
try: try:
if cmdjson["toType"] == "x":
await self.Client.publish( await self.Client.publish(
ttopic, str(cmdjson["payload"]).encode(), QOS_0 ttopic, str(cmdjson["payload"]).encode(), QOS_0
) )
if cmdjson["toType"] == "j":
await self.Client.publish(
ttopic, json.dumps(cmdjson["payload"]).encode(), QOS_0
)
except Exception as e: except Exception as e:
helperbotlog.exception("{}".format(e)) helperbotlog.exception("{}".format(e))

View file

@ -280,8 +280,9 @@ async def test_helperbot_sendcommand():
"ret": "ok", "ret": "ok",
} }
mqtt_helperbot.Client.disconnect() #mqtt_helperbot.Client.disconnect()
# Test GetLifeSpan (xml command)
cmdjson = { cmdjson = {
"toType": "ls1ok3", "toType": "ls1ok3",
"payloadType": "x", "payloadType": "x",
@ -303,11 +304,7 @@ async def test_helperbot_sendcommand():
0.2 0.2
) # Override wait_resp_timeout (so we don't wait 10 seconds for timeout) ) # Override wait_resp_timeout (so we don't wait 10 seconds for timeout)
# Send response beforehand # Send response beforehand
msg_payload = ( msg_payload = "<ctl ret='ok' type='Brush' left='4142' total='18000'/>"
"{'id': 'testx', 'ret': 'ok', 'resp': "
"<ctl ret='ok' type='Brush' left='4142' total='18000'/>"
"}"
)
msg_topic_name = ( msg_topic_name = (
"iot/p2p/GetLifeSpan/bot_serial/ls1ok3/wC3g/helper1/bumper/helper1/p/testx/q" "iot/p2p/GetLifeSpan/bot_serial/ls1ok3/wC3g/helper1/bumper/helper1/p/testx/q"
) )
@ -318,7 +315,54 @@ async def test_helperbot_sendcommand():
commandresult = await mqtt_helperbot.send_command(cmdjson, "testx") commandresult = await mqtt_helperbot.send_command(cmdjson, "testx")
assert commandresult == { assert commandresult == {
"id": "testx", "id": "testx",
"resp": "{'id': 'testx', 'ret': 'ok', 'resp': <ctl ret='ok' type='Brush' left='4142' total='18000'/>}", "resp": "<ctl ret='ok' type='Brush' left='4142' total='18000'/>",
"ret": "ok",
}
# Test json payload (OZMO950)
cmdjson = {
"toType": "ls1ok3",
"payloadType": "j",
"toRes": "wC3g",
"payload": {
"header": {
"pri": 1,
"ts": "1569380075887",
"tzm": -240,
"ver": "0.0.50"
}
},
"td": "q",
"toId": "bot_serial",
"cmdName": "getStats",
"auth": {
"token": "us_52cb21fef8e547f38f4ec9a699a5d77e",
"resource": "IOSF53D07BA",
"userid": "fuid_tmpuser",
"with": "users",
"realm": "ecouser.net",
},
}
mqtt_helperbot.wait_resp_timeout_seconds = (
0.2
) # Override wait_resp_timeout (so we don't wait 10 seconds for timeout)
# Send response beforehand
msg_payload = (
'{"body":{"code":0,"data":{"area":0,"cid":"111","start":"1569378657","time":6,"type":"auto"},"msg":"ok"},"header":{"fwVer":"1.6.4","hwVer":"0.1.1","pri":1,"ts":"1569380074036","tzm":480,"ver":"0.0.1"}}'
)
msg_topic_name = (
"iot/p2p/getStats/bot_serial/ls1ok3/wC3g/helper1/bumper/helper1/p/testj/j"
)
await mqtt_helperbot.Client.publish(
msg_topic_name, msg_payload.encode(), hbmqtt.client.QOS_0
)
commandresult = await mqtt_helperbot.send_command(cmdjson, "testj")
assert commandresult == {
"id": "testj",
"resp": {'body':{'code':0,'data':{'area':0,'cid':'111','start':'1569378657','time':6,'type':'auto'},'msg':'ok'},'header':{'fwVer':'1.6.4','hwVer':'0.1.1','pri':1,'ts':'1569380074036','tzm':480,'ver':'0.0.1'}},
"ret": "ok", "ret": "ok",
} }