2015-05-10 21:45:47 +00:00
|
|
|
"""
|
2016-02-24 09:38:06 +00:00
|
|
|
Demo light platform that implements lights.
|
2015-05-10 21:45:47 +00:00
|
|
|
|
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:45:47 +00:00
|
|
|
"""
|
2015-02-28 15:31:39 +00:00
|
|
|
import random
|
|
|
|
|
2015-06-13 23:42:09 +00:00
|
|
|
from homeassistant.components.light import (
|
2016-02-19 05:27:50 +00:00
|
|
|
ATTR_BRIGHTNESS, ATTR_COLOR_TEMP, ATTR_RGB_COLOR, Light)
|
2015-02-28 15:31:39 +00:00
|
|
|
|
|
|
|
LIGHT_COLORS = [
|
2015-11-07 09:25:33 +00:00
|
|
|
[237, 224, 33],
|
|
|
|
[255, 63, 111],
|
2015-02-28 15:31:39 +00:00
|
|
|
]
|
|
|
|
|
2015-11-07 09:25:33 +00:00
|
|
|
LIGHT_TEMPS = [240, 380]
|
2015-10-27 22:45:35 +00:00
|
|
|
|
2015-02-28 15:31:39 +00:00
|
|
|
|
|
|
|
def setup_platform(hass, config, add_devices_callback, discovery_info=None):
|
2016-02-24 09:38:06 +00:00
|
|
|
"""Setup demo light platform."""
|
2015-02-28 15:31:39 +00:00
|
|
|
add_devices_callback([
|
2015-06-13 23:42:09 +00:00
|
|
|
DemoLight("Bed Light", False),
|
2015-11-07 09:25:33 +00:00
|
|
|
DemoLight("Ceiling Lights", True, LIGHT_COLORS[0], LIGHT_TEMPS[1]),
|
|
|
|
DemoLight("Kitchen Lights", True, LIGHT_COLORS[1], LIGHT_TEMPS[0])
|
2015-02-28 15:31:39 +00:00
|
|
|
])
|
|
|
|
|
|
|
|
|
2015-06-13 23:42:09 +00:00
|
|
|
class DemoLight(Light):
|
2016-03-07 21:08:21 +00:00
|
|
|
"""Provide a demo light."""
|
|
|
|
|
2015-10-27 22:49:45 +00:00
|
|
|
# pylint: disable=too-many-arguments
|
2015-11-07 09:25:33 +00:00
|
|
|
def __init__(self, name, state, rgb=None, ct=None, brightness=180):
|
2016-03-07 21:08:21 +00:00
|
|
|
"""Initialize the light."""
|
2015-06-13 23:42:09 +00:00
|
|
|
self._name = name
|
2015-02-28 15:31:39 +00:00
|
|
|
self._state = state
|
2015-11-07 09:25:33 +00:00
|
|
|
self._rgb = rgb or random.choice(LIGHT_COLORS)
|
2015-10-27 22:45:35 +00:00
|
|
|
self._ct = ct or random.choice(LIGHT_TEMPS)
|
2015-02-28 15:31:39 +00:00
|
|
|
self._brightness = brightness
|
|
|
|
|
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 light."""
|
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 light if any."""
|
2015-02-28 15:31:39 +00:00
|
|
|
return self._name
|
|
|
|
|
|
|
|
@property
|
2015-06-13 23:42:09 +00:00
|
|
|
def brightness(self):
|
2016-02-24 09:38:06 +00:00
|
|
|
"""Return the brightness of this light between 0..255."""
|
2015-06-13 23:42:09 +00:00
|
|
|
return self._brightness
|
2015-02-28 15:31:39 +00:00
|
|
|
|
|
|
|
@property
|
2015-11-07 09:25:33 +00:00
|
|
|
def rgb_color(self):
|
2016-02-24 09:38:06 +00:00
|
|
|
"""Return the RBG color value."""
|
2015-11-07 09:25:33 +00:00
|
|
|
return self._rgb
|
2015-02-28 15:31:39 +00:00
|
|
|
|
2015-10-27 22:45:35 +00:00
|
|
|
@property
|
2015-10-28 23:12:16 +00:00
|
|
|
def color_temp(self):
|
2016-02-24 09:38:06 +00:00
|
|
|
"""Return the CT color temperature."""
|
2015-10-27 22:45:35 +00:00
|
|
|
return self._ct
|
|
|
|
|
2015-02-28 15:31:39 +00:00
|
|
|
@property
|
|
|
|
def is_on(self):
|
2016-02-24 09:38:06 +00:00
|
|
|
"""Return true if light is on."""
|
2015-06-13 23:42:09 +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 light on."""
|
2015-06-13 23:42:09 +00:00
|
|
|
self._state = True
|
2015-02-28 15:31:39 +00:00
|
|
|
|
2015-11-07 09:25:33 +00:00
|
|
|
if ATTR_RGB_COLOR in kwargs:
|
|
|
|
self._rgb = kwargs[ATTR_RGB_COLOR]
|
2015-02-28 15:31:39 +00:00
|
|
|
|
2015-10-28 23:12:16 +00:00
|
|
|
if ATTR_COLOR_TEMP in kwargs:
|
|
|
|
self._ct = kwargs[ATTR_COLOR_TEMP]
|
2015-10-27 22:45:35 +00:00
|
|
|
|
2015-02-28 15:31:39 +00:00
|
|
|
if ATTR_BRIGHTNESS in kwargs:
|
|
|
|
self._brightness = kwargs[ATTR_BRIGHTNESS]
|
|
|
|
|
2015-06-13 23:42:09 +00:00
|
|
|
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 light off."""
|
2015-06-13 23:42:09 +00:00
|
|
|
self._state = False
|
|
|
|
self.update_ha_state()
|