Add configurable color datapoint (#4383)

* Add configurable color datapoint

* Lint fixes

* Review comments

* Linting
This commit is contained in:
irtimaled
2023-02-19 13:50:46 -08:00
committed by GitHub
parent 5c49730cb9
commit f68d577986
3 changed files with 97 additions and 63 deletions
+22 -8
View File
@@ -23,9 +23,23 @@ CONF_COLOR_TEMPERATURE_INVERT = "color_temperature_invert"
CONF_COLOR_TEMPERATURE_MAX_VALUE = "color_temperature_max_value"
CONF_RGB_DATAPOINT = "rgb_datapoint"
CONF_HSV_DATAPOINT = "hsv_datapoint"
CONF_COLOR_DATAPOINT = "color_datapoint"
CONF_COLOR_TYPE = "color_type"
TuyaColorType = tuya_ns.enum("TuyaColorType")
COLOR_TYPES = {
"RGB": TuyaColorType.RGB,
"HSV": TuyaColorType.HSV,
"RGBHSV": TuyaColorType.RGBHSV,
}
TuyaLight = tuya_ns.class_("TuyaLight", light.LightOutput, cg.Component)
COLOR_CONFIG_ERROR = (
"This option has been removed, use color_datapoint and color_type instead."
)
CONFIG_SCHEMA = cv.All(
light.BRIGHTNESS_ONLY_LIGHT_SCHEMA.extend(
{
@@ -34,8 +48,10 @@ CONFIG_SCHEMA = cv.All(
cv.Optional(CONF_DIMMER_DATAPOINT): cv.uint8_t,
cv.Optional(CONF_MIN_VALUE_DATAPOINT): cv.uint8_t,
cv.Optional(CONF_SWITCH_DATAPOINT): cv.uint8_t,
cv.Exclusive(CONF_RGB_DATAPOINT, "color"): cv.uint8_t,
cv.Exclusive(CONF_HSV_DATAPOINT, "color"): cv.uint8_t,
cv.Optional(CONF_RGB_DATAPOINT): cv.invalid(COLOR_CONFIG_ERROR),
cv.Optional(CONF_HSV_DATAPOINT): cv.invalid(COLOR_CONFIG_ERROR),
cv.Inclusive(CONF_COLOR_DATAPOINT, "color"): cv.uint8_t,
cv.Inclusive(CONF_COLOR_TYPE, "color"): cv.enum(COLOR_TYPES, upper=True),
cv.Optional(CONF_COLOR_INTERLOCK, default=False): cv.boolean,
cv.Inclusive(
CONF_COLOR_TEMPERATURE_DATAPOINT, "color_temperature"
@@ -61,8 +77,7 @@ CONFIG_SCHEMA = cv.All(
cv.has_at_least_one_key(
CONF_DIMMER_DATAPOINT,
CONF_SWITCH_DATAPOINT,
CONF_RGB_DATAPOINT,
CONF_HSV_DATAPOINT,
CONF_COLOR_DATAPOINT,
),
)
@@ -78,10 +93,9 @@ async def to_code(config):
cg.add(var.set_min_value_datapoint_id(config[CONF_MIN_VALUE_DATAPOINT]))
if CONF_SWITCH_DATAPOINT in config:
cg.add(var.set_switch_id(config[CONF_SWITCH_DATAPOINT]))
if CONF_RGB_DATAPOINT in config:
cg.add(var.set_rgb_id(config[CONF_RGB_DATAPOINT]))
elif CONF_HSV_DATAPOINT in config:
cg.add(var.set_hsv_id(config[CONF_HSV_DATAPOINT]))
if CONF_COLOR_DATAPOINT in config:
cg.add(var.set_color_id(config[CONF_COLOR_DATAPOINT]))
cg.add(var.set_color_type(config[CONF_COLOR_TYPE]))
if CONF_COLOR_TEMPERATURE_DATAPOINT in config:
cg.add(var.set_color_temperature_id(config[CONF_COLOR_TEMPERATURE_DATAPOINT]))
cg.add(var.set_color_temperature_invert(config[CONF_COLOR_TEMPERATURE_INVERT]))