From 3af7c67bf1a66b43b982f4598420c34c3d4fcfb4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ville=20Skytt=C3=A4?= Date: Sat, 27 Jan 2018 16:20:28 +0200 Subject: [PATCH] Fix asuswrt AttributeError on neigh for unknown device (#11960) --- homeassistant/components/device_tracker/asuswrt.py | 3 ++- tests/components/device_tracker/test_asuswrt.py | 3 +++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/homeassistant/components/device_tracker/asuswrt.py b/homeassistant/components/device_tracker/asuswrt.py index 0d27c4b5efd..2196dd78fdb 100644 --- a/homeassistant/components/device_tracker/asuswrt.py +++ b/homeassistant/components/device_tracker/asuswrt.py @@ -214,7 +214,8 @@ class AsusWrtDeviceScanner(DeviceScanner): for device in result: if device['mac'] is not None: mac = device['mac'].upper() - old_ip = cur_devices.get(mac, {}).ip or None + old_device = cur_devices.get(mac) + old_ip = old_device.ip if old_device else None devices[mac] = Device(mac, device.get('ip', old_ip), None) return devices diff --git a/tests/components/device_tracker/test_asuswrt.py b/tests/components/device_tracker/test_asuswrt.py index 808d3569b8b..6e646e9862d 100644 --- a/tests/components/device_tracker/test_asuswrt.py +++ b/tests/components/device_tracker/test_asuswrt.py @@ -447,6 +447,9 @@ class TestComponentsDeviceTrackerASUSWRT(unittest.TestCase): scanner = get_scanner(self.hass, VALID_CONFIG_ROUTER_SSH) scanner.connection = mocked_ssh self.assertEqual(NEIGH_DEVICES, scanner._get_neigh(ARP_DEVICES.copy())) + self.assertEqual(NEIGH_DEVICES, scanner._get_neigh({ + 'UN:KN:WN:DE:VI:CE': Device('UN:KN:WN:DE:VI:CE', None, None), + })) mocked_ssh.run_command.return_value = '' self.assertEqual({}, scanner._get_neigh(ARP_DEVICES.copy()))