-
-
Notifications
You must be signed in to change notification settings - Fork 38.2k
Added EAP-Controller (Omada) #15382
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
Added EAP-Controller (Omada) #15382
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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 | ||
|
|
@@ -412,3 +412,69 @@ def _update_info(self): | |
| return True | ||
|
|
||
| return False | ||
|
|
||
| class TplinkEAPControllerDeviceScanner(TplinkDeviceScanner): | ||
| """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): | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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))) | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. missing whitespace after ',' |
||
| if(login.status_code != 200): | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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)) | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. line too long (83 > 79 characters) |
||
| else: | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. trailing whitespace |
||
| json = login.json() | ||
| if(json['success'] == False): | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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: | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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) | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. line too long (80 > 79 characters) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. line too long (80 > 79 characters) |
||
| post_data = (('currentPage',1),('currentPageSize',1000)) | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. missing whitespace after ',' |
||
|
|
||
| clients = session.post(client_list_url,data=post_data) | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. missing whitespace after ',' |
||
|
|
||
| try: | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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']), | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 | ||
There was a problem hiding this comment.
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