core/homeassistant/components/switch/demo.py

61 lines
1.5 KiB
Python
Raw Normal View History

2015-05-10 21:44:27 +00:00
"""
homeassistant.components.switch.demo
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Demo platform that has two fake switches.
"""
2015-06-13 21:56:20 +00:00
from homeassistant.components.switch import SwitchDevice
from homeassistant.const import DEVICE_DEFAULT_NAME
2015-03-01 09:35:58 +00:00
# pylint: disable=unused-argument
def setup_platform(hass, config, add_devices_callback, discovery_info=None):
""" Find and return demo switches. """
2015-03-01 09:35:58 +00:00
add_devices_callback([
2015-08-30 20:48:40 +00:00
DemoSwitch('Decorative Lights', True),
2015-06-13 21:56:20 +00:00
DemoSwitch('AC', False)
2015-03-01 09:35:58 +00:00
])
2015-06-13 21:56:20 +00:00
class DemoSwitch(SwitchDevice):
""" Provides a demo switch. """
def __init__(self, name, state):
self._name = name or DEVICE_DEFAULT_NAME
self._state = state
@property
def should_poll(self):
""" No polling needed for a demo switch. """
return False
@property
def name(self):
""" Returns the name of the device if any. """
return self._name
@property
2015-06-13 21:56:20 +00:00
def current_power_mwh(self):
""" Current power usage in mwh. """
if self._state:
return 100
@property
def today_power_mw(self):
""" Today total power usage in mw. """
return 1500
@property
def is_on(self):
""" True if device is on. """
2015-06-13 21:56:20 +00:00
return self._state
def turn_on(self, **kwargs):
""" Turn the device on. """
2015-06-13 21:56:20 +00:00
self._state = True
self.update_ha_state()
def turn_off(self, **kwargs):
""" Turn the device off. """
2015-06-13 21:56:20 +00:00
self._state = False
self.update_ha_state()