From 3b37a7b73785940793e01eb183509a7b05c2a678 Mon Sep 17 00:00:00 2001 From: Nolan Gilley Date: Wed, 28 Oct 2015 17:20:15 -0400 Subject: [PATCH 1/4] bugfix for actiontec device tracker --- .../components/device_tracker/actiontec.py | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/homeassistant/components/device_tracker/actiontec.py b/homeassistant/components/device_tracker/actiontec.py index a2f94f34c3a..1c13fedec48 100644 --- a/homeassistant/components/device_tracker/actiontec.py +++ b/homeassistant/components/device_tracker/actiontec.py @@ -30,7 +30,9 @@ _LOGGER = logging.getLogger(__name__) _LEASES_REGEX = re.compile( r'(?P([0-9]{1,3}[\.]){3}[0-9]{1,3})' + - r'\smac:\s(?P([0-9a-f]{2}[:-]){5}([0-9a-f]{2}))') + r'\smac:\s(?P([0-9a-f]{2}[:-]){5}([0-9a-f]{2}))' + + r'\svalid\sfor:\s(?P(-?\d+))' + + r'\ssec') # pylint: disable=unused-argument @@ -40,9 +42,7 @@ def get_scanner(hass, config): {DOMAIN: [CONF_HOST, CONF_USERNAME, CONF_PASSWORD]}, _LOGGER): return None - scanner = ActiontecDeviceScanner(config[DOMAIN]) - return scanner if scanner.success_init else None Device = namedtuple("Device", ["mac", "ip", "last_update"]) @@ -60,11 +60,8 @@ class ActiontecDeviceScanner(object): self.password = config[CONF_PASSWORD] minutes = convert(config.get(CONF_HOME_INTERVAL), int, 0) self.home_interval = timedelta(minutes=minutes) - self.lock = threading.Lock() - self.last_results = [] - # Test the router is accessible data = self.get_actiontec_data() self.success_init = data is not None @@ -109,7 +106,6 @@ class ActiontecDeviceScanner(object): exclude_targets.add(host) if len(exclude_targets) > 0: exclude_target_list = [t.ip for t in exclude_targets] - actiontec_data = self.get_actiontec_data() if not actiontec_data: return False @@ -118,8 +114,9 @@ class ActiontecDeviceScanner(object): if client in actiontec_data: actiontec_data.pop(client) for name, data in actiontec_data.items(): - device = Device(data['mac'], name, now) - self.last_results.append(device) + if data['timevalid'] > 0: + device = Device(data['mac'], name, now) + self.last_results.append(device) self.last_results.extend(exclude_targets) _LOGGER.info("actiontec scan successful") return True @@ -153,6 +150,7 @@ class ActiontecDeviceScanner(object): if match is not None: devices[match.group('ip')] = { 'ip': match.group('ip'), - 'mac': match.group('mac').upper() + 'mac': match.group('mac').upper(), + 'timevalid': int(match.group('timevalid')) } return devices From 8eeca945171b1975a3097f5ebc959d51f33a4dac Mon Sep 17 00:00:00 2001 From: Nolan Gilley Date: Wed, 28 Oct 2015 17:43:41 -0400 Subject: [PATCH 2/4] removed home_interval option since it was added to the main device_tracker component --- .../components/device_tracker/actiontec.py | 13 ------------- 1 file changed, 13 deletions(-) diff --git a/homeassistant/components/device_tracker/actiontec.py b/homeassistant/components/device_tracker/actiontec.py index 1c13fedec48..38f5f78907f 100644 --- a/homeassistant/components/device_tracker/actiontec.py +++ b/homeassistant/components/device_tracker/actiontec.py @@ -23,9 +23,6 @@ from homeassistant.components.device_tracker import DOMAIN # Return cached results if last scan was less then this time ago MIN_TIME_BETWEEN_SCANS = timedelta(seconds=5) -# Interval in minutes to exclude devices from a scan while they are home -CONF_HOME_INTERVAL = "home_interval" - _LOGGER = logging.getLogger(__name__) _LEASES_REGEX = re.compile( @@ -58,16 +55,12 @@ class ActiontecDeviceScanner(object): self.host = config[CONF_HOST] self.username = config[CONF_USERNAME] self.password = config[CONF_PASSWORD] - minutes = convert(config.get(CONF_HOME_INTERVAL), int, 0) - self.home_interval = timedelta(minutes=minutes) self.lock = threading.Lock() self.last_results = [] # Test the router is accessible data = self.get_actiontec_data() self.success_init = data is not None _LOGGER.info("actiontec scanner initialized") - if self.home_interval: - _LOGGER.info("home_interval set to: %s", self.home_interval) def scan_devices(self): """ @@ -100,12 +93,6 @@ class ActiontecDeviceScanner(object): exclude_targets = set() exclude_target_list = [] now = dt_util.now() - if self.home_interval: - for host in self.last_results: - if host.last_update + self.home_interval > now: - exclude_targets.add(host) - if len(exclude_targets) > 0: - exclude_target_list = [t.ip for t in exclude_targets] actiontec_data = self.get_actiontec_data() if not actiontec_data: return False From bcb2451752e6a2603e98a36bed5475ea58c05519 Mon Sep 17 00:00:00 2001 From: Nolan Gilley Date: Wed, 28 Oct 2015 17:47:13 -0400 Subject: [PATCH 3/4] fix pylint warning --- homeassistant/components/device_tracker/actiontec.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/homeassistant/components/device_tracker/actiontec.py b/homeassistant/components/device_tracker/actiontec.py index 38f5f78907f..c627c6fe118 100644 --- a/homeassistant/components/device_tracker/actiontec.py +++ b/homeassistant/components/device_tracker/actiontec.py @@ -17,7 +17,7 @@ import telnetlib import homeassistant.util.dt as dt_util from homeassistant.const import CONF_HOST, CONF_USERNAME, CONF_PASSWORD from homeassistant.helpers import validate_config -from homeassistant.util import Throttle, convert +from homeassistant.util import Throttle from homeassistant.components.device_tracker import DOMAIN # Return cached results if last scan was less then this time ago From e961dd5f95aba15994be339bfa24d95b844a3f24 Mon Sep 17 00:00:00 2001 From: Nolan Gilley Date: Fri, 30 Oct 2015 07:00:35 -0400 Subject: [PATCH 4/4] increase valid for time to 60 since I was having some issues. removed deprecated lines. --- .../components/device_tracker/actiontec.py | 15 +++------------ 1 file changed, 3 insertions(+), 12 deletions(-) diff --git a/homeassistant/components/device_tracker/actiontec.py b/homeassistant/components/device_tracker/actiontec.py index c627c6fe118..6296d766456 100644 --- a/homeassistant/components/device_tracker/actiontec.py +++ b/homeassistant/components/device_tracker/actiontec.py @@ -57,7 +57,6 @@ class ActiontecDeviceScanner(object): self.password = config[CONF_PASSWORD] self.lock = threading.Lock() self.last_results = [] - # Test the router is accessible data = self.get_actiontec_data() self.success_init = data is not None _LOGGER.info("actiontec scanner initialized") @@ -90,21 +89,13 @@ class ActiontecDeviceScanner(object): return False with self.lock: - exclude_targets = set() - exclude_target_list = [] now = dt_util.now() actiontec_data = self.get_actiontec_data() if not actiontec_data: return False - self.last_results = [] - for client in exclude_target_list: - if client in actiontec_data: - actiontec_data.pop(client) - for name, data in actiontec_data.items(): - if data['timevalid'] > 0: - device = Device(data['mac'], name, now) - self.last_results.append(device) - self.last_results.extend(exclude_targets) + self.last_results = [Device(data['mac'], name, now) + for name, data in actiontec_data.items() + if data['timevalid'] > -60] _LOGGER.info("actiontec scan successful") return True