Additional demo fan with only speed support (#7985)

* Additional demo fan with only speed support

* Update demo fan tests
pull/8004/head
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)
from homeassistant.const import STATE_OFF
FAN_NAME = 'Living Room Fan'
FAN_ENTITY_ID = 'fan.living_room_fan'
DEMO_SUPPORT = SUPPORT_SET_SPEED | SUPPORT_OSCILLATE | SUPPORT_DIRECTION
FULL_SUPPORT = SUPPORT_SET_SPEED | SUPPORT_OSCILLATE | SUPPORT_DIRECTION
LIMITED_SUPPORT = SUPPORT_SET_SPEED
# pylint: disable=unused-argument
def setup_platform(hass, config, add_devices_callback, discovery_info=None):
"""Set up the demo fan platform."""
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):
"""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."""
self.hass = hass
self._speed = initial_state
self.oscillating = False
self.direction = "forward"
self._supported_features = supported_features
self._speed = STATE_OFF
self.oscillating = None
self.direction = None
self._name = name
if supported_features & SUPPORT_OSCILLATE:
self.oscillating = False
if supported_features & SUPPORT_DIRECTION:
self.direction = "forward"
@property
def name(self) -> str:
"""Get entity name."""
@ -88,4 +93,4 @@ class DemoFan(FanEntity):
@property
def supported_features(self) -> int:
"""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.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
FAN_ENTITY_ID = 'fan.living_room_fan'
class TestDemoFan(unittest.TestCase):
"""Test the fan demo platform."""