Skip to content

Commit

Permalink
Whitelist yeelight predefined effects per device type (#24544)
Browse files Browse the repository at this point in the history
* Whitelist yeelight predefined effects per device type

* Fix support color
  • Loading branch information
zewelor authored and rytilahti committed Jun 16, 2019
1 parent 1e24855 commit 08eca4a
Showing 1 changed file with 34 additions and 14 deletions.
48 changes: 34 additions & 14 deletions homeassistant/components/yeelight/light.py
Expand Up @@ -28,15 +28,14 @@

SUPPORT_YEELIGHT = (SUPPORT_BRIGHTNESS |
SUPPORT_TRANSITION |
SUPPORT_FLASH)
SUPPORT_FLASH |
SUPPORT_EFFECT)

SUPPORT_YEELIGHT_WHITE_TEMP = (SUPPORT_YEELIGHT |
SUPPORT_COLOR_TEMP)

SUPPORT_YEELIGHT_RGB = (SUPPORT_YEELIGHT |
SUPPORT_COLOR |
SUPPORT_EFFECT |
SUPPORT_COLOR_TEMP)
SUPPORT_YEELIGHT_RGB = (SUPPORT_YEELIGHT_WHITE_TEMP |
SUPPORT_COLOR)

ATTR_MODE = 'mode'

Expand All @@ -61,24 +60,33 @@
EFFECT_TWITTER = "Twitter"
EFFECT_STOP = "Stop"

YEELIGHT_EFFECT_LIST = [
EFFECT_DISCO,
YEELIGHT_TEMP_ONLY_EFFECT_LIST = [
EFFECT_TEMP,
EFFECT_STOP,
]

YEELIGHT_MONO_EFFECT_LIST = [
EFFECT_DISCO,
EFFECT_STROBE,
EFFECT_STROBE_COLOR,
EFFECT_ALARM,
EFFECT_POLICE,
EFFECT_POLICE2,
EFFECT_WHATSAPP,
EFFECT_FACEBOOK,
EFFECT_TWITTER,
*YEELIGHT_TEMP_ONLY_EFFECT_LIST
]

YEELIGHT_COLOR_EFFECT_LIST = [
EFFECT_STROBE_COLOR,
EFFECT_POLICE,
EFFECT_CHRISTMAS,
EFFECT_RGB,
EFFECT_RANDOM_LOOP,
EFFECT_FAST_RANDOM_LOOP,
EFFECT_LSD,
EFFECT_SLOWDOWN,
EFFECT_WHATSAPP,
EFFECT_FACEBOOK,
EFFECT_TWITTER,
EFFECT_STOP]
*YEELIGHT_MONO_EFFECT_LIST
]

MODEL_TO_DEVICE_TYPE = {
'mono': BulbType.White,
Expand Down Expand Up @@ -262,7 +270,7 @@ def supported_features(self) -> int:
@property
def effect_list(self):
"""Return the list of supported effects."""
return YEELIGHT_EFFECT_LIST + self.custom_effects_names
return self._predefined_effects + self.custom_effects_names

@property
def color_temp(self) -> int:
Expand Down Expand Up @@ -342,6 +350,10 @@ def _brightness_property(self):
def _power_property(self):
return 'power'

@property
def _predefined_effects(self):
return YEELIGHT_MONO_EFFECT_LIST

@property
def device(self):
"""Return yeelight device."""
Expand Down Expand Up @@ -575,6 +587,10 @@ def supported_features(self) -> int:
"""Flag supported features."""
return SUPPORT_YEELIGHT_RGB

@property
def _predefined_effects(self):
return YEELIGHT_COLOR_EFFECT_LIST


class YeelightWhiteTempLight(YeelightGenericLight):
"""Representation of a Color Yeelight light."""
Expand All @@ -588,6 +604,10 @@ def supported_features(self) -> int:
def _brightness_property(self):
return 'current_brightness'

@property
def _predefined_effects(self):
return YEELIGHT_TEMP_ONLY_EFFECT_LIST


class YeelightWithAmbientLight(YeelightWhiteTempLight):
"""Representation of a Yeelight which has ambilight support."""
Expand Down

0 comments on commit 08eca4a

Please sign in to comment.