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."""
|
||||
import copy
|
||||
import json
|
||||
import logging
|
||||
from typing import Iterable
|
||||
from typing import Any, Iterable
|
||||
|
||||
from aiohttp import web
|
||||
from aiohttp.web_exceptions import HTTPInternalServerError
|
||||
from aiohttp.web_request import Request
|
||||
from aiohttp.web_response import Response
|
||||
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.models import include_EcoVacsHomeProducts_info
|
||||
|
||||
from .. import WebserverPlugin
|
||||
from .pim import get_product_iot_map
|
||||
|
||||
|
||||
# pylint: disable=no-self-use
|
||||
class AppsvrPlugin(WebserverPlugin):
|
||||
"""Appsvr plugin."""
|
||||
|
||||
|
|
@ -26,21 +28,22 @@ class AppsvrPlugin(WebserverPlugin):
|
|||
web.route(
|
||||
"*",
|
||||
"/appsvr/app.do",
|
||||
self._handle_appsvr_app,
|
||||
_handle_appsvr_app,
|
||||
),
|
||||
web.route(
|
||||
"*",
|
||||
"/appsvr/service/list",
|
||||
self._handle_appsvr_service_list,
|
||||
_handle_appsvr_service_list,
|
||||
),
|
||||
web.route(
|
||||
"*",
|
||||
"/appsvr/oauth_callback",
|
||||
self._handle_appsvr_oauth_callback,
|
||||
_handle_appsvr_oauth_callback,
|
||||
),
|
||||
]
|
||||
|
||||
async def _handle_appsvr_app(self, request: Request) -> Response:
|
||||
|
||||
async def _handle_appsvr_app(request: Request) -> Response:
|
||||
if request.method == "GET":
|
||||
# Skip GET for now
|
||||
return web.json_response({"result": "fail", "todo": "result"})
|
||||
|
|
@ -58,7 +61,7 @@ class AppsvrPlugin(WebserverPlugin):
|
|||
devices = []
|
||||
for bot in bots:
|
||||
if bot["class"] != "":
|
||||
device = include_EcoVacsHomeProducts_info(bot)
|
||||
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)
|
||||
|
|
@ -76,7 +79,49 @@ class AppsvrPlugin(WebserverPlugin):
|
|||
|
||||
raise HTTPInternalServerError
|
||||
|
||||
async def _handle_appsvr_service_list(self, _: Request) -> Response:
|
||||
|
||||
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
|
||||
|
|
@ -108,7 +153,8 @@ class AppsvrPlugin(WebserverPlugin):
|
|||
|
||||
raise HTTPInternalServerError
|
||||
|
||||
async def _handle_appsvr_oauth_callback(self, request: Request) -> Response:
|
||||
|
||||
async def _handle_appsvr_oauth_callback(request: Request) -> Response:
|
||||
try:
|
||||
token = token_by_authcode(request.query["code"])
|
||||
oauth = user_add_oauth(token["userid"])
|
||||
|
|
|
|||
|
|
@ -1 +1,13 @@
|
|||
"""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_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 . import get_product_iot_map
|
||||
|
||||
|
||||
class ProductPlugin(WebserverPlugin):
|
||||
"""Product plugin."""
|
||||
|
|
@ -49,7 +51,7 @@ async def _handle_get_product_iot_map(_: Request) -> Response:
|
|||
try:
|
||||
body = {
|
||||
"code": RETURN_API_SUCCESS,
|
||||
"data": EcoVacsHomeProducts,
|
||||
"data": get_product_iot_map(),
|
||||
}
|
||||
return web.json_response(body)
|
||||
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