diff --git a/homeassistant/components/apcupsd/binary_sensor.py b/homeassistant/components/apcupsd/binary_sensor.py index 7438e3236d4..d45ad561d8d 100644 --- a/homeassistant/components/apcupsd/binary_sensor.py +++ b/homeassistant/components/apcupsd/binary_sensor.py @@ -65,8 +65,15 @@ class OnlineStatus(BinarySensorEntity): def update(self) -> None: """Get the status report from APCUPSd and set this entity's state.""" - self._data_service.update() + try: + 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() if key not in self._data_service.status: self._attr_is_on = None diff --git a/homeassistant/components/apcupsd/sensor.py b/homeassistant/components/apcupsd/sensor.py index 27d315f90fd..4e0e46f6392 100644 --- a/homeassistant/components/apcupsd/sensor.py +++ b/homeassistant/components/apcupsd/sensor.py @@ -503,8 +503,15 @@ class APCUPSdSensor(SensorEntity): def update(self) -> None: """Get the latest status and use it to update our sensor state.""" - self._data_service.update() + try: + 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() if key not in self._data_service.status: self._attr_native_value = None