11from typing import Dict , Any
22
33from custom_components .dmx .entity .light import ChannelType
4- from custom_components .dmx .entity .light .light_state import LightState
4+ from custom_components .dmx .entity .light .light_state import LuvLightState
55from custom_components .dmx .io .dmx_io import DmxUniverse
66
77
88class LightController :
9- def __init__ (self , state : LightState , universe : DmxUniverse ):
9+ def __init__ (self , state : LuvLightState , universe : DmxUniverse ):
1010 self .state = state
1111 self .universe = universe
1212 self .is_updating = False
@@ -44,21 +44,23 @@ async def _apply_updates(self, updates: Dict[ChannelType, int]):
4444 def _collect_updates_from_kwargs (self , kwargs : Dict [str , Any ]) -> Dict [ChannelType , int ]:
4545 updates = {}
4646
47- if "brightness" in kwargs :
48- brightness = kwargs ["brightness" ]
49- updates .update (self .state .get_scaled_brightness_updates (brightness ))
50-
5147 if "rgb_color" in kwargs and self .state .has_rgb ():
5248 r , g , b = kwargs ["rgb_color" ]
49+ # Update the internal L*u*v* state
50+ self .state .update_rgb (r , g , b )
5351 updates .update ({ChannelType .RED : r , ChannelType .GREEN : g , ChannelType .BLUE : b })
5452
5553 if "rgbw_color" in kwargs :
5654 r , g , b , w = kwargs ["rgbw_color" ]
55+ # Update the internal L*u*v* state
56+ self .state .update_rgbw (r , g , b , w )
5757 updates .update ({ChannelType .RED : r , ChannelType .GREEN : g , ChannelType .BLUE : b , ChannelType .WARM_WHITE : w })
5858
5959 if "rgbww_color" in kwargs :
6060 r , g , b , cw , ww = kwargs ["rgbww_color" ]
61- updates .update ({ChannelType .RED : r , ChannelType .GREEN : g , ChannelType .BLUE : b ,ChannelType .COLD_WHITE : cw , ChannelType .WARM_WHITE : ww })
61+ # Update the internal L*u*v* state
62+ self .state .update_rgbww (r , g , b , cw , ww )
63+ updates .update ({ChannelType .RED : r , ChannelType .GREEN : g , ChannelType .BLUE : b , ChannelType .COLD_WHITE : cw , ChannelType .WARM_WHITE : ww })
6264
6365 if "color_temp_kelvin" in kwargs :
6466 kelvin = kwargs ["color_temp_kelvin" ]
@@ -71,6 +73,12 @@ def _collect_updates_from_kwargs(self, kwargs: Dict[str, Any]) -> Dict[ChannelTy
7173 cw , ww = self .state .converter .temp_to_cw_ww (kelvin , brightness )
7274 updates .update ({ChannelType .COLD_WHITE : cw , ChannelType .WARM_WHITE : ww })
7375
76+ if "brightness" in kwargs :
77+ brightness = kwargs ["brightness" ]
78+ # Treat brightness as L* value and update accordingly
79+ self .state .update_brightness (brightness )
80+ updates .update (self .state .get_scaled_brightness_updates (brightness ))
81+
7482 return updates
7583
7684 def _restore_previous_state (self ) -> Dict [ChannelType , int ]:
@@ -94,7 +102,7 @@ def _restore_previous_state(self) -> Dict[ChannelType, int]:
94102 def _capture_current_state (self ) -> dict :
95103 return {
96104 'brightness' : self .state .brightness ,
97- 'rgb ' : self .state .rgb ,
105+ 'luv_color ' : self .state .luv_color ,
98106 'cold_white' : self .state .cold_white ,
99107 'warm_white' : self .state .warm_white ,
100108 'color_temp_kelvin' : self .state .color_temp_kelvin ,
@@ -103,8 +111,8 @@ def _capture_current_state(self) -> dict:
103111
104112 def _save_last_state (self , s : dict ):
105113 self .state .last_brightness = s ['brightness' ]
106- self .state .last_rgb = s ['rgb' ]
114+ self .state .set_last_luv_color ( s ['luv_color' ])
107115 self .state .last_cold_white = s ['cold_white' ]
108116 self .state .last_warm_white = s ['warm_white' ]
109117 self .state .last_color_temp_kelvin = s ['color_temp_kelvin' ]
110- self .state .last_color_temp_dmx = s ['color_temp_dmx' ]
118+ self .state .last_color_temp_dmx = s ['color_temp_dmx' ]
0 commit comments