mirror of
https://github.com/home-assistant/core.git
synced 2025-07-19 11:17:21 +00:00
Added effects to Yeelight bulbs (#7152)
* Added effects to Yeelight bulbs * Fix Typo and Use randint instead of randrange * Added Effects * updated requirements_all.txt * fix empty line * minor fixes * fix passing effects as parameter
This commit is contained in:
parent
7d4adbbef5
commit
7d24efc690
@ -16,13 +16,13 @@ from homeassistant.util.color import (
|
|||||||
from homeassistant.const import CONF_DEVICES, CONF_NAME
|
from homeassistant.const import CONF_DEVICES, CONF_NAME
|
||||||
from homeassistant.components.light import (
|
from homeassistant.components.light import (
|
||||||
ATTR_BRIGHTNESS, ATTR_RGB_COLOR, ATTR_TRANSITION, ATTR_COLOR_TEMP,
|
ATTR_BRIGHTNESS, ATTR_RGB_COLOR, ATTR_TRANSITION, ATTR_COLOR_TEMP,
|
||||||
ATTR_FLASH, FLASH_SHORT, FLASH_LONG,
|
ATTR_FLASH, FLASH_SHORT, FLASH_LONG, ATTR_EFFECT,
|
||||||
SUPPORT_BRIGHTNESS, SUPPORT_RGB_COLOR, SUPPORT_TRANSITION,
|
SUPPORT_BRIGHTNESS, SUPPORT_RGB_COLOR, SUPPORT_TRANSITION,
|
||||||
SUPPORT_COLOR_TEMP, SUPPORT_FLASH,
|
SUPPORT_COLOR_TEMP, SUPPORT_FLASH, SUPPORT_EFFECT,
|
||||||
Light, PLATFORM_SCHEMA)
|
Light, PLATFORM_SCHEMA)
|
||||||
import homeassistant.helpers.config_validation as cv
|
import homeassistant.helpers.config_validation as cv
|
||||||
|
|
||||||
REQUIREMENTS = ['yeelight==0.2.2']
|
REQUIREMENTS = ['yeelight==0.3.0']
|
||||||
|
|
||||||
_LOGGER = logging.getLogger(__name__)
|
_LOGGER = logging.getLogger(__name__)
|
||||||
|
|
||||||
@ -50,8 +50,44 @@ SUPPORT_YEELIGHT = (SUPPORT_BRIGHTNESS |
|
|||||||
|
|
||||||
SUPPORT_YEELIGHT_RGB = (SUPPORT_YEELIGHT |
|
SUPPORT_YEELIGHT_RGB = (SUPPORT_YEELIGHT |
|
||||||
SUPPORT_RGB_COLOR |
|
SUPPORT_RGB_COLOR |
|
||||||
|
SUPPORT_EFFECT |
|
||||||
SUPPORT_COLOR_TEMP)
|
SUPPORT_COLOR_TEMP)
|
||||||
|
|
||||||
|
EFFECT_DISCO = "Disco"
|
||||||
|
EFFECT_TEMP = "Slow Temp"
|
||||||
|
EFFECT_STROBE = "Strobe epilepsy!"
|
||||||
|
EFFECT_STROBE_COLOR = "Strobe color"
|
||||||
|
EFFECT_ALARM = "Alarm"
|
||||||
|
EFFECT_POLICE = "Police"
|
||||||
|
EFFECT_POLICE2 = "Police2"
|
||||||
|
EFFECT_CHRISTMAS = "Christmas"
|
||||||
|
EFFECT_RGB = "RGB"
|
||||||
|
EFFECT_RANDOM_LOOP = "Random Loop"
|
||||||
|
EFFECT_FAST_RANDOM_LOOP = "Fast Random Loop"
|
||||||
|
EFFECT_SLOWDOWN = "Slowdown"
|
||||||
|
EFFECT_WHATSAPP = "WhatsApp"
|
||||||
|
EFFECT_FACEBOOK = "Facebook"
|
||||||
|
EFFECT_TWITTER = "Twitter"
|
||||||
|
EFFECT_STOP = "Stop"
|
||||||
|
|
||||||
|
YEELIGHT_EFFECT_LIST = [
|
||||||
|
EFFECT_DISCO,
|
||||||
|
EFFECT_TEMP,
|
||||||
|
EFFECT_STROBE,
|
||||||
|
EFFECT_STROBE_COLOR,
|
||||||
|
EFFECT_ALARM,
|
||||||
|
EFFECT_POLICE,
|
||||||
|
EFFECT_POLICE2,
|
||||||
|
EFFECT_CHRISTMAS,
|
||||||
|
EFFECT_RGB,
|
||||||
|
EFFECT_RANDOM_LOOP,
|
||||||
|
EFFECT_FAST_RANDOM_LOOP,
|
||||||
|
EFFECT_SLOWDOWN,
|
||||||
|
EFFECT_WHATSAPP,
|
||||||
|
EFFECT_FACEBOOK,
|
||||||
|
EFFECT_TWITTER,
|
||||||
|
EFFECT_STOP]
|
||||||
|
|
||||||
|
|
||||||
def _cmd(func):
|
def _cmd(func):
|
||||||
"""Define a wrapper to catch exceptions from the bulb."""
|
"""Define a wrapper to catch exceptions from the bulb."""
|
||||||
@ -116,6 +152,11 @@ class YeelightLight(Light):
|
|||||||
"""Flag supported features."""
|
"""Flag supported features."""
|
||||||
return self._supported_features
|
return self._supported_features
|
||||||
|
|
||||||
|
@property
|
||||||
|
def effect_list(self):
|
||||||
|
"""Return the list of supported effects."""
|
||||||
|
return YEELIGHT_EFFECT_LIST
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def unique_id(self) -> str:
|
def unique_id(self) -> str:
|
||||||
"""Return the ID of this light."""
|
"""Return the ID of this light."""
|
||||||
@ -286,6 +327,54 @@ class YeelightLight(Light):
|
|||||||
except BulbException as ex:
|
except BulbException as ex:
|
||||||
_LOGGER.error("Unable to set flash: %s", ex)
|
_LOGGER.error("Unable to set flash: %s", ex)
|
||||||
|
|
||||||
|
@_cmd
|
||||||
|
def set_effect(self, effect) -> None:
|
||||||
|
"""Activate effect."""
|
||||||
|
if effect:
|
||||||
|
from yeelight import (Flow, BulbException)
|
||||||
|
from yeelight.transitions import (disco, temp, strobe, pulse,
|
||||||
|
strobe_color, alarm, police,
|
||||||
|
police2, christmas, rgb,
|
||||||
|
randomloop, slowdown)
|
||||||
|
if effect == EFFECT_STOP:
|
||||||
|
self._bulb.stop_flow()
|
||||||
|
return
|
||||||
|
if effect == EFFECT_DISCO:
|
||||||
|
flow = Flow(count=0, transitions=disco())
|
||||||
|
if effect == EFFECT_TEMP:
|
||||||
|
flow = Flow(count=0, transitions=temp())
|
||||||
|
if effect == EFFECT_STROBE:
|
||||||
|
flow = Flow(count=0, transitions=strobe())
|
||||||
|
if effect == EFFECT_STROBE_COLOR:
|
||||||
|
flow = Flow(count=0, transitions=strobe_color())
|
||||||
|
if effect == EFFECT_ALARM:
|
||||||
|
flow = Flow(count=0, transitions=alarm())
|
||||||
|
if effect == EFFECT_POLICE:
|
||||||
|
flow = Flow(count=0, transitions=police())
|
||||||
|
if effect == EFFECT_POLICE2:
|
||||||
|
flow = Flow(count=0, transitions=police2())
|
||||||
|
if effect == EFFECT_CHRISTMAS:
|
||||||
|
flow = Flow(count=0, transitions=christmas())
|
||||||
|
if effect == EFFECT_RGB:
|
||||||
|
flow = Flow(count=0, transitions=rgb())
|
||||||
|
if effect == EFFECT_RANDOM_LOOP:
|
||||||
|
flow = Flow(count=0, transitions=randomloop())
|
||||||
|
if effect == EFFECT_FAST_RANDOM_LOOP:
|
||||||
|
flow = Flow(count=0, transitions=randomloop(duration=250))
|
||||||
|
if effect == EFFECT_SLOWDOWN:
|
||||||
|
flow = Flow(count=0, transitions=slowdown())
|
||||||
|
if effect == EFFECT_WHATSAPP:
|
||||||
|
flow = Flow(count=2, transitions=pulse(37, 211, 102))
|
||||||
|
if effect == EFFECT_FACEBOOK:
|
||||||
|
flow = Flow(count=2, transitions=pulse(59, 89, 152))
|
||||||
|
if effect == EFFECT_TWITTER:
|
||||||
|
flow = Flow(count=2, transitions=pulse(0, 172, 237))
|
||||||
|
|
||||||
|
try:
|
||||||
|
self._bulb.start_flow(flow)
|
||||||
|
except BulbException as ex:
|
||||||
|
_LOGGER.error("Unable to set effect: %s", ex)
|
||||||
|
|
||||||
def turn_on(self, **kwargs) -> None:
|
def turn_on(self, **kwargs) -> None:
|
||||||
"""Turn the bulb on."""
|
"""Turn the bulb on."""
|
||||||
import yeelight
|
import yeelight
|
||||||
@ -293,6 +382,7 @@ class YeelightLight(Light):
|
|||||||
colortemp = kwargs.get(ATTR_COLOR_TEMP)
|
colortemp = kwargs.get(ATTR_COLOR_TEMP)
|
||||||
rgb = kwargs.get(ATTR_RGB_COLOR)
|
rgb = kwargs.get(ATTR_RGB_COLOR)
|
||||||
flash = kwargs.get(ATTR_FLASH)
|
flash = kwargs.get(ATTR_FLASH)
|
||||||
|
effect = kwargs.get(ATTR_EFFECT)
|
||||||
|
|
||||||
duration = int(self.config[CONF_TRANSITION]) # in ms
|
duration = int(self.config[CONF_TRANSITION]) # in ms
|
||||||
if ATTR_TRANSITION in kwargs: # passed kwarg overrides config
|
if ATTR_TRANSITION in kwargs: # passed kwarg overrides config
|
||||||
@ -317,6 +407,7 @@ class YeelightLight(Light):
|
|||||||
self.set_colortemp(colortemp, duration)
|
self.set_colortemp(colortemp, duration)
|
||||||
self.set_brightness(brightness, duration)
|
self.set_brightness(brightness, duration)
|
||||||
self.set_flash(flash)
|
self.set_flash(flash)
|
||||||
|
self.set_effect(effect)
|
||||||
except yeelight.BulbException as ex:
|
except yeelight.BulbException as ex:
|
||||||
_LOGGER.error("Unable to set bulb properties: %s", ex)
|
_LOGGER.error("Unable to set bulb properties: %s", ex)
|
||||||
return
|
return
|
||||||
|
@ -879,7 +879,7 @@ yahoo-finance==1.4.0
|
|||||||
yahooweather==0.8
|
yahooweather==0.8
|
||||||
|
|
||||||
# homeassistant.components.light.yeelight
|
# homeassistant.components.light.yeelight
|
||||||
yeelight==0.2.2
|
yeelight==0.3.0
|
||||||
|
|
||||||
# homeassistant.components.light.yeelightsunflower
|
# homeassistant.components.light.yeelightsunflower
|
||||||
yeelightsunflower==0.0.8
|
yeelightsunflower==0.0.8
|
||||||
|
Loading…
x
Reference in New Issue
Block a user