implement basic confserver plugins
- basic plugin system for confserver - allows adding api via plugins that can be saved in user data/plugins folder - relocated routes into internal plugins - add start_site to replace start_server - changed init code for starting confserver, this with the above fixes an issue of initializing the app twice
This commit is contained in:
parent
e4130e4626
commit
d1d2b228ee
18 changed files with 1445 additions and 920 deletions
76
bumper/plugins/bumper_confserver_portal_iot.py
Normal file
76
bumper/plugins/bumper_confserver_portal_iot.py
Normal file
|
|
@ -0,0 +1,76 @@
|
|||
#!/usr/bin/env python3
|
||||
import asyncio
|
||||
from aiohttp import web
|
||||
from bumper import plugins
|
||||
import logging
|
||||
import bumper
|
||||
from bumper.models import *
|
||||
from bumper import plugins
|
||||
from datetime import datetime, timedelta
|
||||
import string
|
||||
import random
|
||||
|
||||
class portal_api_iot(plugins.ConfServerApp):
|
||||
|
||||
def __init__(self):
|
||||
self.name = "portal_api_iot"
|
||||
self.plugin_type = "sub_api"
|
||||
self.sub_api = "portal_api"
|
||||
|
||||
self.routes = [
|
||||
|
||||
web.route("*", "/iot/devmanager.do", self.handle_devmanager_botcommand, name="portal_api_iot_devmanager"),
|
||||
|
||||
]
|
||||
|
||||
self.get_milli_time = bumper.ConfServer.ConfServer_GeneralFunctions().get_milli_time
|
||||
|
||||
async def handle_devmanager_botcommand(self, request):
|
||||
try:
|
||||
json_body = json.loads(await request.text())
|
||||
|
||||
randomid = "".join(random.sample(string.ascii_letters, 6))
|
||||
did = ""
|
||||
if "toId" in json_body: # Its a command
|
||||
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
|
||||
logging.debug("Send Bot - {}".format(json_body))
|
||||
logging.debug("Bot Response - {}".format(body))
|
||||
return web.json_response(body)
|
||||
else:
|
||||
# No response, send error back
|
||||
logging.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)
|
||||
|
||||
else:
|
||||
if "td" in json_body: # Seen when doing initial wifi config
|
||||
if json_body["td"] == "PollSCResult":
|
||||
body = {"ret": "ok"}
|
||||
return web.json_response(body)
|
||||
|
||||
if json_body["td"] == "HasUnreadMsg": # EcoVacs Home
|
||||
body = {"ret": "ok", "unRead": False}
|
||||
return web.json_response(body)
|
||||
|
||||
except Exception as e:
|
||||
logging.exception("{}".format(e))
|
||||
|
||||
plugin = portal_api_iot()
|
||||
|
||||
Loading…
Add table
Add a link
Reference in a new issue