Additional demo fan with only speed support (#7985)

* Additional demo fan with only speed support

* Update demo fan tests
This commit is contained in:
Adam Mills 2017-06-12 01:12:56 -04:00 committed by Paulus Schoutsen
parent 1c06b51968
commit 401309c3b2
2 changed files with 17 additions and 11 deletions

View File

@ -9,31 +9,36 @@ from homeassistant.components.fan import (SPEED_LOW, SPEED_MEDIUM, SPEED_HIGH,
SUPPORT_OSCILLATE, SUPPORT_DIRECTION) SUPPORT_OSCILLATE, SUPPORT_DIRECTION)
from homeassistant.const import STATE_OFF from homeassistant.const import STATE_OFF
FAN_NAME = 'Living Room Fan' FULL_SUPPORT = SUPPORT_SET_SPEED | SUPPORT_OSCILLATE | SUPPORT_DIRECTION
FAN_ENTITY_ID = 'fan.living_room_fan' LIMITED_SUPPORT = SUPPORT_SET_SPEED
DEMO_SUPPORT = SUPPORT_SET_SPEED | SUPPORT_OSCILLATE | SUPPORT_DIRECTION
# pylint: disable=unused-argument # pylint: disable=unused-argument
def setup_platform(hass, config, add_devices_callback, discovery_info=None): def setup_platform(hass, config, add_devices_callback, discovery_info=None):
"""Set up the demo fan platform.""" """Set up the demo fan platform."""
add_devices_callback([ add_devices_callback([
DemoFan(hass, FAN_NAME, STATE_OFF), DemoFan(hass, "Living Room Fan", FULL_SUPPORT),
DemoFan(hass, "Ceiling Fan", LIMITED_SUPPORT),
]) ])
class DemoFan(FanEntity): class DemoFan(FanEntity):
"""A demonstration fan component.""" """A demonstration fan component."""
def __init__(self, hass, name: str, initial_state: str) -> None: def __init__(self, hass, name: str, supported_features: int) -> None:
"""Initialize the entity.""" """Initialize the entity."""
self.hass = hass self.hass = hass
self._speed = initial_state self._supported_features = supported_features
self.oscillating = False self._speed = STATE_OFF
self.direction = "forward" self.oscillating = None
self.direction = None
self._name = name self._name = name
if supported_features & SUPPORT_OSCILLATE:
self.oscillating = False
if supported_features & SUPPORT_DIRECTION:
self.direction = "forward"
@property @property
def name(self) -> str: def name(self) -> str:
"""Get entity name.""" """Get entity name."""
@ -88,4 +93,4 @@ class DemoFan(FanEntity):
@property @property
def supported_features(self) -> int: def supported_features(self) -> int:
"""Flag supported features.""" """Flag supported features."""
return DEMO_SUPPORT return self._supported_features

View File

@ -4,11 +4,12 @@ import unittest
from homeassistant.setup import setup_component from homeassistant.setup import setup_component
from homeassistant.components import fan from homeassistant.components import fan
from homeassistant.components.fan.demo import FAN_ENTITY_ID
from homeassistant.const import STATE_OFF, STATE_ON from homeassistant.const import STATE_OFF, STATE_ON
from tests.common import get_test_home_assistant from tests.common import get_test_home_assistant
FAN_ENTITY_ID = 'fan.living_room_fan'
class TestDemoFan(unittest.TestCase): class TestDemoFan(unittest.TestCase):
"""Test the fan demo platform.""" """Test the fan demo platform."""