11from homeassistant .components .light import ColorMode , LightEntity , LightEntityFeature
2- from homeassistant .util .color import color_temperature_to_hs
32
43from .core .entity import YandexEntity
54from .hass import hass_utils
1110 "devices.types.light.garland" ,
1211 "devices.types.light.lamp" ,
1312 "devices.types.light.strip" ,
13+ "devices.types.smart_speaker.yandex.station.orion" ,
1414)
1515
1616
@@ -38,10 +38,17 @@ class YandexLight(LightEntity, YandexEntity):
3838 max_brightness : int
3939 min_brightness : int
4040 effects : list
41+ on_instance : str
4142
4243 def internal_init (self , capabilities : dict , properties : dict ):
4344 self ._attr_color_mode = ColorMode .ONOFF
4445
46+ # backlight for Yandex Station 3 and maybe some others
47+ for instance in ("on" , "backlight" ):
48+ if instance in capabilities :
49+ self .on_instance = instance
50+ break
51+
4552 if bright := capabilities .get ("brightness" ):
4653 self .max_brightness = bright ["range" ]["max" ]
4754 self .min_brightness = bright ["range" ]["min" ]
@@ -71,8 +78,8 @@ def internal_init(self, capabilities: dict, properties: dict):
7178 self ._attr_supported_color_modes = modes or {self ._attr_color_mode }
7279
7380 def internal_update (self , capabilities : dict , properties : dict ):
74- if "on" in capabilities :
75- self ._attr_is_on = capabilities ["on" ]
81+ if self . on_instance in capabilities :
82+ self ._attr_is_on = capabilities [self . on_instance ]
7683
7784 if "brightness" in capabilities :
7885 value = capabilities ["brightness" ]
@@ -95,6 +102,7 @@ def internal_update(self, capabilities: dict, properties: dict):
95102 self ._attr_color_temp_kelvin = value
96103 self ._attr_color_mode = ColorMode .COLOR_TEMP
97104 else :
105+ self ._attr_color_temp_kelvin = None
98106 self ._attr_hs_color = None
99107
100108 if name := color .get ("name" ):
@@ -106,6 +114,22 @@ def internal_update(self, capabilities: dict, properties: dict):
106114 else :
107115 self ._attr_effect = None
108116
117+ elif animation := capabilities .get ("color_animation" ):
118+ animation_type = animation ["current_animation_type" ]
119+ if animation_type == "color" :
120+ color = animation ["animations" ]["color" ]
121+ state = color ["internal_state" ]
122+ if state ["instance" ] == "hsv" :
123+ value = state ["value" ]
124+ self ._attr_hs_color = (value ["h" ], value ["s" ])
125+ self ._attr_color_mode = ColorMode .HS
126+ elif animation_type == "scene" :
127+ scene = animation ["animations" ]["scene" ]
128+ id = scene ["variant" ]
129+ self ._attr_effect = next (
130+ i ["name" ] for i in self .effects if i ["id" ] == id
131+ )
132+
109133 async def async_turn_on (
110134 self ,
111135 brightness : int = None ,
@@ -136,9 +160,9 @@ async def async_turn_on(
136160 payload [key ] = color ["id" ]
137161
138162 if not payload :
139- payload ["on" ] = True
163+ payload [self . on_instance ] = True
140164
141165 await self .device_actions (** payload )
142166
143167 async def async_turn_off (self , ** kwargs ):
144- await self .device_actions ( on = False )
168+ await self .device_action ( self . on_instance , False )
0 commit comments