Skip to content

Commit

Permalink
Rename air pollutants to air quality (home-assistant#19448)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
eliseomartelli authored and balloob committed Jan 5, 2019
1 parent 6872373 commit 3a5ba77
Show file tree
Hide file tree
Showing 10 changed files with 97 additions and 97 deletions.
2 changes: 1 addition & 1 deletion .coveragerc
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -13,43 +13,43 @@

_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'

DOMAIN = 'air_pollutants'
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_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)
Expand All @@ -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):
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -28,11 +28,11 @@ def __init__(self, name, pm_2_5, pm_10, n2o):
@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
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -34,7 +34,7 @@

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)
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion homeassistant/components/demo.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
DOMAIN = 'demo'

COMPONENTS_WITH_DEMO_PLATFORM = [
'air_pollutants',
'air_quality',
'alarm_control_panel',
'binary_sensor',
'calendar',
Expand Down
2 changes: 1 addition & 1 deletion requirements_all.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 0 additions & 1 deletion tests/components/air_pollutants/__init__.py

This file was deleted.

42 changes: 0 additions & 42 deletions tests/components/air_pollutants/test_air_pollutants.py

This file was deleted.

1 change: 1 addition & 0 deletions tests/components/air_quality/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
"""The tests for Air Quality platforms."""
42 changes: 42 additions & 0 deletions tests/components/air_quality/test_air_quality.py
Original file line number Diff line number Diff line change
@@ -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'

0 comments on commit 3a5ba77

Please sign in to comment.