Tuya rgb support (#2278)

Co-authored-by: Oxan van Leeuwen <oxan@oxanvanleeuwen.nl>
Co-authored-by: Jesse Hills <3060199+jesserockz@users.noreply.github.com>
This commit is contained in:
irtimaled
2021-09-26 01:34:06 -07:00
committed by GitHub
parent bdcffc7ba9
commit 7246f42a8e
9 changed files with 129 additions and 30 deletions
+11 -1
View File
@@ -10,6 +10,7 @@ from esphome.const import (
CONF_SWITCH_DATAPOINT,
CONF_COLD_WHITE_COLOR_TEMPERATURE,
CONF_WARM_WHITE_COLOR_TEMPERATURE,
CONF_COLOR_INTERLOCK,
)
from .. import tuya_ns, CONF_TUYA_ID, Tuya
@@ -20,6 +21,7 @@ CONF_MIN_VALUE_DATAPOINT = "min_value_datapoint"
CONF_COLOR_TEMPERATURE_DATAPOINT = "color_temperature_datapoint"
CONF_COLOR_TEMPERATURE_INVERT = "color_temperature_invert"
CONF_COLOR_TEMPERATURE_MAX_VALUE = "color_temperature_max_value"
CONF_RGB_DATAPOINT = "rgb_datapoint"
TuyaLight = tuya_ns.class_("TuyaLight", light.LightOutput, cg.Component)
@@ -31,6 +33,8 @@ 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.Optional(CONF_RGB_DATAPOINT): cv.uint8_t,
cv.Optional(CONF_COLOR_INTERLOCK, default=False): cv.boolean,
cv.Inclusive(
CONF_COLOR_TEMPERATURE_DATAPOINT, "color_temperature"
): cv.uint8_t,
@@ -52,7 +56,9 @@ CONFIG_SCHEMA = cv.All(
): cv.positive_time_period_milliseconds,
}
).extend(cv.COMPONENT_SCHEMA),
cv.has_at_least_one_key(CONF_DIMMER_DATAPOINT, CONF_SWITCH_DATAPOINT),
cv.has_at_least_one_key(
CONF_DIMMER_DATAPOINT, CONF_SWITCH_DATAPOINT, CONF_RGB_DATAPOINT
),
)
@@ -67,6 +73,8 @@ 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]))
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]))
@@ -87,5 +95,7 @@ async def to_code(config):
config[CONF_COLOR_TEMPERATURE_MAX_VALUE]
)
)
cg.add(var.set_color_interlock(config[CONF_COLOR_INTERLOCK]))
paren = await cg.get_variable(config[CONF_TUYA_ID])
cg.add(var.set_tuya_parent(paren))