OpenUV: Fixed issue with missing protection window data (#17051)
parent
0954eefa9f
commit
71e3047f5c
|
@ -93,7 +93,11 @@ class OpenUvBinarySensor(OpenUvEntity, BinarySensorDevice):
|
|||
|
||||
async def async_update(self):
|
||||
"""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:
|
||||
self._state = parse_datetime(
|
||||
data['from_time']) <= utcnow() <= parse_datetime(
|
||||
|
|
|
@ -212,8 +212,15 @@ class OpenUV:
|
|||
async def async_update(self):
|
||||
"""Update sensor/binary sensor data."""
|
||||
if TYPE_PROTECTION_WINDOW in self.binary_sensor_conditions:
|
||||
data = await self.client.uv_protection_window()
|
||||
self.data[DATA_PROTECTION_WINDOW] = data
|
||||
resp = await self.client.uv_protection_window()
|
||||
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):
|
||||
data = await self.client.uv_index()
|
||||
|
|
Loading…
Reference in New Issue