forked from home-assistant/core
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update fan/demo tests to async (home-assistant#18109)
* Update fan/demo tests to async * Use async_create_task
- Loading branch information
Showing
3 changed files
with
654 additions
and
639 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
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,108 +1,108 @@ | ||
"""Test cases around the demo fan platform.""" | ||
import pytest | ||
|
||
import unittest | ||
|
||
from homeassistant.setup import setup_component | ||
from homeassistant.setup import async_setup_component | ||
from homeassistant.components import fan | ||
from homeassistant.const import STATE_OFF, STATE_ON | ||
|
||
from tests.common import get_test_home_assistant | ||
from tests.components.fan import common | ||
|
||
FAN_ENTITY_ID = 'fan.living_room_fan' | ||
|
||
|
||
class TestDemoFan(unittest.TestCase): | ||
"""Test the fan demo platform.""" | ||
def get_entity(hass): | ||
"""Get the fan entity.""" | ||
return hass.states.get(FAN_ENTITY_ID) | ||
|
||
def get_entity(self): | ||
"""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() | ||
assert setup_component(self.hass, fan.DOMAIN, {'fan': { | ||
@pytest.fixture(autouse=True) | ||
def setup_comp(hass): | ||
"""Initialize components.""" | ||
hass.loop.run_until_complete(async_setup_component(hass, fan.DOMAIN, { | ||
'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.""" | ||
assert STATE_OFF == self.get_entity().state | ||
|
||
common.turn_on(self.hass, FAN_ENTITY_ID) | ||
self.hass.block_till_done() | ||
assert STATE_OFF != self.get_entity().state | ||
|
||
common.turn_on(self.hass, FAN_ENTITY_ID, fan.SPEED_HIGH) | ||
self.hass.block_till_done() | ||
assert STATE_ON == self.get_entity().state | ||
assert fan.SPEED_HIGH == \ | ||
self.get_entity().attributes[fan.ATTR_SPEED] | ||
|
||
def test_turn_off(self): | ||
"""Test turning off the device.""" | ||
assert STATE_OFF == self.get_entity().state | ||
|
||
common.turn_on(self.hass, FAN_ENTITY_ID) | ||
self.hass.block_till_done() | ||
assert STATE_OFF != self.get_entity().state | ||
|
||
common.turn_off(self.hass, FAN_ENTITY_ID) | ||
self.hass.block_till_done() | ||
assert STATE_OFF == self.get_entity().state | ||
|
||
def test_turn_off_without_entity_id(self): | ||
"""Test turning off all fans.""" | ||
assert STATE_OFF == self.get_entity().state | ||
|
||
common.turn_on(self.hass, FAN_ENTITY_ID) | ||
self.hass.block_till_done() | ||
assert STATE_OFF != self.get_entity().state | ||
|
||
common.turn_off(self.hass) | ||
self.hass.block_till_done() | ||
assert STATE_OFF == self.get_entity().state | ||
|
||
def test_set_direction(self): | ||
"""Test setting the direction of the device.""" | ||
assert STATE_OFF == self.get_entity().state | ||
|
||
common.set_direction(self.hass, FAN_ENTITY_ID, fan.DIRECTION_REVERSE) | ||
self.hass.block_till_done() | ||
assert fan.DIRECTION_REVERSE == \ | ||
self.get_entity().attributes.get('direction') | ||
|
||
def test_set_speed(self): | ||
"""Test setting the speed of the device.""" | ||
assert STATE_OFF == self.get_entity().state | ||
|
||
common.set_speed(self.hass, FAN_ENTITY_ID, fan.SPEED_LOW) | ||
self.hass.block_till_done() | ||
assert fan.SPEED_LOW == \ | ||
self.get_entity().attributes.get('speed') | ||
|
||
def test_oscillate(self): | ||
"""Test oscillating the fan.""" | ||
assert not self.get_entity().attributes.get('oscillating') | ||
|
||
common.oscillate(self.hass, FAN_ENTITY_ID, True) | ||
self.hass.block_till_done() | ||
assert self.get_entity().attributes.get('oscillating') | ||
|
||
common.oscillate(self.hass, FAN_ENTITY_ID, False) | ||
self.hass.block_till_done() | ||
assert not self.get_entity().attributes.get('oscillating') | ||
|
||
def test_is_on(self): | ||
"""Test is on service call.""" | ||
assert not fan.is_on(self.hass, FAN_ENTITY_ID) | ||
|
||
common.turn_on(self.hass, FAN_ENTITY_ID) | ||
self.hass.block_till_done() | ||
assert fan.is_on(self.hass, FAN_ENTITY_ID) | ||
} | ||
})) | ||
|
||
|
||
async def test_turn_on(hass): | ||
"""Test turning on the device.""" | ||
assert STATE_OFF == get_entity(hass).state | ||
|
||
common.async_turn_on(hass, FAN_ENTITY_ID) | ||
await hass.async_block_till_done() | ||
assert STATE_OFF != get_entity(hass).state | ||
|
||
common.async_turn_on(hass, FAN_ENTITY_ID, fan.SPEED_HIGH) | ||
await hass.async_block_till_done() | ||
assert STATE_ON == get_entity(hass).state | ||
assert fan.SPEED_HIGH == \ | ||
get_entity(hass).attributes[fan.ATTR_SPEED] | ||
|
||
|
||
async def test_turn_off(hass): | ||
"""Test turning off the device.""" | ||
assert STATE_OFF == get_entity(hass).state | ||
|
||
common.async_turn_on(hass, FAN_ENTITY_ID) | ||
await hass.async_block_till_done() | ||
assert STATE_OFF != get_entity(hass).state | ||
|
||
common.async_turn_off(hass, FAN_ENTITY_ID) | ||
await hass.async_block_till_done() | ||
assert STATE_OFF == get_entity(hass).state | ||
|
||
|
||
async def test_turn_off_without_entity_id(hass): | ||
"""Test turning off all fans.""" | ||
assert STATE_OFF == get_entity(hass).state | ||
|
||
common.async_turn_on(hass, FAN_ENTITY_ID) | ||
await hass.async_block_till_done() | ||
assert STATE_OFF != get_entity(hass).state | ||
|
||
common.async_turn_off(hass) | ||
await hass.async_block_till_done() | ||
assert STATE_OFF == get_entity(hass).state | ||
|
||
|
||
async def test_set_direction(hass): | ||
"""Test setting the direction of the device.""" | ||
assert STATE_OFF == get_entity(hass).state | ||
|
||
common.async_set_direction(hass, FAN_ENTITY_ID, fan.DIRECTION_REVERSE) | ||
await hass.async_block_till_done() | ||
assert fan.DIRECTION_REVERSE == \ | ||
get_entity(hass).attributes.get('direction') | ||
|
||
|
||
async def test_set_speed(hass): | ||
"""Test setting the speed of the device.""" | ||
assert STATE_OFF == get_entity(hass).state | ||
|
||
common.async_set_speed(hass, FAN_ENTITY_ID, fan.SPEED_LOW) | ||
await hass.async_block_till_done() | ||
assert fan.SPEED_LOW == \ | ||
get_entity(hass).attributes.get('speed') | ||
|
||
|
||
async def test_oscillate(hass): | ||
"""Test oscillating the fan.""" | ||
assert not get_entity(hass).attributes.get('oscillating') | ||
|
||
common.async_oscillate(hass, FAN_ENTITY_ID, True) | ||
await hass.async_block_till_done() | ||
assert get_entity(hass).attributes.get('oscillating') | ||
|
||
common.async_oscillate(hass, FAN_ENTITY_ID, False) | ||
await hass.async_block_till_done() | ||
assert not get_entity(hass).attributes.get('oscillating') | ||
|
||
|
||
async def test_is_on(hass): | ||
"""Test is on service call.""" | ||
assert not fan.is_on(hass, FAN_ENTITY_ID) | ||
|
||
common.async_turn_on(hass, FAN_ENTITY_ID) | ||
await hass.async_block_till_done() | ||
assert fan.is_on(hass, FAN_ENTITY_ID) |
Oops, something went wrong.