@@ -78,6 +78,9 @@ def __init__(
7878 self ._warm_white = 255
7979 self ._color_temp_value = 255 # Direct color temp channel value
8080
81+ # Initialize default values from channels' capabilities
82+ self ._initialize_default_values ()
83+
8184 # Map channels by type for easy access
8285 self ._channel_map : Dict [LightChannel , AccumulatedLightChannel ] = {
8386 channel .light_channel : channel for channel in channels
@@ -99,6 +102,63 @@ def __init__(
99102 self ._is_updating = False
100103 self ._register_channel_listeners ()
101104
105+ def _initialize_default_values (self ):
106+ """Initialize default values for channels based on their capabilities."""
107+ for channel_data in self ._channels :
108+ channel = channel_data .channel
109+ light_channel = channel_data .light_channel
110+
111+ # Check if there's a capability with menu_click
112+ if channel .capabilities and len (channel .capabilities ) > 0 :
113+ capability = channel .capabilities [0 ]
114+
115+ # Set the default value based on menu_click
116+ if capability .menu_click :
117+ default_value = capability .menu_click_value
118+ else :
119+ default_value = 0
120+
121+ # Update the corresponding state attribute based on channel type
122+ self ._set_initial_channel_value (light_channel , default_value )
123+
124+ def _set_initial_channel_value (self , light_channel : LightChannel , value : int ):
125+ """Set the initial value for a channel based on its type."""
126+ if light_channel == LightChannel .RED :
127+ self ._rgb_color = (value , self ._rgb_color [1 ], self ._rgb_color [2 ])
128+ self ._rgbw_color = (value , self ._rgbw_color [1 ], self ._rgbw_color [2 ], self ._rgbw_color [3 ])
129+ self ._rgbww_color = (value , self ._rgbww_color [1 ], self ._rgbww_color [2 ],
130+ self ._rgbww_color [3 ], self ._rgbww_color [4 ])
131+ elif light_channel == LightChannel .GREEN :
132+ self ._rgb_color = (self ._rgb_color [0 ], value , self ._rgb_color [2 ])
133+ self ._rgbw_color = (self ._rgbw_color [0 ], value , self ._rgbw_color [2 ], self ._rgbw_color [3 ])
134+ self ._rgbww_color = (self ._rgbww_color [0 ], value , self ._rgbww_color [2 ],
135+ self ._rgbww_color [3 ], self ._rgbww_color [4 ])
136+ elif light_channel == LightChannel .BLUE :
137+ self ._rgb_color = (self ._rgb_color [0 ], self ._rgb_color [1 ], value )
138+ self ._rgbw_color = (self ._rgbw_color [0 ], self ._rgbw_color [1 ], value , self ._rgbw_color [3 ])
139+ self ._rgbww_color = (self ._rgbww_color [0 ], self ._rgbww_color [1 ], value ,
140+ self ._rgbww_color [3 ], self ._rgbww_color [4 ])
141+ elif light_channel == LightChannel .COLD_WHITE :
142+ self ._cold_white = value
143+ self ._rgbw_color = (self ._rgbw_color [0 ], self ._rgbw_color [1 ], self ._rgbw_color [2 ], value )
144+ self ._rgbww_color = (self ._rgbww_color [0 ], self ._rgbww_color [1 ], self ._rgbww_color [2 ],
145+ value , self ._rgbww_color [4 ])
146+ elif light_channel == LightChannel .WARM_WHITE :
147+ self ._warm_white = value
148+ self ._rgbww_color = (self ._rgbww_color [0 ], self ._rgbww_color [1 ], self ._rgbww_color [2 ],
149+ self ._rgbww_color [3 ], value )
150+ elif light_channel == LightChannel .COLOR_TEMPERATURE :
151+ self ._color_temp_value = value
152+ # Convert DMX value to mired color temperature
153+ if hasattr (self , "min_mireds" ) and hasattr (self , "max_mireds" ):
154+ ratio = value / 255
155+ self ._color_temp = self .min_mireds + ratio * (self .max_mireds - self .min_mireds )
156+ elif light_channel == LightChannel .DIMMER :
157+ self ._brightness = value
158+ # If value > 0, also set state to True
159+ if value > 0 :
160+ self ._state = True
161+
102162 def _setup_turn_on_handlers (self ):
103163 """Pre-configure optimized handlers for different turn_on scenarios."""
104164 self ._turn_on_handlers = {}
@@ -471,4 +531,4 @@ async def _update_channel_value(self, channel_data: AccumulatedLightChannel, val
471531
472532 # Update all associated DMX channels (some light channels may use multiple DMX channels)
473533 for dmx_index in channel_data .dmx_channel_indexes :
474- await channel_data .universe .update_value (dmx_index , dmx_value )
534+ await channel_data .universe .update_value (dmx_index , dmx_value )
0 commit comments