mirror of
https://github.com/home-assistant/core.git
synced 2025-07-23 13:17:32 +00:00
Merge pull request #7289 from jminardi/jminardi/tplink-logout
Log out of TP-Link router after devices are recorded.
This commit is contained in:
commit
12910de9ae
@ -163,6 +163,7 @@ class Tplink3DeviceScanner(TplinkDeviceScanner):
|
|||||||
def scan_devices(self):
|
def scan_devices(self):
|
||||||
"""Scan for new devices and return a list with found device IDs."""
|
"""Scan for new devices and return a list with found device IDs."""
|
||||||
self._update_info()
|
self._update_info()
|
||||||
|
self._log_out()
|
||||||
return self.last_results.keys()
|
return self.last_results.keys()
|
||||||
|
|
||||||
# pylint: disable=no-self-use
|
# pylint: disable=no-self-use
|
||||||
@ -195,8 +196,9 @@ class Tplink3DeviceScanner(TplinkDeviceScanner):
|
|||||||
self.sysauth = regex_result.group(1)
|
self.sysauth = regex_result.group(1)
|
||||||
_LOGGER.info(self.sysauth)
|
_LOGGER.info(self.sysauth)
|
||||||
return True
|
return True
|
||||||
except ValueError:
|
except (ValueError, KeyError) as _:
|
||||||
_LOGGER.error("Couldn't fetch auth tokens!")
|
_LOGGER.error("Couldn't fetch auth tokens! Response was: %s",
|
||||||
|
response.text)
|
||||||
return False
|
return False
|
||||||
|
|
||||||
@Throttle(MIN_TIME_BETWEEN_SCANS)
|
@Throttle(MIN_TIME_BETWEEN_SCANS)
|
||||||
@ -250,6 +252,21 @@ class Tplink3DeviceScanner(TplinkDeviceScanner):
|
|||||||
|
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
def _log_out(self):
|
||||||
|
with self.lock:
|
||||||
|
_LOGGER.info("Logging out of router admin interface...")
|
||||||
|
|
||||||
|
url = ('http://{}/cgi-bin/luci/;stok={}/admin/system?'
|
||||||
|
'form=logout').format(self.host, self.stok)
|
||||||
|
referer = 'http://{}/webpages/index.html'.format(self.host)
|
||||||
|
|
||||||
|
requests.post(url,
|
||||||
|
params={'operation': 'write'},
|
||||||
|
headers={'referer': referer},
|
||||||
|
cookies={'sysauth': self.sysauth})
|
||||||
|
self.stok = ''
|
||||||
|
self.sysauth = ''
|
||||||
|
|
||||||
|
|
||||||
class Tplink4DeviceScanner(TplinkDeviceScanner):
|
class Tplink4DeviceScanner(TplinkDeviceScanner):
|
||||||
"""This class queries an Archer C7 router with TP-Link firmware 150427."""
|
"""This class queries an Archer C7 router with TP-Link firmware 150427."""
|
||||||
|
Loading…
x
Reference in New Issue
Block a user