add some missing endpoints for app v2
This commit is contained in:
parent
03277b9d41
commit
ca32e0e2bc
3 changed files with 284 additions and 34 deletions
37
bumper/db.py
37
bumper/db.py
|
|
@ -1,13 +1,13 @@
|
|||
#!/usr/bin/env python3
|
||||
import bumper
|
||||
from bumper.models import VacBotClient, VacBotDevice, BumperUser, EcoVacsHomeProducts, OAuth
|
||||
from tinydb import TinyDB, Query
|
||||
from tinydb.storages import MemoryStorage
|
||||
from datetime import datetime, timedelta
|
||||
import os
|
||||
import json
|
||||
import logging
|
||||
import os
|
||||
from datetime import datetime, timedelta
|
||||
|
||||
from tinydb import TinyDB, Query
|
||||
|
||||
import bumper
|
||||
from bumper.models import VacBotClient, VacBotDevice, BumperUser, EcoVacsHomeProducts, OAuth
|
||||
|
||||
bumperlog = logging.getLogger("bumper")
|
||||
|
||||
|
|
@ -249,8 +249,8 @@ def check_authcode(uid, authcode):
|
|||
tmpauth = tokens.get(
|
||||
(Query().authcode == authcode)
|
||||
& ( # Match authcode
|
||||
(Query().userid == uid.replace("fuid_", ""))
|
||||
| (Query().userid == "fuid_{}".format(uid))
|
||||
(Query().userid == uid.replace("fuid_", ""))
|
||||
| (Query().userid == "fuid_{}".format(uid))
|
||||
) # Userid with or without fuid_
|
||||
)
|
||||
if tmpauth:
|
||||
|
|
@ -281,8 +281,8 @@ def check_token(uid, token):
|
|||
tmpauth = tokens.get(
|
||||
(Query().token == token)
|
||||
& ( # Match token
|
||||
(Query().userid == uid.replace("fuid_", ""))
|
||||
| (Query().userid == "fuid_{}".format(uid))
|
||||
(Query().userid == uid.replace("fuid_", ""))
|
||||
| (Query().userid == "fuid_{}".format(uid))
|
||||
) # Userid with or without fuid_
|
||||
)
|
||||
if tmpauth:
|
||||
|
|
@ -310,7 +310,7 @@ def bot_add(sn, did, devclass, resource, company):
|
|||
bot = bot_get(did)
|
||||
if not bot: # Not existing bot in database
|
||||
if (
|
||||
not devclass == "" or "@" not in sn or "tmp" not in sn
|
||||
not devclass == "" or "@" not in sn or "tmp" not in sn
|
||||
): # try to prevent bad additions to the bot list
|
||||
bumperlog.info(
|
||||
"Adding new bot with SN: {} DID: {}".format(newbot.name, newbot.did)
|
||||
|
|
@ -338,6 +338,19 @@ def bot_toEcoVacsHome_JSON(bot): # EcoVacs Home
|
|||
bot["ota"] = botprod["product"]["ota"]
|
||||
bot["icon"] = botprod["product"]["iconUrl"]
|
||||
bot["model"] = botprod["product"]["model"]
|
||||
bot["pip"] = botprod["product"]["_id"]
|
||||
bot["deviceName"] = botprod["product"]["name"]
|
||||
bot["materialNo"] = botprod["product"]["materialNo"]
|
||||
bot["product_category"] = "DEEBOT" if botprod["product"]["name"].startswith("DEEBOT") else "UNKNOWN"
|
||||
# bot["updateInfo"] = {
|
||||
# "changeLog": "",
|
||||
# "needUpdate": False
|
||||
# }
|
||||
# bot["service"] = {
|
||||
# "jmq": "jmq-ngiot-eu.dc.ww.ecouser.net",
|
||||
# "mqs": "api-ngiot.dc-as.ww.ecouser.net"
|
||||
# }
|
||||
|
||||
return json.dumps(
|
||||
bot, default=lambda o: o.__dict__, sort_keys=False
|
||||
) # , indent=4)
|
||||
|
|
@ -381,12 +394,14 @@ def client_add(userid, realm, resource):
|
|||
bumperlog.info("Adding new client with resource {}".format(newclient.resource))
|
||||
client_full_upsert(newclient.asdict())
|
||||
|
||||
|
||||
def client_remove(resource):
|
||||
clients = db_get().table("clients")
|
||||
client = client_get(resource)
|
||||
if client:
|
||||
clients.remove(doc_ids=[client.doc_id])
|
||||
|
||||
|
||||
def client_get(resource):
|
||||
clients = db_get().table("clients")
|
||||
Client = Query()
|
||||
|
|
|
|||
38
bumper/plugins/bumper_confserver_portal_ecms.py
Normal file
38
bumper/plugins/bumper_confserver_portal_ecms.py
Normal file
|
|
@ -0,0 +1,38 @@
|
|||
#!/usr/bin/env python3
|
||||
import logging
|
||||
|
||||
from aiohttp import web
|
||||
|
||||
from bumper import plugins
|
||||
from bumper.models import *
|
||||
|
||||
|
||||
class portal_api_ecms(plugins.ConfServerApp):
|
||||
|
||||
def __init__(self):
|
||||
self.name = "portal_api_ecms"
|
||||
self.plugin_type = "sub_api"
|
||||
self.sub_api = "portal_api"
|
||||
|
||||
self.routes = [
|
||||
web.route("*", "/ecms/app/ad/res", self.handle_ad_res, name="portal_api_ecms_ad_res"),
|
||||
]
|
||||
|
||||
self.get_milli_time = bumper.ConfServer.ConfServer_GeneralFunctions().get_milli_time
|
||||
|
||||
async def handle_ad_res(self, request):
|
||||
try:
|
||||
body = {
|
||||
"code": 0,
|
||||
"data": [],
|
||||
"message": "success",
|
||||
"success": True
|
||||
}
|
||||
|
||||
return web.json_response(body)
|
||||
|
||||
except Exception as e:
|
||||
logging.exception("{}".format(e))
|
||||
|
||||
|
||||
plugin = portal_api_ecms()
|
||||
|
|
@ -1,14 +1,13 @@
|
|||
#!/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 os
|
||||
|
||||
from aiohttp import web
|
||||
|
||||
from bumper import plugins
|
||||
from bumper.models import *
|
||||
|
||||
|
||||
class portal_api_pim(plugins.ConfServerApp):
|
||||
|
||||
def __init__(self):
|
||||
|
|
@ -17,13 +16,12 @@ class portal_api_pim(plugins.ConfServerApp):
|
|||
self.sub_api = "portal_api"
|
||||
|
||||
self.routes = [
|
||||
|
||||
web.route("*", "/pim/product/getProductIotMap", self.handle_getProductIotMap, name="portal_api_pim_getProductIotMap"),
|
||||
web.route("*", "/pim/file/get/{id}", self.handle_pimFile, name="portal_api_pim_file"),
|
||||
web.route("*", "/pim/product/getConfignetAll", self.handle_getConfignetAll, name="portal_api_pim_getConfignetAll"),
|
||||
web.route("*", "/pim/product/getConfigGroups", self.handle_getConfigGroups, name="portal_api_pim_getConfigGroups"),
|
||||
web.route("*", "/pim/dictionary/getErrDetail", self.handle_getErrDetail, name="portal_api_pim_getErrDetail"),
|
||||
|
||||
web.route("*", "/pim/product/software/config/batch", self.handle_product_config_batch, name="portal_api_pim_product_config_batch"),
|
||||
]
|
||||
|
||||
self.get_milli_time = bumper.ConfServer.ConfServer_GeneralFunctions().get_milli_time
|
||||
|
|
@ -43,7 +41,7 @@ class portal_api_pim(plugins.ConfServerApp):
|
|||
try:
|
||||
fileID = request.match_info.get("id", "")
|
||||
|
||||
return web.FileResponse(os.path.join(bumper.bumper_dir,"bumper","web","images","robotvac_image.jpg"))
|
||||
return web.FileResponse(os.path.join(bumper.bumper_dir, "bumper", "web", "images", "robotvac_image.jpg"))
|
||||
|
||||
except Exception as e:
|
||||
logging.exception("{}".format(e))
|
||||
|
|
@ -67,15 +65,43 @@ class portal_api_pim(plugins.ConfServerApp):
|
|||
async def handle_getErrDetail(self, request):
|
||||
try:
|
||||
body = {
|
||||
"code": -1,
|
||||
"data": [],
|
||||
"msg": "This errcode's detail is not exists"
|
||||
}
|
||||
"code": -1,
|
||||
"data": [],
|
||||
"msg": "This errcode's detail is not exists"
|
||||
}
|
||||
return web.json_response(body)
|
||||
|
||||
except Exception as e:
|
||||
logging.exception("{}".format(e))
|
||||
|
||||
async def handle_product_config_batch(self, request):
|
||||
try:
|
||||
json_body = json.loads(await request.text())
|
||||
data = []
|
||||
for pid in json_body["pids"]:
|
||||
for productConfig in productConfigBatch:
|
||||
if pid == productConfig["pid"]:
|
||||
data.append(productConfig)
|
||||
continue
|
||||
|
||||
# not found in productConfigBatch
|
||||
# some devices don't have any product configuration
|
||||
data.append({
|
||||
"cfg": {},
|
||||
"pid": pid
|
||||
})
|
||||
|
||||
body = {
|
||||
"code": 200,
|
||||
"data": data,
|
||||
"message": "success"
|
||||
}
|
||||
return web.json_response(body)
|
||||
|
||||
except Exception as e:
|
||||
logging.exception("{}".format(e))
|
||||
|
||||
|
||||
plugin = portal_api_pim()
|
||||
|
||||
confignetAllResponse = {
|
||||
|
|
@ -2681,3 +2707,174 @@ configGroupsResponse = {
|
|||
"contactUS": "helper"
|
||||
}
|
||||
}
|
||||
|
||||
productConfigBatch = [
|
||||
{
|
||||
"pid": "5e14196a6e71b80001b60fda",
|
||||
"cfg": {
|
||||
"supported": {
|
||||
"tmallstand": False,
|
||||
"video": False,
|
||||
"battery": True,
|
||||
"clean": True,
|
||||
"charge": True
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"pid": "5e8e8d8a032edd8457c66bfb",
|
||||
"cfg": {
|
||||
"supported": {
|
||||
"tmallstand": False,
|
||||
"video": False,
|
||||
"battery": True,
|
||||
"clean": True,
|
||||
"charge": True
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"pid": "5c19a91ca1e6ee000178224a",
|
||||
"cfg": {
|
||||
"supported": {
|
||||
"tmallstand": False,
|
||||
"video": False,
|
||||
"battery": True,
|
||||
"clean": True,
|
||||
"charge": True
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"pid": "5e8e8d2a032edd3c03c66bf7",
|
||||
"cfg": {
|
||||
"supported": {
|
||||
"tmallstand": False,
|
||||
"video": False,
|
||||
"battery": True,
|
||||
"clean": True,
|
||||
"charge": True
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"pid": "5de0d86ed88546000195239a",
|
||||
"cfg": {
|
||||
"supported": {
|
||||
"tmallstand": False,
|
||||
"video": True,
|
||||
"battery": True,
|
||||
"clean": True,
|
||||
"charge": True
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"pid": "5c19a8f3a1e6ee0001782247",
|
||||
"cfg": {
|
||||
"supported": {
|
||||
"tmallstand": False,
|
||||
"video": False,
|
||||
"battery": True,
|
||||
"clean": True,
|
||||
"charge": True
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"pid": "5e698a6306f6de52c264c61b",
|
||||
"cfg": {
|
||||
"supported": {
|
||||
"tmallstand": False,
|
||||
"video": False,
|
||||
"battery": True,
|
||||
"clean": True,
|
||||
"charge": True
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"pid": "5e699a4106f6de83ea64c620",
|
||||
"cfg": {
|
||||
"supported": {
|
||||
"tmallstand": False,
|
||||
"video": False,
|
||||
"battery": True,
|
||||
"clean": True,
|
||||
"charge": True
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"pid": "5edd998afdd6a30008da039b",
|
||||
"cfg": {
|
||||
"supported": {
|
||||
"tmallstand": False,
|
||||
"video": True,
|
||||
"battery": True,
|
||||
"clean": True,
|
||||
"charge": True
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"pid": "5edd9a4075f2fc000636086c",
|
||||
"cfg": {
|
||||
"supported": {
|
||||
"tmallstand": False,
|
||||
"video": True,
|
||||
"battery": True,
|
||||
"clean": True,
|
||||
"charge": True
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"pid": "5ed5e4d3a719ea460ec3216c",
|
||||
"cfg": {
|
||||
"supported": {
|
||||
"tmallstand": False,
|
||||
"video": False,
|
||||
"battery": True,
|
||||
"clean": True,
|
||||
"charge": True
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"pid": "5f88195e6cf8de0008ed7c11",
|
||||
"cfg": {
|
||||
"supported": {
|
||||
"tmallstand": False,
|
||||
"video": False,
|
||||
"battery": True,
|
||||
"clean": True,
|
||||
"charge": True
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"pid": "5f8819156cf8de0008ed7c0d",
|
||||
"cfg": {
|
||||
"supported": {
|
||||
"tmallstand": False,
|
||||
"video": False,
|
||||
"battery": True,
|
||||
"clean": True,
|
||||
"charge": True
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"pid": "5fa105c6d16a99000667eb54",
|
||||
"cfg": {
|
||||
"supported": {
|
||||
"tmallstand": False,
|
||||
"video": False,
|
||||
"battery": True,
|
||||
"clean": True,
|
||||
"charge": True
|
||||
}
|
||||
}
|
||||
}
|
||||
]
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue