diff --git a/custom_components/localtuya/light.py b/custom_components/localtuya/light.py index 5a33192..7c74e49 100644 --- a/custom_components/localtuya/light.py +++ b/custom_components/localtuya/light.py @@ -377,16 +377,17 @@ class LocaltuyaLight(LocalTuyaEntity, LightEntity): if ATTR_COLOR_TEMP in kwargs and (features & SUPPORT_COLOR_TEMP): if brightness is None: brightness = self._brightness - color_temp_value = ( - (self._max_mired - self._min_mired) - - (int(kwargs[ATTR_COLOR_TEMP]) - self._min_mired) - if self._color_temp_reverse - else (int(kwargs[ATTR_COLOR_TEMP]) - self._min_mired) - ) + mired = int(kwargs[ATTR_COLOR_TEMP]) + if self._color_temp_reverse: + mired = self._max_mired - (mired - self._min_mired) + if mired < self._min_mired: + mired = self._min_mired + elif mired > self._max_mired: + mired = self._max_mired color_temp = int( self._upper_color_temp - (self._upper_color_temp / (self._max_mired - self._min_mired)) - * color_temp_value + * (mired - self._min_mired) ) states[self._config.get(CONF_COLOR_MODE)] = MODE_WHITE states[self._config.get(CONF_BRIGHTNESS)] = brightness