Prevent error when no forecast data was available (#9176)

* Prevent error when no forecast data was available

Prevent an Error when buienradar data was available, but no forecasted data was retrieved for the requested day.

* Update buienradar.py

* Update buienradar.py
pull/9215/head
mjj4791 2017-08-29 15:33:47 +02:00 committed by Pascal Vizeli
parent 75559cb81f
commit 5d800c1d51
1 changed files with 11 additions and 2 deletions

View File

@ -220,7 +220,12 @@ class BrSensor(Entity):
# update all other sensors # update all other sensors
if self.type.startswith(SYMBOL) or self.type.startswith(CONDITION): if self.type.startswith(SYMBOL) or self.type.startswith(CONDITION):
condition = data.get(FORECAST)[fcday].get(CONDITION) try:
condition = data.get(FORECAST)[fcday].get(CONDITION)
except IndexError:
_LOGGER.warning("No forecast for fcday=%s...", fcday)
return False
if condition: if condition:
new_state = condition.get(CONDITION, None) new_state = condition.get(CONDITION, None)
if self.type.startswith(SYMBOL): if self.type.startswith(SYMBOL):
@ -240,7 +245,11 @@ class BrSensor(Entity):
return True return True
return False return False
else: else:
new_state = data.get(FORECAST)[fcday].get(self.type[:-3]) try:
new_state = data.get(FORECAST)[fcday].get(self.type[:-3])
except IndexError:
_LOGGER.warning("No forecast for fcday=%s...", fcday)
return False
if new_state != self._state: if new_state != self._state:
self._state = new_state self._state = new_state