Re-org and start of API #47
1 changed files with 108 additions and 108 deletions
|
|
@ -231,8 +231,6 @@ class ConfServer:
|
||||||
await bumper.mqtt_helperbot.Client.disconnect()
|
await bumper.mqtt_helperbot.Client.disconnect()
|
||||||
await bumper.mqtt_helperbot.start_helper_bot()
|
await bumper.mqtt_helperbot.start_helper_bot()
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
async def restart_MQTT(self):
|
async def restart_MQTT(self):
|
||||||
mqttserver = bumper.mqtt_server.broker
|
mqttserver = bumper.mqtt_server.broker
|
||||||
|
|
||||||
|
|
@ -249,6 +247,10 @@ class ConfServer:
|
||||||
while not bumper.mqtt_server.broker.transitions.state == "started":
|
while not bumper.mqtt_server.broker.transitions.state == "started":
|
||||||
await asyncio.sleep(0.1)
|
await asyncio.sleep(0.1)
|
||||||
|
|
||||||
|
async def restart_XMPP(self):
|
||||||
|
bumper.xmpp_server.disconnect()
|
||||||
|
await bumper.xmpp_server.start_async_server()
|
||||||
|
|
||||||
async def handle_RestartService(self, request):
|
async def handle_RestartService(self, request):
|
||||||
try:
|
try:
|
||||||
service = request.match_info.get("service", "")
|
service = request.match_info.get("service", "")
|
||||||
|
|
@ -261,7 +263,9 @@ class ConfServer:
|
||||||
aloop.call_later(
|
aloop.call_later(
|
||||||
2, lambda: asyncio.create_task(self.restart_Helper())
|
2, lambda: asyncio.create_task(self.restart_Helper())
|
||||||
) # In 2 seconds restart Helperbot
|
) # In 2 seconds restart Helperbot
|
||||||
|
return web.json_response({"status": "complete"})
|
||||||
|
elif service == "XMPPServer":
|
||||||
|
await self.restart_XMPP()
|
||||||
return web.json_response({"status": "complete"})
|
return web.json_response({"status": "complete"})
|
||||||
else:
|
else:
|
||||||
return web.json_response({"status": "invalid service"})
|
return web.json_response({"status": "invalid service"})
|
||||||
|
|
@ -1105,130 +1109,126 @@ class ConfServer:
|
||||||
confserverlog.exception("{}".format(e))
|
confserverlog.exception("{}".format(e))
|
||||||
|
|
||||||
async def handle_lg_log(self, request): # EcoVacs Home
|
async def handle_lg_log(self, request): # EcoVacs Home
|
||||||
try:
|
try:
|
||||||
json_body = json.loads(await request.text())
|
json_body = json.loads(await request.text())
|
||||||
|
|
||||||
randomid = "".join(random.sample(string.ascii_letters, 6))
|
randomid = "".join(random.sample(string.ascii_letters, 6))
|
||||||
did = json_body["did"]
|
did = json_body["did"]
|
||||||
|
|
||||||
botdetails = bumper.bot_get(did)
|
botdetails = bumper.bot_get(did)
|
||||||
if botdetails:
|
if botdetails:
|
||||||
if not "cmdName" in json_body:
|
if not "cmdName" in json_body:
|
||||||
if "td" in json_body:
|
if "td" in json_body:
|
||||||
json_body["cmdName"] = json_body["td"]
|
json_body["cmdName"] = json_body["td"]
|
||||||
# json_body["td"] = "q"
|
# json_body["td"] = "q"
|
||||||
|
|
||||||
if not "toId" in json_body:
|
if not "toId" in json_body:
|
||||||
json_body["toId"] = did
|
json_body["toId"] = did
|
||||||
|
|
||||||
if not "toType" in json_body:
|
if not "toType" in json_body:
|
||||||
json_body["toType"] = botdetails["class"]
|
json_body["toType"] = botdetails["class"]
|
||||||
|
|
||||||
if not "toRes" in json_body:
|
if not "toRes" in json_body:
|
||||||
json_body["toRes"] = botdetails["resource"]
|
json_body["toRes"] = botdetails["resource"]
|
||||||
|
|
||||||
if not "payloadType" in json_body:
|
if not "payloadType" in json_body:
|
||||||
json_body["payloadType"] = "x"
|
json_body["payloadType"] = "x"
|
||||||
|
|
||||||
if not "payload" in json_body:
|
if not "payload" in json_body:
|
||||||
json_body["payload"] = ""
|
json_body["payload"] = ""
|
||||||
if json_body["td"] == "GetCleanLogs":
|
if json_body["td"] == "GetCleanLogs":
|
||||||
json_body["td"] = "q"
|
json_body["td"] = "q"
|
||||||
json_body["payload"] = '<ctl count="30"/>' # <ctl />"
|
json_body["payload"] = '<ctl count="30"/>' # <ctl />"
|
||||||
|
|
||||||
if did != "":
|
if did != "":
|
||||||
bot = bumper.bot_get(did)
|
bot = bumper.bot_get(did)
|
||||||
if bot["company"] == "eco-ng":
|
if bot["company"] == "eco-ng":
|
||||||
body = ""
|
body = ""
|
||||||
retcmd = await bumper.mqtt_helperbot.send_command(
|
retcmd = await bumper.mqtt_helperbot.send_command(
|
||||||
json_body, randomid
|
json_body, randomid
|
||||||
)
|
)
|
||||||
confserverlog.debug("Send Bot - {}".format(json_body))
|
confserverlog.debug("Send Bot - {}".format(json_body))
|
||||||
confserverlog.debug("Bot Response - {}".format(body))
|
confserverlog.debug("Bot Response - {}".format(body))
|
||||||
logs = []
|
logs = []
|
||||||
logsroot = ET.fromstring(retcmd["resp"])
|
logsroot = ET.fromstring(retcmd["resp"])
|
||||||
if logsroot.attrib["ret"] == "ok":
|
if logsroot.attrib["ret"] == "ok":
|
||||||
cleanlogs = logsroot.getchildren()
|
cleanlogs = logsroot.getchildren()
|
||||||
for l in cleanlogs:
|
for l in cleanlogs:
|
||||||
logs.append(l.attrib)
|
logs.append(l.attrib)
|
||||||
|
|
||||||
body = {
|
|
||||||
"ret": "ok",
|
|
||||||
# "logs": logs, #TODO: Doesn't parse correctly, new protocol & server side processing
|
|
||||||
"logs": [],
|
|
||||||
}
|
|
||||||
|
|
||||||
else:
|
|
||||||
body = {"ret": "ok", "logs": []}
|
|
||||||
|
|
||||||
confserverlog.debug(
|
|
||||||
"POST: {} - Response: {}".format(json_body, body)
|
|
||||||
)
|
|
||||||
|
|
||||||
return web.json_response(body)
|
|
||||||
else:
|
|
||||||
# No response, send error back
|
|
||||||
confserverlog.error(
|
|
||||||
"No bots with DID: {} connected to MQTT".format(
|
|
||||||
json_body["toId"]
|
|
||||||
)
|
|
||||||
)
|
|
||||||
body = {
|
body = {
|
||||||
"id": randomid,
|
"ret": "ok",
|
||||||
"errno": bumper.ERR_COMMON,
|
# "logs": logs, #TODO: Doesn't parse correctly, new protocol & server side processing
|
||||||
"ret": "fail",
|
"logs": [],
|
||||||
}
|
}
|
||||||
return web.json_response(body)
|
|
||||||
|
|
||||||
except Exception as e:
|
else:
|
||||||
confserverlog.exception("{}".format(e))
|
body = {"ret": "ok", "logs": []}
|
||||||
|
|
||||||
|
confserverlog.debug(
|
||||||
|
"POST: {} - Response: {}".format(json_body, body)
|
||||||
|
)
|
||||||
|
|
||||||
|
return web.json_response(body)
|
||||||
|
else:
|
||||||
|
# No response, send error back
|
||||||
|
confserverlog.error(
|
||||||
|
"No bots with DID: {} connected to MQTT".format(
|
||||||
|
json_body["toId"]
|
||||||
|
)
|
||||||
|
)
|
||||||
|
body = {"id": randomid, "errno": bumper.ERR_COMMON, "ret": "fail"}
|
||||||
|
return web.json_response(body)
|
||||||
|
|
||||||
|
except Exception as e:
|
||||||
|
confserverlog.exception("{}".format(e))
|
||||||
|
|
||||||
async def handle_devmanager_botcommand(self, request):
|
async def handle_devmanager_botcommand(self, request):
|
||||||
try:
|
try:
|
||||||
json_body = json.loads(await request.text())
|
json_body = json.loads(await request.text())
|
||||||
|
|
||||||
randomid = "".join(random.sample(string.ascii_letters, 6))
|
randomid = "".join(random.sample(string.ascii_letters, 6))
|
||||||
did = ""
|
did = ""
|
||||||
if "toId" in json_body: # Its a command
|
if "toId" in json_body: # Its a command
|
||||||
did = json_body["toId"]
|
did = json_body["toId"]
|
||||||
|
|
||||||
if did != "":
|
|
||||||
bot = bumper.bot_get(did)
|
|
||||||
if bot["company"] == "eco-ng":
|
|
||||||
retcmd = await bumper.mqtt_helperbot.send_command(
|
|
||||||
json_body, randomid
|
|
||||||
)
|
|
||||||
body = retcmd
|
|
||||||
confserverlog.debug("Send Bot - {}".format(json_body))
|
|
||||||
confserverlog.debug("Bot Response - {}".format(body))
|
|
||||||
return web.json_response(body)
|
|
||||||
else:
|
|
||||||
# No response, send error back
|
|
||||||
confserverlog.error(
|
|
||||||
"No bots with DID: {} connected to MQTT".format(
|
|
||||||
json_body["toId"]
|
|
||||||
)
|
|
||||||
)
|
|
||||||
body = {
|
|
||||||
"id": randomid,
|
|
||||||
"errno": 500,
|
|
||||||
"ret": "fail",
|
|
||||||
"debug": "wait for response timed out",
|
|
||||||
}
|
|
||||||
return web.json_response(body)
|
|
||||||
|
|
||||||
|
if did != "":
|
||||||
|
bot = bumper.bot_get(did)
|
||||||
|
if bot["company"] == "eco-ng":
|
||||||
|
retcmd = await bumper.mqtt_helperbot.send_command(
|
||||||
|
json_body, randomid
|
||||||
|
)
|
||||||
|
body = retcmd
|
||||||
|
confserverlog.debug("Send Bot - {}".format(json_body))
|
||||||
|
confserverlog.debug("Bot Response - {}".format(body))
|
||||||
|
return web.json_response(body)
|
||||||
else:
|
else:
|
||||||
if "td" in json_body: # Seen when doing initial wifi config
|
# No response, send error back
|
||||||
if json_body["td"] == "PollSCResult":
|
confserverlog.error(
|
||||||
body = {"ret": "ok"}
|
"No bots with DID: {} connected to MQTT".format(
|
||||||
return web.json_response(body)
|
json_body["toId"]
|
||||||
|
)
|
||||||
|
)
|
||||||
|
body = {
|
||||||
|
"id": randomid,
|
||||||
|
"errno": 500,
|
||||||
|
"ret": "fail",
|
||||||
|
"debug": "wait for response timed out",
|
||||||
|
}
|
||||||
|
return web.json_response(body)
|
||||||
|
|
||||||
if json_body["td"] == "HasUnreadMsg": # EcoVacs Home
|
else:
|
||||||
body = {"ret": "ok", "unRead": False}
|
if "td" in json_body: # Seen when doing initial wifi config
|
||||||
return web.json_response(body)
|
if json_body["td"] == "PollSCResult":
|
||||||
|
body = {"ret": "ok"}
|
||||||
|
return web.json_response(body)
|
||||||
|
|
||||||
except Exception as e:
|
if json_body["td"] == "HasUnreadMsg": # EcoVacs Home
|
||||||
confserverlog.exception("{}".format(e))
|
body = {"ret": "ok", "unRead": False}
|
||||||
|
return web.json_response(body)
|
||||||
|
|
||||||
|
except Exception as e:
|
||||||
|
confserverlog.exception("{}".format(e))
|
||||||
|
|
||||||
async def handle_dim_devmanager(self, request): # Used in EcoVacs Home App
|
async def handle_dim_devmanager(self, request): # Used in EcoVacs Home App
|
||||||
try:
|
try:
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue