1
mirror of https://github.com/home-assistant/core synced 2024-08-31 05:57:13 +02:00

Set Plex sensor availability properly (#48546)

This commit is contained in:
jjlawren 2021-03-31 10:02:23 -05:00 committed by GitHub
parent e2f8bce0a0
commit 7dfe63e06f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -4,7 +4,6 @@ import logging
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
@ -150,6 +149,7 @@ class PlexLibrarySectionSensor(SensorEntity):
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):
@ -168,8 +168,9 @@ class PlexLibrarySectionSensor(SensorEntity):
_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):
@ -186,6 +187,11 @@ class PlexLibrarySectionSensor(SensorEntity):
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."""