Rename air pollutants to air quality (#19448)

* mv component folder

* moved in airquality

* changed names in files

* renamed test init

* renamed test air quality

* renamed in tests

* renamed coverage

* fixed naming

* corrected attr names

* changed attr names
pull/19852/head
Eliseo Martelli 2019-01-05 17:42:36 +01:00 committed by Paulus Schoutsen
parent 68723730a7
commit 3a5ba77e04
10 changed files with 96 additions and 96 deletions

View File

@ -442,7 +442,7 @@ omit =
homeassistant/components/spider.py
homeassistant/components/*/spider.py
homeassistant/components/air_pollutants/opensensemap.py
homeassistant/components/air_quality/opensensemap.py
homeassistant/components/alarm_control_panel/alarmdotcom.py
homeassistant/components/alarm_control_panel/canary.py
homeassistant/components/alarm_control_panel/concord232.py

View File

@ -1,8 +1,8 @@
"""
Component for handling Air Pollutants data for your location.
Component for handling Air Quality data for your location.
For more details about this component, please refer to the documentation at
https://home-assistant.io/components/air_pollutants/
https://home-assistant.io/components/air_quality/
"""
from datetime import timedelta
import logging
@ -13,43 +13,43 @@ from homeassistant.helpers.entity import Entity
_LOGGER = logging.getLogger(__name__)
ATTR_AIR_POLLUTANTS_AQI = 'air_quality_index'
ATTR_AIR_POLLUTANTS_ATTRIBUTION = 'attribution'
ATTR_AIR_POLLUTANTS_C02 = 'carbon_dioxide'
ATTR_AIR_POLLUTANTS_CO = 'carbon_monoxide'
ATTR_AIR_POLLUTANTS_N2O = 'nitrogen_oxide'
ATTR_AIR_POLLUTANTS_NO = 'nitrogen_monoxide'
ATTR_AIR_POLLUTANTS_NO2 = 'nitrogen_dioxide'
ATTR_AIR_POLLUTANTS_OZONE = 'ozone'
ATTR_AIR_POLLUTANTS_PM_0_1 = 'particulate_matter_0_1'
ATTR_AIR_POLLUTANTS_PM_10 = 'particulate_matter_10'
ATTR_AIR_POLLUTANTS_PM_2_5 = 'particulate_matter_2_5'
ATTR_AIR_POLLUTANTS_SO2 = 'sulphur_dioxide'
ATTR_AQI = 'air_quality_index'
ATTR_ATTRIBUTION = 'attribution'
ATTR_C02 = 'carbon_dioxide'
ATTR_CO = 'carbon_monoxide'
ATTR_N2O = 'nitrogen_oxide'
ATTR_NO = 'nitrogen_monoxide'
ATTR_NO2 = 'nitrogen_dioxide'
ATTR_OZONE = 'ozone'
ATTR_PM_0_1 = 'particulate_matter_0_1'
ATTR_PM_10 = 'particulate_matter_10'
ATTR_PM_2_5 = 'particulate_matter_2_5'
ATTR_SO2 = 'sulphur_dioxide'
DOMAIN = 'air_pollutants'
DOMAIN = 'air_quality'
ENTITY_ID_FORMAT = DOMAIN + '.{}'
SCAN_INTERVAL = timedelta(seconds=30)
PROP_TO_ATTR = {
'air_quality_index': ATTR_AIR_POLLUTANTS_AQI,
'attribution': ATTR_AIR_POLLUTANTS_ATTRIBUTION,
'carbon_dioxide': ATTR_AIR_POLLUTANTS_C02,
'carbon_monoxide': ATTR_AIR_POLLUTANTS_CO,
'nitrogen_oxide': ATTR_AIR_POLLUTANTS_N2O,
'nitrogen_monoxide': ATTR_AIR_POLLUTANTS_NO,
'nitrogen_dioxide': ATTR_AIR_POLLUTANTS_NO2,
'ozone': ATTR_AIR_POLLUTANTS_OZONE,
'particulate_matter_0_1': ATTR_AIR_POLLUTANTS_PM_0_1,
'particulate_matter_10': ATTR_AIR_POLLUTANTS_PM_10,
'particulate_matter_2_5': ATTR_AIR_POLLUTANTS_PM_2_5,
'sulphur_dioxide': ATTR_AIR_POLLUTANTS_SO2,
'air_quality_index': ATTR_AQI,
'attribution': ATTR_ATTRIBUTION,
'carbon_dioxide': ATTR_C02,
'carbon_monoxide': ATTR_CO,
'nitrogen_oxide': ATTR_N2O,
'nitrogen_monoxide': ATTR_NO,
'nitrogen_dioxide': ATTR_NO2,
'ozone': ATTR_OZONE,
'particulate_matter_0_1': ATTR_PM_0_1,
'particulate_matter_10': ATTR_PM_10,
'particulate_matter_2_5': ATTR_PM_2_5,
'sulphur_dioxide': ATTR_SO2,
}
async def async_setup(hass, config):
"""Set up the air pollutants component."""
"""Set up the air quality component."""
component = hass.data[DOMAIN] = EntityComponent(
_LOGGER, DOMAIN, hass, SCAN_INTERVAL)
await component.async_setup(config)
@ -66,8 +66,8 @@ async def async_unload_entry(hass, entry):
return await hass.data[DOMAIN].async_unload_entry(entry)
class AirPollutantsEntity(Entity):
"""ABC for air pollutants data."""
class AirQualityEntity(Entity):
"""ABC for air quality data."""
@property
def particulate_matter_2_5(self):

View File

@ -1,25 +1,25 @@
"""
Demo platform that offers fake air pollutants data.
Demo platform that offers fake air quality data.
For more details about this platform, please refer to the documentation
https://home-assistant.io/components/demo/
"""
from homeassistant.components.air_pollutants import AirPollutantsEntity
from homeassistant.components.air_quality import AirQualityEntity
def setup_platform(hass, config, add_entities, discovery_info=None):
"""Set up the Air Pollutants."""
"""Set up the Air Quality."""
add_entities([
DemoAirPollutants('Home', 14, 23, 100),
DemoAirPollutants('Office', 4, 16, None)
DemoAirQuality('Home', 14, 23, 100),
DemoAirQuality('Office', 4, 16, None)
])
class DemoAirPollutants(AirPollutantsEntity):
"""Representation of Air Pollutants data."""
class DemoAirQuality(AirQualityEntity):
"""Representation of Air Quality data."""
def __init__(self, name, pm_2_5, pm_10, n2o):
"""Initialize the Demo Air Pollutants."""
"""Initialize the Demo Air Quality."""
self._name = name
self._pm_2_5 = pm_2_5
self._pm_10 = pm_10
@ -28,11 +28,11 @@ class DemoAirPollutants(AirPollutantsEntity):
@property
def name(self):
"""Return the name of the sensor."""
return '{} {}'.format('Demo Air Pollutants', self._name)
return '{} {}'.format('Demo Air Quality', self._name)
@property
def should_poll(self):
"""No polling needed for Demo Air Pollutants."""
"""No polling needed for Demo Air Quality."""
return False
@property

View File

@ -1,16 +1,16 @@
"""
Support for openSenseMap Air Pollutants data.
Support for openSenseMap Air Quality data.
For more details about this platform, please refer to the documentation at
https://home-assistant.io/components/air_pollutants_opensensemap/
https://home-assistant.io/components/air_quality/opensensemap/
"""
from datetime import timedelta
import logging
import voluptuous as vol
from homeassistant.components.air_pollutants import (
PLATFORM_SCHEMA, AirPollutantsEntity)
from homeassistant.components.air_quality import (
PLATFORM_SCHEMA, AirQualityEntity)
from homeassistant.const import CONF_NAME
from homeassistant.helpers.aiohttp_client import async_get_clientsession
import homeassistant.helpers.config_validation as cv
@ -34,7 +34,7 @@ PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend({
async def async_setup_platform(
hass, config, async_add_entities, discovery_info=None):
"""Set up the openSenseMap air pollutants platform."""
"""Set up the openSenseMap air quality platform."""
from opensensemap_api import OpenSenseMap
name = config.get(CONF_NAME)
@ -51,20 +51,20 @@ async def async_setup_platform(
station_name = osm_api.api.data['name'] if name is None else name
async_add_entities([OpenSenseMapPollutants(station_name, osm_api)], True)
async_add_entities([OpenSenseMapQuality(station_name, osm_api)], True)
class OpenSenseMapPollutants(AirPollutantsEntity):
"""Implementation of an openSenseMap air pollutants entity."""
class OpenSenseMapQuality(AirQualityEntity):
"""Implementation of an openSenseMap air quality entity."""
def __init__(self, name, osm):
"""Initialize the air pollutants entity."""
"""Initialize the air quality entity."""
self._name = name
self._osm = osm
@property
def name(self):
"""Return the name of the air pollutants entity."""
"""Return the name of the air quality entity."""
return self._name
@property

View File

@ -15,7 +15,7 @@ DEPENDENCIES = ['conversation', 'introduction', 'zone']
DOMAIN = 'demo'
COMPONENTS_WITH_DEMO_PLATFORM = [
'air_pollutants',
'air_quality',
'alarm_control_panel',
'binary_sensor',
'calendar',

View File

@ -746,7 +746,7 @@ openevsewifi==0.4
# homeassistant.components.media_player.openhome
openhomedevice==0.4.2
# homeassistant.components.air_pollutants.opensensemap
# homeassistant.components.air_quality.opensensemap
opensensemap-api==0.1.3
# homeassistant.components.switch.orvibo

View File

@ -1 +0,0 @@
"""The tests for Air Pollutants platforms."""

View File

@ -1,42 +0,0 @@
"""The tests for the Air Pollutants component."""
from homeassistant.components.air_pollutants import (
ATTR_AIR_POLLUTANTS_ATTRIBUTION, ATTR_AIR_POLLUTANTS_N2O,
ATTR_AIR_POLLUTANTS_OZONE, ATTR_AIR_POLLUTANTS_PM_10)
from homeassistant.setup import async_setup_component
async def test_state(hass):
"""Test Air Pollutants state."""
config = {
'air_pollutants': {
'platform': 'demo',
}
}
assert await async_setup_component(hass, 'air_pollutants', config)
state = hass.states.get('air_pollutants.demo_air_pollutants_home')
assert state is not None
assert state.state == '14'
async def test_attributes(hass):
"""Test Air Pollutants attributes."""
config = {
'air_pollutants': {
'platform': 'demo',
}
}
assert await async_setup_component(hass, 'air_pollutants', config)
state = hass.states.get('air_pollutants.demo_air_pollutants_office')
assert state is not None
data = state.attributes
assert data.get(ATTR_AIR_POLLUTANTS_PM_10) == 16
assert data.get(ATTR_AIR_POLLUTANTS_N2O) is None
assert data.get(ATTR_AIR_POLLUTANTS_OZONE) is None
assert data.get(ATTR_AIR_POLLUTANTS_ATTRIBUTION) == \
'Powered by Home Assistant'

View File

@ -0,0 +1 @@
"""The tests for Air Quality platforms."""

View File

@ -0,0 +1,42 @@
"""The tests for the Air Quality component."""
from homeassistant.components.air_quality import (
ATTR_ATTRIBUTION, ATTR_N2O,
ATTR_OZONE, ATTR_PM_10)
from homeassistant.setup import async_setup_component
async def test_state(hass):
"""Test Air Quality state."""
config = {
'air_quality': {
'platform': 'demo',
}
}
assert await async_setup_component(hass, 'air_quality', config)
state = hass.states.get('air_quality.demo_air_quality_home')
assert state is not None
assert state.state == '14'
async def test_attributes(hass):
"""Test Air Quality attributes."""
config = {
'air_quality': {
'platform': 'demo',
}
}
assert await async_setup_component(hass, 'air_quality', config)
state = hass.states.get('air_quality.demo_air_quality_office')
assert state is not None
data = state.attributes
assert data.get(ATTR_PM_10) == 16
assert data.get(ATTR_N2O) is None
assert data.get(ATTR_OZONE) is None
assert data.get(ATTR_ATTRIBUTION) == \
'Powered by Home Assistant'