From 9be77631444e80ea621ad80f83f82e0f73c3ea5f Mon Sep 17 00:00:00 2001 From: Aaron Bach Date: Tue, 17 Oct 2017 02:02:03 -0600 Subject: [PATCH] Fixes (#9911) --- homeassistant/components/sensor/airvisual.py | 30 +++++++------------- 1 file changed, 11 insertions(+), 19 deletions(-) diff --git a/homeassistant/components/sensor/airvisual.py b/homeassistant/components/sensor/airvisual.py index 10b57749741..82486a63d31 100644 --- a/homeassistant/components/sensor/airvisual.py +++ b/homeassistant/components/sensor/airvisual.py @@ -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')