2015-05-10 21:44:27 +00:00
|
|
|
"""
|
|
|
|
Demo platform that has two fake switches.
|
2016-02-24 09:38:06 +00:00
|
|
|
|
|
|
|
For more details about this platform, please refer to the documentation
|
|
|
|
https://home-assistant.io/components/demo/
|
2015-05-10 21:44:27 +00:00
|
|
|
"""
|
2015-06-13 21:56:20 +00:00
|
|
|
from homeassistant.components.switch import SwitchDevice
|
|
|
|
from homeassistant.const import DEVICE_DEFAULT_NAME
|
2015-02-28 15:31:39 +00:00
|
|
|
|
|
|
|
|
2015-03-01 09:35:58 +00:00
|
|
|
# pylint: disable=unused-argument
|
|
|
|
def setup_platform(hass, config, add_devices_callback, discovery_info=None):
|
2016-02-24 09:38:06 +00:00
|
|
|
"""Setup the demo switches."""
|
2015-03-01 09:35:58 +00:00
|
|
|
add_devices_callback([
|
2016-02-14 07:42:11 +00:00
|
|
|
DemoSwitch('Decorative Lights', True, None, True),
|
|
|
|
DemoSwitch('AC', False, 'mdi:air-conditioner', False)
|
2015-03-01 09:35:58 +00:00
|
|
|
])
|
2015-02-28 15:31:39 +00:00
|
|
|
|
|
|
|
|
2015-06-13 21:56:20 +00:00
|
|
|
class DemoSwitch(SwitchDevice):
|
2016-02-24 09:38:06 +00:00
|
|
|
"""Provide a demo switch."""
|
2016-02-14 07:42:11 +00:00
|
|
|
def __init__(self, name, state, icon, assumed):
|
2015-02-28 15:31:39 +00:00
|
|
|
self._name = name or DEVICE_DEFAULT_NAME
|
|
|
|
self._state = state
|
2015-11-03 08:20:48 +00:00
|
|
|
self._icon = icon
|
2016-02-14 07:42:11 +00:00
|
|
|
self._assumed = assumed
|
2015-02-28 15:31:39 +00:00
|
|
|
|
2015-03-17 05:20:31 +00:00
|
|
|
@property
|
|
|
|
def should_poll(self):
|
2016-02-24 09:38:06 +00:00
|
|
|
"""No polling needed for a demo switch."""
|
2015-03-17 05:20:31 +00:00
|
|
|
return False
|
|
|
|
|
2015-02-28 15:31:39 +00:00
|
|
|
@property
|
|
|
|
def name(self):
|
2016-02-24 09:38:06 +00:00
|
|
|
"""Return the name of the device if any."""
|
2015-02-28 15:31:39 +00:00
|
|
|
return self._name
|
|
|
|
|
2015-11-03 08:20:48 +00:00
|
|
|
@property
|
|
|
|
def icon(self):
|
2016-02-24 09:38:06 +00:00
|
|
|
"""Return the icon to use for device if any."""
|
2015-11-03 08:20:48 +00:00
|
|
|
return self._icon
|
|
|
|
|
2016-02-14 07:42:11 +00:00
|
|
|
@property
|
|
|
|
def assumed_state(self):
|
|
|
|
"""Return if the state is based on assumptions."""
|
|
|
|
return self._assumed
|
|
|
|
|
2015-02-28 15:31:39 +00:00
|
|
|
@property
|
2015-06-13 21:56:20 +00:00
|
|
|
def current_power_mwh(self):
|
2016-02-24 09:38:06 +00:00
|
|
|
"""Returns the current power usage in mwh."""
|
2015-06-13 21:56:20 +00:00
|
|
|
if self._state:
|
|
|
|
return 100
|
|
|
|
|
|
|
|
@property
|
|
|
|
def today_power_mw(self):
|
2016-02-24 09:38:06 +00:00
|
|
|
"""Return the today total power usage in mw."""
|
2015-06-13 21:56:20 +00:00
|
|
|
return 1500
|
2015-02-28 15:31:39 +00:00
|
|
|
|
|
|
|
@property
|
|
|
|
def is_on(self):
|
2016-02-24 09:38:06 +00:00
|
|
|
"""Return true if switch is on."""
|
2015-06-13 21:56:20 +00:00
|
|
|
return self._state
|
2015-02-28 15:31:39 +00:00
|
|
|
|
|
|
|
def turn_on(self, **kwargs):
|
2016-02-24 09:38:06 +00:00
|
|
|
"""Turn the switch on."""
|
2015-06-13 21:56:20 +00:00
|
|
|
self._state = True
|
|
|
|
self.update_ha_state()
|
2015-02-28 15:31:39 +00:00
|
|
|
|
|
|
|
def turn_off(self, **kwargs):
|
2016-02-24 09:38:06 +00:00
|
|
|
"""Turn the device off."""
|
2015-06-13 21:56:20 +00:00
|
|
|
self._state = False
|
|
|
|
self.update_ha_state()
|