mirror of
https://github.com/home-assistant/core.git
synced 2025-07-21 20:27:08 +00:00
Add vendor effects to Yeelight integration (#42711)
Add effects shipped by Yeelight in their apps, as these effects are quite popular and have been missing from Home Assistant.
This commit is contained in:
parent
0b5851e403
commit
498654a1e0
@ -9,6 +9,7 @@ from yeelight import (
|
||||
Flow,
|
||||
RGBTransition,
|
||||
SleepTransition,
|
||||
flows,
|
||||
transitions as yee_transitions,
|
||||
)
|
||||
from yeelight.enums import BulbType, LightType, PowerMode, SceneClass
|
||||
@ -100,6 +101,15 @@ EFFECT_WHATSAPP = "WhatsApp"
|
||||
EFFECT_FACEBOOK = "Facebook"
|
||||
EFFECT_TWITTER = "Twitter"
|
||||
EFFECT_STOP = "Stop"
|
||||
EFFECT_HOME = "Home"
|
||||
EFFECT_NIGHT_MODE = "Night Mode"
|
||||
EFFECT_DATE_NIGHT = "Date Night"
|
||||
EFFECT_MOVIE = "Movie"
|
||||
EFFECT_SUNRISE = "Sunrise"
|
||||
EFFECT_SUNSET = "Sunset"
|
||||
EFFECT_ROMANCE = "Romance"
|
||||
EFFECT_HAPPY_BIRTHDAY = "Happy Birthday"
|
||||
EFFECT_CANDLE_FLICKER = "Candle Flicker"
|
||||
|
||||
YEELIGHT_TEMP_ONLY_EFFECT_LIST = [EFFECT_TEMP, EFFECT_STOP]
|
||||
|
||||
@ -111,6 +121,8 @@ YEELIGHT_MONO_EFFECT_LIST = [
|
||||
EFFECT_WHATSAPP,
|
||||
EFFECT_FACEBOOK,
|
||||
EFFECT_TWITTER,
|
||||
EFFECT_HOME,
|
||||
EFFECT_CANDLE_FLICKER,
|
||||
*YEELIGHT_TEMP_ONLY_EFFECT_LIST,
|
||||
]
|
||||
|
||||
@ -123,22 +135,38 @@ YEELIGHT_COLOR_EFFECT_LIST = [
|
||||
EFFECT_FAST_RANDOM_LOOP,
|
||||
EFFECT_LSD,
|
||||
EFFECT_SLOWDOWN,
|
||||
EFFECT_NIGHT_MODE,
|
||||
EFFECT_DATE_NIGHT,
|
||||
EFFECT_MOVIE,
|
||||
EFFECT_SUNRISE,
|
||||
EFFECT_SUNSET,
|
||||
EFFECT_ROMANCE,
|
||||
EFFECT_HAPPY_BIRTHDAY,
|
||||
*YEELIGHT_MONO_EFFECT_LIST,
|
||||
]
|
||||
|
||||
EFFECTS_MAP = {
|
||||
EFFECT_DISCO: yee_transitions.disco,
|
||||
EFFECT_TEMP: yee_transitions.temp,
|
||||
EFFECT_STROBE: yee_transitions.strobe,
|
||||
EFFECT_STROBE_COLOR: yee_transitions.strobe_color,
|
||||
EFFECT_ALARM: yee_transitions.alarm,
|
||||
EFFECT_POLICE: yee_transitions.police,
|
||||
EFFECT_POLICE2: yee_transitions.police2,
|
||||
EFFECT_CHRISTMAS: yee_transitions.christmas,
|
||||
EFFECT_RGB: yee_transitions.rgb,
|
||||
EFFECT_RANDOM_LOOP: yee_transitions.random_loop,
|
||||
EFFECT_LSD: yee_transitions.lsd,
|
||||
EFFECT_SLOWDOWN: yee_transitions.slowdown,
|
||||
EFFECT_DISCO: flows.disco,
|
||||
EFFECT_TEMP: flows.temp,
|
||||
EFFECT_STROBE: flows.strobe,
|
||||
EFFECT_STROBE_COLOR: flows.strobe_color,
|
||||
EFFECT_ALARM: flows.alarm,
|
||||
EFFECT_POLICE: flows.police,
|
||||
EFFECT_POLICE2: flows.police2,
|
||||
EFFECT_CHRISTMAS: flows.christmas,
|
||||
EFFECT_RGB: flows.rgb,
|
||||
EFFECT_RANDOM_LOOP: flows.random_loop,
|
||||
EFFECT_LSD: flows.lsd,
|
||||
EFFECT_SLOWDOWN: flows.slowdown,
|
||||
EFFECT_HOME: flows.home,
|
||||
EFFECT_NIGHT_MODE: flows.night_mode,
|
||||
EFFECT_DATE_NIGHT: flows.date_night,
|
||||
EFFECT_MOVIE: flows.movie,
|
||||
EFFECT_SUNRISE: flows.sunrise,
|
||||
EFFECT_SUNSET: flows.sunset,
|
||||
EFFECT_ROMANCE: flows.romance,
|
||||
EFFECT_HAPPY_BIRTHDAY: flows.happy_birthday,
|
||||
EFFECT_CANDLE_FLICKER: flows.candle_flicker,
|
||||
}
|
||||
|
||||
VALID_BRIGHTNESS = vol.All(vol.Coerce(int), vol.Range(min=1, max=100))
|
||||
@ -652,9 +680,9 @@ class YeelightGenericLight(YeelightEntity, LightEntity):
|
||||
if effect in self.custom_effects_names:
|
||||
flow = Flow(**self.custom_effects[effect])
|
||||
elif effect in EFFECTS_MAP:
|
||||
flow = Flow(count=0, transitions=EFFECTS_MAP[effect]())
|
||||
flow = EFFECTS_MAP[effect]()
|
||||
elif effect == EFFECT_FAST_RANDOM_LOOP:
|
||||
flow = Flow(count=0, transitions=yee_transitions.random_loop(duration=250))
|
||||
flow = flows.random_loop(duration=250)
|
||||
elif effect == EFFECT_WHATSAPP:
|
||||
flow = Flow(count=2, transitions=yee_transitions.pulse(37, 211, 102))
|
||||
elif effect == EFFECT_FACEBOOK:
|
||||
|
@ -13,7 +13,7 @@ from yeelight import (
|
||||
TemperatureTransition,
|
||||
transitions,
|
||||
)
|
||||
from yeelight.flow import Flow
|
||||
from yeelight.flow import Action, Flow
|
||||
from yeelight.main import _MODEL_SPECS
|
||||
|
||||
from homeassistant.components.light import (
|
||||
@ -51,10 +51,19 @@ from homeassistant.components.yeelight import (
|
||||
from homeassistant.components.yeelight.light import (
|
||||
ATTR_MINUTES,
|
||||
ATTR_MODE,
|
||||
EFFECT_CANDLE_FLICKER,
|
||||
EFFECT_DATE_NIGHT,
|
||||
EFFECT_DISCO,
|
||||
EFFECT_FACEBOOK,
|
||||
EFFECT_FAST_RANDOM_LOOP,
|
||||
EFFECT_HAPPY_BIRTHDAY,
|
||||
EFFECT_HOME,
|
||||
EFFECT_MOVIE,
|
||||
EFFECT_NIGHT_MODE,
|
||||
EFFECT_ROMANCE,
|
||||
EFFECT_STOP,
|
||||
EFFECT_SUNRISE,
|
||||
EFFECT_SUNSET,
|
||||
EFFECT_TWITTER,
|
||||
EFFECT_WHATSAPP,
|
||||
SERVICE_SET_AUTO_DELAY_OFF_SCENE,
|
||||
@ -569,6 +578,96 @@ async def test_effects(hass: HomeAssistant):
|
||||
EFFECT_WHATSAPP: Flow(count=2, transitions=transitions.pulse(37, 211, 102)),
|
||||
EFFECT_FACEBOOK: Flow(count=2, transitions=transitions.pulse(59, 89, 152)),
|
||||
EFFECT_TWITTER: Flow(count=2, transitions=transitions.pulse(0, 172, 237)),
|
||||
EFFECT_HOME: Flow(
|
||||
count=0,
|
||||
action=Action.recover,
|
||||
transitions=[
|
||||
TemperatureTransition(degrees=3200, duration=500, brightness=80)
|
||||
],
|
||||
),
|
||||
EFFECT_NIGHT_MODE: Flow(
|
||||
count=0,
|
||||
action=Action.recover,
|
||||
transitions=[RGBTransition(0xFF, 0x99, 0x00, duration=500, brightness=1)],
|
||||
),
|
||||
EFFECT_DATE_NIGHT: Flow(
|
||||
count=0,
|
||||
action=Action.recover,
|
||||
transitions=[RGBTransition(0xFF, 0x66, 0x00, duration=500, brightness=50)],
|
||||
),
|
||||
EFFECT_MOVIE: Flow(
|
||||
count=0,
|
||||
action=Action.recover,
|
||||
transitions=[
|
||||
RGBTransition(
|
||||
red=0x14, green=0x14, blue=0x32, duration=500, brightness=50
|
||||
)
|
||||
],
|
||||
),
|
||||
EFFECT_SUNRISE: Flow(
|
||||
count=1,
|
||||
action=Action.stay,
|
||||
transitions=[
|
||||
RGBTransition(
|
||||
red=0xFF, green=0x4D, blue=0x00, duration=50, brightness=1
|
||||
),
|
||||
TemperatureTransition(degrees=1700, duration=360000, brightness=10),
|
||||
TemperatureTransition(degrees=2700, duration=540000, brightness=100),
|
||||
],
|
||||
),
|
||||
EFFECT_SUNSET: Flow(
|
||||
count=1,
|
||||
action=Action.off,
|
||||
transitions=[
|
||||
TemperatureTransition(degrees=2700, duration=50, brightness=10),
|
||||
TemperatureTransition(degrees=1700, duration=180000, brightness=5),
|
||||
RGBTransition(
|
||||
red=0xFF, green=0x4C, blue=0x00, duration=420000, brightness=1
|
||||
),
|
||||
],
|
||||
),
|
||||
EFFECT_ROMANCE: Flow(
|
||||
count=0,
|
||||
action=Action.stay,
|
||||
transitions=[
|
||||
RGBTransition(
|
||||
red=0x59, green=0x15, blue=0x6D, duration=4000, brightness=1
|
||||
),
|
||||
RGBTransition(
|
||||
red=0x66, green=0x14, blue=0x2A, duration=4000, brightness=1
|
||||
),
|
||||
],
|
||||
),
|
||||
EFFECT_HAPPY_BIRTHDAY: Flow(
|
||||
count=0,
|
||||
action=Action.stay,
|
||||
transitions=[
|
||||
RGBTransition(
|
||||
red=0xDC, green=0x50, blue=0x19, duration=1996, brightness=80
|
||||
),
|
||||
RGBTransition(
|
||||
red=0xDC, green=0x78, blue=0x1E, duration=1996, brightness=80
|
||||
),
|
||||
RGBTransition(
|
||||
red=0xAA, green=0x32, blue=0x14, duration=1996, brightness=80
|
||||
),
|
||||
],
|
||||
),
|
||||
EFFECT_CANDLE_FLICKER: Flow(
|
||||
count=0,
|
||||
action=Action.recover,
|
||||
transitions=[
|
||||
TemperatureTransition(degrees=2700, duration=800, brightness=50),
|
||||
TemperatureTransition(degrees=2700, duration=800, brightness=30),
|
||||
TemperatureTransition(degrees=2700, duration=1200, brightness=80),
|
||||
TemperatureTransition(degrees=2700, duration=800, brightness=60),
|
||||
TemperatureTransition(degrees=2700, duration=1200, brightness=90),
|
||||
TemperatureTransition(degrees=2700, duration=2400, brightness=50),
|
||||
TemperatureTransition(degrees=2700, duration=1200, brightness=80),
|
||||
TemperatureTransition(degrees=2700, duration=800, brightness=60),
|
||||
TemperatureTransition(degrees=2700, duration=400, brightness=70),
|
||||
],
|
||||
),
|
||||
}
|
||||
|
||||
for name, target in effects.items():
|
||||
|
Loading…
x
Reference in New Issue
Block a user