1
mirror of https://github.com/home-assistant/core synced 2024-09-15 17:29:45 +02:00

OpenUV: Fixed issue with missing protection window data (#17051)

This commit is contained in:
Aaron Bach 2018-10-02 02:34:12 -06:00 committed by Paulus Schoutsen
parent 0954eefa9f
commit 71e3047f5c
2 changed files with 14 additions and 3 deletions

View File

@ -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(

View File

@ -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()