Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add call to account status endpoint before attempting to login to fix authentication. #38

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
19 changes: 18 additions & 1 deletion libpurecool/dyson.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,23 @@ def login(self):
urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)
_LOGGER.debug("Disabling insecure request warnings since "
"dyson are using a self signed certificate.")
# Must first check account status
accountstatus = requests.get(
"https://{0}/v1/userregistration/userstatus".format(self._dyson_api_url),
params={"country": self._country, "email": self._email},
headers=self._headers,
verify=False,
)
# pylint: disable=no-member
if accountstatus.status_code == requests.codes.ok:
json_status = accountstatus.json()
if json_status['accountStatus'] != "ACTIVE":
# The account is not active
self._logged = False
return self._logged
else:
self._logged = False
return self._logged

request_body = {
"Email": self._email,
Expand All @@ -61,7 +78,7 @@ def login(self):
"https://{0}/v1/userregistration/authenticate?country={1}".format(
self._dyson_api_url, self._country),
headers=self._headers,
data=request_body,
json=request_body,
verify=False
)
# pylint: disable=no-member
Expand Down