2015-04-24 08:26:41 +02:00
|
|
|
""" Demo platform that has two fake switches. """
|
2015-03-21 19:16:13 -07:00
|
|
|
from homeassistant.helpers.entity import ToggleEntity
|
2015-02-28 20:10:39 -08:00
|
|
|
from homeassistant.const import STATE_ON, STATE_OFF, DEVICE_DEFAULT_NAME
|
2015-02-28 07:31:39 -08:00
|
|
|
|
|
|
|
|
2015-03-01 01:35:58 -08:00
|
|
|
# pylint: disable=unused-argument
|
|
|
|
def setup_platform(hass, config, add_devices_callback, discovery_info=None):
|
2015-02-28 07:31:39 -08:00
|
|
|
""" Find and return demo switches. """
|
2015-03-01 01:35:58 -08:00
|
|
|
add_devices_callback([
|
2015-02-28 07:31:39 -08:00
|
|
|
DemoSwitch('Ceiling', STATE_ON),
|
|
|
|
DemoSwitch('AC', STATE_OFF)
|
2015-03-01 01:35:58 -08:00
|
|
|
])
|
2015-02-28 07:31:39 -08:00
|
|
|
|
|
|
|
|
2015-03-21 19:16:13 -07:00
|
|
|
class DemoSwitch(ToggleEntity):
|
2015-02-28 07:31:39 -08:00
|
|
|
""" Provides a demo switch. """
|
|
|
|
def __init__(self, name, state):
|
|
|
|
self._name = name or DEVICE_DEFAULT_NAME
|
|
|
|
self._state = state
|
|
|
|
|
2015-03-16 22:20:31 -07:00
|
|
|
@property
|
|
|
|
def should_poll(self):
|
|
|
|
""" No polling needed for a demo switch. """
|
|
|
|
return False
|
|
|
|
|
2015-02-28 07:31:39 -08:00
|
|
|
@property
|
|
|
|
def name(self):
|
|
|
|
""" Returns the name of the device if any. """
|
|
|
|
return self._name
|
|
|
|
|
|
|
|
@property
|
|
|
|
def state(self):
|
2015-04-24 08:26:41 +02:00
|
|
|
""" Returns the state of the device if any. """
|
2015-02-28 07:31:39 -08:00
|
|
|
return self._state
|
|
|
|
|
|
|
|
@property
|
|
|
|
def is_on(self):
|
|
|
|
""" True if device is on. """
|
|
|
|
return self._state == STATE_ON
|
|
|
|
|
|
|
|
def turn_on(self, **kwargs):
|
|
|
|
""" Turn the device on. """
|
|
|
|
self._state = STATE_ON
|
|
|
|
|
|
|
|
def turn_off(self, **kwargs):
|
|
|
|
""" Turn the device off. """
|
|
|
|
self._state = STATE_OFF
|