Skip to content

Commit

Permalink
Also fix when self._error_report is True
Browse files Browse the repository at this point in the history
  • Loading branch information
WilliamRandol authored Oct 28, 2018
1 parent 73f033a commit 6378ede
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions pyW215/pyW215.py
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,7 @@ def state(self, value):
else:
raise TypeError("State %s is not valid." % str(value))

def get_state(self):
def get_state(self):
"""Get the device state (i.e. ON or OFF)."""
return self.state

Expand Down Expand Up @@ -340,10 +340,13 @@ def auth(self):
_LOGGER.warning("Failed to receive initial authentication from smartplug.")
self._error_report = True
return None
else:
Challenge = ChallengeResponse.text
Cookie = CookieResponse.text
Publickey = PublickeyResponse.text

if self._error_report is True:
return None

Challenge = ChallengeResponse.text
Cookie = CookieResponse.text
Publickey = PublickeyResponse.text

# Generate hash responses
PrivateKey = hmac.new((Publickey+self.password).encode(), (Challenge).encode()).hexdigest().upper()
Expand Down

1 comment on commit 6378ede

@vilsufi
Copy link

Choose a reason for hiding this comment

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

This commit actually breaks the re-authentication after failed operation. Once _error_report is set due to some failed operation, authentication will always return None and the module ceases to function. Recursion makes the bug hard to see. I ended up refactoring this a at 0936faf. Added some logging as well.

Please sign in to comment.