8000 Corrects mistaken async items in AirVisual by bachya · Pull Request #9911 · home-assistant/core · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Corrects mistaken async items in AirVisual #9911

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 17, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 11 additions & 19 deletions homeassistant/components/sensor/airvisual.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
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

Expand Down Expand Up @@ -80,8 +79,7 @@
})


@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

Expand All @@ -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):
Expand Down Expand Up @@ -170,20 +169,14 @@ def state(self):
"""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] = [
Expand All @@ -205,10 +198,9 @@ def unit_of_measurement(self):
"""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))
Expand All @@ -231,10 +223,10 @@ def device_state_attributes(self):
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')
Expand Down
0