From 6a6ea263cfad48d0ec1f21bfc1537cc03acb5a0a Mon Sep 17 00:00:00 2001 From: William Scanlon Date: Sun, 21 Jan 2018 12:13:28 -0500 Subject: [PATCH] Fix Unifi direct errors caused by AP reboot. (#11835) * Fix Unifi direct errors caused by AP reboot. * Inverted logic in update --- homeassistant/components/device_tracker/unifi_direct.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/homeassistant/components/device_tracker/unifi_direct.py b/homeassistant/components/device_tracker/unifi_direct.py index 57a0186a2e2..168ab04ec6f 100644 --- a/homeassistant/components/device_tracker/unifi_direct.py +++ b/homeassistant/components/device_tracker/unifi_direct.py @@ -98,11 +98,15 @@ class UnifiDeviceScanner(DeviceScanner): self.connected = False def _get_update(self): - from pexpect import pxssh + from pexpect import pxssh, exceptions try: if not self.connected: self._connect() + # If we still aren't connected at this point + # don't try to send anything to the AP. + if not self.connected: + return None self.ssh.sendline(UNIFI_COMMAND) self.ssh.prompt() return self.ssh.before @@ -110,7 +114,7 @@ class UnifiDeviceScanner(DeviceScanner): _LOGGER.error("Unexpected SSH error: %s", str(err)) self._disconnect() return None - except AssertionError as err: + except (AssertionError, exceptions.EOF) as err: _LOGGER.error("Connection to AP unavailable: %s", str(err)) self._disconnect() return None