Skip to content

Commit

Permalink
Add effects (home-assistant#8442)
Browse files Browse the repository at this point in the history
  • Loading branch information
fabaff authored and dethpickle committed Aug 18, 2017
1 parent 045f290 commit 0655431
Showing 1 changed file with 22 additions and 4 deletions.
26 changes: 22 additions & 4 deletions homeassistant/components/light/mystrom.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,27 @@

import voluptuous as vol

import homeassistant.helpers.config_validation as cv
from homeassistant.components.light import (
Light, PLATFORM_SCHEMA, ATTR_BRIGHTNESS, SUPPORT_BRIGHTNESS)
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
import homeassistant.helpers.config_validation as cv

REQUIREMENTS = ['python-mystrom==0.3.8']

_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,
Expand Down Expand Up @@ -58,7 +67,6 @@ def __init__(self, bulb, name):
self._state = None
self._available = False
self._brightness = 0
self._rgb_color = [0, 0, 0]

@property
def name(self):
Expand All @@ -80,6 +88,11 @@ def available(self) -> bool:
"""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."""
Expand All @@ -90,12 +103,17 @@ def turn_on(self, **kwargs):
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")

Expand Down

0 comments on commit 0655431

Please sign in to comment.