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

Commit

Permalink
Update tpclient.py
Browse files Browse the repository at this point in the history
  • Loading branch information
cziter15 authored Aug 24, 2023
1 parent ac3d65d commit 69a2eba
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions custom_components/mr6400sms/tpclient.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,14 +51,14 @@ async def encryptCredentials(self, username, password):
headers = {'Referer': self._baseurl}
async with self.websession.post(url, headers=headers) as response:
if response.status != 200:
raise TPCError("Invalid encryption key request, status: " + str(response.status))
raise TPCError("Invalid encryption key request beause of status " + str(response.status))
responseText = await response.text()
ee = self.extractKeyPart(responseText, r'(?<=ee=")(.{5}(?:\s|.))')
nn = self.extractKeyPart(responseText, r'(?<=nn=")(.{255}(?:\s|.))')
self._encryptedUsername = self.encryptString(username, nn, ee)
self._encryptedPassword = self.encryptString(password, nn, ee)
except (TimeoutError, ClientError, TPCError) as e:
raise TPCError("Could not retrieve encryption key, reason: " + str(e))
raise TPCError("Could not retrieve encryption key due to " + str(e))

async def login(self, websession, username, password):
try:
Expand All @@ -79,22 +79,22 @@ async def login(self, websession, username, password):
raise TPCError("Invalid credentials")
except (TimeoutError, ClientError, TPCError) as e:
self.websession = None
raise TPCError("Could not login, reason: " + str(e))
raise TPCError("Could not login due to " + str(e))

async def getToken(self):
try:
async with async_timeout.timeout(_LOGIN_TIMEOUT_SECONDS):
url = self.buildUrl('')
async with self.websession.get(url) as response:
if response.status != 200:
raise TPCError("Invalid token request, status: " + str(response.status))
raise TPCError("Invalid token request because of status " + str(response.status))
responseText = await response.text()
p = re.compile(r'(?<=token=")(.{29}(?:\s|.))', re.IGNORECASE)
m = p.search(responseText)
if m:
self.token = m.group(1)
except (TimeoutError, ClientError, TPCError) as e:
raise TPCError("Could not retrieve token, reason: " + str(e))
raise TPCError("Could not retrieve token due to " + str(e))

async def sms(self, phone, message):
url = self.buildUrl('cgi')
Expand Down

0 comments on commit 69a2eba

Please sign in to comment.