From fbf945c18ba539af5dba77ca97299ac25176cc9f Mon Sep 17 00:00:00 2001 From: Fabian Affolter Date: Tue, 11 Jul 2017 21:22:00 +0200 Subject: [PATCH] Add effects (#8442) --- homeassistant/components/light/mystrom.py | 28 +++++++++++++++++++---- 1 file changed, 23 insertions(+), 5 deletions(-) diff --git a/homeassistant/components/light/mystrom.py b/homeassistant/components/light/mystrom.py index 2eb7c106bf2..ecb120e3079 100644 --- a/homeassistant/components/light/mystrom.py +++ b/homeassistant/components/light/mystrom.py @@ -8,10 +8,11 @@ import logging import voluptuous as vol -from homeassistant.components.light import ( - Light, PLATFORM_SCHEMA, ATTR_BRIGHTNESS, SUPPORT_BRIGHTNESS) -from homeassistant.const import CONF_HOST, CONF_MAC, CONF_NAME, STATE_UNKNOWN import homeassistant.helpers.config_validation as cv +from homeassistant.components.light import ( + Light, PLATFORM_SCHEMA, ATTR_BRIGHTNESS, SUPPORT_BRIGHTNESS, + SUPPORT_EFFECT, ATTR_EFFECT, SUPPORT_FLASH) +from homeassistant.const import CONF_HOST, CONF_MAC, CONF_NAME, STATE_UNKNOWN REQUIREMENTS = ['python-mystrom==0.3.8'] @@ -19,7 +20,15 @@ _LOGGER = logging.getLogger(__name__) DEFAULT_NAME = 'myStrom bulb' -SUPPORT_MYSTROM = (SUPPORT_BRIGHTNESS) +SUPPORT_MYSTROM = (SUPPORT_BRIGHTNESS | SUPPORT_EFFECT | SUPPORT_FLASH) + +EFFECT_RAINBOW = 'rainbow' +EFFECT_SUNRISE = 'sunrise' + +MYSTROM_EFFECT_LIST = [ + EFFECT_RAINBOW, + EFFECT_SUNRISE, +] PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend({ vol.Required(CONF_HOST): cv.string, @@ -58,7 +67,6 @@ class MyStromLight(Light): self._state = None self._available = False self._brightness = 0 - self._rgb_color = [0, 0, 0] @property def name(self): @@ -80,6 +88,11 @@ class MyStromLight(Light): """Return True if entity is available.""" return self._available + @property + def effect_list(self): + """Return the list of supported effects.""" + return MYSTROM_EFFECT_LIST + @property def is_on(self): """Return true if light is on.""" @@ -90,12 +103,17 @@ class MyStromLight(Light): from pymystrom.exceptions import MyStromConnectionError brightness = kwargs.get(ATTR_BRIGHTNESS, 255) + effect = kwargs.get(ATTR_EFFECT) try: if not self.is_on: self._bulb.set_on() if brightness is not None: self._bulb.set_color_hsv(0, 0, round(brightness * 100 / 255)) + if effect == EFFECT_SUNRISE: + self._bulb.set_sunrise(30) + if effect == EFFECT_RAINBOW: + self._bulb.set_rainbow(30) except MyStromConnectionError: _LOGGER.warning("myStrom bulb not online")