Skip to content
Closed
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
72 changes: 69 additions & 3 deletions homeassistant/components/device_tracker/tplink.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,9 @@

def get_scanner(hass, config):
"""Validate the configuration and return a TP-Link scanner."""
for cls in [Tplink5DeviceScanner, Tplink4DeviceScanner,
Tplink3DeviceScanner, Tplink2DeviceScanner,
TplinkDeviceScanner]:
for cls in [TplinkEAPControllerDeviceScanner, Tplink5DeviceScanner,
Tplink4DeviceScanner, Tplink3DeviceScanner,
Tplink2DeviceScanner, TplinkDeviceScanner]:
scanner = cls(config[DOMAIN])
if scanner.success_init:
return scanner
Expand Down Expand Up @@ -412,3 +412,69 @@ def _update_info(self):
return True

return False

class TplinkEAPControllerDeviceScanner(TplinkDeviceScanner):

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

expected 2 blank lines, found 1

"""This class queries a TP-Link EAP Controller Server"""
_LOGGER.info("Using EAP Controller Scanner")

def scan_devices(self):
"""Scan for new devices and return a list with found MAC IDs."""
self._update_info()
return self.last_results.keys()

def get_device_name(self, device):
"""Get firmware doesn't save the name of the wireless device."""
return self.last_results.get(device)['name']

def get_extra_attributes(self, device):
return self.last_results.get(device)
def _update_info(self):

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

expected 1 blank line, found 0

"""Ensure the information from the TP-Link AP is up to date.

Return boolean if scanning successful.
"""

base_url = 'https://{}:8043'.format(self.host)

# Create a session to handle cookie easier
session = requests.session()
session.verify=False

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

missing whitespace around operator


login = session.post('{}/login'.format(base_url), data=(('name',self.username),('password',self.password)))

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

missing whitespace after ','
line too long (115 > 79 characters)

if(login.status_code != 200):

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

trailing whitespace

_LOGGER.error('HTTP Request failed with status'+str(login.status_code))

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

line too long (83 > 79 characters)

else:

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

trailing whitespace

json = login.json()
if(json['success'] == False):

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

comparison to False should be 'if cond is False:' or 'if not cond:'

_LOGGER.error('Login failed, response was: '+json['message'])
else:

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

trailing whitespace

_LOGGER.info("Loading wireless clients...")
client_list_url = '{}/monitor/allActiveClients'.format(base_url)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

line too long (80 > 79 characters)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

line too long (80 > 79 characters)

post_data = (('currentPage',1),('currentPageSize',1000))

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

missing whitespace after ','


clients = session.post(client_list_url,data=post_data)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

missing whitespace after ','


try:

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

trailing whitespace

list_of_devices = clients.json()
except ValueError:
_LOGGER.error("AP didn't respond with JSON. "
"Check if credentials are correct")
return False

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

trailing whitespace


session.close()

if list_of_devices:
self.last_results = {
device['mac'].replace('-', ':'): {
'mac': device['mac'].replace('-', ':'),
'name': device['name'],
'ap': html.unescape(device['apName']),

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

undefined name 'html'

'ssid': device['ssid'],
'snr': device['snr'],
'ip': device['ip']
}
for device in list_of_devices['data']
}
return True

return False