Skip to content

Commit 09f8abe

Browse files
committed
Respect device light temperature boundary
While at it, also migrate from using deprecated Mireds to supporting Kelvin natively.
1 parent 52d3bc0 commit 09f8abe

File tree

2 files changed

+18
-24
lines changed

2 files changed

+18
-24
lines changed

custom_components/govee/const.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,3 @@
55
CONF_DISABLE_ATTRIBUTE_UPDATES = "disable_attribute_updates"
66
CONF_OFFLINE_IS_OFF = "offline_is_off"
77
CONF_USE_ASSUMED_STATE = "use_assumed_state"
8-
9-
COLOR_TEMP_KELVIN_MIN = 2000
10-
COLOR_TEMP_KELVIN_MAX = 9000

custom_components/govee/light.py

Lines changed: 18 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
from homeassistant.components.light import (
1010
ATTR_BRIGHTNESS,
11-
ATTR_COLOR_TEMP,
11+
ATTR_COLOR_TEMP_KELVIN,
1212
ATTR_HS_COLOR,
1313
SUPPORT_BRIGHTNESS,
1414
SUPPORT_COLOR,
@@ -23,8 +23,6 @@
2323
DOMAIN,
2424
CONF_OFFLINE_IS_OFF,
2525
CONF_USE_ASSUMED_STATE,
26-
COLOR_TEMP_KELVIN_MIN,
27-
COLOR_TEMP_KELVIN_MAX,
2826
)
2927

3028

@@ -186,15 +184,16 @@ async def async_turn_on(self, **kwargs):
186184
just_turn_on = False
187185
bright_set = brightness - 1
188186
_, 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)
191189
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+
)
198197

199198
# if there is no known specific command - turn on
200199
if just_turn_on:
@@ -291,21 +290,19 @@ def brightness(self):
291290
return self._device.brightness + 1
292291

293292
@property
294-
def color_temp(self):
293+
def color_temp_kelvin(self):
295294
"""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
299296

300297
@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
304301

305302
@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
309306

310307
@property
311308
def extra_state_attributes(self):

0 commit comments

Comments
 (0)