diff --git a/custom_components/govee/const.py b/custom_components/govee/const.py index 9b90feb..0ffc9bc 100644 --- a/custom_components/govee/const.py +++ b/custom_components/govee/const.py @@ -5,6 +5,3 @@ CONF_DISABLE_ATTRIBUTE_UPDATES = "disable_attribute_updates" CONF_OFFLINE_IS_OFF = "offline_is_off" CONF_USE_ASSUMED_STATE = "use_assumed_state" - -COLOR_TEMP_KELVIN_MIN = 2000 -COLOR_TEMP_KELVIN_MAX = 9000 diff --git a/custom_components/govee/light.py b/custom_components/govee/light.py index aeb9d7d..661f41c 100644 --- a/custom_components/govee/light.py +++ b/custom_components/govee/light.py @@ -8,7 +8,7 @@ from homeassistant.components.light import ( ATTR_BRIGHTNESS, - ATTR_COLOR_TEMP, + ATTR_COLOR_TEMP_KELVIN, ATTR_HS_COLOR, SUPPORT_BRIGHTNESS, SUPPORT_COLOR, @@ -23,8 +23,6 @@ DOMAIN, CONF_OFFLINE_IS_OFF, CONF_USE_ASSUMED_STATE, - COLOR_TEMP_KELVIN_MIN, - COLOR_TEMP_KELVIN_MAX, ) @@ -186,15 +184,16 @@ async def async_turn_on(self, **kwargs): just_turn_on = False bright_set = brightness - 1 _, err = await self._hub.set_brightness(self._device, bright_set) - if ATTR_COLOR_TEMP in kwargs: - color_temp = kwargs.pop(ATTR_COLOR_TEMP) + if ATTR_COLOR_TEMP_KELVIN in kwargs: + color_temp = kwargs.pop(ATTR_COLOR_TEMP_KELVIN) just_turn_on = False - color_temp_kelvin = color.color_temperature_mired_to_kelvin(color_temp) - if color_temp_kelvin > COLOR_TEMP_KELVIN_MAX: - color_temp_kelvin = COLOR_TEMP_KELVIN_MAX - elif color_temp_kelvin < COLOR_TEMP_KELVIN_MIN: - color_temp_kelvin = COLOR_TEMP_KELVIN_MIN - _, err = await self._hub.set_color_temp(self._device, color_temp_kelvin) + color_temp_clamped = min( + self._device.color_temp_max, + max(color_temp, self._device.color_temp_min) + ) + _, err = await self._hub.set_color_temp( + self._device, color_temp_clamped + ) # if there is no known specific command - turn on if just_turn_on: @@ -291,21 +290,19 @@ def brightness(self): return self._device.brightness + 1 @property - def color_temp(self): + def color_temp_kelvin(self): """Return the color_temp of the light.""" - if not self._device.color_temp: - return None - return color.color_temperature_kelvin_to_mired(self._device.color_temp) + return self._device.color_temp or None @property - def min_mireds(self): - """Return the coldest color_temp that this light supports.""" - return color.color_temperature_kelvin_to_mired(COLOR_TEMP_KELVIN_MAX) + def min_color_temp_kelvin(self): + """Return the warmest color_temp that this light supports.""" + return self._device.color_temp_min @property - def max_mireds(self): - """Return the warmest color_temp that this light supports.""" - return color.color_temperature_kelvin_to_mired(COLOR_TEMP_KELVIN_MIN) + def max_color_temp_kelvin(self): + """Return the coldest color_temp that this light supports.""" + return self._device.color_temp_max @property def extra_state_attributes(self):