2016-08-27 14:53:12 -06:00
|
|
|
"""Test cases around the demo fan platform."""
|
|
|
|
|
|
|
|
import unittest
|
|
|
|
|
2017-03-05 01:41:54 -08:00
|
|
|
from homeassistant.setup import setup_component
|
2016-08-27 14:53:12 -06:00
|
|
|
from homeassistant.components import fan
|
|
|
|
from homeassistant.const import STATE_OFF, STATE_ON
|
|
|
|
|
|
|
|
from tests.common import get_test_home_assistant
|
2018-09-26 09:49:55 +02:00
|
|
|
from tests.components.fan import common
|
2016-08-27 14:53:12 -06:00
|
|
|
|
2017-06-12 01:12:56 -04:00
|
|
|
FAN_ENTITY_ID = 'fan.living_room_fan'
|
|
|
|
|
2016-08-27 14:53:12 -06:00
|
|
|
|
|
|
|
class TestDemoFan(unittest.TestCase):
|
|
|
|
"""Test the fan demo platform."""
|
|
|
|
|
|
|
|
def get_entity(self):
|
2018-08-24 11:28:43 +03:00
|
|
|
"""Get the fan entity."""
|
2016-08-27 14:53:12 -06:00
|
|
|
return self.hass.states.get(FAN_ENTITY_ID)
|
|
|
|
|
|
|
|
def setUp(self):
|
|
|
|
"""Initialize unit test data."""
|
|
|
|
self.hass = get_test_home_assistant()
|
2018-10-24 12:10:05 +02:00
|
|
|
assert setup_component(self.hass, fan.DOMAIN, {'fan': {
|
2016-08-27 14:53:12 -06:00
|
|
|
'platform': 'demo',
|
2018-10-24 12:10:05 +02:00
|
|
|
}})
|
2016-09-12 19:16:14 -07:00
|
|
|
self.hass.block_till_done()
|
2016-08-27 14:53:12 -06:00
|
|
|
|
|
|
|
def tearDown(self):
|
|
|
|
"""Tear down unit test data."""
|
|
|
|
self.hass.stop()
|
|
|
|
|
|
|
|
def test_turn_on(self):
|
|
|
|
"""Test turning on the device."""
|
2018-10-24 12:10:05 +02:00
|
|
|
assert STATE_OFF == self.get_entity().state
|
2016-08-27 14:53:12 -06:00
|
|
|
|
2018-09-26 09:49:55 +02:00
|
|
|
common.turn_on(self.hass, FAN_ENTITY_ID)
|
2016-09-12 19:16:14 -07:00
|
|
|
self.hass.block_till_done()
|
2018-10-24 12:10:05 +02:00
|
|
|
assert STATE_OFF != self.get_entity().state
|
2016-08-27 14:53:12 -06:00
|
|
|
|
2018-09-26 09:49:55 +02:00
|
|
|
common.turn_on(self.hass, FAN_ENTITY_ID, fan.SPEED_HIGH)
|
2016-09-12 19:16:14 -07:00
|
|
|
self.hass.block_till_done()
|
2018-10-24 12:10:05 +02:00
|
|
|
assert STATE_ON == self.get_entity().state
|
|
|
|
assert fan.SPEED_HIGH == \
|
|
|
|
self.get_entity().attributes[fan.ATTR_SPEED]
|
2016-08-27 14:53:12 -06:00
|
|
|
|
|
|
|
def test_turn_off(self):
|
|
|
|
"""Test turning off the device."""
|
2018-10-24 12:10:05 +02:00
|
|
|
assert STATE_OFF == self.get_entity().state
|
2016-08-27 14:53:12 -06:00
|
|
|
|
2018-09-26 09:49:55 +02:00
|
|
|
common.turn_on(self.hass, FAN_ENTITY_ID)
|
2016-09-12 19:16:14 -07:00
|
|
|
self.hass.block_till_done()
|
2018-10-24 12:10:05 +02:00
|
|
|
assert STATE_OFF != self.get_entity().state
|
2016-08-27 14:53:12 -06:00
|
|
|
|
2018-09-26 09:49:55 +02:00
|
|
|
common.turn_off(self.hass, FAN_ENTITY_ID)
|
2016-09-12 19:16:14 -07:00
|
|
|
self.hass.block_till_done()
|
2018-10-24 12:10:05 +02:00
|
|
|
assert STATE_OFF == self.get_entity().state
|
2016-08-27 14:53:12 -06:00
|
|
|
|
2017-06-13 08:28:05 -07:00
|
|
|
def test_turn_off_without_entity_id(self):
|
|
|
|
"""Test turning off all fans."""
|
2018-10-24 12:10:05 +02:00
|
|
|
assert STATE_OFF == self.get_entity().state
|
2017-06-13 08:28:05 -07:00
|
|
|
|
2018-09-26 09:49:55 +02:00
|
|
|
common.turn_on(self.hass, FAN_ENTITY_ID)
|
2017-06-13 08:28:05 -07:00
|
|
|
self.hass.block_till_done()
|
2018-10-24 12:10:05 +02:00
|
|
|
assert STATE_OFF != self.get_entity().state
|
2017-06-13 08:28:05 -07:00
|
|
|
|
2018-09-26 09:49:55 +02:00
|
|
|
common.turn_off(self.hass)
|
2017-06-13 08:28:05 -07:00
|
|
|
self.hass.block_till_done()
|
2018-10-24 12:10:05 +02:00
|
|
|
assert STATE_OFF == self.get_entity().state
|
2017-06-13 08:28:05 -07:00
|
|
|
|
2017-01-14 01:08:13 -05:00
|
|
|
def test_set_direction(self):
|
|
|
|
"""Test setting the direction of the device."""
|
2018-10-24 12:10:05 +02:00
|
|
|
assert STATE_OFF == self.get_entity().state
|
2017-01-14 01:08:13 -05:00
|
|
|
|
2018-09-26 09:49:55 +02:00
|
|
|
common.set_direction(self.hass, FAN_ENTITY_ID, fan.DIRECTION_REVERSE)
|
2017-01-14 01:08:13 -05:00
|
|
|
self.hass.block_till_done()
|
2018-10-24 12:10:05 +02:00
|
|
|
assert fan.DIRECTION_REVERSE == \
|
|
|
|
self.get_entity().attributes.get('direction')
|
2017-01-14 01:08:13 -05:00
|
|
|
|
2016-08-27 14:53:12 -06:00
|
|
|
def test_set_speed(self):
|
|
|
|
"""Test setting the speed of the device."""
|
2018-10-24 12:10:05 +02:00
|
|
|
assert STATE_OFF == self.get_entity().state
|
2016-08-27 14:53:12 -06:00
|
|
|
|
2018-09-26 09:49:55 +02:00
|
|
|
common.set_speed(self.hass, FAN_ENTITY_ID, fan.SPEED_LOW)
|
2016-09-12 19:16:14 -07:00
|
|
|
self.hass.block_till_done()
|
2018-10-24 12:10:05 +02:00
|
|
|
assert fan.SPEED_LOW == \
|
|
|
|
self.get_entity().attributes.get('speed')
|
2016-08-27 14:53:12 -06:00
|
|
|
|
|
|
|
def test_oscillate(self):
|
|
|
|
"""Test oscillating the fan."""
|
2018-10-24 12:10:05 +02:00
|
|
|
assert not self.get_entity().attributes.get('oscillating')
|
2016-08-27 14:53:12 -06:00
|
|
|
|
2018-09-26 09:49:55 +02:00
|
|
|
common.oscillate(self.hass, FAN_ENTITY_ID, True)
|
2016-09-12 19:16:14 -07:00
|
|
|
self.hass.block_till_done()
|
2018-10-24 12:10:05 +02:00
|
|
|
assert self.get_entity().attributes.get('oscillating')
|
2016-08-27 14:53:12 -06:00
|
|
|
|
2018-09-26 09:49:55 +02:00
|
|
|
common.oscillate(self.hass, FAN_ENTITY_ID, False)
|
2016-09-12 19:16:14 -07:00
|
|
|
self.hass.block_till_done()
|
2018-10-24 12:10:05 +02:00
|
|
|
assert not self.get_entity().attributes.get('oscillating')
|
2016-08-27 14:53:12 -06:00
|
|
|
|
|
|
|
def test_is_on(self):
|
|
|
|
"""Test is on service call."""
|
2018-10-24 12:10:05 +02:00
|
|
|
assert not fan.is_on(self.hass, FAN_ENTITY_ID)
|
2016-08-27 14:53:12 -06:00
|
|
|
|
2018-09-26 09:49:55 +02:00
|
|
|
common.turn_on(self.hass, FAN_ENTITY_ID)
|
2016-09-12 19:16:14 -07:00
|
|
|
self.hass.block_till_done()
|
2018-10-24 12:10:05 +02:00
|
|
|
assert fan.is_on(self.hass, FAN_ENTITY_ID)
|