More graceful exception handling in Plex library sensors (#52969)

This commit is contained in:
jjlawren 2021-07-13 13:22:31 -05:00 committed by GitHub
parent ff56ede960
commit f39f087b10
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 39 additions and 0 deletions

View file

@ -2,6 +2,7 @@
import logging
from plexapi.exceptions import NotFound
import requests.exceptions
from homeassistant.components.sensor import SensorEntity
from homeassistant.helpers.debounce import Debouncer
@ -148,6 +149,13 @@ class PlexLibrarySectionSensor(SensorEntity):
self._attr_available = True
except NotFound:
self._attr_available = False
except requests.exceptions.RequestException as err:
_LOGGER.error(
"Could not update library sensor for '%s': %s",
self.library_section.title,
err,
)
self._attr_available = False
self.async_write_ha_state()
def _update_state_and_attrs(self):