Allow OpenUV entities to be unavailable (#31018)
* Allow OpenUV entities to be unavailable * Empty commit to re-trigger build
This commit is contained in:
parent
1639432463
commit
662c12715e
3 changed files with 17 additions and 1 deletions
|
@ -289,9 +289,15 @@ class OpenUvEntity(Entity):
|
||||||
def __init__(self, openuv):
|
def __init__(self, openuv):
|
||||||
"""Initialize."""
|
"""Initialize."""
|
||||||
self._attrs = {ATTR_ATTRIBUTION: DEFAULT_ATTRIBUTION}
|
self._attrs = {ATTR_ATTRIBUTION: DEFAULT_ATTRIBUTION}
|
||||||
|
self._available = True
|
||||||
self._name = None
|
self._name = None
|
||||||
self.openuv = openuv
|
self.openuv = openuv
|
||||||
|
|
||||||
|
@property
|
||||||
|
def available(self) -> bool:
|
||||||
|
"""Return True if entity is available."""
|
||||||
|
return self._available
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def device_state_attributes(self):
|
def device_state_attributes(self):
|
||||||
"""Return the state attributes."""
|
"""Return the state attributes."""
|
||||||
|
|
|
@ -100,8 +100,11 @@ class OpenUvBinarySensor(OpenUvEntity, BinarySensorDevice):
|
||||||
data = self.openuv.data[DATA_PROTECTION_WINDOW]
|
data = self.openuv.data[DATA_PROTECTION_WINDOW]
|
||||||
|
|
||||||
if not data:
|
if not data:
|
||||||
|
self._available = False
|
||||||
return
|
return
|
||||||
|
|
||||||
|
self._available = True
|
||||||
|
|
||||||
for key in ("from_time", "to_time", "from_uv", "to_uv"):
|
for key in ("from_time", "to_time", "from_uv", "to_uv"):
|
||||||
if not data.get(key):
|
if not data.get(key):
|
||||||
_LOGGER.info("Skipping update due to missing data: %s", key)
|
_LOGGER.info("Skipping update due to missing data: %s", key)
|
||||||
|
|
|
@ -124,7 +124,14 @@ class OpenUvSensor(OpenUvEntity):
|
||||||
|
|
||||||
async def async_update(self):
|
async def async_update(self):
|
||||||
"""Update the state."""
|
"""Update the state."""
|
||||||
data = self.openuv.data[DATA_UV]["result"]
|
data = self.openuv.data[DATA_UV].get("result")
|
||||||
|
|
||||||
|
if not data:
|
||||||
|
self._available = False
|
||||||
|
return
|
||||||
|
|
||||||
|
self._available = True
|
||||||
|
|
||||||
if self._sensor_type == TYPE_CURRENT_OZONE_LEVEL:
|
if self._sensor_type == TYPE_CURRENT_OZONE_LEVEL:
|
||||||
self._state = data["ozone"]
|
self._state = data["ozone"]
|
||||||
elif self._sensor_type == TYPE_CURRENT_UV_INDEX:
|
elif self._sensor_type == TYPE_CURRENT_UV_INDEX:
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue