Fix asuswrt spamming logs with exceptions (#37063)

This commit is contained in:
RogerSelwyn 2020-06-24 17:50:58 +01:00 committed by GitHub
parent 4a65bed0eb
commit d9a3b04e30
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 31 additions and 4 deletions

View File

@ -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
)

View File

@ -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):