Fix apcupsd spamming logs when host is unavailable (#85920)

fixes undefined
pull/85938/head
ondras12345 2023-01-15 14:45:05 +01:00 committed by GitHub
parent 2850583085
commit cef1809536
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 16 additions and 2 deletions

View File

@ -65,8 +65,15 @@ class OnlineStatus(BinarySensorEntity):
def update(self) -> None: def update(self) -> None:
"""Get the status report from APCUPSd and set this entity's state.""" """Get the status report from APCUPSd and set this entity's state."""
try:
self._data_service.update() self._data_service.update()
except OSError as ex:
if self._attr_available:
self._attr_available = False
_LOGGER.exception("Got exception while fetching state: %s", ex)
return
self._attr_available = True
key = self.entity_description.key.upper() key = self.entity_description.key.upper()
if key not in self._data_service.status: if key not in self._data_service.status:
self._attr_is_on = None self._attr_is_on = None

View File

@ -503,8 +503,15 @@ class APCUPSdSensor(SensorEntity):
def update(self) -> None: def update(self) -> None:
"""Get the latest status and use it to update our sensor state.""" """Get the latest status and use it to update our sensor state."""
try:
self._data_service.update() self._data_service.update()
except OSError as ex:
if self._attr_available:
self._attr_available = False
_LOGGER.exception("Got exception while fetching state: %s", ex)
return
self._attr_available = True
key = self.entity_description.key.upper() key = self.entity_description.key.upper()
if key not in self._data_service.status: if key not in self._data_service.status:
self._attr_native_value = None self._attr_native_value = None