diff --git a/homeassistant/components/asuswrt/device_tracker.py b/homeassistant/components/asuswrt/device_tracker.py index 5e3297da8ff..bb11436b2c5 100644 --- a/homeassistant/components/asuswrt/device_tracker.py +++ b/homeassistant/components/asuswrt/device_tracker.py @@ -24,6 +24,7 @@ class AsusWrtDeviceScanner(DeviceScanner): self.last_results = {} self.success_init = False self.connection = api + self._connect_error = False async def async_connect(self): """Initialize connection to the router.""" @@ -49,4 +50,15 @@ class AsusWrtDeviceScanner(DeviceScanner): """ _LOGGER.debug("Checking Devices") - self.last_results = await self.connection.async_get_connected_devices() + try: + self.last_results = await self.connection.async_get_connected_devices() + if self._connect_error: + self._connect_error = False + _LOGGER.error("Reconnected to ASUS router for device update") + + except OSError as err: + if not self._connect_error: + self._connect_error = True + _LOGGER.error( + "Error connecting to ASUS router for device update: %s", err + ) diff --git a/homeassistant/components/asuswrt/sensor.py b/homeassistant/components/asuswrt/sensor.py index cbe32a1ec43..77555deaba4 100644 --- a/homeassistant/components/asuswrt/sensor.py +++ b/homeassistant/components/asuswrt/sensor.py @@ -49,6 +49,7 @@ class AsuswrtSensor(Entity): self._devices = None self._rates = None self._speed = None + self._connect_error = False @property def name(self): @@ -62,9 +63,23 @@ class AsuswrtSensor(Entity): async def async_update(self): """Fetch status from asuswrt.""" - self._devices = await self._api.async_get_connected_devices() - self._rates = await self._api.async_get_bytes_total() - self._speed = await self._api.async_get_current_transfer_rates() + try: + self._devices = await self._api.async_get_connected_devices() + self._rates = await self._api.async_get_bytes_total() + self._speed = await self._api.async_get_current_transfer_rates() + if self._connect_error: + self._connect_error = False + _LOGGER.error( + "Reconnected to ASUS router for %s update", self.entity_id + ) + except OSError as err: + if not self._connect_error: + self._connect_error = True + _LOGGER.error( + "Error connecting to ASUS router for %s update: %s", + self.entity_id, + err, + ) class AsuswrtDevicesSensor(AsuswrtSensor):