8 static const char *
const TAG =
"tuya.light";
14 ESP_LOGD(TAG,
"Light is transitioning, datapoint change ignored");
32 ESP_LOGD(TAG,
"Light is transitioning, datapoint change ignored");
36 auto call = this->state_->make_call();
37 call.set_brightness(
float(datapoint.
value_uint) / this->max_value_);
44 ESP_LOGD(TAG,
"Light is transitioning, datapoint change ignored");
48 auto call = this->state_->make_call();
56 ESP_LOGD(TAG,
"Light is transitioning, datapoint change ignored");
60 float red, green, blue;
64 auto rgb = parse_hex<uint32_t>(datapoint.
value_string.substr(0, 6));
68 red = (*rgb >> 16) / 255.0f;
69 green = ((*rgb >> 8) & 0xff) / 255.0f;
70 blue = (*rgb & 0xff) / 255.0f;
74 auto hue = parse_hex<uint16_t>(datapoint.
value_string.substr(0, 4));
75 auto saturation = parse_hex<uint16_t>(datapoint.
value_string.substr(4, 4));
76 auto value = parse_hex<uint16_t>(datapoint.
value_string.substr(8, 4));
77 if (!hue.has_value() || !saturation.has_value() || !value.has_value())
80 hsv_to_rgb(*hue,
float(*saturation) / 1000,
float(*value) / 1000, red, green, blue);
85 float current_red, current_green, current_blue;
87 if (red == current_red && green == current_green && blue == current_blue)
90 rgb_call.
set_rgb(red, green, blue);
101 ESP_LOGCONFIG(TAG,
"Tuya Dimmer:");
103 ESP_LOGCONFIG(TAG,
" Dimmer has datapoint ID %u", *this->
dimmer_id_);
106 ESP_LOGCONFIG(TAG,
" Switch has datapoint ID %u", *this->
switch_id_);
109 ESP_LOGCONFIG(TAG,
" Color has datapoint ID %u", *this->
color_id_);
120 traits.set_supported_color_modes(
147 float red = 0.0f, green = 0.0f, blue = 0.0f;
148 float color_temperature = 0.0f, brightness = 0.0f;
173 color_temp_int = this->color_temperature_max_value_ - color_temp_int;
179 auto brightness_int =
static_cast<uint32_t
>(brightness * this->
max_value_);
180 brightness_int = std::max(brightness_int, this->
min_value_);
187 std::string color_value;
191 sprintf(buffer,
"%02X%02X%02X",
int(red * 255),
int(green * 255),
int(blue * 255));
192 color_value = buffer;
197 float saturation, value;
198 rgb_to_hsv(red, green, blue, hue, saturation, value);
200 sprintf(buffer,
"%04X%04X%04X", hue,
int(saturation * 1000),
int(value * 1000));
201 color_value = buffer;
206 float saturation, value;
207 rgb_to_hsv(red, green, blue, hue, saturation, value);
209 sprintf(buffer,
"%02X%02X%02X%04X%02X%02X",
int(red * 255),
int(green * 255),
int(blue * 255), hue,
210 int(saturation * 255),
int(value * 255));
211 color_value = buffer;
void hsv_to_rgb(int hue, float saturation, float value, float &red, float &green, float &blue)
Convert hue (0-360), saturation (0-1) and value (0-1) to red, green and blue (all 0-1)...
This class represents the communication layer between the front-end MQTT layer and the hardware outpu...
optional< uint8_t > min_value_datapoint_id_
bool color_temperature_invert_
bool is_on() const
Get the binary true/false state of these light color values.
optional< TuyaColorType > color_type_
LightColorValues current_values
The current values of the light as outputted to the light.
float warm_white_temperature_
light::LightTraits get_traits() override
RGB color output and a separate white output.
LightCall & set_rgb(float red, float green, float blue)
Set the RGB color of the light by RGB values.
Color temperature can be controlled.
void register_listener(uint8_t datapoint_id, const std::function< void(TuyaDatapoint)> &func)
uint32_t color_temperature_max_value_
optional< uint8_t > color_temperature_id_
void write_state(light::LightState *state) override
void current_values_as_rgb(float *red, float *green, float *blue, bool color_interlock=false)
optional< uint8_t > dimmer_id_
void current_values_as_rgbct(float *red, float *green, float *blue, float *color_temperature, float *white_brightness)
void setup_state(light::LightState *state) override
float state_
ON / OFF, float for transition.
void dump_config() override
void rgb_to_hsv(float red, float green, float blue, int &hue, float &saturation, float &value)
Convert red, green and blue (all 0-1) values to hue (0-360), saturation (0-1) and value (0-1)...
optional< uint8_t > color_id_
void current_values_as_brightness(float *brightness)
Light can be turned on/off.
RGB color output and a separate white output with controllable color temperature. ...
Master brightness of the light can be controlled.
void current_values_as_ct(float *color_temperature, float *white_brightness)
White output only (use only if the light also has another color mode such as RGB).
This class is used to represent the capabilities of a light.
void set_boolean_datapoint_value(uint8_t datapoint_id, bool value)
void set_integer_datapoint_value(uint8_t datapoint_id, uint32_t value)
float cold_white_temperature_
void set_string_datapoint_value(uint8_t datapoint_id, const std::string &value)
Implementation of SPI Controller mode.
Color can be controlled using RGB format (includes a brightness control for the color).
light::LightState * state_
optional< uint8_t > switch_id_
void current_values_as_rgbw(float *red, float *green, float *blue, float *white, bool color_interlock=false)