Merge pull request #27 from forstermatth/white-value-brightness

feat: add white value to service data
This commit is contained in:
Bas Nijholt 2020-10-27 16:51:08 +01:00 committed by GitHub
commit f97ccac857
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -22,6 +22,7 @@ from homeassistant.components.light import (
ATTR_BRIGHTNESS_PCT,
ATTR_BRIGHTNESS_STEP,
ATTR_BRIGHTNESS_STEP_PCT,
ATTR_WHITE_VALUE,
ATTR_COLOR_NAME,
ATTR_COLOR_TEMP,
ATTR_HS_COLOR,
@ -35,6 +36,7 @@ from homeassistant.components.light import (
SUPPORT_COLOR,
SUPPORT_COLOR_TEMP,
SUPPORT_TRANSITION,
SUPPORT_WHITE_VALUE,
VALID_TRANSITION,
is_on,
)
@ -122,6 +124,7 @@ from .const import (
_SUPPORT_OPTS = {
"brightness": SUPPORT_BRIGHTNESS,
"white_value": SUPPORT_WHITE_VALUE,
"color_temp": SUPPORT_COLOR_TEMP,
"color": SUPPORT_COLOR,
"transition": SUPPORT_TRANSITION,
@ -145,12 +148,12 @@ COLOR_ATTRS = { # Should ATTR_PROFILE be in here?
ATTR_HS_COLOR,
ATTR_KELVIN,
ATTR_RGB_COLOR,
ATTR_WHITE_VALUE, # Should this be here?
ATTR_XY_COLOR,
}
BRIGHTNESS_ATTRS = {
ATTR_BRIGHTNESS,
ATTR_WHITE_VALUE, # White value is treated the same as brightness in all respects
ATTR_BRIGHTNESS_PCT,
ATTR_BRIGHTNESS_STEP,
ATTR_BRIGHTNESS_STEP_PCT,
@ -386,6 +389,24 @@ def _attributes_have_changed(
)
return True
if (
adapt_brightness
and ATTR_WHITE_VALUE in old_attributes
and ATTR_WHITE_VALUE in new_attributes
):
last_white_value = old_attributes[ATTR_WHITE_VALUE]
current_white_value = new_attributes[ATTR_WHITE_VALUE]
if abs(current_white_value - last_white_value) > BRIGHTNESS_CHANGE:
_LOGGER.debug(
"White Value of '%s' significantly changed from %s to %s with"
" context.id='%s'",
light,
last_white_value,
current_white_value,
context.id,
)
return True
if (
adapt_color
and ATTR_COLOR_TEMP in old_attributes
@ -684,6 +705,10 @@ class AdaptiveSwitch(SwitchEntity, RestoreEntity):
brightness = round(255 * self._settings["brightness_pct"] / 100)
service_data[ATTR_BRIGHTNESS] = brightness
if "white_value" in features and adapt_brightness:
white_value = round(255 * self._settings["brightness_pct"] / 100)
service_data[ATTR_WHITE_VALUE] = white_value
if (
"color_temp" in features
and adapt_color