split api module out, split out api constants, refer to api constants in mqtt module, pulling logger back into individual modules

This commit is contained in:
bittles
2023-01-15 17:07:51 -05:00
parent 2b66ffa426
commit c7051bd51b
7 changed files with 244 additions and 216 deletions
+6 -4
View File
@@ -9,9 +9,11 @@ from paho.mqtt.client import Client as ClientMQTT
from paho.mqtt import publish as MQTTPublish
from paho.mqtt import subscribe as MQTTSubscribe
from sleekxmppfs.xmlstream import ET
from .sucks import EcoVacsAPI
from .const import LOGGER
from .sucks_api_const import API_REALM, API_IOTDEVMANAGERAPI
import logging
LOGGER = logging.getLogger(__name__)
def str_to_bool_or_cert(s):
if s == 'True' or s == True:
@@ -132,7 +134,7 @@ class EcoVacsIOTMQ(ClientMQTT):
payloadxml.attrib.pop("td")
return {
'auth': {
'realm': EcoVacsAPI.REALM,
'realm': API_REALM,
'resource': self.resource,
'token': self.secret,
'userid': self.user,
@@ -152,7 +154,7 @@ class EcoVacsIOTMQ(ClientMQTT):
LOGGER.debug("calling iotdevmanager api with {}".format(args))
params = {}
params.update(args)
url = (EcoVacsAPI.PORTAL_URL_FORMAT + "/iot/devmanager.do").format(continent=self.continent)
url = (API_PORTAL_URL_FORMAT + "/" + API_IOTDEVMANAGERAPI).format(continent=self.continent)
response = None
try: #The RestAPI sometimes doesnt provide a response depending on command, reduce timeout to 3 to accomodate and make requests faster
response = requests.post(url, json=params, timeout=3, verify=verify_ssl) #May think about having timeout as an arg that could be provided in the future