mirror of
https://github.com/home-assistant/core.git
synced 2025-07-10 06:47:09 +00:00
Merge pull request #5545 from fabaff/waqi-pm10
[sensor.waqi] Add missing particle value and refactor attributes
This commit is contained in:
commit
75c52ff9c4
@ -24,8 +24,10 @@ ATTR_DOMINENTPOL = 'dominentpol'
|
|||||||
ATTR_HUMIDITY = 'humidity'
|
ATTR_HUMIDITY = 'humidity'
|
||||||
ATTR_NITROGEN_DIOXIDE = 'nitrogen_dioxide'
|
ATTR_NITROGEN_DIOXIDE = 'nitrogen_dioxide'
|
||||||
ATTR_OZONE = 'ozone'
|
ATTR_OZONE = 'ozone'
|
||||||
ATTR_PARTICLE = 'particle'
|
ATTR_PM10 = 'pm_10'
|
||||||
|
ATTR_PM2_5 = 'pm_2_5'
|
||||||
ATTR_PRESSURE = 'pressure'
|
ATTR_PRESSURE = 'pressure'
|
||||||
|
ATTR_SULFUR_DIOXIDE = 'sulfur_dioxide'
|
||||||
ATTR_TIME = 'time'
|
ATTR_TIME = 'time'
|
||||||
ATTRIBUTION = 'Data provided by the World Air Quality Index project'
|
ATTRIBUTION = 'Data provided by the World Air Quality Index project'
|
||||||
|
|
||||||
@ -52,7 +54,7 @@ def setup_platform(hass, config, add_devices, discovery_info=None):
|
|||||||
station_filter = config.get(CONF_STATIONS)
|
station_filter = config.get(CONF_STATIONS)
|
||||||
for location_name in config.get(CONF_LOCATIONS):
|
for location_name in config.get(CONF_LOCATIONS):
|
||||||
station_ids = pwaqi.findStationCodesByCity(location_name)
|
station_ids = pwaqi.findStationCodesByCity(location_name)
|
||||||
_LOGGER.info('The following stations were returned: %s', station_ids)
|
_LOGGER.info("The following stations were returned: %s", station_ids)
|
||||||
for station in station_ids:
|
for station in station_ids:
|
||||||
waqi_sensor = WaqiSensor(WaqiData(station), station)
|
waqi_sensor = WaqiSensor(WaqiData(station), station)
|
||||||
if (not station_filter) or \
|
if (not station_filter) or \
|
||||||
@ -107,22 +109,35 @@ class WaqiSensor(Entity):
|
|||||||
return 'AQI'
|
return 'AQI'
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def state_attributes(self):
|
def device_state_attributes(self):
|
||||||
"""Return the state attributes of the last update."""
|
"""Return the state attributes of the last update."""
|
||||||
try:
|
attrs = {}
|
||||||
return {
|
|
||||||
ATTR_ATTRIBUTION: ATTRIBUTION,
|
if self.data is not None:
|
||||||
ATTR_TIME: self._details.get('time'),
|
try:
|
||||||
ATTR_HUMIDITY: self._details['iaqi'][5]['cur'],
|
attrs[ATTR_ATTRIBUTION] = ATTRIBUTION
|
||||||
ATTR_PRESSURE: self._details['iaqi'][4]['cur'],
|
attrs[ATTR_TIME] = self._details.get('time')
|
||||||
ATTR_TEMPERATURE: self._details['iaqi'][3]['cur'],
|
attrs[ATTR_DOMINENTPOL] = self._details.get('dominentpol')
|
||||||
ATTR_OZONE: self._details['iaqi'][1]['cur'],
|
for values in self._details['iaqi']:
|
||||||
ATTR_PARTICLE: self._details['iaqi'][0]['cur'],
|
if values['p'] == 'pm25':
|
||||||
ATTR_NITROGEN_DIOXIDE: self._details['iaqi'][2]['cur'],
|
attrs[ATTR_PM2_5] = values['cur']
|
||||||
ATTR_DOMINENTPOL: self._details.get('dominentpol'),
|
elif values['p'] == 'pm10':
|
||||||
}
|
attrs[ATTR_PM10] = values['cur']
|
||||||
except (IndexError, KeyError):
|
elif values['p'] == 'h':
|
||||||
return {ATTR_ATTRIBUTION: ATTRIBUTION}
|
attrs[ATTR_HUMIDITY] = values['cur']
|
||||||
|
elif values['p'] == 'p':
|
||||||
|
attrs[ATTR_PRESSURE] = values['cur']
|
||||||
|
elif values['p'] == 't':
|
||||||
|
attrs[ATTR_TEMPERATURE] = values['cur']
|
||||||
|
elif values['p'] == 'o3':
|
||||||
|
attrs[ATTR_OZONE] = values['cur']
|
||||||
|
elif values['p'] == 'no2':
|
||||||
|
attrs[ATTR_NITROGEN_DIOXIDE] = values['cur']
|
||||||
|
elif values['p'] == 'so2':
|
||||||
|
attrs[ATTR_SULFUR_DIOXIDE] = values['cur']
|
||||||
|
return attrs
|
||||||
|
except (IndexError, KeyError):
|
||||||
|
return {ATTR_ATTRIBUTION: ATTRIBUTION}
|
||||||
|
|
||||||
def update(self):
|
def update(self):
|
||||||
"""Get the latest data and updates the states."""
|
"""Get the latest data and updates the states."""
|
||||||
|
Loading…
x
Reference in New Issue
Block a user