always use color_temp over rgb

This commit is contained in:
Bas Nijholt 2020-09-28 16:31:41 +02:00
commit e6e51dac76
2 changed files with 16 additions and 8 deletions

View file

@ -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),

View file

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