* Add event loop to the core * Add block_till_done to HA core object * Fix some tests * Linting core * Fix statemachine tests * Core test fixes * fix block_till_done to wait for loop and queue to empty * fix test_core for passing, and correct start/stop/block_till_done * Fix remote tests * Fix tests: block_till_done * Fix linting * Fix more tests * Fix final linting * Fix remote test * remove unnecessary import * reduce sleep to avoid slowing down the tests excessively * fix remaining tests to wait for non-threadsafe operations * Add async_ doc strings for event loop / coroutine info * Fix command line test to block for the right timeout * Fix py3.4.2 loop var access * Fix SERVICE_CALL_LIMIT being in effect for other tests * Fix lint errors * Fix lint error with proper placement * Fix slave start to not start a timer * Add asyncio compatible listeners. * Increase min Python version to 3.4.2 * Move async backports to util * Add backported async tests * Fix linting * Simplify Python version check * Fix lint * Remove unneeded try/except and queue listener appproriately. * Fix tuple vs. list unorderable error on version compare. * Fix version tests
84 lines
2.8 KiB
Python
84 lines
2.8 KiB
Python
"""Test cases around the demo fan platform."""
|
|
|
|
import unittest
|
|
|
|
from homeassistant.components import fan
|
|
from homeassistant.components.fan.demo import FAN_ENTITY_ID
|
|
from homeassistant.const import STATE_OFF, STATE_ON
|
|
|
|
from tests.common import get_test_home_assistant
|
|
|
|
|
|
class TestDemoFan(unittest.TestCase):
|
|
"""Test the fan demo platform."""
|
|
|
|
def get_entity(self):
|
|
"""Helper method to get the fan entity."""
|
|
return self.hass.states.get(FAN_ENTITY_ID)
|
|
|
|
def setUp(self):
|
|
"""Initialize unit test data."""
|
|
self.hass = get_test_home_assistant()
|
|
self.assertTrue(fan.setup(self.hass, {'fan': {
|
|
'platform': 'demo',
|
|
}}))
|
|
self.hass.block_till_done()
|
|
|
|
def tearDown(self):
|
|
"""Tear down unit test data."""
|
|
self.hass.stop()
|
|
|
|
def test_turn_on(self):
|
|
"""Test turning on the device."""
|
|
self.assertEqual(STATE_OFF, self.get_entity().state)
|
|
|
|
fan.turn_on(self.hass, FAN_ENTITY_ID)
|
|
self.hass.block_till_done()
|
|
self.assertNotEqual(STATE_OFF, self.get_entity().state)
|
|
|
|
fan.turn_on(self.hass, FAN_ENTITY_ID, fan.SPEED_HIGH)
|
|
self.hass.block_till_done()
|
|
self.assertEqual(STATE_ON, self.get_entity().state)
|
|
self.assertEqual(fan.SPEED_HIGH,
|
|
self.get_entity().attributes[fan.ATTR_SPEED])
|
|
|
|
def test_turn_off(self):
|
|
"""Test turning off the device."""
|
|
self.assertEqual(STATE_OFF, self.get_entity().state)
|
|
|
|
fan.turn_on(self.hass, FAN_ENTITY_ID)
|
|
self.hass.block_till_done()
|
|
self.assertNotEqual(STATE_OFF, self.get_entity().state)
|
|
|
|
fan.turn_off(self.hass, FAN_ENTITY_ID)
|
|
self.hass.block_till_done()
|
|
self.assertEqual(STATE_OFF, self.get_entity().state)
|
|
|
|
def test_set_speed(self):
|
|
"""Test setting the speed of the device."""
|
|
self.assertEqual(STATE_OFF, self.get_entity().state)
|
|
|
|
fan.set_speed(self.hass, FAN_ENTITY_ID, fan.SPEED_LOW)
|
|
self.hass.block_till_done()
|
|
self.assertEqual(fan.SPEED_LOW,
|
|
self.get_entity().attributes.get('speed'))
|
|
|
|
def test_oscillate(self):
|
|
"""Test oscillating the fan."""
|
|
self.assertFalse(self.get_entity().attributes.get('oscillating'))
|
|
|
|
fan.oscillate(self.hass, FAN_ENTITY_ID, True)
|
|
self.hass.block_till_done()
|
|
self.assertTrue(self.get_entity().attributes.get('oscillating'))
|
|
|
|
fan.oscillate(self.hass, FAN_ENTITY_ID, False)
|
|
self.hass.block_till_done()
|
|
self.assertFalse(self.get_entity().attributes.get('oscillating'))
|
|
|
|
def test_is_on(self):
|
|
"""Test is on service call."""
|
|
self.assertFalse(fan.is_on(self.hass, FAN_ENTITY_ID))
|
|
|
|
fan.turn_on(self.hass, FAN_ENTITY_ID)
|
|
self.hass.block_till_done()
|
|
self.assertTrue(fan.is_on(self.hass, FAN_ENTITY_ID))
|