Skip to content

Commit

Permalink
Owner-requested changes
Browse files Browse the repository at this point in the history
  • Loading branch information
bachya committed Nov 3, 2017
1 parent 0482ae9 commit 60de11c
Showing 1 changed file with 27 additions and 68 deletions.
95 changes: 27 additions & 68 deletions homeassistant/components/sensor/airvisual.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,57 +39,22 @@

MIN_TIME_BETWEEN_UPDATES = timedelta(minutes=10)

POLLUTANT_LEVEL_MAPPING = [{
'label': 'Good',
'minimum': 0,
'maximum': 50
}, {
'label': 'Moderate',
'minimum': 51,
'maximum': 100
}, {
'label': 'Unhealthy for sensitive group',
'minimum': 101,
'maximum': 150
}, {
'label': 'Unhealthy',
'minimum': 151,
'maximum': 200
}, {
'label': 'Very Unhealthy',
'minimum': 201,
'maximum': 300
}, {
'label': 'Hazardous',
'minimum': 301,
'maximum': 10000
}]
POLLUTANT_LEVEL_MAPPING = [
{'label': 'Good', 'minimum': 0, 'maximum': 50},
{'label': 'Moderate', 'minimum': 51, 'maximum': 100},
{'label': 'Unhealthy for sensitive group', 'minimum': 101, 'maximum': 150},
{'label': 'Unhealthy', 'minimum': 151, 'maximum': 200},
{'label': 'Very Unhealthy', 'minimum': 201, 'maximum': 300},
{'label': 'Hazardous', 'minimum': 301, 'maximum': 10000}
]

POLLUTANT_MAPPING = {
'co': {
'label': 'Carbon Monoxide',
'unit': MASS_PARTS_PER_MILLION
},
'n2': {
'label': 'Nitrogen Dioxide',
'unit': MASS_PARTS_PER_BILLION
},
'o3': {
'label': 'Ozone',
'unit': MASS_PARTS_PER_BILLION
},
'p1': {
'label': 'PM10',
'unit': VOLUME_MICROGRAMS_PER_CUBIC_METER
},
'p2': {
'label': 'PM2.5',
'unit': VOLUME_MICROGRAMS_PER_CUBIC_METER
},
's2': {
'label': 'Sulfur Dioxide',
'unit': MASS_PARTS_PER_BILLION
},
'co': {'label': 'Carbon Monoxide', 'unit': MASS_PARTS_PER_MILLION},
'n2': {'label': 'Nitrogen Dioxide', 'unit': MASS_PARTS_PER_BILLION},
'o3': {'label': 'Ozone', 'unit': MASS_PARTS_PER_BILLION},
'p1': {'label': 'PM10', 'unit': VOLUME_MICROGRAMS_PER_CUBIC_METER},
'p2': {'label': 'PM2.5', 'unit': VOLUME_MICROGRAMS_PER_CUBIC_METER},
's2': {'label': 'Sulfur Dioxide', 'unit': MASS_PARTS_PER_BILLION},
}

SENSOR_LOCALES = {'cn': 'Chinese', 'us': 'U.S.'}
Expand All @@ -101,8 +66,8 @@

PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend({
vol.Required(CONF_API_KEY): cv.string,
vol.Required(CONF_MONITORED_CONDITIONS): vol.All(
cv.ensure_list, [vol.In(SENSOR_LOCALES)]),
vol.Required(CONF_MONITORED_CONDITIONS):
vol.All(cv.ensure_list, [vol.In(SENSOR_LOCALES)]),
vol.Optional(CONF_CITY): cv.string,
vol.Optional(CONF_COUNTRY): cv.string,
vol.Optional(CONF_LATITUDE): cv.latitude,
Expand All @@ -128,23 +93,17 @@ def setup_platform(hass, config, add_devices, discovery_info=None):
show_on_map = config.get(CONF_SHOW_ON_MAP)

if city and state and country:
_LOGGER.debug("Using city, state, and country: %s, %s, %s", city,
state, country)
_LOGGER.debug(
"Using city, state, and country: %s, %s, %s", city, state, country)
data = AirVisualData(
pav.Client(api_key),
city=city,
state=state,
country=country,
pav.Client(api_key), city=city, state=state, country=country,
show_on_map=show_on_map)
else:
_LOGGER.debug("Using latitude and longitude: %s, %s", latitude,
longitude)
_LOGGER.debug(
"Using latitude and longitude: %s, %s", latitude, longitude)
data = AirVisualData(
pav.Client(api_key),
latitude=latitude,
longitude=longitude,
radius=radius,
show_on_map=show_on_map)
pav.Client(api_key), latitude=latitude, longitude=longitude,
radius=radius, show_on_map=show_on_map)

data.update()
sensors = []
Expand Down Expand Up @@ -297,13 +256,13 @@ def update(self):

try:
if self.city and self.state and self.country:
resp = self._client.city(self.city, self.state,
self.country).get('data')
resp = self._client.city(
self.city, self.state, self.country).get('data')
self.longitude, self.latitude = resp.get('location').get(
'coordinates')
else:
resp = self._client.nearest_city(self.latitude, self.longitude,
self._radius).get('data')
resp = self._client.nearest_city(
self.latitude, self.longitude, self._radius).get('data')
_LOGGER.debug("New data retrieved: %s", resp)

self.pollution_info = resp.get('current', {}).get('pollution', {})
Expand Down

0 comments on commit 60de11c

Please sign in to comment.