Fix nanoleaf incorrect effect update (#36517)

pull/36626/head
Donnie 2020-06-09 11:26:37 -07:00 committed by Paulus Schoutsen
parent e1ad108b6d
commit 5a9a95abe4
1 changed files with 10 additions and 1 deletions

View File

@ -210,6 +210,10 @@ class NanoleafLight(LightEntity):
self._light.brightness = int(brightness / 2.55) self._light.brightness = int(brightness / 2.55)
if effect: if effect:
if effect not in self._effects_list:
raise ValueError(
f"Attempting to apply effect not in the effect list: '{effect}'"
)
self._light.effect = effect self._light.effect = effect
def turn_off(self, **kwargs): def turn_off(self, **kwargs):
@ -227,8 +231,13 @@ class NanoleafLight(LightEntity):
self._available = self._light.available self._available = self._light.available
self._brightness = self._light.brightness self._brightness = self._light.brightness
self._color_temp = self._light.color_temperature self._color_temp = self._light.color_temperature
self._effect = self._light.effect
self._effects_list = self._light.effects self._effects_list = self._light.effects
# Nanoleaf api returns non-existent effect named "*Solid*" when light set to solid color.
# This causes various issues with scening (see https://github.com/home-assistant/core/issues/36359).
# Until fixed at the library level, we should ensure the effect exists before saving to light properties
self._effect = (
self._light.effect if self._light.effect in self._effects_list else None
)
self._hs_color = self._light.hue, self._light.saturation self._hs_color = self._light.hue, self._light.saturation
self._state = self._light.on self._state = self._light.on
except Unavailable as err: except Unavailable as err: