|
8 | 8 |
|
9 | 9 | from homeassistant.components.light import ( |
10 | 10 | ATTR_BRIGHTNESS, |
11 | | - ATTR_COLOR_TEMP, |
| 11 | + ATTR_COLOR_TEMP_KELVIN, |
12 | 12 | ATTR_HS_COLOR, |
13 | 13 | SUPPORT_BRIGHTNESS, |
14 | 14 | SUPPORT_COLOR, |
|
23 | 23 | DOMAIN, |
24 | 24 | CONF_OFFLINE_IS_OFF, |
25 | 25 | CONF_USE_ASSUMED_STATE, |
26 | | - COLOR_TEMP_KELVIN_MIN, |
27 | | - COLOR_TEMP_KELVIN_MAX, |
28 | 26 | ) |
29 | 27 |
|
30 | 28 |
|
@@ -186,15 +184,16 @@ async def async_turn_on(self, **kwargs): |
186 | 184 | just_turn_on = False |
187 | 185 | bright_set = brightness - 1 |
188 | 186 | _, err = await self._hub.set_brightness(self._device, bright_set) |
189 | | - if ATTR_COLOR_TEMP in kwargs: |
190 | | - color_temp = kwargs.pop(ATTR_COLOR_TEMP) |
| 187 | + if ATTR_COLOR_TEMP_KELVIN in kwargs: |
| 188 | + color_temp = kwargs.pop(ATTR_COLOR_TEMP_KELVIN) |
191 | 189 | just_turn_on = False |
192 | | - color_temp_kelvin = color.color_temperature_mired_to_kelvin(color_temp) |
193 | | - if color_temp_kelvin > COLOR_TEMP_KELVIN_MAX: |
194 | | - color_temp_kelvin = COLOR_TEMP_KELVIN_MAX |
195 | | - elif color_temp_kelvin < COLOR_TEMP_KELVIN_MIN: |
196 | | - color_temp_kelvin = COLOR_TEMP_KELVIN_MIN |
197 | | - _, err = await self._hub.set_color_temp(self._device, color_temp_kelvin) |
| 190 | + color_temp_clamped = min( |
| 191 | + self._device.color_temp_max, |
| 192 | + max(color_temp, self._device.color_temp_min) |
| 193 | + ) |
| 194 | + _, err = await self._hub.set_color_temp( |
| 195 | + self._device, color_temp_clamped |
| 196 | + ) |
198 | 197 |
|
199 | 198 | # if there is no known specific command - turn on |
200 | 199 | if just_turn_on: |
@@ -291,21 +290,19 @@ def brightness(self): |
291 | 290 | return self._device.brightness + 1 |
292 | 291 |
|
293 | 292 | @property |
294 | | - def color_temp(self): |
| 293 | + def color_temp_kelvin(self): |
295 | 294 | """Return the color_temp of the light.""" |
296 | | - if not self._device.color_temp: |
297 | | - return None |
298 | | - return color.color_temperature_kelvin_to_mired(self._device.color_temp) |
| 295 | + return self._device.color_temp or None |
299 | 296 |
|
300 | 297 | @property |
301 | | - def min_mireds(self): |
302 | | - """Return the coldest color_temp that this light supports.""" |
303 | | - return color.color_temperature_kelvin_to_mired(COLOR_TEMP_KELVIN_MAX) |
| 298 | + def min_color_temp_kelvin(self): |
| 299 | + """Return the warmest color_temp that this light supports.""" |
| 300 | + return self._device.color_temp_min |
304 | 301 |
|
305 | 302 | @property |
306 | | - def max_mireds(self): |
307 | | - """Return the warmest color_temp that this light supports.""" |
308 | | - return color.color_temperature_kelvin_to_mired(COLOR_TEMP_KELVIN_MIN) |
| 303 | + def max_color_temp_kelvin(self): |
| 304 | + """Return the coldest color_temp that this light supports.""" |
| 305 | + return self._device.color_temp_max |
309 | 306 |
|
310 | 307 | @property |
311 | 308 | def extra_state_attributes(self): |
|
0 commit comments