@@ -124,25 +124,34 @@ async def async_turn_on(self, **kwargs):
124124 brightness = kwargs .get ("brightness" , 255 )
125125 rgbw_color = kwargs .get ("rgbw_color" , (255 , 255 , 255 , 255 ))
126126
127- # Convert to device scale (0-100) - only do this once!
128- white = min (100 , max (0 , round ( rgbw_color [3 ] / 2.55 ) ))
129- blue = min (100 , max (0 , round ( rgbw_color [2 ] / 2.55 ) ))
130- green = min (100 , max (0 , round ( rgbw_color [1 ] / 2.55 ) ))
131- red = min (100 , max (0 , round ( rgbw_color [0 ] / 2.55 ) ))
127+ # Convert to device scale (0-100)
128+ white = min (100 , max (0 , rgbw_color [3 ] / 2.55 ))
129+ blue = min (100 , max (0 , rgbw_color [2 ] / 2.55 ))
130+ green = min (100 , max (0 , rgbw_color [1 ] / 2.55 ))
131+ red = min (100 , max (0 , rgbw_color [0 ] / 2.55 ))
132132
133133 # Apply brightness scaling if needed
134134 if brightness < 255 :
135135 scale = brightness / 255.0
136- white = min (100 , round ( white * scale ) )
137- blue = min (100 , round ( blue * scale ) )
138- green = min (100 , round ( green * scale ) )
139- red = min (100 , round ( red * scale ) )
136+ white = min (100 , white * scale )
137+ blue = min (100 , blue * scale )
138+ green = min (100 , green * scale )
139+ red = min (100 , red * scale )
140140
141141 _LOGGER .debug ("Setting light to W:%d B:%d G:%d R:%d" , white , blue , green , red )
142142
143+ # Enable manual override for 5 seconds
144+ await self .coordinator .set_manual_override (True , 5 )
145+
143146 try :
144- # Set the light state - values are already in 0-100 range
145- await self ._controller .start_manual_color_simulation (1439 )
147+ # Set the light state
148+ #await self._controller.start_manual_color_simulation(1439)
149+ # duration_hours = self.hass.states.get(f"number.{self._attr_unique_id}_manual_color_simulation_duration").state
150+ duration_hours = self .coordinator .data .get ("manual_color_simulation_duration" , 12 )
151+ duration_minutes = int (float (duration_hours ) * 60 )
152+ _LOGGER .debug ("Manual Hours: %s Manual Minutes: %s" , duration_hours , duration_minutes )
153+ # Set the light state with the configured duration
154+ await self ._controller .start_manual_color_simulation (duration_minutes )
146155 await self ._controller .set_manual_color (white , blue , green , red )
147156
148157 # Update local state immediately
@@ -153,15 +162,18 @@ async def async_turn_on(self, **kwargs):
153162
154163 except Exception as e :
155164 _LOGGER .error ("Error setting light state: %s" , e )
165+ await self .coordinator .set_manual_override (False )
156166 raise
157167
158168 async def async_turn_off (self , ** kwargs ):
159169 """Turn the light off."""
160170 _LOGGER .debug ("Turning off Juwel Helialux light" )
161- await self ._controller .start_manual_color_simulation (1439 )
171+ duration_hours = self .coordinator .data .get ("manual_color_simulation_duration" , 12 ) # default 12 hours
172+ duration_minutes = int (duration_hours * 60 )
173+ await self ._controller .start_manual_color_simulation (duration_minutes )
162174 await self ._controller .set_manual_color (0 , 0 , 0 , 0 )
163175 self ._attr_is_on = False
164176 self ._attr_brightness = 0
165177 self ._attr_rgbw_color = (0 , 0 , 0 , 0 )
166178
167- self .async_write_ha_state ()
179+ self .async_write_ha_state ()
0 commit comments