Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 15 additions & 10 deletions homeassistant/components/fan/demo.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,31 +9,36 @@
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."""
Expand Down Expand Up @@ -88,4 +93,4 @@ def current_direction(self) -> str:
@property
def supported_features(self) -> int:
"""Flag supported features."""
return DEMO_SUPPORT
return self._supported_features
3 changes: 2 additions & 1 deletion tests/components/fan/test_demo.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,12 @@

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."""
Expand Down