mirror of
https://github.com/home-assistant/core.git
synced 2025-07-18 18:57:06 +00:00
FIxed some linting issues
This commit is contained in:
parent
c8c38e498a
commit
7e6af57186
@ -1,6 +1,5 @@
|
|||||||
""" Supports scanning a DD-WRT router. """
|
""" Supports scanning a DD-WRT router. """
|
||||||
import logging
|
import logging
|
||||||
import json
|
|
||||||
from datetime import timedelta
|
from datetime import timedelta
|
||||||
import re
|
import re
|
||||||
import threading
|
import threading
|
||||||
@ -73,19 +72,19 @@ class DdWrtDeviceScanner(object):
|
|||||||
|
|
||||||
dhcp_leases = data.get('dhcp_leases', None)
|
dhcp_leases = data.get('dhcp_leases', None)
|
||||||
if dhcp_leases:
|
if dhcp_leases:
|
||||||
|
|
||||||
# remove leading and trailing single quotes
|
# remove leading and trailing single quotes
|
||||||
cleaned_str = dhcp_leases.strip().strip('"')
|
cleaned_str = dhcp_leases.strip().strip('"')
|
||||||
elements = cleaned_str.split('","')
|
elements = cleaned_str.split('","')
|
||||||
num_clients = int(len(elements)/5)
|
num_clients = int(len(elements)/5)
|
||||||
self.mac2name = {}
|
self.mac2name = {}
|
||||||
for x in range(0, num_clients):
|
for idx in range(0, num_clients):
|
||||||
# this is stupid but the data is a single array
|
# this is stupid but the data is a single array
|
||||||
# every 5 elements represents one hosts, the MAC
|
# every 5 elements represents one hosts, the MAC
|
||||||
# is the third element and the name is the first
|
# is the third element and the name is the first
|
||||||
mac_index = (x * 5) + 2
|
mac_index = (idx * 5) + 2
|
||||||
if mac_index < len(elements):
|
if mac_index < len(elements):
|
||||||
self.mac2name[elements[mac_index]] = elements[x * 5]
|
mac = elements[mac_index]
|
||||||
|
self.mac2name[mac] = elements[idx * 5]
|
||||||
|
|
||||||
return self.mac2name.get(device, None)
|
return self.mac2name.get(device, None)
|
||||||
|
|
||||||
@ -109,18 +108,19 @@ class DdWrtDeviceScanner(object):
|
|||||||
self.last_results = []
|
self.last_results = []
|
||||||
active_clients = data.get('active_wireless', None)
|
active_clients = data.get('active_wireless', None)
|
||||||
if active_clients:
|
if active_clients:
|
||||||
# This is really lame, instead of using JSON the ddwrt UI uses
|
# This is really lame, instead of using JSON the ddwrt UI
|
||||||
# it's own data format for some reason and then regex's out
|
# uses it's own data format for some reason and then
|
||||||
# values so I guess I have to do the same, LAME!!!
|
# regex's out values so I guess I have to do the same,
|
||||||
|
# LAME!!!
|
||||||
|
|
||||||
# remove leading and trailing single quotes
|
# remove leading and trailing single quotes
|
||||||
clean_str = active_clients.strip().strip("'")
|
clean_str = active_clients.strip().strip("'")
|
||||||
elements = clean_str.split("','")
|
elements = clean_str.split("','")
|
||||||
|
|
||||||
num_clients = int(len(elements)/9)
|
num_clients = int(len(elements)/9)
|
||||||
for x in range(0, num_clients):
|
for idx in range(0, num_clients):
|
||||||
# get every 9th element which is the MAC address
|
# get every 9th element which is the MAC address
|
||||||
index = x * 9
|
index = idx * 9
|
||||||
if index < len(elements):
|
if index < len(elements):
|
||||||
self.last_results.append(elements[index])
|
self.last_results.append(elements[index])
|
||||||
|
|
||||||
@ -138,14 +138,14 @@ class DdWrtDeviceScanner(object):
|
|||||||
return
|
return
|
||||||
if response.status_code == 200:
|
if response.status_code == 200:
|
||||||
return _parse_ddwrt_response(response.text)
|
return _parse_ddwrt_response(response.text)
|
||||||
elif res.status_code == 401:
|
elif response.status_code == 401:
|
||||||
# Authentication error
|
# Authentication error
|
||||||
_LOGGER.exception(
|
_LOGGER.exception(
|
||||||
"Failed to authenticate, "
|
"Failed to authenticate, "
|
||||||
"please check your username and password")
|
"please check your username and password")
|
||||||
return
|
return
|
||||||
else:
|
else:
|
||||||
_LOGGER.error("Invalid response from ddwrt: %s", res)
|
_LOGGER.error("Invalid response from ddwrt: %s", response)
|
||||||
|
|
||||||
|
|
||||||
def _parse_ddwrt_response(data_str):
|
def _parse_ddwrt_response(data_str):
|
||||||
|
Loading…
x
Reference in New Issue
Block a user