Add effects (#8442)
This commit is contained in:
parent
609c25691a
commit
fbf945c18b
1 changed files with 23 additions and 5 deletions
|
@ -8,10 +8,11 @@ import logging
|
||||||
|
|
||||||
import voluptuous as vol
|
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
|
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']
|
REQUIREMENTS = ['python-mystrom==0.3.8']
|
||||||
|
|
||||||
|
@ -19,7 +20,15 @@ _LOGGER = logging.getLogger(__name__)
|
||||||
|
|
||||||
DEFAULT_NAME = 'myStrom bulb'
|
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({
|
PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend({
|
||||||
vol.Required(CONF_HOST): cv.string,
|
vol.Required(CONF_HOST): cv.string,
|
||||||
|
@ -58,7 +67,6 @@ class MyStromLight(Light):
|
||||||
self._state = None
|
self._state = None
|
||||||
self._available = False
|
self._available = False
|
||||||
self._brightness = 0
|
self._brightness = 0
|
||||||
self._rgb_color = [0, 0, 0]
|
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def name(self):
|
def name(self):
|
||||||
|
@ -80,6 +88,11 @@ class MyStromLight(Light):
|
||||||
"""Return True if entity is available."""
|
"""Return True if entity is available."""
|
||||||
return self._available
|
return self._available
|
||||||
|
|
||||||
|
@property
|
||||||
|
def effect_list(self):
|
||||||
|
"""Return the list of supported effects."""
|
||||||
|
return MYSTROM_EFFECT_LIST
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def is_on(self):
|
def is_on(self):
|
||||||
"""Return true if light is on."""
|
"""Return true if light is on."""
|
||||||
|
@ -90,12 +103,17 @@ class MyStromLight(Light):
|
||||||
from pymystrom.exceptions import MyStromConnectionError
|
from pymystrom.exceptions import MyStromConnectionError
|
||||||
|
|
||||||
brightness = kwargs.get(ATTR_BRIGHTNESS, 255)
|
brightness = kwargs.get(ATTR_BRIGHTNESS, 255)
|
||||||
|
effect = kwargs.get(ATTR_EFFECT)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
if not self.is_on:
|
if not self.is_on:
|
||||||
self._bulb.set_on()
|
self._bulb.set_on()
|
||||||
if brightness is not None:
|
if brightness is not None:
|
||||||
self._bulb.set_color_hsv(0, 0, round(brightness * 100 / 255))
|
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:
|
except MyStromConnectionError:
|
||||||
_LOGGER.warning("myStrom bulb not online")
|
_LOGGER.warning("myStrom bulb not online")
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue