Skip to content

Commit

Permalink
Change tests
Browse files Browse the repository at this point in the history
  • Loading branch information
fabaff committed Dec 10, 2018
1 parent 7e1ad3c commit a2eeb46
Showing 1 changed file with 38 additions and 39 deletions.
77 changes: 38 additions & 39 deletions tests/components/air_pollutants/test_air_pollutants.py
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'

0 comments on commit a2eeb46

Please sign in to comment.