From e6e51dac7668f2b44bc065c41932640097d2c26d Mon Sep 17 00:00:00 2001 From: Bas Nijholt Date: Mon, 28 Sep 2020 16:31:41 +0200 Subject: [PATCH] always use color_temp over rgb --- custom_components/adaptive_lighting/const.py | 7 +++++-- custom_components/adaptive_lighting/switch.py | 17 +++++++++++------ 2 files changed, 16 insertions(+), 8 deletions(-) diff --git a/custom_components/adaptive_lighting/const.py b/custom_components/adaptive_lighting/const.py index d194efc8..f49188ab 100644 --- a/custom_components/adaptive_lighting/const.py +++ b/custom_components/adaptive_lighting/const.py @@ -16,7 +16,10 @@ CONF_DISABLE_BRIGHTNESS_ADJUST, DEFAULT_DISABLE_BRIGHTNESS_ADJUST = ( "disable_brightness_adjust", False, ) -CONF_DISABLE_COLOR_ADJUST, DEFAULT_DISABLE_COLOR_ADJUST = "disable_color_adjust", False +CONF_DISABLE_COLOR_TEMP_ADJUST, DEFAULT_DISABLE_COLOR_TEMP_ADJUST = ( + "disable_color_temp_adjust", + False, +) CONF_DISABLE_ENTITY = "disable_entity" CONF_DISABLE_STATE = "disable_state" CONF_INITIAL_TRANSITION, DEFAULT_INITIAL_TRANSITION = "initial_transition", 1 @@ -55,7 +58,7 @@ def int_between(min_int, max_int): VALIDATION_TUPLES = [ (CONF_LIGHTS, DEFAULT_LIGHTS, cv.entity_ids), (CONF_DISABLE_BRIGHTNESS_ADJUST, DEFAULT_DISABLE_BRIGHTNESS_ADJUST, bool), - (CONF_DISABLE_COLOR_ADJUST, DEFAULT_DISABLE_COLOR_ADJUST, bool), + (CONF_DISABLE_COLOR_TEMP_ADJUST, DEFAULT_DISABLE_COLOR_TEMP_ADJUST, bool), (CONF_DISABLE_ENTITY, NONE_STR, cv.entity_id), (CONF_DISABLE_STATE, NONE_STR, str), (CONF_INITIAL_TRANSITION, DEFAULT_INITIAL_TRANSITION, VALID_TRANSITION), diff --git a/custom_components/adaptive_lighting/switch.py b/custom_components/adaptive_lighting/switch.py index 9f28be3c..93d7955a 100755 --- a/custom_components/adaptive_lighting/switch.py +++ b/custom_components/adaptive_lighting/switch.py @@ -60,7 +60,7 @@ from .const import ( ATTR_TURN_ON_OFF_LISTENER, CONF_COLORS_ONLY, CONF_DISABLE_BRIGHTNESS_ADJUST, - CONF_DISABLE_COLOR_ADJUST, + CONF_DISABLE_COLOR_TEMP_ADJUST, CONF_DISABLE_ENTITY, CONF_DISABLE_STATE, CONF_INITIAL_TRANSITION, @@ -182,7 +182,7 @@ class AdaptiveSwitch(SwitchEntity, RestoreEntity): self._name = data[CONF_NAME] self._lights = data[CONF_LIGHTS] self._disable_brightness_adjust = data[CONF_DISABLE_BRIGHTNESS_ADJUST] - self._disable_color_adjust = data[CONF_DISABLE_COLOR_ADJUST] + self._disable_color_temp_adjust = data[CONF_DISABLE_COLOR_TEMP_ADJUST] self._disable_entity = data[CONF_DISABLE_ENTITY] self._disable_state = data[CONF_DISABLE_STATE] self._initial_transition = data[CONF_INITIAL_TRANSITION] @@ -469,10 +469,13 @@ class AdaptiveSwitch(SwitchEntity, RestoreEntity): ): service_data[ATTR_BRIGHTNESS_PCT] = self._brightness - if "color" in features and not self._disable_color_adjust: + if "color_temp" in features and not self._disable_color_temp_adjust: + attributes = self.hass.states.get(light).attributes + min_mireds, max_mireds = attributes["min_mireds"], attributes["max_mireds"] + color_temp_mired = max(min(self._color_temp_mired, max_mireds), min_mireds) + service_data[ATTR_COLOR_TEMP] = color_temp_mired + elif "color" in features: service_data[ATTR_RGB_COLOR] = self._rgb_color - elif "color_temp" in features: - service_data[ATTR_COLOR_TEMP] = self._color_temp_mired _LOGGER.debug( "%s: Scheduling 'light.turn_on' with the following 'service_data': %s", @@ -623,7 +626,9 @@ class TurnOnOffListener: for _ in range(3): # It can happen that the actual transition time is longer than the # specified time in the 'turn_off' service. - await asyncio.sleep(delay) + await asyncio.sleep( + delay + ) # TODO: cancel this somehow when 'turn_on' event happens if not is_on(self.hass, entity_id): return True delay = TURNING_OFF_DELAY # next time only wait this long