fixes for Paulus' comments.

This commit is contained in:
Nolan Gilley 2015-09-02 11:46:09 -04:00
parent d2a13da930
commit 5b643a8106

View File

@ -37,7 +37,8 @@ The password for your given admin account.
home_interval home_interval
*Optional *Optional
Number of minutes it will not scan devices that it found in previous results. If the home_interval is set then the component will not let a device
be AWAY if it has been HOME in the last home_interval seconds.
""" """
import logging import logging
from datetime import timedelta from datetime import timedelta
@ -94,7 +95,7 @@ class ActiontecDeviceScanner(object):
self.lock = threading.Lock() self.lock = threading.Lock()
self.last_results = {} self.last_results = []
# Test the router is accessible # Test the router is accessible
data = self.get_actiontec_data() data = self.get_actiontec_data()
@ -129,26 +130,27 @@ class ActiontecDeviceScanner(object):
with self.lock: with self.lock:
exclude_targets = set() exclude_targets = set()
target_list = [] exclude_target_list = []
self.last_results = []
now = dt_util.now() now = dt_util.now()
if self.home_interval: if self.home_interval:
for host in self.last_results: for host in self.last_results:
if host.last_update + self.home_interval > now: if host.last_update + self.home_interval > now:
exclude_targets.add(host) exclude_targets.add(host)
if len(exclude_targets) > 0: if len(exclude_targets) > 0:
target_list = [t.ip for t in exclude_targets] exclude_target_list = [t.ip for t in exclude_targets]
devices = self.get_actiontec_data() self.last_results = []
if not devices: actiontec_data = self.get_actiontec_data()
if not actiontec_data:
return False return False
for client in target_list: for client in exclude_target_list:
if client in devices: if client in actiontec_data:
devices.pop(client) actiontec_data.pop(client)
for name, data in devices.items(): for name, data in actiontec_data.items():
device = Device(data['mac'], name, now) device = Device(data['mac'], name, now)
self.last_results.append(device) self.last_results.append(device)
self.last_results.extend(exclude_targets)
_LOGGER.info("actiontec scan successful")
return True return True
def get_actiontec_data(self): def get_actiontec_data(self):