-
-
Notifications
You must be signed in to change notification settings - Fork 30k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
38 additions
and
39 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,43 +1,42 @@ | ||
"""The tests for the Air Pollutants component.""" | ||
import unittest | ||
|
||
from homeassistant.components import air_pollutants | ||
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 setup_component | ||
from homeassistant.util.unit_system import METRIC_SYSTEM | ||
|
||
from tests.common import get_test_home_assistant | ||
|
||
|
||
class TestAirPollutants(unittest.TestCase): | ||
"""Test the Air Pollutants component.""" | ||
|
||
def setUp(self): | ||
"""Set up things to be run when tests are started.""" | ||
self.hass = get_test_home_assistant() | ||
self.hass.config.units = METRIC_SYSTEM | ||
assert setup_component(self.hass, air_pollutants.DOMAIN, { | ||
'air_pollutants': { | ||
'platform': 'demo', | ||
} | ||
}) | ||
|
||
def tearDown(self): | ||
"""Stop down everything that was started.""" | ||
self.hass.stop() | ||
|
||
def test_attributes(self): | ||
"""Test Air Pollutants attributes.""" | ||
state = self.hass.states.get('air_pollutants.demo_air_pollutants_home') | ||
assert state is not None | ||
|
||
assert state.state == '14' | ||
|
||
data = state.attributes | ||
assert data.get(ATTR_AIR_POLLUTANTS_PM_10) == 23 | ||
assert data.get(ATTR_AIR_POLLUTANTS_N2O) == 100 | ||
assert data.get(ATTR_AIR_POLLUTANTS_OZONE) is None | ||
assert data.get(ATTR_AIR_POLLUTANTS_ATTRIBUTION) == \ | ||
'Powered by Home Assistant' | ||
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' |