Update pynetgear to latest version

This commit is contained in:
Paulus Schoutsen 2015-01-17 13:49:22 -08:00
parent 8562b8f09d
commit 45e295c1d3
2 changed files with 16 additions and 21 deletions

View File

@ -22,7 +22,10 @@ def get_scanner(hass, config):
_LOGGER): _LOGGER):
return None return None
scanner = NetgearDeviceScanner(config[DOMAIN]) info = config[DOMAIN]
scanner = NetgearDeviceScanner(
info[CONF_HOST], info[CONF_USERNAME], info[CONF_PASSWORD])
return scanner if scanner.success_init else None return scanner if scanner.success_init else None
@ -30,10 +33,7 @@ def get_scanner(hass, config):
class NetgearDeviceScanner(object): class NetgearDeviceScanner(object):
""" This class queries a Netgear wireless router using the SOAP-api. """ """ This class queries a Netgear wireless router using the SOAP-api. """
def __init__(self, config): def __init__(self, host, username, password):
host = config[CONF_HOST]
username, password = config[CONF_USERNAME], config[CONF_PASSWORD]
self.last_results = [] self.last_results = []
try: try:
@ -54,32 +54,27 @@ class NetgearDeviceScanner(object):
self.lock = threading.Lock() self.lock = threading.Lock()
_LOGGER.info("Logging in") _LOGGER.info("Logging in")
if self._api.login():
self.success_init = True
self._update_info()
self.success_init = self._api.login()
if self.success_init:
self._update_info()
else: else:
_LOGGER.error("Failed to Login") _LOGGER.error("Failed to Login")
self.success_init = False
def scan_devices(self): def scan_devices(self):
""" Scans for new devices and return a """ Scans for new devices and return a
list containing found device ids. """ list containing found device ids. """
self._update_info() self._update_info()
return [device.mac for device in self.last_results] return (device.mac for device in self.last_results)
def get_device_name(self, mac): def get_device_name(self, mac):
""" Returns the name of the given device or None if we don't know. """ """ Returns the name of the given device or None if we don't know. """
try:
filter_named = [device.name for device in self.last_results return next(device.name for device in self.last_results
if device.mac == mac] if device.mac == mac)
except StopIteration:
if filter_named:
return filter_named[0]
else:
return None return None
@Throttle(MIN_TIME_BETWEEN_SCANS) @Throttle(MIN_TIME_BETWEEN_SCANS)
@ -92,4 +87,4 @@ class NetgearDeviceScanner(object):
with self.lock: with self.lock:
_LOGGER.info("Scanning") _LOGGER.info("Scanning")
self.last_results = self._api.get_attached_devices() self.last_results = self._api.get_attached_devices() or []

@ -1 +1 @@
Subproject commit 991fbc9c42abe3e8bcce50fbf549d9fceefe1e29 Subproject commit e76b2df5170d65c56d406d79d9944b724de6382e