add workaround for mqtt bot status
This commit is contained in:
parent
b48d3c8ad9
commit
91ebc285b0
3 changed files with 43 additions and 40 deletions
31
bumper/db.py
31
bumper/db.py
|
|
@ -352,37 +352,6 @@ def bot_get(did):
|
|||
Bot = Query()
|
||||
return bots.get(Bot.did == did)
|
||||
|
||||
|
||||
def bot_toEcoVacsHome_JSON(bot): # EcoVacs Home
|
||||
for botprod in EcoVacsHomeProducts:
|
||||
if botprod["classid"] == bot["class"]:
|
||||
bot["UILogicId"] = botprod["product"]["UILogicId"]
|
||||
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"
|
||||
# }
|
||||
bot["status"] = 1 if bot["mqtt_connection"] or bot["xmpp_connection"] else 0
|
||||
|
||||
return json.dumps(
|
||||
bot, default=lambda o: o.__dict__, sort_keys=False
|
||||
) # , indent=4)
|
||||
|
||||
|
||||
def bot_full_upsert(vacbot):
|
||||
bots = db_get().table("bots")
|
||||
Bot = Query()
|
||||
|
|
|
|||
|
|
@ -1,7 +1,9 @@
|
|||
#!/usr/bin/env python3
|
||||
import copy
|
||||
import json
|
||||
import uuid
|
||||
from datetime import datetime, timedelta
|
||||
from typing import Dict, Any
|
||||
|
||||
import bumper
|
||||
|
||||
|
|
@ -120,6 +122,44 @@ class OAuth:
|
|||
return data
|
||||
|
||||
|
||||
def include_EcoVacsHomeProducts_info(bot) -> Dict[str, Any]:
|
||||
result = copy.deepcopy(bot)
|
||||
|
||||
for botprod in EcoVacsHomeProducts:
|
||||
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"
|
||||
# }
|
||||
|
||||
# todo refactor it
|
||||
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
|
||||
for session in bumper.mqtt_server.broker._sessions:
|
||||
did = str(session[0].client_id).split("@")[0]
|
||||
if did == bot["did"]:
|
||||
result["status"] = 1
|
||||
|
||||
return result
|
||||
|
||||
|
||||
# EcoVacs Home Product IOT Map - 2021-04-15
|
||||
# https://portal-ww.ecouser.net/api/pim/product/getProductIotMap
|
||||
EcoVacsHomeProducts = [
|
||||
|
|
|
|||
|
|
@ -41,12 +41,8 @@ class portal_api_appsvr(plugins.ConfServerApp):
|
|||
async def handle_appsvr_app(self, request):
|
||||
if not request.method == "GET": # Skip GET for now
|
||||
try:
|
||||
|
||||
body = {}
|
||||
postbody = {}
|
||||
if request.content_type == "application/x-www-form-urlencoded":
|
||||
postbody = await request.post()
|
||||
|
||||
else:
|
||||
postbody = json.loads(await request.text())
|
||||
|
||||
|
|
@ -57,11 +53,9 @@ class portal_api_appsvr(plugins.ConfServerApp):
|
|||
botlist = []
|
||||
for bot in bots:
|
||||
if bot["class"] != "":
|
||||
b = bumper.bot_toEcoVacsHome_JSON(bot)
|
||||
if (
|
||||
not b is None
|
||||
): # Happens if the bot isn't on the EcoVacs Home list
|
||||
botlist.append(json.loads(b))
|
||||
b = bumper.include_EcoVacsHomeProducts_info(bot)
|
||||
if b is not None: # Happens if the bot isn't on the EcoVacs Home list
|
||||
botlist.append(b)
|
||||
|
||||
body = {
|
||||
"code": 0,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue