mirror of
https://github.com/home-assistant/core.git
synced 2025-04-29 03:37:51 +00:00
Fixed Pollen.com bugs with ZIP codes and invalid API responses (#12790)
This commit is contained in:
parent
b556b86301
commit
a0eca9c6d1
@ -107,7 +107,7 @@ RATING_MAPPING = [{
|
|||||||
|
|
||||||
|
|
||||||
PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend({
|
PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend({
|
||||||
vol.Required(CONF_ZIP_CODE): cv.positive_int,
|
vol.Required(CONF_ZIP_CODE): cv.string,
|
||||||
vol.Required(CONF_MONITORED_CONDITIONS):
|
vol.Required(CONF_MONITORED_CONDITIONS):
|
||||||
vol.All(cv.ensure_list, [vol.In(CONDITIONS)]),
|
vol.All(cv.ensure_list, [vol.In(CONDITIONS)]),
|
||||||
})
|
})
|
||||||
@ -209,11 +209,16 @@ class AllergyAverageSensor(BaseSensor):
|
|||||||
"""Update the status of the sensor."""
|
"""Update the status of the sensor."""
|
||||||
self.data.update()
|
self.data.update()
|
||||||
|
|
||||||
|
try:
|
||||||
data_attr = getattr(self.data, self._data_params['data_attr'])
|
data_attr = getattr(self.data, self._data_params['data_attr'])
|
||||||
indices = [
|
indices = [
|
||||||
p['Index']
|
p['Index']
|
||||||
for p in data_attr['Location']['periods']
|
for p in data_attr['Location']['periods']
|
||||||
]
|
]
|
||||||
|
except KeyError:
|
||||||
|
_LOGGER.error("Pollen.com API didn't return any data")
|
||||||
|
return
|
||||||
|
|
||||||
average = round(mean(indices), 1)
|
average = round(mean(indices), 1)
|
||||||
|
|
||||||
self._attrs[ATTR_TREND] = calculate_trend(indices)
|
self._attrs[ATTR_TREND] = calculate_trend(indices)
|
||||||
@ -238,7 +243,12 @@ class AllergyIndexSensor(BaseSensor):
|
|||||||
"""Update the status of the sensor."""
|
"""Update the status of the sensor."""
|
||||||
self.data.update()
|
self.data.update()
|
||||||
|
|
||||||
|
try:
|
||||||
location_data = self.data.current_data['Location']
|
location_data = self.data.current_data['Location']
|
||||||
|
except KeyError:
|
||||||
|
_LOGGER.error("Pollen.com API didn't return any data")
|
||||||
|
return
|
||||||
|
|
||||||
[period] = [
|
[period] = [
|
||||||
p for p in location_data['periods']
|
p for p in location_data['periods']
|
||||||
if p['Type'] == self._data_params['key']
|
if p['Type'] == self._data_params['key']
|
||||||
@ -276,6 +286,7 @@ class DataBase(object):
|
|||||||
"""Get data from a particular point in the API."""
|
"""Get data from a particular point in the API."""
|
||||||
from pypollencom.exceptions import HTTPError
|
from pypollencom.exceptions import HTTPError
|
||||||
|
|
||||||
|
data = {}
|
||||||
try:
|
try:
|
||||||
data = getattr(getattr(self._client, module), operation)()
|
data = getattr(getattr(self._client, module), operation)()
|
||||||
_LOGGER.debug('Received "%s_%s" data: %s', module,
|
_LOGGER.debug('Received "%s_%s" data: %s', module,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user