mirror of
https://github.com/home-assistant/core.git
synced 2025-07-23 13:17:32 +00:00
OpenUV: Fixed issue with missing protection window data (#17051)
This commit is contained in:
parent
0954eefa9f
commit
71e3047f5c
@ -93,7 +93,11 @@ class OpenUvBinarySensor(OpenUvEntity, BinarySensorDevice):
|
|||||||
|
|
||||||
async def async_update(self):
|
async def async_update(self):
|
||||||
"""Update the state."""
|
"""Update the state."""
|
||||||
data = self.openuv.data[DATA_PROTECTION_WINDOW]['result']
|
data = self.openuv.data[DATA_PROTECTION_WINDOW]
|
||||||
|
|
||||||
|
if not data:
|
||||||
|
return
|
||||||
|
|
||||||
if self._sensor_type == TYPE_PROTECTION_WINDOW:
|
if self._sensor_type == TYPE_PROTECTION_WINDOW:
|
||||||
self._state = parse_datetime(
|
self._state = parse_datetime(
|
||||||
data['from_time']) <= utcnow() <= parse_datetime(
|
data['from_time']) <= utcnow() <= parse_datetime(
|
||||||
|
@ -212,8 +212,15 @@ class OpenUV:
|
|||||||
async def async_update(self):
|
async def async_update(self):
|
||||||
"""Update sensor/binary sensor data."""
|
"""Update sensor/binary sensor data."""
|
||||||
if TYPE_PROTECTION_WINDOW in self.binary_sensor_conditions:
|
if TYPE_PROTECTION_WINDOW in self.binary_sensor_conditions:
|
||||||
data = await self.client.uv_protection_window()
|
resp = await self.client.uv_protection_window()
|
||||||
self.data[DATA_PROTECTION_WINDOW] = data
|
data = resp['result']
|
||||||
|
|
||||||
|
if data.get('from_time') and data.get('to_time'):
|
||||||
|
self.data[DATA_PROTECTION_WINDOW] = data
|
||||||
|
else:
|
||||||
|
_LOGGER.error(
|
||||||
|
'No valid protection window data for this location')
|
||||||
|
self.data[DATA_PROTECTION_WINDOW] = {}
|
||||||
|
|
||||||
if any(c in self.sensor_conditions for c in SENSORS):
|
if any(c in self.sensor_conditions for c in SENSORS):
|
||||||
data = await self.client.uv_index()
|
data = await self.client.uv_index()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user