Skip to content
This repository has been archived by the owner on Jan 19, 2024. It is now read-only.

Commit

Permalink
Allow profile files with broken MD5 checksum.
Browse files Browse the repository at this point in the history
Allow profile files with broken MD5 checksum.
  • Loading branch information
tomeko12 committed Oct 29, 2023
1 parent dafdf06 commit da82420
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 10 deletions.
2 changes: 1 addition & 1 deletion setup.py
Expand Up @@ -5,7 +5,7 @@

setuptools.setup(
name='pyelectroluxconnect',
version='0.3.19',
version='0.3.20',
description='Interface for Electrolux Connectivity Platform API',
long_description=long_description,
long_description_content_type="text/markdown",
Expand Down
26 changes: 17 additions & 9 deletions src/pyelectroluxconnect/Session.py
Expand Up @@ -136,6 +136,7 @@ def __exit__(self, exc_type, exc_val, exc_tb):

def _headers(self):
headers = {
"Authorization": f'Basic {urls.getEcpClientId(self._region)}',
"x-ibm-client-id": urls.getEcpClientId(self._region),
"x-api-key": urls.getEcpClientId(self._region),
"Content-Type": "application/json",
Expand Down Expand Up @@ -244,9 +245,10 @@ def _getApplianceConfiguration(self, pnc, elc, sn):
except requests.exceptions.RequestException as ex:
raise RequestError(ex)

if(os.path.exists(applianceConfigFilePath)
and f'md5-{hashlib.md5(open(applianceConfigFilePath,"rb").read()).hexdigest()}' ==
if(os.path.exists(applianceConfigFilePath)):
if(f'md5-{hashlib.md5(open(applianceConfigFilePath,"rb").read()).hexdigest()}' !=
_json[0]["configuration_file"][applianceConfigFileName]["digest"]):
_LOGGER.warn(f'Configuration file {applianceConfigFilePath} has wrong MD5 checksum')

with zipfile.ZipFile(applianceConfigFilePath, "r") as archive:
result["Translations"] = {}
Expand Down Expand Up @@ -923,11 +925,15 @@ def _requestHttp(self, operation, payload=None, verifySSL=None):
elif (operation[1] == "POST"):
response = requests.post(operation[0], json=payload,
headers=self._headers(), verify=verifySSL)
elif (operation[1] == "DEL"):
response = requests.delete(operation[0], json=payload,
headers=self._headers(), verify=verifySSL)
else:
_LOGGER.error(f"Unsupported request definition: {operation[1]}")
raise Error(f"Unsupported request definition: {operation[1]}")

_LOGGER.debug(f"HTTP Respose body: {response.text}")
_LOGGER.debug(f"HTTP Respose headers: {response.headers}")

if 2 != response.status_code // 100:
raise HttpResponseError(response.status_code, response.text) from None
Expand Down Expand Up @@ -1246,22 +1252,24 @@ def registerMQTT(self):
"""
try:
_json = self._requestApi(urls.registerMQTT(), None)
_json = self._requestApi(urls.registerMQTT(self._region), None)
except ResponseError as err:
if(err.status_code == "ECP0206"):
""" Device registered already, unregister first to get new token """
_LOGGER.warn(f"Device registered already in Electrolux MQTT broker, unregistering to get new token")
self.unregisterMQTT()
_json = self._requestApi(
urls.registerMQTT(), None)
urls.registerMQTT(self._region), None)
else:
raise
finally:
return {
"Url": _json["MQTTURL"],
"OrgId": _json["ECP_org_id"],
"DeviceToken": _json["DeviceToken"],
"ClientID": _json["ClientID"],
"Url": _json["mqttUrl"],
# "OrgId": _json["ECP_org_id"],
# "DeviceToken": _json["DeviceToken"],
"ClientID": _json["clientId"],
"topic": _json["topic"],
"featureTopic": _json["featureTopic"],
}


Expand All @@ -1270,7 +1278,7 @@ def unregisterMQTT(self):
"""
Unregister device from Electrolux MQTT broker
"""
self._requestApi(urls.unregisterMQTT(), None)
self._requestApi(urls.unregisterMQTT(self._region), None)


def getSSLCert(self):
Expand Down

1 comment on commit da82420

@tomeko12
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

#18

Please sign in to comment.