move productIotMap into own file
This commit is contained in:
parent
9b85d45407
commit
f09cacda9e
5 changed files with 1756 additions and 1744 deletions
1665
bumper/models.py
1665
bumper/models.py
File diff suppressed because it is too large
Load diff
|
|
@ -1,21 +1,23 @@
|
||||||
"""Appsvr plugin module."""
|
"""Appsvr plugin module."""
|
||||||
|
import copy
|
||||||
import json
|
import json
|
||||||
import logging
|
import logging
|
||||||
from typing import Iterable
|
from typing import Any, Iterable
|
||||||
|
|
||||||
from aiohttp import web
|
from aiohttp import web
|
||||||
from aiohttp.web_exceptions import HTTPInternalServerError
|
from aiohttp.web_exceptions import HTTPInternalServerError
|
||||||
from aiohttp.web_request import Request
|
from aiohttp.web_request import Request
|
||||||
from aiohttp.web_response import Response
|
from aiohttp.web_response import Response
|
||||||
from aiohttp.web_routedef import AbstractRouteDef
|
from aiohttp.web_routedef import AbstractRouteDef
|
||||||
|
from amqtt.session import Session
|
||||||
|
|
||||||
|
import bumper
|
||||||
from bumper.db import db_get, token_by_authcode, user_add_oauth
|
from bumper.db import db_get, token_by_authcode, user_add_oauth
|
||||||
from bumper.models import include_EcoVacsHomeProducts_info
|
|
||||||
|
|
||||||
from .. import WebserverPlugin
|
from .. import WebserverPlugin
|
||||||
|
from .pim import get_product_iot_map
|
||||||
|
|
||||||
|
|
||||||
# pylint: disable=no-self-use
|
|
||||||
class AppsvrPlugin(WebserverPlugin):
|
class AppsvrPlugin(WebserverPlugin):
|
||||||
"""Appsvr plugin."""
|
"""Appsvr plugin."""
|
||||||
|
|
||||||
|
|
@ -26,102 +28,146 @@ class AppsvrPlugin(WebserverPlugin):
|
||||||
web.route(
|
web.route(
|
||||||
"*",
|
"*",
|
||||||
"/appsvr/app.do",
|
"/appsvr/app.do",
|
||||||
self._handle_appsvr_app,
|
_handle_appsvr_app,
|
||||||
),
|
),
|
||||||
web.route(
|
web.route(
|
||||||
"*",
|
"*",
|
||||||
"/appsvr/service/list",
|
"/appsvr/service/list",
|
||||||
self._handle_appsvr_service_list,
|
_handle_appsvr_service_list,
|
||||||
),
|
),
|
||||||
web.route(
|
web.route(
|
||||||
"*",
|
"*",
|
||||||
"/appsvr/oauth_callback",
|
"/appsvr/oauth_callback",
|
||||||
self._handle_appsvr_oauth_callback,
|
_handle_appsvr_oauth_callback,
|
||||||
),
|
),
|
||||||
]
|
]
|
||||||
|
|
||||||
async def _handle_appsvr_app(self, request: Request) -> Response:
|
|
||||||
if request.method == "GET":
|
|
||||||
# Skip GET for now
|
|
||||||
return web.json_response({"result": "fail", "todo": "result"})
|
|
||||||
|
|
||||||
try:
|
async def _handle_appsvr_app(request: Request) -> Response:
|
||||||
if request.content_type == "application/x-www-form-urlencoded":
|
if request.method == "GET":
|
||||||
postbody = await request.post()
|
# Skip GET for now
|
||||||
else:
|
return web.json_response({"result": "fail", "todo": "result"})
|
||||||
postbody = json.loads(await request.text())
|
|
||||||
|
|
||||||
todo = postbody["todo"]
|
try:
|
||||||
|
if request.content_type == "application/x-www-form-urlencoded":
|
||||||
|
postbody = await request.post()
|
||||||
|
else:
|
||||||
|
postbody = json.loads(await request.text())
|
||||||
|
|
||||||
if todo == "GetGlobalDeviceList": # EcoVacs Home
|
todo = postbody["todo"]
|
||||||
bots = db_get().table("bots").all()
|
|
||||||
devices = []
|
|
||||||
for bot in bots:
|
|
||||||
if bot["class"] != "":
|
|
||||||
device = include_EcoVacsHomeProducts_info(bot)
|
|
||||||
# Happens if the bot isn't on the EcoVacs Home list
|
|
||||||
if device is not None:
|
|
||||||
devices.append(device)
|
|
||||||
|
|
||||||
body = {
|
if todo == "GetGlobalDeviceList": # EcoVacs Home
|
||||||
"code": 0,
|
bots = db_get().table("bots").all()
|
||||||
"devices": devices,
|
devices = []
|
||||||
"ret": "ok",
|
for bot in bots:
|
||||||
"todo": "result",
|
if bot["class"] != "":
|
||||||
}
|
device = _include_product_iot_map_info(bot)
|
||||||
|
# Happens if the bot isn't on the EcoVacs Home list
|
||||||
|
if device is not None:
|
||||||
|
devices.append(device)
|
||||||
|
|
||||||
return web.json_response(body)
|
|
||||||
except Exception: # pylint: disable=broad-except
|
|
||||||
logging.error("Unexpected exception occurred", exc_info=True)
|
|
||||||
|
|
||||||
raise HTTPInternalServerError
|
|
||||||
|
|
||||||
async def _handle_appsvr_service_list(self, _: Request) -> Response:
|
|
||||||
try:
|
|
||||||
# original urls comment out as they are sub sub domain, which the current certificate is not valid
|
|
||||||
# using url, where the certs is valid
|
|
||||||
# data = {
|
|
||||||
# "account": "users-base.dc-eu.ww.ecouser.net",
|
|
||||||
# "jmq": "jmq-ngiot-eu.dc.ww.ecouser.net",
|
|
||||||
# "lb": "lbo.ecouser.net",
|
|
||||||
# "magw": "api-app.dc-eu.ww.ecouser.net",
|
|
||||||
# "msgcloud": "msg-eu.ecouser.net:5223",
|
|
||||||
# "ngiotLb": "jmq-ngiot-eu.area.ww.ecouser.net",
|
|
||||||
# "rop": "api-rop.dc-eu.ww.ecouser.net"
|
|
||||||
# }
|
|
||||||
|
|
||||||
data = {
|
|
||||||
"account": "users-base.ecouser.net",
|
|
||||||
"jmq": "jmq-ngiot-eu.ecouser.net",
|
|
||||||
"lb": "lbo.ecouser.net",
|
|
||||||
"magw": "api-app.ecouser.net",
|
|
||||||
"msgcloud": "msg-eu.ecouser.net:5223",
|
|
||||||
"ngiotLb": "jmq-ngiot-eu.ecouser.net",
|
|
||||||
"rop": "api-rop.ecouser.net",
|
|
||||||
}
|
|
||||||
|
|
||||||
body = {"code": 0, "data": data, "ret": "ok", "todo": "result"}
|
|
||||||
|
|
||||||
return web.json_response(body)
|
|
||||||
except Exception: # pylint: disable=broad-except
|
|
||||||
logging.error("Unexpected exception occurred", exc_info=True)
|
|
||||||
|
|
||||||
raise HTTPInternalServerError
|
|
||||||
|
|
||||||
async def _handle_appsvr_oauth_callback(self, request: Request) -> Response:
|
|
||||||
try:
|
|
||||||
token = token_by_authcode(request.query["code"])
|
|
||||||
oauth = user_add_oauth(token["userid"])
|
|
||||||
body = {
|
body = {
|
||||||
"code": 0,
|
"code": 0,
|
||||||
"data": oauth.toResponse(),
|
"devices": devices,
|
||||||
"ret": "ok",
|
"ret": "ok",
|
||||||
"todo": "result",
|
"todo": "result",
|
||||||
}
|
}
|
||||||
|
|
||||||
return web.json_response(body)
|
return web.json_response(body)
|
||||||
|
except Exception: # pylint: disable=broad-except
|
||||||
|
logging.error("Unexpected exception occurred", exc_info=True)
|
||||||
|
|
||||||
except Exception: # pylint: disable=broad-except
|
raise HTTPInternalServerError
|
||||||
logging.error("Unexpected exception occurred", exc_info=True)
|
|
||||||
|
|
||||||
raise HTTPInternalServerError
|
|
||||||
|
def _include_product_iot_map_info(bot: dict[str, Any]) -> dict[str, Any]:
|
||||||
|
result = copy.deepcopy(bot)
|
||||||
|
|
||||||
|
for botprod in get_product_iot_map():
|
||||||
|
if botprod["classid"] == result["class"]:
|
||||||
|
result["UILogicId"] = botprod["product"]["UILogicId"]
|
||||||
|
result["ota"] = botprod["product"]["ota"]
|
||||||
|
result["icon"] = botprod["product"]["iconUrl"]
|
||||||
|
result["model"] = botprod["product"]["model"]
|
||||||
|
result["pip"] = botprod["product"]["_id"]
|
||||||
|
result["deviceName"] = botprod["product"]["name"]
|
||||||
|
result["materialNo"] = botprod["product"]["materialNo"]
|
||||||
|
result["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"
|
||||||
|
# }
|
||||||
|
|
||||||
|
result["status"] = (
|
||||||
|
1 if bot["mqtt_connection"] or bot["xmpp_connection"] else 0
|
||||||
|
)
|
||||||
|
|
||||||
|
# mqtt_connection is not always set correctly, therefore workaround until fixed properly
|
||||||
|
session: Session
|
||||||
|
for (session, _) in bumper.mqtt_server.broker._sessions.values():
|
||||||
|
did = session.client_id.split("@")[0]
|
||||||
|
if did == bot["did"] and session.transitions.state == "connected":
|
||||||
|
result["status"] = 1
|
||||||
|
|
||||||
|
break
|
||||||
|
return result
|
||||||
|
|
||||||
|
|
||||||
|
async def _handle_appsvr_service_list(_: Request) -> Response:
|
||||||
|
try:
|
||||||
|
# original urls comment out as they are sub sub domain, which the current certificate is not valid
|
||||||
|
# using url, where the certs is valid
|
||||||
|
# data = {
|
||||||
|
# "account": "users-base.dc-eu.ww.ecouser.net",
|
||||||
|
# "jmq": "jmq-ngiot-eu.dc.ww.ecouser.net",
|
||||||
|
# "lb": "lbo.ecouser.net",
|
||||||
|
# "magw": "api-app.dc-eu.ww.ecouser.net",
|
||||||
|
# "msgcloud": "msg-eu.ecouser.net:5223",
|
||||||
|
# "ngiotLb": "jmq-ngiot-eu.area.ww.ecouser.net",
|
||||||
|
# "rop": "api-rop.dc-eu.ww.ecouser.net"
|
||||||
|
# }
|
||||||
|
|
||||||
|
data = {
|
||||||
|
"account": "users-base.ecouser.net",
|
||||||
|
"jmq": "jmq-ngiot-eu.ecouser.net",
|
||||||
|
"lb": "lbo.ecouser.net",
|
||||||
|
"magw": "api-app.ecouser.net",
|
||||||
|
"msgcloud": "msg-eu.ecouser.net:5223",
|
||||||
|
"ngiotLb": "jmq-ngiot-eu.ecouser.net",
|
||||||
|
"rop": "api-rop.ecouser.net",
|
||||||
|
}
|
||||||
|
|
||||||
|
body = {"code": 0, "data": data, "ret": "ok", "todo": "result"}
|
||||||
|
|
||||||
|
return web.json_response(body)
|
||||||
|
except Exception: # pylint: disable=broad-except
|
||||||
|
logging.error("Unexpected exception occurred", exc_info=True)
|
||||||
|
|
||||||
|
raise HTTPInternalServerError
|
||||||
|
|
||||||
|
|
||||||
|
async def _handle_appsvr_oauth_callback(request: Request) -> Response:
|
||||||
|
try:
|
||||||
|
token = token_by_authcode(request.query["code"])
|
||||||
|
oauth = user_add_oauth(token["userid"])
|
||||||
|
body = {
|
||||||
|
"code": 0,
|
||||||
|
"data": oauth.toResponse(),
|
||||||
|
"ret": "ok",
|
||||||
|
"todo": "result",
|
||||||
|
}
|
||||||
|
|
||||||
|
return web.json_response(body)
|
||||||
|
|
||||||
|
except Exception: # pylint: disable=broad-except
|
||||||
|
logging.error("Unexpected exception occurred", exc_info=True)
|
||||||
|
|
||||||
|
raise HTTPInternalServerError
|
||||||
|
|
|
||||||
|
|
@ -1 +1,13 @@
|
||||||
"""Api pim module plugin."""
|
"""Api pim module plugin."""
|
||||||
|
import json
|
||||||
|
import os
|
||||||
|
from typing import Any
|
||||||
|
|
||||||
|
|
||||||
|
def get_product_iot_map() -> tuple[Any]:
|
||||||
|
"""Get product iot map."""
|
||||||
|
with open(
|
||||||
|
os.path.join(os.path.dirname(__file__), "productIotMap.json"),
|
||||||
|
encoding="utf-8",
|
||||||
|
) as file:
|
||||||
|
return (json.load(file),)
|
||||||
|
|
|
||||||
|
|
@ -10,9 +10,11 @@ from aiohttp.web_request import Request
|
||||||
from aiohttp.web_response import Response
|
from aiohttp.web_response import Response
|
||||||
from aiohttp.web_routedef import AbstractRouteDef
|
from aiohttp.web_routedef import AbstractRouteDef
|
||||||
|
|
||||||
from bumper.models import RETURN_API_SUCCESS, EcoVacsHomeProducts
|
from bumper.models import RETURN_API_SUCCESS
|
||||||
from bumper.web.plugins import WebserverPlugin
|
from bumper.web.plugins import WebserverPlugin
|
||||||
|
|
||||||
|
from . import get_product_iot_map
|
||||||
|
|
||||||
|
|
||||||
class ProductPlugin(WebserverPlugin):
|
class ProductPlugin(WebserverPlugin):
|
||||||
"""Product plugin."""
|
"""Product plugin."""
|
||||||
|
|
@ -49,7 +51,7 @@ async def _handle_get_product_iot_map(_: Request) -> Response:
|
||||||
try:
|
try:
|
||||||
body = {
|
body = {
|
||||||
"code": RETURN_API_SUCCESS,
|
"code": RETURN_API_SUCCESS,
|
||||||
"data": EcoVacsHomeProducts,
|
"data": get_product_iot_map(),
|
||||||
}
|
}
|
||||||
return web.json_response(body)
|
return web.json_response(body)
|
||||||
except Exception: # pylint: disable=broad-except
|
except Exception: # pylint: disable=broad-except
|
||||||
|
|
|
||||||
1617
bumper/web/plugins/api/pim/productIotMap.json
Normal file
1617
bumper/web/plugins/api/pim/productIotMap.json
Normal file
File diff suppressed because it is too large
Load diff
Loading…
Add table
Add a link
Reference in a new issue