Fixes (#9911)
parent
875edef3f0
commit
9be7763144
|
@ -4,7 +4,6 @@ Support for AirVisual air quality sensors.
|
|||
For more details about this platform, please refer to the documentation at
|
||||
https://home-assistant.io/components/sensor.airvisual/
|
||||
"""
|
||||
import asyncio
|
||||
from logging import getLogger
|
||||
from datetime import timedelta
|
||||
|
||||
|
@ -80,8 +79,7 @@ PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend({
|
|||
})
|
||||
|
||||
|
||||
@asyncio.coroutine
|
||||
def async_setup_platform(hass, config, async_add_devices, discovery_info=None):
|
||||
def setup_platform(hass, config, add_devices, discovery_info=None):
|
||||
"""Configure the platform and add the sensors."""
|
||||
import pyairvisual as pav
|
||||
|
||||
|
@ -108,12 +106,13 @@ def async_setup_platform(hass, config, async_add_devices, discovery_info=None):
|
|||
pav.Client(api_key), latitude=latitude, longitude=longitude,
|
||||
radius=radius, show_on_map=show_on_map)
|
||||
|
||||
data.update()
|
||||
sensors = []
|
||||
for locale in monitored_locales:
|
||||
for sensor_class, name, icon in SENSOR_TYPES:
|
||||
sensors.append(globals()[sensor_class](data, name, icon, locale))
|
||||
|
||||
async_add_devices(sensors, True)
|
||||
add_devices(sensors, True)
|
||||
|
||||
|
||||
def merge_two_dicts(dict1, dict2):
|
||||
|
@ -170,20 +169,14 @@ class AirVisualBaseSensor(Entity):
|
|||
"""Return the state."""
|
||||
return self._state
|
||||
|
||||
@asyncio.coroutine
|
||||
def async_update(self):
|
||||
"""Update the status of the sensor."""
|
||||
_LOGGER.debug("Updating sensor: %s", self._name)
|
||||
self._data.update()
|
||||
|
||||
|
||||
class AirPollutionLevelSensor(AirVisualBaseSensor):
|
||||
"""Define a sensor to measure air pollution level."""
|
||||
|
||||
@asyncio.coroutine
|
||||
def async_update(self):
|
||||
def update(self):
|
||||
"""Update the status of the sensor."""
|
||||
yield from super().async_update()
|
||||
self._data.update()
|
||||
|
||||
aqi = self._data.pollution_info.get('aqi{0}'.format(self._locale))
|
||||
try:
|
||||
[level] = [
|
||||
|
@ -205,10 +198,9 @@ class AirQualityIndexSensor(AirVisualBaseSensor):
|
|||
"""Return the unit the value is expressed in."""
|
||||
return 'PSI'
|
||||
|
||||
@asyncio.coroutine
|
||||
def async_update(self):
|
||||
def update(self):
|
||||
"""Update the status of the sensor."""
|
||||
yield from super().async_update()
|
||||
self._data.update()
|
||||
|
||||
self._state = self._data.pollution_info.get(
|
||||
'aqi{0}'.format(self._locale))
|
||||
|
@ -231,10 +223,10 @@ class MainPollutantSensor(AirVisualBaseSensor):
|
|||
ATTR_POLLUTANT_UNIT: self._unit
|
||||
})
|
||||
|
||||
@asyncio.coroutine
|
||||
def async_update(self):
|
||||
def update(self):
|
||||
"""Update the status of the sensor."""
|
||||
yield from super().async_update()
|
||||
self._data.update()
|
||||
|
||||
symbol = self._data.pollution_info.get('main{0}'.format(self._locale))
|
||||
pollution_info = POLLUTANT_MAPPING.get(symbol, {})
|
||||
self._state = pollution_info.get('label')
|
||||
|
|
Loading…
Reference in New Issue