mirror of
https://github.com/esphome/esphome.git
synced 2026-02-08 00:31:58 +00:00
[tuya] add color_type_lowercase option (#13101)
Co-authored-by: lullius <>
This commit is contained in:
@@ -26,6 +26,7 @@ CONF_RGB_DATAPOINT = "rgb_datapoint"
|
|||||||
CONF_HSV_DATAPOINT = "hsv_datapoint"
|
CONF_HSV_DATAPOINT = "hsv_datapoint"
|
||||||
CONF_COLOR_DATAPOINT = "color_datapoint"
|
CONF_COLOR_DATAPOINT = "color_datapoint"
|
||||||
CONF_COLOR_TYPE = "color_type"
|
CONF_COLOR_TYPE = "color_type"
|
||||||
|
CONF_COLOR_TYPE_LOWERCASE = "color_type_lowercase"
|
||||||
|
|
||||||
TuyaColorType = tuya_ns.enum("TuyaColorType")
|
TuyaColorType = tuya_ns.enum("TuyaColorType")
|
||||||
|
|
||||||
@@ -47,6 +48,7 @@ CONFIG_SCHEMA = cv.All(
|
|||||||
cv.Optional(CONF_SWITCH_DATAPOINT): cv.uint8_t,
|
cv.Optional(CONF_SWITCH_DATAPOINT): cv.uint8_t,
|
||||||
cv.Inclusive(CONF_COLOR_DATAPOINT, "color"): cv.uint8_t,
|
cv.Inclusive(CONF_COLOR_DATAPOINT, "color"): cv.uint8_t,
|
||||||
cv.Inclusive(CONF_COLOR_TYPE, "color"): cv.enum(COLOR_TYPES, upper=True),
|
cv.Inclusive(CONF_COLOR_TYPE, "color"): cv.enum(COLOR_TYPES, upper=True),
|
||||||
|
cv.Optional(CONF_COLOR_TYPE_LOWERCASE, default=False): cv.boolean,
|
||||||
cv.Optional(CONF_COLOR_INTERLOCK, default=False): cv.boolean,
|
cv.Optional(CONF_COLOR_INTERLOCK, default=False): cv.boolean,
|
||||||
cv.Inclusive(
|
cv.Inclusive(
|
||||||
CONF_COLOR_TEMPERATURE_DATAPOINT, "color_temperature"
|
CONF_COLOR_TEMPERATURE_DATAPOINT, "color_temperature"
|
||||||
@@ -91,6 +93,7 @@ async def to_code(config):
|
|||||||
if CONF_COLOR_DATAPOINT in config:
|
if CONF_COLOR_DATAPOINT in config:
|
||||||
cg.add(var.set_color_id(config[CONF_COLOR_DATAPOINT]))
|
cg.add(var.set_color_id(config[CONF_COLOR_DATAPOINT]))
|
||||||
cg.add(var.set_color_type(config[CONF_COLOR_TYPE]))
|
cg.add(var.set_color_type(config[CONF_COLOR_TYPE]))
|
||||||
|
cg.add(var.set_color_type_lowercase(config[CONF_COLOR_TYPE_LOWERCASE]))
|
||||||
if CONF_COLOR_TEMPERATURE_DATAPOINT in config:
|
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_id(config[CONF_COLOR_TEMPERATURE_DATAPOINT]))
|
||||||
cg.add(var.set_color_temperature_invert(config[CONF_COLOR_TEMPERATURE_INVERT]))
|
cg.add(var.set_color_temperature_invert(config[CONF_COLOR_TEMPERATURE_INVERT]))
|
||||||
|
|||||||
@@ -190,7 +190,8 @@ void TuyaLight::write_state(light::LightState *state) {
|
|||||||
switch (*this->color_type_) {
|
switch (*this->color_type_) {
|
||||||
case TuyaColorType::RGB: {
|
case TuyaColorType::RGB: {
|
||||||
char buffer[7];
|
char buffer[7];
|
||||||
sprintf(buffer, "%02X%02X%02X", int(red * 255), int(green * 255), int(blue * 255));
|
const char *format_str = this->color_type_lowercase_ ? "%02x%02x%02x" : "%02X%02X%02X";
|
||||||
|
sprintf(buffer, format_str, int(red * 255), int(green * 255), int(blue * 255));
|
||||||
color_value = buffer;
|
color_value = buffer;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@@ -199,7 +200,8 @@ void TuyaLight::write_state(light::LightState *state) {
|
|||||||
float saturation, value;
|
float saturation, value;
|
||||||
rgb_to_hsv(red, green, blue, hue, saturation, value);
|
rgb_to_hsv(red, green, blue, hue, saturation, value);
|
||||||
char buffer[13];
|
char buffer[13];
|
||||||
sprintf(buffer, "%04X%04X%04X", hue, int(saturation * 1000), int(value * 1000));
|
const char *format_str = this->color_type_lowercase_ ? "%04x%04x%04x" : "%04X%04X%04X";
|
||||||
|
sprintf(buffer, format_str, hue, int(saturation * 1000), int(value * 1000));
|
||||||
color_value = buffer;
|
color_value = buffer;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@@ -208,8 +210,9 @@ void TuyaLight::write_state(light::LightState *state) {
|
|||||||
float saturation, value;
|
float saturation, value;
|
||||||
rgb_to_hsv(red, green, blue, hue, saturation, value);
|
rgb_to_hsv(red, green, blue, hue, saturation, value);
|
||||||
char buffer[15];
|
char buffer[15];
|
||||||
sprintf(buffer, "%02X%02X%02X%04X%02X%02X", int(red * 255), int(green * 255), int(blue * 255), hue,
|
const char *format_str = this->color_type_lowercase_ ? "%02x%02x%02x%04x%02x%02x" : "%02X%02X%02X%04X%02X%02X";
|
||||||
int(saturation * 255), int(value * 255));
|
sprintf(buffer, format_str, int(red * 255), int(green * 255), int(blue * 255), hue, int(saturation * 255),
|
||||||
|
int(value * 255));
|
||||||
color_value = buffer;
|
color_value = buffer;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,11 +7,7 @@
|
|||||||
namespace esphome {
|
namespace esphome {
|
||||||
namespace tuya {
|
namespace tuya {
|
||||||
|
|
||||||
enum TuyaColorType {
|
enum TuyaColorType { RGB, HSV, RGBHSV };
|
||||||
RGB,
|
|
||||||
HSV,
|
|
||||||
RGBHSV,
|
|
||||||
};
|
|
||||||
|
|
||||||
class TuyaLight : public Component, public light::LightOutput {
|
class TuyaLight : public Component, public light::LightOutput {
|
||||||
public:
|
public:
|
||||||
@@ -28,6 +24,7 @@ class TuyaLight : public Component, public light::LightOutput {
|
|||||||
void set_color_temperature_invert(bool color_temperature_invert) {
|
void set_color_temperature_invert(bool color_temperature_invert) {
|
||||||
this->color_temperature_invert_ = color_temperature_invert;
|
this->color_temperature_invert_ = color_temperature_invert;
|
||||||
}
|
}
|
||||||
|
void set_color_type_lowercase(bool color_type_lowercase) { this->color_type_lowercase_ = color_type_lowercase; }
|
||||||
void set_tuya_parent(Tuya *parent) { this->parent_ = parent; }
|
void set_tuya_parent(Tuya *parent) { this->parent_ = parent; }
|
||||||
void set_min_value(uint32_t min_value) { min_value_ = min_value; }
|
void set_min_value(uint32_t min_value) { min_value_ = min_value; }
|
||||||
void set_max_value(uint32_t max_value) { max_value_ = max_value; }
|
void set_max_value(uint32_t max_value) { max_value_ = max_value; }
|
||||||
@@ -63,6 +60,7 @@ class TuyaLight : public Component, public light::LightOutput {
|
|||||||
float cold_white_temperature_;
|
float cold_white_temperature_;
|
||||||
float warm_white_temperature_;
|
float warm_white_temperature_;
|
||||||
bool color_temperature_invert_{false};
|
bool color_temperature_invert_{false};
|
||||||
|
bool color_type_lowercase_{false};
|
||||||
bool color_interlock_{false};
|
bool color_interlock_{false};
|
||||||
light::LightState *state_{nullptr};
|
light::LightState *state_{nullptr};
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -38,11 +38,14 @@ light:
|
|||||||
dimmer_datapoint: 2
|
dimmer_datapoint: 2
|
||||||
min_value_datapoint: 3
|
min_value_datapoint: 3
|
||||||
color_temperature_datapoint: 4
|
color_temperature_datapoint: 4
|
||||||
|
color_datapoint: 5
|
||||||
min_value: 1
|
min_value: 1
|
||||||
max_value: 100
|
max_value: 100
|
||||||
cold_white_color_temperature: 153 mireds
|
cold_white_color_temperature: 153 mireds
|
||||||
warm_white_color_temperature: 500 mireds
|
warm_white_color_temperature: 500 mireds
|
||||||
gamma_correct: 1
|
gamma_correct: 1
|
||||||
|
color_type: RGB
|
||||||
|
color_type_lowercase: true
|
||||||
|
|
||||||
number:
|
number:
|
||||||
- platform: tuya
|
- platform: tuya
|
||||||
|
|||||||
Reference in New Issue
Block a user