Format with black
Formatting code with black - pipenv update
This commit is contained in:
parent
401af5652f
commit
c3098e03e4
8 changed files with 741 additions and 663 deletions
6
Pipfile.lock
generated
6
Pipfile.lock
generated
|
|
@ -333,11 +333,11 @@
|
|||
},
|
||||
"pbr": {
|
||||
"hashes": [
|
||||
"sha256:6901995b9b686cb90cceba67a0f6d4d14ae003cd59bc12beb61549bdfbe3bc89",
|
||||
"sha256:d950c64aeea5456bbd147468382a5bb77fe692c13c9f00f0219814ce5b642755"
|
||||
"sha256:0ce920b865091450bbcd452b35cf6d6eb8a6d9ce13ad2210d6e77557f85cf32b",
|
||||
"sha256:93d2dc6ee0c9af4dbc70bc1251d0e545a9910ca8863774761f92716dece400b6"
|
||||
],
|
||||
"index": "pypi",
|
||||
"version": "==5.2.0"
|
||||
"version": "==5.2.1"
|
||||
},
|
||||
"pylint": {
|
||||
"hashes": [
|
||||
|
|
|
|||
|
|
@ -27,7 +27,9 @@ db = None
|
|||
# Logs
|
||||
os.makedirs("logs", exist_ok=True) # Ensure logs directory exists or create
|
||||
# Set format for all logs
|
||||
logformat = logging.Formatter("[%(asctime)s] :: %(levelname)s :: %(name)s :: %(module)s :: %(funcName)s :: %(lineno)d :: %(message)s")
|
||||
logformat = logging.Formatter(
|
||||
"[%(asctime)s] :: %(levelname)s :: %(name)s :: %(module)s :: %(funcName)s :: %(lineno)d :: %(message)s"
|
||||
)
|
||||
|
||||
bumperlog = logging.getLogger("bumper")
|
||||
bumper_rotate = RotatingFileHandler("logs/bumper.log", maxBytes=5000000, backupCount=5)
|
||||
|
|
@ -37,28 +39,36 @@ bumperlog.addHandler(bumper_rotate)
|
|||
# bumperlog.setLevel(logging.INFO)
|
||||
|
||||
confserverlog = logging.getLogger("confserver")
|
||||
conf_rotate = RotatingFileHandler("logs/confserver.log", maxBytes=5000000, backupCount=5)
|
||||
conf_rotate = RotatingFileHandler(
|
||||
"logs/confserver.log", maxBytes=5000000, backupCount=5
|
||||
)
|
||||
conf_rotate.setFormatter(logformat)
|
||||
confserverlog.addHandler(conf_rotate)
|
||||
# Override the logging level
|
||||
# confserverlog.setLevel(logging.INFO)
|
||||
|
||||
mqttserverlog = logging.getLogger("mqttserver")
|
||||
mqtt_rotate = RotatingFileHandler("logs/mqttserver.log", maxBytes=5000000, backupCount=5)
|
||||
mqtt_rotate = RotatingFileHandler(
|
||||
"logs/mqttserver.log", maxBytes=5000000, backupCount=5
|
||||
)
|
||||
mqtt_rotate.setFormatter(logformat)
|
||||
mqttserverlog.addHandler(mqtt_rotate)
|
||||
# Override the logging level
|
||||
# mqttserverlog.setLevel(logging.INFO)
|
||||
|
||||
helperbotlog = logging.getLogger("helperbot")
|
||||
helperbot_rotate = RotatingFileHandler("logs/helperbot.log", maxBytes=5000000, backupCount=5)
|
||||
helperbot_rotate = RotatingFileHandler(
|
||||
"logs/helperbot.log", maxBytes=5000000, backupCount=5
|
||||
)
|
||||
helperbot_rotate.setFormatter(logformat)
|
||||
helperbotlog.addHandler(helperbot_rotate)
|
||||
# Override the logging level
|
||||
# helperbotlog.setLevel(logging.INFO)
|
||||
|
||||
xmppserverlog = logging.getLogger("xmppserver")
|
||||
xmpp_rotate = RotatingFileHandler("logs/xmppserver.log", maxBytes=5000000, backupCount=5)
|
||||
xmpp_rotate = RotatingFileHandler(
|
||||
"logs/xmppserver.log", maxBytes=5000000, backupCount=5
|
||||
)
|
||||
xmpp_rotate.setFormatter(logformat)
|
||||
xmppserverlog.addHandler(xmpp_rotate)
|
||||
# Override the logging level
|
||||
|
|
@ -81,12 +91,17 @@ def db_file():
|
|||
|
||||
def os_db_path():
|
||||
if platform.system() == "Windows":
|
||||
os.makedirs(os.getenv("APPDATA"), exist_ok=True) #Ensure db_path directory exists or create
|
||||
os.makedirs(
|
||||
os.getenv("APPDATA"), exist_ok=True
|
||||
) # Ensure db_path directory exists or create
|
||||
return os.path.join(os.getenv("APPDATA"), "bumper.db")
|
||||
else:
|
||||
os.makedirs(os.path.expanduser("~/.config"), exist_ok=True) #Ensure db_path directory exists or create
|
||||
os.makedirs(
|
||||
os.path.expanduser("~/.config"), exist_ok=True
|
||||
) # Ensure db_path directory exists or create
|
||||
return os.path.expanduser("~/.config/bumper.db")
|
||||
|
||||
|
||||
def db_get():
|
||||
try:
|
||||
# Will create the database if it doesn't exist
|
||||
|
|
@ -100,7 +115,6 @@ def db_get():
|
|||
|
||||
return db
|
||||
|
||||
|
||||
except json.decoder.JSONDecodeError as jerr:
|
||||
bumperlog.error("JsonErr: {} - Doc: {}".format(jerr.msg, jerr.doc))
|
||||
|
||||
|
|
@ -284,16 +298,15 @@ class VacBotDevice(object):
|
|||
}
|
||||
|
||||
def toJSON(self):
|
||||
return json.dumps(self, default=lambda o: o.__dict__,
|
||||
sort_keys=False)#, indent=4)
|
||||
return json.dumps(
|
||||
self, default=lambda o: o.__dict__, sort_keys=False
|
||||
) # , indent=4)
|
||||
|
||||
|
||||
class GlobalVacBotDevice(VacBotDevice): # EcoVacs Home
|
||||
UILogicId = ""
|
||||
ota = True
|
||||
updateInfo = {
|
||||
"changeLog": "",
|
||||
"needUpdate": False
|
||||
}
|
||||
updateInfo = {"changeLog": "", "needUpdate": False}
|
||||
icon = ""
|
||||
deviceName = ""
|
||||
|
||||
|
|
@ -315,9 +328,9 @@ EcoVacsHomeProducts = [
|
|||
"alexa": True,
|
||||
"assistant": True,
|
||||
"share": True,
|
||||
"tmjl": False
|
||||
}
|
||||
}
|
||||
"tmjl": False,
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
"classid": "02uwxm",
|
||||
|
|
@ -333,9 +346,9 @@ EcoVacsHomeProducts = [
|
|||
"alexa": True,
|
||||
"assistant": True,
|
||||
"share": True,
|
||||
"tmjl": False
|
||||
}
|
||||
}
|
||||
"tmjl": False,
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
"classid": "y79a7u",
|
||||
|
|
@ -351,9 +364,9 @@ EcoVacsHomeProducts = [
|
|||
"alexa": True,
|
||||
"assistant": True,
|
||||
"share": True,
|
||||
"tmjl": False
|
||||
}
|
||||
}
|
||||
"tmjl": False,
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
"classid": "jr3pqa",
|
||||
|
|
@ -369,9 +382,9 @@ EcoVacsHomeProducts = [
|
|||
"alexa": True,
|
||||
"assistant": True,
|
||||
"share": True,
|
||||
"tmjl": False
|
||||
}
|
||||
}
|
||||
"tmjl": False,
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
"classid": "uv242z",
|
||||
|
|
@ -387,9 +400,9 @@ EcoVacsHomeProducts = [
|
|||
"alexa": True,
|
||||
"assistant": True,
|
||||
"share": True,
|
||||
"tmjl": False
|
||||
}
|
||||
}
|
||||
"tmjl": False,
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
"classid": "ls1ok3",
|
||||
|
|
@ -405,9 +418,9 @@ EcoVacsHomeProducts = [
|
|||
"alexa": True,
|
||||
"assistant": True,
|
||||
"share": True,
|
||||
"tmjl": False
|
||||
}
|
||||
}
|
||||
"tmjl": False,
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
"classid": "eyi9jv",
|
||||
|
|
@ -423,9 +436,9 @@ EcoVacsHomeProducts = [
|
|||
"alexa": True,
|
||||
"assistant": True,
|
||||
"share": True,
|
||||
"tmjl": False
|
||||
}
|
||||
}
|
||||
"tmjl": False,
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
"classid": "4zfacv",
|
||||
|
|
@ -441,9 +454,9 @@ EcoVacsHomeProducts = [
|
|||
"alexa": True,
|
||||
"assistant": True,
|
||||
"share": True,
|
||||
"tmjl": False
|
||||
}
|
||||
}
|
||||
"tmjl": False,
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
"classid": "vi829v",
|
||||
|
|
@ -459,9 +472,9 @@ EcoVacsHomeProducts = [
|
|||
"alexa": True,
|
||||
"assistant": True,
|
||||
"share": True,
|
||||
"tmjl": False
|
||||
}
|
||||
}
|
||||
"tmjl": False,
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
"classid": "gd4uut",
|
||||
|
|
@ -477,9 +490,9 @@ EcoVacsHomeProducts = [
|
|||
"alexa": True,
|
||||
"assistant": True,
|
||||
"share": False,
|
||||
"tmjl": False
|
||||
}
|
||||
}
|
||||
"tmjl": False,
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
"classid": "9akc61",
|
||||
|
|
@ -495,9 +508,9 @@ EcoVacsHomeProducts = [
|
|||
"alexa": True,
|
||||
"assistant": True,
|
||||
"share": True,
|
||||
"tmjl": False
|
||||
}
|
||||
}
|
||||
"tmjl": False,
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
"classid": "r8ead0",
|
||||
|
|
@ -513,9 +526,9 @@ EcoVacsHomeProducts = [
|
|||
"alexa": True,
|
||||
"assistant": True,
|
||||
"share": True,
|
||||
"tmjl": False
|
||||
}
|
||||
}
|
||||
"tmjl": False,
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
"classid": "emzppx",
|
||||
|
|
@ -531,9 +544,9 @@ EcoVacsHomeProducts = [
|
|||
"alexa": True,
|
||||
"assistant": True,
|
||||
"share": True,
|
||||
"tmjl": False
|
||||
}
|
||||
}
|
||||
"tmjl": False,
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
"classid": "vsc5ia",
|
||||
|
|
@ -549,9 +562,9 @@ EcoVacsHomeProducts = [
|
|||
"alexa": True,
|
||||
"assistant": True,
|
||||
"share": True,
|
||||
"tmjl": False
|
||||
}
|
||||
}
|
||||
"tmjl": False,
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
"classid": "aqdd5p",
|
||||
|
|
@ -567,16 +580,13 @@ EcoVacsHomeProducts = [
|
|||
"alexa": False,
|
||||
"assistant": False,
|
||||
"share": False,
|
||||
"tmjl": False
|
||||
}
|
||||
}
|
||||
}
|
||||
"tmjl": False,
|
||||
},
|
||||
},
|
||||
},
|
||||
]
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
class VacBotClient(object):
|
||||
def __init__(self, userid="", realm="", token=""):
|
||||
self.userid = userid
|
||||
|
|
@ -616,6 +626,7 @@ def check_authcode(uid, authcode):
|
|||
|
||||
return False
|
||||
|
||||
|
||||
def loginByItToken(authcode):
|
||||
bumperlog.debug("Checking for authcode: {}".format(authcode))
|
||||
tokens = db_get().table("tokens")
|
||||
|
|
@ -666,7 +677,9 @@ 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: # try to prevent bad additions to the bot list
|
||||
if (
|
||||
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)
|
||||
)
|
||||
|
|
@ -691,8 +704,9 @@ def bot_toEcoVacsHome_JSON(bot): #EcoVacs Home
|
|||
bot["UILogicId"] = botprod["product"]["UILogicId"]
|
||||
bot["ota"] = botprod["product"]["ota"]
|
||||
bot["icon"] = botprod["product"]["iconUrl"]
|
||||
return json.dumps(bot, default=lambda o: o.__dict__,
|
||||
sort_keys=False)#, indent=4)
|
||||
return json.dumps(
|
||||
bot, default=lambda o: o.__dict__, sort_keys=False
|
||||
) # , indent=4)
|
||||
|
||||
|
||||
def bot_full_upsert(vacbot):
|
||||
|
|
|
|||
|
|
@ -31,7 +31,10 @@ class aiohttp_filter(logging.Filter):
|
|||
|
||||
|
||||
confserverlog = logging.getLogger("confserver")
|
||||
logging.getLogger("aiohttp.access").addFilter(aiohttp_filter()) #Add logging filter above to aiohttp.access
|
||||
logging.getLogger("aiohttp.access").addFilter(
|
||||
aiohttp_filter()
|
||||
) # Add logging filter above to aiohttp.access
|
||||
|
||||
|
||||
class EcoVacs_Login:
|
||||
accessToken = ""
|
||||
|
|
@ -41,14 +44,17 @@ class EcoVacs_Login:
|
|||
username = ""
|
||||
|
||||
def toJSON(self):
|
||||
return json.dumps(self, default=lambda o: o.__dict__,
|
||||
sort_keys=False)#, indent=4)
|
||||
return json.dumps(
|
||||
self, default=lambda o: o.__dict__, sort_keys=False
|
||||
) # , indent=4)
|
||||
|
||||
|
||||
class EcoVacsHome_Login(EcoVacs_Login):
|
||||
loginName = ""
|
||||
mobile = ""
|
||||
ucUid = ""
|
||||
|
||||
|
||||
class ConfServer:
|
||||
def __init__(self, address, usessl=False, helperbot=None):
|
||||
self.helperbot = helperbot
|
||||
|
|
@ -85,8 +91,7 @@ class ConfServer:
|
|||
self.handle_getAuthCode,
|
||||
),
|
||||
web.get( # EcoVacs Home GetAuthCode
|
||||
"/{apiversion}/{apptype}/auth/getAuthCode",
|
||||
self.handle_getAuthCode
|
||||
"/{apiversion}/{apptype}/auth/getAuthCode", self.handle_getAuthCode
|
||||
),
|
||||
web.get(
|
||||
"/{apiversion}/private/{country}/{language}/{devid}/{apptype}/{appversion}/{devtype}/{aid}/user/checkAgreement",
|
||||
|
|
@ -121,8 +126,7 @@ class ConfServer:
|
|||
self.handle_hasUnreadMessage,
|
||||
),
|
||||
web.get( # EcoVacs Home neng message hasUnreadMsg
|
||||
"/api/neng/message/hasUnreadMsg",
|
||||
self.handle_neng_hasUnreadMessage,
|
||||
"/api/neng/message/hasUnreadMsg", self.handle_neng_hasUnreadMessage
|
||||
),
|
||||
web.get( # EcoVacs Home message getMsgList
|
||||
"/{apiversion}/private/{country}/{language}/{devid}/{apptype}/{appversion}/{devtype}/{aid}/message/getMsgList",
|
||||
|
|
@ -149,7 +153,9 @@ class ConfServer:
|
|||
),
|
||||
web.post("/api/lg/log.do", self.handle_lg_log), # EcoVacs Home
|
||||
web.post("/api/iot/devmanager.do", self.handle_devmanager_botcommand),
|
||||
web.post("/api/dim/devmanager.do", self.handle_dim_devmanager), #EcoVacs Home
|
||||
web.post(
|
||||
"/api/dim/devmanager.do", self.handle_dim_devmanager
|
||||
), # EcoVacs Home
|
||||
web.post("/lookup.do", self.handle_lookup),
|
||||
]
|
||||
)
|
||||
|
|
@ -158,7 +164,9 @@ class ConfServer:
|
|||
|
||||
async def start_server(self):
|
||||
try:
|
||||
confserverlog.info("Starting ConfServer at {}:{}".format(self.address[0], self.address[1]))
|
||||
confserverlog.info(
|
||||
"Starting ConfServer at {}:{}".format(self.address[0], self.address[1])
|
||||
)
|
||||
runner = web.AppRunner(self.app)
|
||||
await runner.setup()
|
||||
|
||||
|
|
@ -221,7 +229,9 @@ class ConfServer:
|
|||
if "global_" in apptype: # EcoVacs Home
|
||||
login_details = EcoVacsHome_Login()
|
||||
login_details.ucUid = "fuid_{}".format(user["userid"])
|
||||
login_details.loginName = "fusername_{}".format(user["userid"])
|
||||
login_details.loginName = "fusername_{}".format(
|
||||
user["userid"]
|
||||
)
|
||||
login_details.mobile = None
|
||||
|
||||
else:
|
||||
|
|
@ -293,8 +303,7 @@ class ConfServer:
|
|||
|
||||
body = {
|
||||
"code": bumper.RETURN_API_SUCCESS,
|
||||
"data":
|
||||
{
|
||||
"data": {
|
||||
"email": login_details.email,
|
||||
"hasMobile": "N",
|
||||
"hasPassword": "Y",
|
||||
|
|
@ -302,7 +311,7 @@ class ConfServer:
|
|||
"userName": login_details.username,
|
||||
"obfuscatedMobile": None,
|
||||
"mobile": None,
|
||||
"loginName": login_details.loginName
|
||||
"loginName": login_details.loginName,
|
||||
},
|
||||
"msg": "操作成功",
|
||||
"time": bumper.get_milli_time(datetime.utcnow().timestamp()),
|
||||
|
|
@ -312,7 +321,6 @@ class ConfServer:
|
|||
except Exception as e:
|
||||
confserverlog.exception("{}".format(e))
|
||||
|
||||
|
||||
def check_token(self, apptype, countrycode, user, token):
|
||||
try:
|
||||
if bumper.check_token(user["userid"], token):
|
||||
|
|
@ -431,7 +439,6 @@ class ConfServer:
|
|||
# Deactivate old tokens and authcodes
|
||||
bumper.user_revoke_expired_tokens(tmpuser["userid"])
|
||||
|
||||
|
||||
body = {
|
||||
"code": bumper.RETURN_API_SUCCESS,
|
||||
"data": json.loads(login_details.toJSON()),
|
||||
|
|
@ -646,30 +653,20 @@ class ConfServer:
|
|||
except Exception as e:
|
||||
confserverlog.exception("{}".format(e))
|
||||
|
||||
|
||||
async def handle_neng_hasUnreadMessage(self, request): # EcoVacs Home
|
||||
try:
|
||||
body = {
|
||||
"code": 0,
|
||||
"data": {
|
||||
"hasUnRead": True
|
||||
},
|
||||
}
|
||||
body = {"code": 0, "data": {"hasUnRead": True}}
|
||||
|
||||
return web.json_response(body)
|
||||
|
||||
except Exception as e:
|
||||
confserverlog.exception("{}".format(e))
|
||||
|
||||
|
||||
async def handle_getMsgList(self, request): # EcoVacs Home
|
||||
try:
|
||||
body = {
|
||||
"code": bumper.RETURN_API_SUCCESS,
|
||||
"data": {
|
||||
"hasNextPage": 0,
|
||||
"items": []
|
||||
},
|
||||
"data": {"hasNextPage": 0, "items": []},
|
||||
"msg": "操作成功",
|
||||
"success": True,
|
||||
"time": bumper.get_milli_time(datetime.utcnow().timestamp()),
|
||||
|
|
@ -688,7 +685,7 @@ class ConfServer:
|
|||
"myShopShowFlag": "N",
|
||||
"myShopUrl": "",
|
||||
"shopIndexShowFlag": "N",
|
||||
"shopIndexUrl": ""
|
||||
"shopIndexUrl": "",
|
||||
},
|
||||
"msg": "操作成功",
|
||||
"success": True,
|
||||
|
|
@ -704,16 +701,13 @@ class ConfServer:
|
|||
try:
|
||||
body = {
|
||||
"code": bumper.RETURN_API_SUCCESS,
|
||||
"data":
|
||||
{
|
||||
"iosGradeTime": {
|
||||
"iodGradeFlag": "N"
|
||||
},
|
||||
"data": {
|
||||
"iosGradeTime": {"iodGradeFlag": "N"},
|
||||
"openNotification": {
|
||||
"openNotificationContent": None,
|
||||
"openNotificationFlag": "N",
|
||||
"openNotificationTitle": None
|
||||
}
|
||||
"openNotificationTitle": None,
|
||||
},
|
||||
},
|
||||
"msg": "操作成功",
|
||||
"success": True,
|
||||
|
|
@ -737,15 +731,15 @@ class ConfServer:
|
|||
"id": "20180804040641_7d746faf18b8cb22a50d145598fe4c90",
|
||||
"type": "USER",
|
||||
"url": "https://bumper.ecovacs.com/content/agreement?id=20180804040641_7d746faf18b8cb22a50d145598fe4c90&language=EN", # "https://gl-us-wap.ecovacs.com/content/agreement?id=20180804040641_7d746faf18b8cb22a50d145598fe4c90&language=EN
|
||||
"version": "1.01"
|
||||
"version": "1.01",
|
||||
},
|
||||
{
|
||||
"force": "N",
|
||||
"id": "20180804040245_4e7c56dfb7ebd3b81b1f2747d0859fac",
|
||||
"type": "PRIVACY",
|
||||
"url": "https://bumper.ecovacs.com/content/agreement?id=20180804040245_4e7c56dfb7ebd3b81b1f2747d0859fac&language=EN", # "https://gl-us-wap.ecovacs.com/content/agreement?id=20180804040245_4e7c56dfb7ebd3b81b1f2747d0859fac&language=EN"
|
||||
"version": "1.01"
|
||||
}
|
||||
"version": "1.01",
|
||||
},
|
||||
],
|
||||
"msg": "操作成功",
|
||||
"success": True,
|
||||
|
|
@ -886,18 +880,18 @@ class ConfServer:
|
|||
srvip = socket.gethostbyname(socket.gethostname())
|
||||
srvport = 5223
|
||||
confserverlog.info(
|
||||
"Reporting FindBest-EcoMsgNew Server to Bot as: {}:{}".format(srvip, srvport)
|
||||
"Reporting FindBest-EcoMsgNew Server to Bot as: {}:{}".format(
|
||||
srvip, srvport
|
||||
)
|
||||
body = {
|
||||
"result": "ok",
|
||||
"ip": srvip,
|
||||
"port": srvport,
|
||||
}
|
||||
)
|
||||
body = {"result": "ok", "ip": srvip, "port": srvport}
|
||||
elif service == "EcoUpdate":
|
||||
srvip = "47.88.66.164" # EcoVacs Server
|
||||
srvport = 8005
|
||||
confserverlog.info(
|
||||
"Reporting FindBest-EcoUpdate Server to Bot as: {}:{}".format(srvip, srvport)
|
||||
"Reporting FindBest-EcoUpdate Server to Bot as: {}:{}".format(
|
||||
srvip, srvport
|
||||
)
|
||||
)
|
||||
body = {"result": "ok", "ip": srvip, "port": srvport}
|
||||
|
||||
|
|
@ -924,7 +918,6 @@ class ConfServer:
|
|||
else:
|
||||
body = {"result": "fail", "todo": "result"}
|
||||
|
||||
|
||||
elif todo == "GetDeviceList":
|
||||
body = {
|
||||
"devices": bumper.db_get().table("bots").all(),
|
||||
|
|
@ -957,8 +950,6 @@ class ConfServer:
|
|||
body = {"result": "fail", "todo": "result"}
|
||||
return web.json_response(body)
|
||||
|
||||
|
||||
|
||||
async def handle_appsvr_api(self, request):
|
||||
if not request.method == "GET": # Skip GET for now
|
||||
try:
|
||||
|
|
@ -979,7 +970,9 @@ class ConfServer:
|
|||
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
|
||||
if (
|
||||
not b is None
|
||||
): # Happens if the bot isn't on the EcoVacs Home list
|
||||
botlist.append(json.loads(b))
|
||||
|
||||
body = {
|
||||
|
|
@ -1002,7 +995,6 @@ class ConfServer:
|
|||
body = {"result": "fail", "todo": "result"}
|
||||
return web.json_response(body)
|
||||
|
||||
|
||||
async def handle_lookup(self, request):
|
||||
try:
|
||||
|
||||
|
|
@ -1023,7 +1015,9 @@ class ConfServer:
|
|||
srvip = socket.gethostbyname(socket.gethostname())
|
||||
srvport = 5223
|
||||
confserverlog.info(
|
||||
"Reporting FindBest-EcoMsgNew Server to Bot as: {}:{}".format(srvip, srvport)
|
||||
"Reporting FindBest-EcoMsgNew Server to Bot as: {}:{}".format(
|
||||
srvip, srvport
|
||||
)
|
||||
)
|
||||
msgserver = {"ip": srvip, "port": srvport, "result": "ok"}
|
||||
msgserver = json.dumps(msgserver)
|
||||
|
|
@ -1047,7 +1041,6 @@ class ConfServer:
|
|||
except Exception as e:
|
||||
confserverlog.exception("{}".format(e))
|
||||
|
||||
|
||||
async def handle_lg_log(self, request): # EcoVacs Home
|
||||
try:
|
||||
json_body = json.loads(await request.text())
|
||||
|
|
@ -1078,20 +1071,15 @@ class ConfServer:
|
|||
json_body["payload"] = ""
|
||||
if json_body["td"] == "GetCleanLogs":
|
||||
json_body["td"] = "q"
|
||||
json_body["payload"] = '<ctl count=\"30\"/>' #<ctl />"
|
||||
|
||||
json_body["payload"] = '<ctl count="30"/>' # <ctl />"
|
||||
|
||||
if did != "":
|
||||
bot = bumper.bot_get(did)
|
||||
if bot["company"] == "eco-ng" and bot["mqtt_connection"] == True:
|
||||
body = ""
|
||||
retcmd = await self.helperbot.send_command(json_body, randomid)
|
||||
confserverlog.debug(
|
||||
"Send Bot - {}".format(json_body)
|
||||
)
|
||||
confserverlog.debug(
|
||||
"Bot Response - {}".format(body)
|
||||
)
|
||||
confserverlog.debug("Send Bot - {}".format(json_body))
|
||||
confserverlog.debug("Bot Response - {}".format(body))
|
||||
logs = []
|
||||
logsroot = ET.fromstring(retcmd["resp"])
|
||||
if logsroot.attrib["ret"] == "ok":
|
||||
|
|
@ -1102,14 +1090,11 @@ class ConfServer:
|
|||
body = {
|
||||
"ret": "ok",
|
||||
# "logs": logs, #TODO: Doesn't parse correctly, new protocol & server side processing
|
||||
"logs": []
|
||||
"logs": [],
|
||||
}
|
||||
|
||||
else:
|
||||
body = {
|
||||
"ret": "ok",
|
||||
"logs": [],
|
||||
}
|
||||
body = {"ret": "ok", "logs": []}
|
||||
|
||||
confserverlog.debug(
|
||||
"\r\n POST: {} \r\n Response: {}".format(json_body, body)
|
||||
|
|
@ -1126,7 +1111,6 @@ class ConfServer:
|
|||
body = {"id": randomid, "errno": bumper.ERR_COMMON, "ret": "fail"}
|
||||
return web.json_response(body)
|
||||
|
||||
|
||||
except Exception as e:
|
||||
confserverlog.exception("{}".format(e))
|
||||
|
||||
|
|
@ -1144,12 +1128,8 @@ class ConfServer:
|
|||
if bot["company"] == "eco-ng" and bot["mqtt_connection"] == True:
|
||||
retcmd = await self.helperbot.send_command(json_body, randomid)
|
||||
body = retcmd
|
||||
confserverlog.debug(
|
||||
"Send Bot - {}".format(json_body)
|
||||
)
|
||||
confserverlog.debug(
|
||||
"Bot Response - {}".format(body)
|
||||
)
|
||||
confserverlog.debug("Send Bot - {}".format(json_body))
|
||||
confserverlog.debug("Bot Response - {}".format(body))
|
||||
return web.json_response(body)
|
||||
else:
|
||||
# No response, send error back
|
||||
|
|
@ -1158,7 +1138,12 @@ class ConfServer:
|
|||
json_body["toId"]
|
||||
)
|
||||
)
|
||||
body = {"id": randomid, "errno": 500, "ret": "fail", "debug": "wait for response timed out"}
|
||||
body = {
|
||||
"id": randomid,
|
||||
"errno": 500,
|
||||
"ret": "fail",
|
||||
"debug": "wait for response timed out",
|
||||
}
|
||||
return web.json_response(body)
|
||||
|
||||
else:
|
||||
|
|
@ -1174,7 +1159,6 @@ class ConfServer:
|
|||
except Exception as e:
|
||||
confserverlog.exception("{}".format(e))
|
||||
|
||||
|
||||
async def handle_dim_devmanager(self, request): # Used in EcoVacs Home App
|
||||
try:
|
||||
json_body = json.loads(await request.text())
|
||||
|
|
@ -1189,12 +1173,8 @@ class ConfServer:
|
|||
if bot["company"] == "eco-ng" and bot["mqtt_connection"] == True:
|
||||
retcmd = await self.helperbot.send_command(json_body, randomid)
|
||||
body = retcmd
|
||||
confserverlog.debug(
|
||||
"Send Bot - {}".format(json_body)
|
||||
)
|
||||
confserverlog.debug(
|
||||
"Bot Response - {}".format(body)
|
||||
)
|
||||
confserverlog.debug("Send Bot - {}".format(json_body))
|
||||
confserverlog.debug("Bot Response - {}".format(body))
|
||||
return web.json_response(body)
|
||||
else:
|
||||
# No response, send error back
|
||||
|
|
|
|||
|
|
@ -34,10 +34,7 @@ class MQTTHelperBot:
|
|||
|
||||
Client = MQTTClient()
|
||||
|
||||
def __init__(
|
||||
self,
|
||||
address
|
||||
):
|
||||
def __init__(self, address):
|
||||
self.address = address
|
||||
self.client_id = "helper1@bumper/helper1"
|
||||
self.command_responses = []
|
||||
|
|
@ -72,7 +69,11 @@ class MQTTHelperBot:
|
|||
|
||||
if str(message.topic).split("/")[6] == "helper1":
|
||||
# Response to command
|
||||
helperbotlog.debug("Received Response - Topic: {} - Message: {}".format(message.topic, str(message.data.decode("utf-8"))))
|
||||
helperbotlog.debug(
|
||||
"Received Response - Topic: {} - Message: {}".format(
|
||||
message.topic, str(message.data.decode("utf-8"))
|
||||
)
|
||||
)
|
||||
self.command_responses.append(
|
||||
{
|
||||
"time": time.time(),
|
||||
|
|
@ -82,12 +83,24 @@ class MQTTHelperBot:
|
|||
)
|
||||
elif str(message.topic).split("/")[3] == "helper1":
|
||||
# Helperbot sending command
|
||||
helperbotlog.debug("Send Command - Topic: {} - Message: {}".format(message.topic, str(message.data.decode("utf-8"))))
|
||||
helperbotlog.debug(
|
||||
"Send Command - Topic: {} - Message: {}".format(
|
||||
message.topic, str(message.data.decode("utf-8"))
|
||||
)
|
||||
)
|
||||
elif str(message.topic).split("/")[1] == "atr":
|
||||
# Broadcast message received on atr
|
||||
helperbotlog.debug("Received Broadcast - Topic: {} - Message: {}".format(message.topic, str(message.data.decode("utf-8"))))
|
||||
helperbotlog.debug(
|
||||
"Received Broadcast - Topic: {} - Message: {}".format(
|
||||
message.topic, str(message.data.decode("utf-8"))
|
||||
)
|
||||
)
|
||||
else:
|
||||
helperbotlog.debug("Received Message - Topic: {} - Message: {}".format(message.topic, str(message.data.decode("utf-8"))))
|
||||
helperbotlog.debug(
|
||||
"Received Message - Topic: {} - Message: {}".format(
|
||||
message.topic, str(message.data.decode("utf-8"))
|
||||
)
|
||||
)
|
||||
|
||||
# Cleanup "expired messages" > 60 seconds from time
|
||||
for msg in self.command_responses:
|
||||
|
|
@ -95,10 +108,13 @@ class MQTTHelperBot:
|
|||
datetime.fromtimestamp(msg["time"]) + timedelta(seconds=10)
|
||||
).timestamp()
|
||||
if time.time() > expire_time:
|
||||
helperbotlog.debug("Pruning Message Time: {}, MsgTime: {}, MsgTime+60: {}".format(time.time(), msg['time'], expire_time))
|
||||
helperbotlog.debug(
|
||||
"Pruning Message Time: {}, MsgTime: {}, MsgTime+60: {}".format(
|
||||
time.time(), msg["time"], expire_time
|
||||
)
|
||||
)
|
||||
self.command_responses.remove(msg)
|
||||
|
||||
|
||||
async def wait_for_resp(self, requestid):
|
||||
try:
|
||||
|
||||
|
|
@ -119,13 +135,28 @@ class MQTTHelperBot:
|
|||
self.command_responses.remove(msg)
|
||||
return resp
|
||||
|
||||
return {"id": requestid, "errno": 500, "ret": "fail", "debug": "wait for response timed out"}
|
||||
return {
|
||||
"id": requestid,
|
||||
"errno": 500,
|
||||
"ret": "fail",
|
||||
"debug": "wait for response timed out",
|
||||
}
|
||||
except asyncio.CancelledError as e:
|
||||
helperbotlog.debug("wait_for_resp cancelled by asyncio")
|
||||
return {"id": requestid, "errno": 500, "ret": "fail", "debug": "wait for response timed out"}
|
||||
return {
|
||||
"id": requestid,
|
||||
"errno": 500,
|
||||
"ret": "fail",
|
||||
"debug": "wait for response timed out",
|
||||
}
|
||||
except Exception as e:
|
||||
helperbotlog.exception("{}".format(e))
|
||||
return {"id": requestid, "errno": 500, "ret": "fail", "debug": "wait for response timed out"}
|
||||
return {
|
||||
"id": requestid,
|
||||
"errno": 500,
|
||||
"ret": "fail",
|
||||
"debug": "wait for response timed out",
|
||||
}
|
||||
|
||||
async def send_command(self, cmdjson, requestid):
|
||||
try:
|
||||
|
|
@ -158,7 +189,9 @@ class MQTTServer:
|
|||
|
||||
async def broker_coro(self):
|
||||
try:
|
||||
mqttserverlog.info("Starting MQTT Server at {}:{}".format(self.address[0], self.address[1]))
|
||||
mqttserverlog.info(
|
||||
"Starting MQTT Server at {}:{}".format(self.address[0], self.address[1])
|
||||
)
|
||||
broker = hbmqtt.broker.Broker(config=self.default_config)
|
||||
await broker.start()
|
||||
|
||||
|
|
@ -175,11 +208,7 @@ class MQTTServer:
|
|||
mqttserverlog.exception("{}".format(e))
|
||||
exit(1)
|
||||
|
||||
|
||||
def __init__(
|
||||
self,
|
||||
address
|
||||
):
|
||||
def __init__(self, address):
|
||||
try:
|
||||
self.mqttserverthread = None
|
||||
self.address = address
|
||||
|
|
@ -254,8 +283,8 @@ class BumperMQTTServer_Plugin:
|
|||
|
||||
didsplit = str(client_id).split("@")
|
||||
if not ( # if ecouser or bumper aren't in details it is a bot
|
||||
"ecouser" in didsplit[1]
|
||||
or "bumper" in didsplit[1]):
|
||||
"ecouser" in didsplit[1] or "bumper" in didsplit[1]
|
||||
):
|
||||
tmpbotdetail = str(didsplit[1]).split("/")
|
||||
bumper.bot_add(
|
||||
username,
|
||||
|
|
@ -298,7 +327,9 @@ class BumperMQTTServer_Plugin:
|
|||
authenticated = False
|
||||
|
||||
except Exception as e:
|
||||
mqttserverlog.exception("Session: {} - {}".format((kwargs.get("session", None)),e))
|
||||
mqttserverlog.exception(
|
||||
"Session: {} - {}".format((kwargs.get("session", None)), e)
|
||||
)
|
||||
authenticated = False
|
||||
|
||||
return authenticated
|
||||
|
|
|
|||
|
|
@ -9,7 +9,8 @@ import asyncio, functools
|
|||
|
||||
xmppserverlog = logging.getLogger("xmppserver")
|
||||
|
||||
class XMPPServer():
|
||||
|
||||
class XMPPServer:
|
||||
server_id = "ecouser.net"
|
||||
clients = []
|
||||
exit_flag = False
|
||||
|
|
@ -45,6 +46,7 @@ class XMPPServer():
|
|||
except Exception as e:
|
||||
xmppserverlog.error("{}".format(e))
|
||||
|
||||
|
||||
class XMPPServer_Protocol(asyncio.Protocol):
|
||||
client_id = None
|
||||
exit_flag = False
|
||||
|
|
@ -56,7 +58,9 @@ class XMPPServer_Protocol(asyncio.Protocol):
|
|||
|
||||
def connection_made(self, transport):
|
||||
if self.aclient: # Existing client... upgrading to TLS
|
||||
xmppserverlog.debug("Upgraded connection for {}".format(self.aclient.address))
|
||||
xmppserverlog.debug(
|
||||
"Upgraded connection for {}".format(self.aclient.address)
|
||||
)
|
||||
self.aclient.transport = transport
|
||||
else:
|
||||
aclient = XMPPAsyncClient(transport)
|
||||
|
|
@ -65,11 +69,16 @@ class XMPPServer_Protocol(asyncio.Protocol):
|
|||
self.aclient.state = getattr(aclient, "CONNECT")
|
||||
xmppserverlog.debug("New Connection from {}".format(aclient.address))
|
||||
|
||||
|
||||
def connection_lost(self, error):
|
||||
XMPPServer.clients.remove(self.aclient)
|
||||
self.aclient._set_state("DISCONNECT")
|
||||
xmppserverlog.debug("End Connection for ({}:{} | {})".format(self.aclient.address[0], self.aclient.address[1], self.aclient.bumper_jid))
|
||||
xmppserverlog.debug(
|
||||
"End Connection for ({}:{} | {})".format(
|
||||
self.aclient.address[0],
|
||||
self.aclient.address[1],
|
||||
self.aclient.bumper_jid,
|
||||
)
|
||||
)
|
||||
|
||||
def data_received(self, data):
|
||||
self.aclient._parse_data(data)
|
||||
|
|
@ -103,7 +112,11 @@ class XMPPAsyncClient:
|
|||
def send(self, command):
|
||||
try:
|
||||
if self.log_sent_message:
|
||||
xmppserverlog.debug("send to ({}:{} | {}) - {}".format(self.address[0], self.address[1], self.bumper_jid, command))
|
||||
xmppserverlog.debug(
|
||||
"send to ({}:{} | {}) - {}".format(
|
||||
self.address[0], self.address[1], self.bumper_jid, command
|
||||
)
|
||||
)
|
||||
|
||||
self.transport.write(command.encode())
|
||||
|
||||
|
|
@ -145,7 +158,11 @@ class XMPPAsyncClient:
|
|||
)
|
||||
)
|
||||
|
||||
xmppserverlog.debug("({}:{} | {}) state: {}".format(self.address[0],self.address[1],self.bumper_jid, state))
|
||||
xmppserverlog.debug(
|
||||
"({}:{} | {}) state: {}".format(
|
||||
self.address[0], self.address[1], self.bumper_jid, state
|
||||
)
|
||||
)
|
||||
|
||||
self.state = new_state
|
||||
|
||||
|
|
@ -172,7 +189,8 @@ class XMPPAsyncClient:
|
|||
self.send(
|
||||
'<iq type="error" id="{}"><error type="cancel" code="501"><feature-not-implemented xmlns="urn:ietf:params:xml:ns:xmpp-stanzas"/></error></iq>'.format(
|
||||
xml.get("id")
|
||||
))
|
||||
)
|
||||
)
|
||||
return
|
||||
|
||||
if "disco#info" in data:
|
||||
|
|
@ -184,7 +202,6 @@ class XMPPAsyncClient:
|
|||
)
|
||||
return
|
||||
|
||||
|
||||
if xml.get("type") == "set":
|
||||
if (
|
||||
"com:sf" in data and xml.get("to") == "rl.ecorobot.net"
|
||||
|
|
@ -255,7 +272,6 @@ class XMPPAsyncClient:
|
|||
pingstring = pingstring.replace('iq xmlns="urn:xmpp:ping"', "iq")
|
||||
pingstring = pingstring.replace("<ping", '<ping xmlns="urn:xmpp:ping"')
|
||||
|
||||
|
||||
for client in XMPPServer.clients:
|
||||
if (
|
||||
client.bumper_jid != self.bumper_jid
|
||||
|
|
@ -267,10 +283,11 @@ class XMPPAsyncClient:
|
|||
except Exception as e:
|
||||
xmppserverlog.exception("{}".format(e))
|
||||
|
||||
|
||||
async def schedule_ping(self, time):
|
||||
if not self.state == 5: # disconnected
|
||||
pingstring = "<iq from='{}' to='{}' id='s2c1' type='get'><ping xmlns='urn:xmpp:ping'/></iq>".format(XMPPServer.server_id, self.bumper_jid)
|
||||
pingstring = "<iq from='{}' to='{}' id='s2c1' type='get'><ping xmlns='urn:xmpp:ping'/></iq>".format(
|
||||
XMPPServer.server_id, self.bumper_jid
|
||||
)
|
||||
self.send(pingstring)
|
||||
await asyncio.sleep(time)
|
||||
asyncio.Task(self.schedule_ping(time))
|
||||
|
|
@ -290,7 +307,9 @@ class XMPPAsyncClient:
|
|||
adminuser = ctlerr.replace("permission denied, please contact ", "")
|
||||
adminuser = adminuser.replace(" ", "")
|
||||
if not (
|
||||
adminuser.startswith("fuid_") or adminuser.startswith("fusername_") or bumper.use_auth
|
||||
adminuser.startswith("fuid_")
|
||||
or adminuser.startswith("fusername_")
|
||||
or bumper.use_auth
|
||||
): # if not fuid_ then its ecovacs OR ignore bumper auth
|
||||
# TODO: Implement auth later, should this user have access to bot?
|
||||
|
||||
|
|
@ -435,13 +454,20 @@ class XMPPAsyncClient:
|
|||
except Exception as e:
|
||||
xmppserverlog.exception("{}".format(e))
|
||||
|
||||
|
||||
async def _handle_starttls(self, data):
|
||||
try:
|
||||
if self.TLSUpgraded == False:
|
||||
self.TLSUpgraded = True #Set TLSUpgraded true to prevent further attempts to upgrade connection
|
||||
xmppserverlog.debug("Upgrading connection with STARTTLS for {}:{}".format(self.address[0],self.address[1]))
|
||||
self.send("<proceed xmlns='urn:ietf:params:xml:ns:xmpp-tls'/>") #send process to client
|
||||
self.TLSUpgraded = (
|
||||
True
|
||||
) # Set TLSUpgraded true to prevent further attempts to upgrade connection
|
||||
xmppserverlog.debug(
|
||||
"Upgrading connection with STARTTLS for {}:{}".format(
|
||||
self.address[0], self.address[1]
|
||||
)
|
||||
)
|
||||
self.send(
|
||||
"<proceed xmlns='urn:ietf:params:xml:ns:xmpp-tls'/>"
|
||||
) # send process to client
|
||||
|
||||
# After proceed the connection should be upgraded to TLS
|
||||
loop = asyncio.get_event_loop()
|
||||
|
|
@ -452,14 +478,14 @@ class XMPPAsyncClient:
|
|||
ssl_ctx.load_cert_chain(bumper.server_cert, bumper.server_key)
|
||||
ssl_ctx.load_verify_locations(cafile=bumper.ca_cert)
|
||||
|
||||
new_transport = await loop.start_tls(transport , protocol, ssl_ctx, server_side=True)
|
||||
new_transport = await loop.start_tls(
|
||||
transport, protocol, ssl_ctx, server_side=True
|
||||
)
|
||||
protocol.connection_made(new_transport)
|
||||
|
||||
|
||||
except Exception as e:
|
||||
xmppserverlog.exception("{}".format(e))
|
||||
|
||||
|
||||
def _handle_iq_auth(self, data):
|
||||
try:
|
||||
xml = ET.fromstring(data.decode("utf-8"))
|
||||
|
|
@ -525,9 +551,7 @@ class XMPPAsyncClient:
|
|||
self._set_state("INIT")
|
||||
|
||||
# Successful auth
|
||||
self.send(
|
||||
'<iq type="result" id="{}"/>'.format(xml.get("id"))
|
||||
)
|
||||
self.send('<iq type="result" id="{}"/>'.format(xml.get("id")))
|
||||
|
||||
else:
|
||||
# Failed auth
|
||||
|
|
@ -631,7 +655,11 @@ class XMPPAsyncClient:
|
|||
self.bumper_jid = "{}@{}.ecorobot.net/atom".format(
|
||||
self.uid, self.devclass
|
||||
)
|
||||
xmppserverlog.debug("new bot ({}:{} | {})".format(self.address[0],self.address[1], self.bumper_jid))
|
||||
xmppserverlog.debug(
|
||||
"new bot ({}:{} | {})".format(
|
||||
self.address[0], self.address[1], self.bumper_jid
|
||||
)
|
||||
)
|
||||
res = '<iq type="result" id="{}"><bind xmlns="urn:ietf:params:xml:ns:xmpp-bind"><jid>{}</jid></bind></iq>'.format(
|
||||
xml.get("id"), self.bumper_jid
|
||||
)
|
||||
|
|
@ -641,14 +669,22 @@ class XMPPAsyncClient:
|
|||
self.bumper_jid = "{}@{}/{}".format(
|
||||
self.uid, XMPPServer.server_id, self.clientresource
|
||||
)
|
||||
xmppserverlog.debug("new client ({}:{} | {})".format(self.address[0],self.address[1], self.bumper_jid))
|
||||
xmppserverlog.debug(
|
||||
"new client ({}:{} | {})".format(
|
||||
self.address[0], self.address[1], self.bumper_jid
|
||||
)
|
||||
)
|
||||
res = '<iq type="result" id="{}"><bind xmlns="urn:ietf:params:xml:ns:xmpp-bind"><jid>{}</jid></bind></iq>'.format(
|
||||
xml.get("id"), self.bumper_jid
|
||||
)
|
||||
else:
|
||||
self.name = "XMPP_Client_{}_{}".format(self.uid, self.address)
|
||||
self.bumper_jid = "{}@{}".format(self.uid, XMPPServer.server_id)
|
||||
xmppserverlog.debug("new client ({}:{} | {})".format(self.address[0],self.address[1], self.bumper_jid))
|
||||
xmppserverlog.debug(
|
||||
"new client ({}:{} | {})".format(
|
||||
self.address[0], self.address[1], self.bumper_jid
|
||||
)
|
||||
)
|
||||
res = '<iq type="result" id="{}"><bind xmlns="urn:ietf:params:xml:ns:xmpp-bind"><jid>{}</jid></bind></iq>'.format(
|
||||
xml.get("id"), self.bumper_jid
|
||||
)
|
||||
|
|
@ -666,7 +702,6 @@ class XMPPAsyncClient:
|
|||
self.send(res)
|
||||
asyncio.Task(self.schedule_ping(30))
|
||||
|
||||
|
||||
except Exception as e:
|
||||
xmppserverlog.exception("{}".format(e))
|
||||
|
||||
|
|
@ -675,7 +710,9 @@ class XMPPAsyncClient:
|
|||
|
||||
if len(xml) and xml[0].tag == "status":
|
||||
xmppserverlog.debug(
|
||||
"bot presence {} ".format(ET.tostring(xml, encoding="utf-8").decode("utf-8"))
|
||||
"bot presence {} ".format(
|
||||
ET.tostring(xml, encoding="utf-8").decode("utf-8")
|
||||
)
|
||||
)
|
||||
# Most likely a bot, possibly hello world in text
|
||||
|
||||
|
|
@ -684,8 +721,6 @@ class XMPPAsyncClient:
|
|||
'<presence to="{}"> dummy </presence>'.format(self.bumper_jid)
|
||||
)
|
||||
|
||||
|
||||
|
||||
# If it is a BOT, send extras
|
||||
if self.type == self.BOT:
|
||||
# get device info
|
||||
|
|
@ -695,17 +730,18 @@ class XMPPAsyncClient:
|
|||
)
|
||||
)
|
||||
|
||||
|
||||
|
||||
else:
|
||||
xmppserverlog.debug(
|
||||
"client presence - {} ".format(ET.tostring(xml, encoding="utf-8").decode("utf-8"))
|
||||
"client presence - {} ".format(
|
||||
ET.tostring(xml, encoding="utf-8").decode("utf-8")
|
||||
)
|
||||
)
|
||||
|
||||
if xml.get("type") == "available":
|
||||
xmppserverlog.debug(
|
||||
"client presence available - {} ".format(
|
||||
ET.tostring(xml, encoding="utf-8").decode("utf-8"))
|
||||
ET.tostring(xml, encoding="utf-8").decode("utf-8")
|
||||
)
|
||||
)
|
||||
|
||||
# Send dummy return
|
||||
|
|
@ -715,7 +751,8 @@ class XMPPAsyncClient:
|
|||
elif xml.get("type") == "unavailable":
|
||||
xmppserverlog.debug(
|
||||
"client presence unavailable (DISCONNECT) - {} ".format(
|
||||
ET.tostring(xml, encoding="utf-8").decode("utf-8"))
|
||||
ET.tostring(xml, encoding="utf-8").decode("utf-8")
|
||||
)
|
||||
)
|
||||
|
||||
self._set_state("DISCONNECT")
|
||||
|
|
@ -756,7 +793,9 @@ class XMPPAsyncClient:
|
|||
if self.log_incoming_data:
|
||||
xmppserverlog.debug(
|
||||
"from ({}:{} | {}) - {}".format(
|
||||
self.address[0],self.address[1],self.bumper_jid,
|
||||
self.address[0],
|
||||
self.address[1],
|
||||
self.bumper_jid,
|
||||
str(
|
||||
ET.tostring(item, encoding="utf-8").decode(
|
||||
"utf-8"
|
||||
|
|
|
|||
|
|
@ -6,6 +6,7 @@ import sys, socket
|
|||
import time
|
||||
import platform
|
||||
import os
|
||||
|
||||
# os.environ['PYTHONASYNCIODEBUG'] = '1' # Uncomment to enable ASYNCIODEBUG
|
||||
import asyncio
|
||||
|
||||
|
|
@ -47,9 +48,7 @@ async def main():
|
|||
xmpp_address = (listen_host, 5223)
|
||||
mqtt_address = (listen_host, 8883)
|
||||
|
||||
xmpp_server = bumper.XMPPServer(
|
||||
xmpp_address
|
||||
)
|
||||
xmpp_server = bumper.XMPPServer(xmpp_address)
|
||||
mqtt_server = bumper.MQTTServer(mqtt_address)
|
||||
mqtt_helperbot = bumper.MQTTHelperBot(mqtt_address)
|
||||
conf_server = bumper.ConfServer(
|
||||
|
|
@ -86,6 +85,7 @@ async def main():
|
|||
task.cancel()
|
||||
loop.close()
|
||||
|
||||
|
||||
async def maintenance_tasks():
|
||||
while True:
|
||||
await asyncio.sleep(30) # Sleep 30 seconds
|
||||
|
|
@ -101,4 +101,3 @@ if __name__ == "__main__":
|
|||
pass
|
||||
finally:
|
||||
bumper.bumperlog.info("Bumper Exiting!")
|
||||
|
||||
|
|
|
|||
|
|
@ -181,4 +181,7 @@ def test_client_db():
|
|||
assert_false(
|
||||
bumper.client_get("resource_123")["xmpp_connection"]
|
||||
) # Test that xmpp was set False for client
|
||||
assert_equals(len(bumper.get_disconnected_xmpp_clients()), 1) # Test len of connected xmpp clients is 1
|
||||
assert_equals(
|
||||
len(bumper.get_disconnected_xmpp_clients()), 1
|
||||
) # Test len of connected xmpp clients is 1
|
||||
|
||||
|
|
|
|||
|
|
@ -12,13 +12,14 @@ confserver = bumper.ConfServer("127.0.0.1:11111", False, mock.MagicMock)
|
|||
confserver.confserver_app()
|
||||
app = confserver.app
|
||||
|
||||
|
||||
def async_return(result):
|
||||
f = asyncio.Future()
|
||||
f.set_result(result)
|
||||
return f
|
||||
|
||||
def test_disconnect():
|
||||
|
||||
def test_disconnect():
|
||||
async def test_disconnect_async():
|
||||
await confserver.disconnect()
|
||||
|
||||
|
|
@ -513,6 +514,7 @@ def test_postLookup():
|
|||
client.close()
|
||||
) # Close test server after all tests are done
|
||||
|
||||
|
||||
def test_devmgr():
|
||||
if os.path.exists("tests/tmp.db"):
|
||||
os.remove("tests/tmp.db") # Remove existing db
|
||||
|
|
@ -551,20 +553,30 @@ def test_devmgr():
|
|||
postbody = {"toId": "did_1234"}
|
||||
|
||||
# Test return get status
|
||||
command_getstatus_resp = { "id": "resp_1234", "resp": "<ctl ret='ok' status='idle'/>", "ret": "ok" }
|
||||
confserver.helperbot.send_command = mock.MagicMock(return_value=async_return(command_getstatus_resp))
|
||||
command_getstatus_resp = {
|
||||
"id": "resp_1234",
|
||||
"resp": "<ctl ret='ok' status='idle'/>",
|
||||
"ret": "ok",
|
||||
}
|
||||
confserver.helperbot.send_command = mock.MagicMock(
|
||||
return_value=async_return(command_getstatus_resp)
|
||||
)
|
||||
# Test
|
||||
loop.run_until_complete(test_devmanager(postbody, command=True))
|
||||
|
||||
# Test return fail timeout
|
||||
command_timeout_resp = {"id": "resp_1234", "errno": "timeout", "ret": "fail"}
|
||||
confserver.helperbot.send_command = mock.MagicMock(return_value=async_return(command_timeout_resp))
|
||||
confserver.helperbot.send_command = mock.MagicMock(
|
||||
return_value=async_return(command_timeout_resp)
|
||||
)
|
||||
# Test
|
||||
loop.run_until_complete(test_devmanager(postbody, command=True))
|
||||
|
||||
# Set bot not on mqtt
|
||||
bumper.bot_set_mqtt("did_1234", False)
|
||||
confserver.helperbot.send_command = mock.MagicMock(return_value=async_return(command_getstatus_resp))
|
||||
confserver.helperbot.send_command = mock.MagicMock(
|
||||
return_value=async_return(command_getstatus_resp)
|
||||
)
|
||||
# Test
|
||||
loop.run_until_complete(test_devmanager(postbody, command=True))
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue