From fc33273464fe9b43af33d93ddfa46cc8157b1e3d Mon Sep 17 00:00:00 2001 From: Karsten Nerdinger Date: Wed, 7 Jan 2015 03:36:39 +0100 Subject: [PATCH 1/2] Check flags in ARP table for NUD_REACHABLE before assuming a device is online. Fixes #18. --- homeassistant/components/device_tracker/luci.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/homeassistant/components/device_tracker/luci.py b/homeassistant/components/device_tracker/luci.py index 9ed73f21375..f3567ab17f3 100644 --- a/homeassistant/components/device_tracker/luci.py +++ b/homeassistant/components/device_tracker/luci.py @@ -101,7 +101,10 @@ class LuciDeviceScanner(object): result = _req_json_rpc(url, 'net.arptable', params={'auth': self.token}) if result: - self.last_results = [x['HW address'] for x in result] + self.last_results = [] + for x in result: + # Check if the Flags for each device contain NUD_REACHABLE and if so, add it to last_results + if int(x['Flags'], 16) & 0x2: self.last_results.append(x['HW address']) return True From 2c5886f6d4f06be1269128f88b5d7c8104a305db Mon Sep 17 00:00:00 2001 From: Karsten Nerdinger Date: Wed, 7 Jan 2015 03:57:06 +0100 Subject: [PATCH 2/2] Fix warnings from flake8 and pylint --- homeassistant/components/device_tracker/luci.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/homeassistant/components/device_tracker/luci.py b/homeassistant/components/device_tracker/luci.py index f3567ab17f3..9dbf503fc94 100644 --- a/homeassistant/components/device_tracker/luci.py +++ b/homeassistant/components/device_tracker/luci.py @@ -102,9 +102,11 @@ class LuciDeviceScanner(object): params={'auth': self.token}) if result: self.last_results = [] - for x in result: - # Check if the Flags for each device contain NUD_REACHABLE and if so, add it to last_results - if int(x['Flags'], 16) & 0x2: self.last_results.append(x['HW address']) + for device_entry in result: + # Check if the Flags for each device contain + # NUD_REACHABLE and if so, add it to last_results + if int(device_entry['Flags'], 16) & 0x2: + self.last_results.append(device_entry['HW address']) return True