@@ -262,29 +262,31 @@ def set_state(self, params: dict):
262262 self ._attr_effect = None
263263
264264 if self .color_mode == ColorMode .COLOR_TEMP :
265- # from 25 to 255
266- cold = int (params ["channel0" ])
267- warm = int (params ["channel1" ])
268- if warm == 0 :
269- self ._attr_color_temp_kelvin = 6500
270- elif cold == warm :
271- self ._attr_color_temp_kelvin = 4250
272- elif cold == 0 :
273- self ._attr_color_temp_kelvin = 2000
274- self ._attr_brightness = conv (max (cold , warm ), 25 , 255 , 1 , 255 )
265+ if "channel0" in params and "channel1" in params :
266+ # from 25 to 255
267+ cold = int (params ["channel0" ])
268+ warm = int (params ["channel1" ])
269+ if warm == 0 :
270+ self ._attr_color_temp_kelvin = 6500
271+ elif cold == warm :
272+ self ._attr_color_temp_kelvin = 4250
273+ elif cold == 0 :
274+ self ._attr_color_temp_kelvin = 2000
275+ self ._attr_brightness = conv (max (cold , warm ), 25 , 255 , 1 , 255 )
275276
276277 else :
277- self ._attr_rgb_color = (
278- int (params ["channel2" ]),
279- int (params ["channel3" ]),
280- int (params ["channel4" ]),
281- )
278+ if "channel2" in params and "channel3" in params and "channel4" in params :
279+ self ._attr_rgb_color = (
280+ int (params ["channel2" ]),
281+ int (params ["channel3" ]),
282+ int (params ["channel4" ]),
283+ )
282284
283285 def get_params (self , brightness , color_temp_kelvin , rgb_color , effect ) -> dict :
284286 if brightness or color_temp_kelvin :
285- ch = str (conv (brightness or self .brightness , 1 , 255 , 25 , 255 ))
287+ ch = str (conv (brightness or self .brightness or 255 , 1 , 255 , 25 , 255 ))
286288 if not color_temp_kelvin :
287- color_temp_kelvin = self .color_temp_kelvin
289+ color_temp_kelvin = self .color_temp_kelvin or 4250
288290 if color_temp_kelvin >= 5000 :
289291 params = {"channel0" : ch , "channel1" : "0" }
290292 elif color_temp_kelvin >= 3500 :
0 commit comments