Skip to content

Commit

Permalink
Update device_tracker.py
Browse files Browse the repository at this point in the history
  • Loading branch information
GuyKh committed May 6, 2020
1 parent 0a83ec4 commit 78134ad
Showing 1 changed file with 35 additions and 10 deletions.
45 changes: 35 additions & 10 deletions custom_components/tplink_router/device_tracker.py
Original file line number Diff line number Diff line change
Expand Up @@ -626,22 +626,14 @@ def _get_auth_tokens(self):

return True

def _update_info(self):
"""Ensure the information from the TP-Link router is up to date.
Return boolean if scanning successful.
"""
if (self.jsessionId == '') or (self.token == ''):
self._get_auth_tokens()

_LOGGER.info("Loading wireless clients...")

def _get_mac_results(self):
referer = 'http:https://{}'.format(self.host)
headers= {
'TokenID': self.token,
REFERER: referer,
COOKIE: 'JSESSIONID=' + self.jsessionId
}

mac_results = []

# Check both the 2.4GHz and 5GHz client lists.
Expand Down Expand Up @@ -676,3 +668,36 @@ def _update_info(self):

self.last_results = mac_results
return True


def _update_info(self):
"""Ensure the information from the TP-Link router is up to date.
Return boolean if scanning successful.
"""

if (self.jsessionId == '') or (self.token == ''):
gotToken = self._get_auth_tokens()
if not gotToken:
# Retry
_LOGGER.info("Failed to get AuthTokens. Retrying in 3 secs.")
time.sleep(3)
gotToken = self._get_auth_tokens()
else:
gotToken = True

if not gotToken:
""" In case of failure - force re-login """
self.jsessionId = ''
self.token = ''
return False

_LOGGER.info("Loading wireless clients...")

macResults = self._get_mac_results()
if not macResults:
""" In case of failure - force re-login """
self.jsessionId = ''
self.token = ''
return False

return True

0 comments on commit 78134ad

Please sign in to comment.