Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions homeassistant/components/plex/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
from plexapi.exceptions import NotFound

from homeassistant.components.sensor import SensorEntity
from homeassistant.const import STATE_UNAVAILABLE
from homeassistant.helpers.debounce import Debouncer
from homeassistant.helpers.dispatcher import async_dispatcher_connect

Expand Down Expand Up @@ -150,6 +149,7 @@ def __init__(self, hass, plex_server, plex_library_section):
self._name = f"{self.server_name} Library - {plex_library_section.title}"
self._unique_id = f"library-{self.server_id}-{plex_library_section.uuid}"
self._state = None
self._available = True
self._attributes = {}

async def async_added_to_hass(self):
Expand All @@ -168,8 +168,9 @@ async def async_refresh_sensor(self):
_LOGGER.debug("Refreshing library sensor for '%s'", self.name)
try:
await self.hass.async_add_executor_job(self._update_state_and_attrs)
self._available = True
except NotFound:
self._state = STATE_UNAVAILABLE
self._available = False
self.async_write_ha_state()

def _update_state_and_attrs(self):
Expand All @@ -186,6 +187,11 @@ def _update_state_and_attrs(self):
libtype=libtype, includeCollections=False
)

@property
def available(self):
"""Return the availability of the client."""
return self._available

@property
def entity_registry_enabled_default(self):
"""Return if sensor should be enabled by default."""
Expand Down