refactor pim endpoint
This commit is contained in:
parent
50d31344c8
commit
9b85d45407
11 changed files with 2782 additions and 2571 deletions
|
|
@ -62,6 +62,11 @@ repos:
|
||||||
rev: v2.6.2
|
rev: v2.6.2
|
||||||
hooks:
|
hooks:
|
||||||
- id: prettier
|
- id: prettier
|
||||||
|
additional_dependencies:
|
||||||
|
- prettier@2.6.2
|
||||||
|
- prettier-plugin-sort-json@0.0.2
|
||||||
|
exclude_types:
|
||||||
|
- python
|
||||||
- repo: https://github.com/adrienverge/yamllint.git
|
- repo: https://github.com/adrienverge/yamllint.git
|
||||||
rev: v1.26.3
|
rev: v1.26.3
|
||||||
hooks:
|
hooks:
|
||||||
|
|
|
||||||
3
.prettierrc
Normal file
3
.prettierrc
Normal file
|
|
@ -0,0 +1,3 @@
|
||||||
|
{
|
||||||
|
"jsonRecursiveSort": true
|
||||||
|
}
|
||||||
File diff suppressed because it is too large
Load diff
1
bumper/web/plugins/api/pim/__init__.py
Normal file
1
bumper/web/plugins/api/pim/__init__.py
Normal file
|
|
@ -0,0 +1 @@
|
||||||
|
"""Api pim module plugin."""
|
||||||
1052
bumper/web/plugins/api/pim/configGroupsResponse.json
Normal file
1052
bumper/web/plugins/api/pim/configGroupsResponse.json
Normal file
File diff suppressed because it is too large
Load diff
1377
bumper/web/plugins/api/pim/configNetAllResponse.json
Normal file
1377
bumper/web/plugins/api/pim/configNetAllResponse.json
Normal file
File diff suppressed because it is too large
Load diff
40
bumper/web/plugins/api/pim/dictionary.py
Normal file
40
bumper/web/plugins/api/pim/dictionary.py
Normal file
|
|
@ -0,0 +1,40 @@
|
||||||
|
"""Pim dictionary plugin module."""
|
||||||
|
import logging
|
||||||
|
from typing import 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 bumper.web.plugins import WebserverPlugin
|
||||||
|
|
||||||
|
|
||||||
|
class DictionaryPlugin(WebserverPlugin):
|
||||||
|
"""Dictionary plugin."""
|
||||||
|
|
||||||
|
@property
|
||||||
|
def routes(self) -> Iterable[AbstractRouteDef]:
|
||||||
|
"""Plugin routes."""
|
||||||
|
return [
|
||||||
|
web.route(
|
||||||
|
"*",
|
||||||
|
"/dictionary/getErrDetail",
|
||||||
|
_handle_get_err_detail,
|
||||||
|
),
|
||||||
|
]
|
||||||
|
|
||||||
|
|
||||||
|
async def _handle_get_err_detail(_: Request) -> Response:
|
||||||
|
"""Get error details."""
|
||||||
|
try:
|
||||||
|
body = {
|
||||||
|
"code": -1,
|
||||||
|
"data": [],
|
||||||
|
"msg": "This errcode's detail is not exists",
|
||||||
|
}
|
||||||
|
return web.json_response(body)
|
||||||
|
except Exception: # pylint: disable=broad-except
|
||||||
|
logging.error("An exception occurred during handling request.", exc_info=True)
|
||||||
|
raise HTTPInternalServerError
|
||||||
23
bumper/web/plugins/api/pim/file.py
Normal file
23
bumper/web/plugins/api/pim/file.py
Normal file
|
|
@ -0,0 +1,23 @@
|
||||||
|
"""File plugin module."""
|
||||||
|
from typing import Iterable
|
||||||
|
|
||||||
|
from aiohttp import web
|
||||||
|
from aiohttp.web_routedef import AbstractRouteDef
|
||||||
|
|
||||||
|
from bumper.web.images import get_bot_image
|
||||||
|
from bumper.web.plugins import WebserverPlugin
|
||||||
|
|
||||||
|
|
||||||
|
class FilePlugin(WebserverPlugin):
|
||||||
|
"""Pim file plugin."""
|
||||||
|
|
||||||
|
@property
|
||||||
|
def routes(self) -> Iterable[AbstractRouteDef]:
|
||||||
|
"""Plugin routes."""
|
||||||
|
return [
|
||||||
|
web.route(
|
||||||
|
"*",
|
||||||
|
"/file/get/{id}",
|
||||||
|
get_bot_image,
|
||||||
|
),
|
||||||
|
]
|
||||||
111
bumper/web/plugins/api/pim/product.py
Normal file
111
bumper/web/plugins/api/pim/product.py
Normal file
|
|
@ -0,0 +1,111 @@
|
||||||
|
"""Pim product plugin module."""
|
||||||
|
import json
|
||||||
|
import logging
|
||||||
|
import os
|
||||||
|
from typing import 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 bumper.models import RETURN_API_SUCCESS, EcoVacsHomeProducts
|
||||||
|
from bumper.web.plugins import WebserverPlugin
|
||||||
|
|
||||||
|
|
||||||
|
class ProductPlugin(WebserverPlugin):
|
||||||
|
"""Product plugin."""
|
||||||
|
|
||||||
|
@property
|
||||||
|
def routes(self) -> Iterable[AbstractRouteDef]:
|
||||||
|
"""Plugin routes."""
|
||||||
|
return [
|
||||||
|
web.route(
|
||||||
|
"*",
|
||||||
|
"/product/getProductIotMap",
|
||||||
|
_handle_get_product_iot_map,
|
||||||
|
),
|
||||||
|
web.route(
|
||||||
|
"*",
|
||||||
|
"/product/getConfignetAll",
|
||||||
|
_handle_get_confignet_all,
|
||||||
|
),
|
||||||
|
web.route(
|
||||||
|
"*",
|
||||||
|
"/product/getConfigGroups",
|
||||||
|
_handle_get_config_groups,
|
||||||
|
),
|
||||||
|
web.route(
|
||||||
|
"*",
|
||||||
|
"/product/software/config/batch",
|
||||||
|
_handle_product_config_batch,
|
||||||
|
),
|
||||||
|
]
|
||||||
|
|
||||||
|
|
||||||
|
async def _handle_get_product_iot_map(_: Request) -> Response:
|
||||||
|
"""Get product iot map."""
|
||||||
|
try:
|
||||||
|
body = {
|
||||||
|
"code": RETURN_API_SUCCESS,
|
||||||
|
"data": EcoVacsHomeProducts,
|
||||||
|
}
|
||||||
|
return web.json_response(body)
|
||||||
|
except Exception: # pylint: disable=broad-except
|
||||||
|
logging.error("An exception occurred during handling request.", exc_info=True)
|
||||||
|
raise HTTPInternalServerError
|
||||||
|
|
||||||
|
|
||||||
|
async def _handle_get_confignet_all(_: Request) -> Response:
|
||||||
|
"""Get config net all."""
|
||||||
|
try:
|
||||||
|
with open(
|
||||||
|
os.path.join(os.path.dirname(__file__), "confignetAllResponse.json"),
|
||||||
|
encoding="utf-8",
|
||||||
|
) as file:
|
||||||
|
return web.json_response(json.load(file))
|
||||||
|
except Exception: # pylint: disable=broad-except
|
||||||
|
logging.error("An exception occurred during handling request.", exc_info=True)
|
||||||
|
raise HTTPInternalServerError
|
||||||
|
|
||||||
|
|
||||||
|
async def _handle_get_config_groups(_: Request) -> Response:
|
||||||
|
"""Get config groups."""
|
||||||
|
try:
|
||||||
|
with open(
|
||||||
|
os.path.join(os.path.dirname(__file__), "configGroupsResponse.json"),
|
||||||
|
encoding="utf-8",
|
||||||
|
) as file:
|
||||||
|
return web.json_response(json.load(file))
|
||||||
|
except Exception: # pylint: disable=broad-except
|
||||||
|
logging.error("An exception occurred during handling request.", exc_info=True)
|
||||||
|
raise HTTPInternalServerError
|
||||||
|
|
||||||
|
|
||||||
|
async def _handle_product_config_batch(request: Request) -> Response:
|
||||||
|
"""Handle product config batch."""
|
||||||
|
try:
|
||||||
|
with open(
|
||||||
|
os.path.join(os.path.dirname(__file__), "productConfigBatch.json"),
|
||||||
|
encoding="utf-8",
|
||||||
|
) as file:
|
||||||
|
product_config_batch = json.load(file)
|
||||||
|
|
||||||
|
json_body = json.loads(await request.text())
|
||||||
|
data = []
|
||||||
|
for pid in json_body["pids"]:
|
||||||
|
for product_config in product_config_batch:
|
||||||
|
if pid == product_config["pid"]:
|
||||||
|
data.append(product_config)
|
||||||
|
continue
|
||||||
|
|
||||||
|
# not found in product_config_batch
|
||||||
|
# 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: # pylint: disable=broad-except
|
||||||
|
logging.error("An exception occurred during handling request.", exc_info=True)
|
||||||
|
raise HTTPInternalServerError
|
||||||
170
bumper/web/plugins/api/pim/productConfigBatch.json
Normal file
170
bumper/web/plugins/api/pim/productConfigBatch.json
Normal file
|
|
@ -0,0 +1,170 @@
|
||||||
|
[
|
||||||
|
{
|
||||||
|
"cfg": {
|
||||||
|
"supported": {
|
||||||
|
"battery": true,
|
||||||
|
"charge": true,
|
||||||
|
"clean": true,
|
||||||
|
"tmallstand": false,
|
||||||
|
"video": false
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"pid": "5e14196a6e71b80001b60fda"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"cfg": {
|
||||||
|
"supported": {
|
||||||
|
"battery": true,
|
||||||
|
"charge": true,
|
||||||
|
"clean": true,
|
||||||
|
"tmallstand": false,
|
||||||
|
"video": false
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"pid": "5e8e8d8a032edd8457c66bfb"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"cfg": {
|
||||||
|
"supported": {
|
||||||
|
"battery": true,
|
||||||
|
"charge": true,
|
||||||
|
"clean": true,
|
||||||
|
"tmallstand": false,
|
||||||
|
"video": false
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"pid": "5c19a91ca1e6ee000178224a"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"cfg": {
|
||||||
|
"supported": {
|
||||||
|
"battery": true,
|
||||||
|
"charge": true,
|
||||||
|
"clean": true,
|
||||||
|
"tmallstand": false,
|
||||||
|
"video": false
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"pid": "5e8e8d2a032edd3c03c66bf7"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"cfg": {
|
||||||
|
"supported": {
|
||||||
|
"battery": true,
|
||||||
|
"charge": true,
|
||||||
|
"clean": true,
|
||||||
|
"tmallstand": false,
|
||||||
|
"video": true
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"pid": "5de0d86ed88546000195239a"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"cfg": {
|
||||||
|
"supported": {
|
||||||
|
"battery": true,
|
||||||
|
"charge": true,
|
||||||
|
"clean": true,
|
||||||
|
"tmallstand": false,
|
||||||
|
"video": false
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"pid": "5c19a8f3a1e6ee0001782247"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"cfg": {
|
||||||
|
"supported": {
|
||||||
|
"battery": true,
|
||||||
|
"charge": true,
|
||||||
|
"clean": true,
|
||||||
|
"tmallstand": false,
|
||||||
|
"video": false
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"pid": "5e698a6306f6de52c264c61b"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"cfg": {
|
||||||
|
"supported": {
|
||||||
|
"battery": true,
|
||||||
|
"charge": true,
|
||||||
|
"clean": true,
|
||||||
|
"tmallstand": false,
|
||||||
|
"video": false
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"pid": "5e699a4106f6de83ea64c620"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"cfg": {
|
||||||
|
"supported": {
|
||||||
|
"battery": true,
|
||||||
|
"charge": true,
|
||||||
|
"clean": true,
|
||||||
|
"tmallstand": false,
|
||||||
|
"video": true
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"pid": "5edd998afdd6a30008da039b"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"cfg": {
|
||||||
|
"supported": {
|
||||||
|
"battery": true,
|
||||||
|
"charge": true,
|
||||||
|
"clean": true,
|
||||||
|
"tmallstand": false,
|
||||||
|
"video": true
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"pid": "5edd9a4075f2fc000636086c"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"cfg": {
|
||||||
|
"supported": {
|
||||||
|
"battery": true,
|
||||||
|
"charge": true,
|
||||||
|
"clean": true,
|
||||||
|
"tmallstand": false,
|
||||||
|
"video": false
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"pid": "5ed5e4d3a719ea460ec3216c"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"cfg": {
|
||||||
|
"supported": {
|
||||||
|
"battery": true,
|
||||||
|
"charge": true,
|
||||||
|
"clean": true,
|
||||||
|
"tmallstand": false,
|
||||||
|
"video": false
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"pid": "5f88195e6cf8de0008ed7c11"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"cfg": {
|
||||||
|
"supported": {
|
||||||
|
"battery": true,
|
||||||
|
"charge": true,
|
||||||
|
"clean": true,
|
||||||
|
"tmallstand": false,
|
||||||
|
"video": false
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"pid": "5f8819156cf8de0008ed7c0d"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"cfg": {
|
||||||
|
"supported": {
|
||||||
|
"battery": true,
|
||||||
|
"charge": true,
|
||||||
|
"clean": true,
|
||||||
|
"tmallstand": false,
|
||||||
|
"video": false
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"pid": "5fa105c6d16a99000667eb54"
|
||||||
|
}
|
||||||
|
]
|
||||||
Loading…
Add table
Add a link
Reference in a new issue