hass-core/homeassistant/components/switch/demo.py

73 lines
1.9 KiB
Python
Raw Normal View History

2015-05-10 23:44:27 +02:00
"""
homeassistant.components.switch.demo
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Demo platform that has two fake switches.
"""
2015-06-13 14:56:20 -07:00
from homeassistant.components.switch import SwitchDevice
from homeassistant.const import DEVICE_DEFAULT_NAME
2015-03-01 01:35:58 -08:00
# pylint: disable=unused-argument
def setup_platform(hass, config, add_devices_callback, discovery_info=None):
""" Find and return demo switches. """
2015-03-01 01:35:58 -08:00
add_devices_callback([
2016-02-13 23:42:11 -08:00
DemoSwitch('Decorative Lights', True, None, True),
DemoSwitch('AC', False, 'mdi:air-conditioner', False)
2015-03-01 01:35:58 -08:00
])
2015-06-13 14:56:20 -07:00
class DemoSwitch(SwitchDevice):
""" Provides a demo switch. """
2016-02-13 23:42:11 -08:00
def __init__(self, name, state, icon, assumed):
self._name = name or DEVICE_DEFAULT_NAME
self._state = state
2015-11-03 00:20:48 -08:00
self._icon = icon
2016-02-13 23:42:11 -08:00
self._assumed = assumed
@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
2015-11-03 00:20:48 -08:00
@property
def icon(self):
""" Returns the icon to use for device if any. """
return self._icon
2016-02-13 23:42:11 -08:00
@property
def assumed_state(self):
"""Return if the state is based on assumptions."""
return self._assumed
@property
2015-06-13 14:56:20 -07: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 14:56:20 -07:00
return self._state
def turn_on(self, **kwargs):
""" Turn the device on. """
2015-06-13 14:56:20 -07:00
self._state = True
self.update_ha_state()
def turn_off(self, **kwargs):
""" Turn the device off. """
2015-06-13 14:56:20 -07:00
self._state = False
self.update_ha_state()