Skip to content

Commit

Permalink
Merge pull request #207 from cantupaz/main
Browse files Browse the repository at this point in the history
Initialize protom_response
  • Loading branch information
cantupaz authored Feb 20, 2024
2 parents 9b8c162 + ed065fe commit 5d38b0c
Showing 1 changed file with 10 additions and 10 deletions.
20 changes: 10 additions & 10 deletions custom_components/securitas/securitas_direct_new_api/apimanager.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ def __init__(
self.command_map = COMMAND_MAP[command_type]
self.delay_check_operation: int = delay_check_operation

self.protom_response: str
self.protom_response: str = ""
self.authentication_token: str = ""
self.authentication_token_exp: datetime = datetime.min
self.login_timestamp: int = 0
Expand Down Expand Up @@ -253,11 +253,10 @@ async def validate_device(
for item in data["auth-phones"]:
phones.append(OtpPhone(item["id"], item["phone"]))
return (otp_hash, phones)
else:
self.authentication_token = response["data"]["xSValidateDevice"]["hash"]
return (None, None)

# FIXME needs testing
self.authentication_token = response["data"]["xSValidateDevice"]["hash"]
return (None, None)

async def refresh_token(self) -> bool:
"""Send a login refresh."""
content = {
Expand Down Expand Up @@ -318,11 +317,12 @@ async def login(self) -> None:
try:
response = await self._execute_request(content, "mkLoginToken")
except SecuritasDirectError as err:
(error_message, result_json, headers, content) = err.args
if result_json["data"]["xSLoginToken"]:
if result_json["data"]["xSLoginToken"]["needDeviceAuthorization"]:
# needs a 2FA
raise Login2FAError(err.args) from err
result_json = err.args[1]
if result_json["data"]:
if result_json["data"]["xSLoginToken"]:
if result_json["data"]["xSLoginToken"]["needDeviceAuthorization"]:
# needs a 2FA
raise Login2FAError(err.args) from err

raise LoginError(err.args) from err

Expand Down

0 comments on commit 5d38b0c

Please sign in to comment.