mirror of
https://github.com/home-assistant/core.git
synced 2025-07-19 11:17:21 +00:00
Fixes (#9911)
This commit is contained in:
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
|
For more details about this platform, please refer to the documentation at
|
||||||
https://home-assistant.io/components/sensor.airvisual/
|
https://home-assistant.io/components/sensor.airvisual/
|
||||||
"""
|
"""
|
||||||
import asyncio
|
|
||||||
from logging import getLogger
|
from logging import getLogger
|
||||||
from datetime import timedelta
|
from datetime import timedelta
|
||||||
|
|
||||||
@ -80,8 +79,7 @@ PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend({
|
|||||||
})
|
})
|
||||||
|
|
||||||
|
|
||||||
@asyncio.coroutine
|
def setup_platform(hass, config, add_devices, discovery_info=None):
|
||||||
def async_setup_platform(hass, config, async_add_devices, discovery_info=None):
|
|
||||||
"""Configure the platform and add the sensors."""
|
"""Configure the platform and add the sensors."""
|
||||||
import pyairvisual as pav
|
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,
|
pav.Client(api_key), latitude=latitude, longitude=longitude,
|
||||||
radius=radius, show_on_map=show_on_map)
|
radius=radius, show_on_map=show_on_map)
|
||||||
|
|
||||||
|
data.update()
|
||||||
sensors = []
|
sensors = []
|
||||||
for locale in monitored_locales:
|
for locale in monitored_locales:
|
||||||
for sensor_class, name, icon in SENSOR_TYPES:
|
for sensor_class, name, icon in SENSOR_TYPES:
|
||||||
sensors.append(globals()[sensor_class](data, name, icon, locale))
|
sensors.append(globals()[sensor_class](data, name, icon, locale))
|
||||||
|
|
||||||
async_add_devices(sensors, True)
|
add_devices(sensors, True)
|
||||||
|
|
||||||
|
|
||||||
def merge_two_dicts(dict1, dict2):
|
def merge_two_dicts(dict1, dict2):
|
||||||
@ -170,20 +169,14 @@ class AirVisualBaseSensor(Entity):
|
|||||||
"""Return the state."""
|
"""Return the state."""
|
||||||
return self._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):
|
class AirPollutionLevelSensor(AirVisualBaseSensor):
|
||||||
"""Define a sensor to measure air pollution level."""
|
"""Define a sensor to measure air pollution level."""
|
||||||
|
|
||||||
@asyncio.coroutine
|
def update(self):
|
||||||
def async_update(self):
|
|
||||||
"""Update the status of the sensor."""
|
"""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))
|
aqi = self._data.pollution_info.get('aqi{0}'.format(self._locale))
|
||||||
try:
|
try:
|
||||||
[level] = [
|
[level] = [
|
||||||
@ -205,10 +198,9 @@ class AirQualityIndexSensor(AirVisualBaseSensor):
|
|||||||
"""Return the unit the value is expressed in."""
|
"""Return the unit the value is expressed in."""
|
||||||
return 'PSI'
|
return 'PSI'
|
||||||
|
|
||||||
@asyncio.coroutine
|
def update(self):
|
||||||
def async_update(self):
|
|
||||||
"""Update the status of the sensor."""
|
"""Update the status of the sensor."""
|
||||||
yield from super().async_update()
|
self._data.update()
|
||||||
|
|
||||||
self._state = self._data.pollution_info.get(
|
self._state = self._data.pollution_info.get(
|
||||||
'aqi{0}'.format(self._locale))
|
'aqi{0}'.format(self._locale))
|
||||||
@ -231,10 +223,10 @@ class MainPollutantSensor(AirVisualBaseSensor):
|
|||||||
ATTR_POLLUTANT_UNIT: self._unit
|
ATTR_POLLUTANT_UNIT: self._unit
|
||||||
})
|
})
|
||||||
|
|
||||||
@asyncio.coroutine
|
def update(self):
|
||||||
def async_update(self):
|
|
||||||
"""Update the status of the sensor."""
|
"""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))
|
symbol = self._data.pollution_info.get('main{0}'.format(self._locale))
|
||||||
pollution_info = POLLUTANT_MAPPING.get(symbol, {})
|
pollution_info = POLLUTANT_MAPPING.get(symbol, {})
|
||||||
self._state = pollution_info.get('label')
|
self._state = pollution_info.get('label')
|
||||||
|
Loading…
x
Reference in New Issue
Block a user