Add HomeKit support for fans (#14351)

This commit is contained in:
Matt Schmitt authored and cdce8p committed 2018-05-16 13:15:59 +02:00
1 parent e20f88c143
commit 25dcddfeef
9 files changed
+294 -15

No files matched your search

@@ -37,6 +37,7 @@ def test_customize_options(config, name):
@pytest.mark.parametrize('type_name, entity_id, state, attrs, config', [
('Fan', 'fan.test', 'on', {}, {}),
('Light', 'light.test', 'on', {}, {}),
('Lock', 'lock.test', 'locked', {}, {}),
+5 -5
View File
@@ -14,18 +14,18 @@ from tests.components.homekit.test_accessories import patch_debounce
@pytest.fixture(scope='module')
def cls(request):
def cls():
"""Patch debounce decorator during import of type_covers."""
patcher = patch_debounce()
patcher.start()
_import = __import__('homeassistant.components.homekit.type_covers',
fromlist=['GarageDoorOpener', 'WindowCovering,',
'WindowCoveringBasic'])
request.addfinalizer(patcher.stop)
patcher_tuple = namedtuple('Cls', ['window', 'window_basic', 'garage'])
return patcher_tuple(window=_import.WindowCovering,
window_basic=_import.WindowCoveringBasic,
garage=_import.GarageDoorOpener)
yield patcher_tuple(window=_import.WindowCovering,
window_basic=_import.WindowCoveringBasic,
garage=_import.GarageDoorOpener)
patcher.stop()
async def test_garage_door_open_close(hass, cls):
+149
View File
@@ -0,0 +1,149 @@
"""Test different accessory types: Fans."""
from collections import namedtuple
import pytest
from homeassistant.components.fan import (
ATTR_DIRECTION, ATTR_OSCILLATING,
DIRECTION_FORWARD, DIRECTION_REVERSE, DOMAIN, SERVICE_OSCILLATE,
SERVICE_SET_DIRECTION, SUPPORT_DIRECTION, SUPPORT_OSCILLATE)
from homeassistant.const import (
ATTR_ENTITY_ID, ATTR_SUPPORTED_FEATURES,
STATE_ON, STATE_OFF, STATE_UNKNOWN, SERVICE_TURN_ON, SERVICE_TURN_OFF)
from tests.common import async_mock_service
from tests.components.homekit.test_accessories import patch_debounce
@pytest.fixture(scope='module')
def cls():
"""Patch debounce decorator during import of type_fans."""
patcher = patch_debounce()
patcher.start()
_import = __import__('homeassistant.components.homekit.type_fans',
fromlist=['Fan'])
patcher_tuple = namedtuple('Cls', ['fan'])
yield patcher_tuple(fan=_import.Fan)
patcher.stop()
async def test_fan_basic(hass, cls):
"""Test fan with char state."""
entity_id = 'fan.demo'
hass.states.async_set(entity_id, STATE_ON,
{ATTR_SUPPORTED_FEATURES: 0})
await hass.async_block_till_done()
acc = cls.fan(hass, 'Fan', entity_id, 2, None)
assert acc.aid == 2
assert acc.category == 3 # Fan
assert acc.char_active.value == 0
await hass.async_add_job(acc.run)
await hass.async_block_till_done()
assert acc.char_active.value == 1
hass.states.async_set(entity_id, STATE_OFF,
{ATTR_SUPPORTED_FEATURES: 0})
await hass.async_block_till_done()
assert acc.char_active.value == 0
hass.states.async_set(entity_id, STATE_UNKNOWN)
await hass.async_block_till_done()
assert acc.char_active.value == 0
hass.states.async_remove(entity_id)
await hass.async_block_till_done()
assert acc.char_active.value == 0
# Set from HomeKit
call_turn_on = async_mock_service(hass, DOMAIN, SERVICE_TURN_ON)
call_turn_off = async_mock_service(hass, DOMAIN, SERVICE_TURN_OFF)
await hass.async_add_job(acc.char_active.client_update_value, 1)
await hass.async_block_till_done()
assert call_turn_on
assert call_turn_on[0].data[ATTR_ENTITY_ID] == entity_id
hass.states.async_set(entity_id, STATE_ON)
await hass.async_block_till_done()
await hass.async_add_job(acc.char_active.client_update_value, 0)
await hass.async_block_till_done()
assert call_turn_off
assert call_turn_off[0].data[ATTR_ENTITY_ID] == entity_id
async def test_fan_direction(hass, cls):
"""Test fan with direction."""
entity_id = 'fan.demo'
hass.states.async_set(entity_id, STATE_ON, {
ATTR_SUPPORTED_FEATURES: SUPPORT_DIRECTION,
ATTR_DIRECTION: DIRECTION_FORWARD})
await hass.async_block_till_done()
acc = cls.fan(hass, 'Fan', entity_id, 2, None)
assert acc.char_direction.value == 0
await hass.async_add_job(acc.run)
await hass.async_block_till_done()
assert acc.char_direction.value == 0
hass.states.async_set(entity_id, STATE_ON,
{ATTR_DIRECTION: DIRECTION_REVERSE})
await hass.async_block_till_done()
assert acc.char_direction.value == 1
# Set from HomeKit
call_set_direction = async_mock_service(hass, DOMAIN,
SERVICE_SET_DIRECTION)
await hass.async_add_job(acc.char_direction.client_update_value, 0)
await hass.async_block_till_done()
assert call_set_direction[0]
assert call_set_direction[0].data[ATTR_ENTITY_ID] == entity_id
assert call_set_direction[0].data[ATTR_DIRECTION] == DIRECTION_FORWARD
await hass.async_add_job(acc.char_direction.client_update_value, 1)
await hass.async_block_till_done()
assert call_set_direction[1]
assert call_set_direction[1].data[ATTR_ENTITY_ID] == entity_id
assert call_set_direction[1].data[ATTR_DIRECTION] == DIRECTION_REVERSE
async def test_fan_oscillate(hass, cls):
"""Test fan with oscillate."""
entity_id = 'fan.demo'
hass.states.async_set(entity_id, STATE_ON, {
ATTR_SUPPORTED_FEATURES: SUPPORT_OSCILLATE, ATTR_OSCILLATING: False})
await hass.async_block_till_done()
acc = cls.fan(hass, 'Fan', entity_id, 2, None)
assert acc.char_swing.value == 0
await hass.async_add_job(acc.run)
await hass.async_block_till_done()
assert acc.char_swing.value == 0
hass.states.async_set(entity_id, STATE_ON,
{ATTR_OSCILLATING: True})
await hass.async_block_till_done()
assert acc.char_swing.value == 1
# Set from HomeKit
call_oscillate = async_mock_service(hass, DOMAIN, SERVICE_OSCILLATE)
await hass.async_add_job(acc.char_swing.client_update_value, 0)
await hass.async_block_till_done()
assert call_oscillate[0]
assert call_oscillate[0].data[ATTR_ENTITY_ID] == entity_id
assert call_oscillate[0].data[ATTR_OSCILLATING] is False
await hass.async_add_job(acc.char_swing.client_update_value, 1)
await hass.async_block_till_done()
assert call_oscillate[1]
assert call_oscillate[1].data[ATTR_ENTITY_ID] == entity_id
assert call_oscillate[1].data[ATTR_OSCILLATING] is True
+3 -3
View File
@@ -15,15 +15,15 @@ from tests.components.homekit.test_accessories import patch_debounce
@pytest.fixture(scope='module')
def cls(request):
def cls():
"""Patch debounce decorator during import of type_lights."""
patcher = patch_debounce()
patcher.start()
_import = __import__('homeassistant.components.homekit.type_lights',
fromlist=['Light'])
request.addfinalizer(patcher.stop)
patcher_tuple = namedtuple('Cls', ['light'])
return patcher_tuple(light=_import.Light)
yield patcher_tuple(light=_import.Light)
patcher.stop()
async def test_light_basic(hass, cls):
@@ -16,15 +16,15 @@ from tests.components.homekit.test_accessories import patch_debounce
@pytest.fixture(scope='module')
def cls(request):
def cls():
"""Patch debounce decorator during import of type_thermostats."""
patcher = patch_debounce()
patcher.start()
_import = __import__('homeassistant.components.homekit.type_thermostats',
fromlist=['Thermostat'])
request.addfinalizer(patcher.stop)
patcher_tuple = namedtuple('Cls', ['thermostat'])
return patcher_tuple(thermostat=_import.Thermostat)
yield patcher_tuple(thermostat=_import.Thermostat)
patcher.stop()
async def test_default_thermostat(hass, cls):