7static const char *
const TAG =
"tuya.light";
13 ESP_LOGD(TAG,
"Light is transitioning, datapoint change ignored");
31 ESP_LOGD(TAG,
"Light is transitioning, datapoint change ignored");
43 ESP_LOGD(TAG,
"Light is transitioning, datapoint change ignored");
55 ESP_LOGD(TAG,
"Light is transitioning, datapoint change ignored");
62 float red, green, blue;
70 red = (*rgb >> 16) / 255.0f;
71 green = ((*rgb >> 8) & 0xff) / 255.0f;
72 blue = (*rgb & 0xff) / 255.0f;
79 if (!hue.has_value() || !saturation.has_value() || !value.has_value())
82 hsv_to_rgb(*hue,
float(*saturation) / 1000,
float(*value) / 1000, red, green, blue);
87 float current_red, current_green, current_blue;
89 if (red == current_red && green == current_green && blue == current_blue)
92 rgb_call.
set_rgb(red, green, blue);
103 ESP_LOGCONFIG(TAG,
"Tuya Dimmer:");
105 ESP_LOGCONFIG(TAG,
" Dimmer has datapoint ID %u", *this->
dimmer_id_);
108 ESP_LOGCONFIG(TAG,
" Switch has datapoint ID %u", *this->
switch_id_);
111 ESP_LOGCONFIG(TAG,
" Color has datapoint ID %u", *this->
color_id_);
122 traits.set_supported_color_modes(
130 }
else if (this->
color_id_.has_value()) {
151 float red = 0.0f, green = 0.0f, blue = 0.0f;
152 float color_temperature = 0.0f, brightness = 0.0f;
160 state->current_values_as_rgb(&red, &green, &blue);
165 state->current_values_as_brightness(&brightness);
168 if (!
state->current_values.is_on() && this->switch_id_.has_value()) {
177 color_temp_int = this->color_temperature_max_value_ - color_temp_int;
184 brightness_int = std::max(brightness_int, this->
min_value_);
191 std::string color_value;
196 snprintf(buffer,
sizeof(buffer), format_str,
int(red * 255),
int(green * 255),
int(blue * 255));
197 color_value = buffer;
202 float saturation, value;
203 rgb_to_hsv(red, green, blue, hue, saturation, value);
206 snprintf(buffer,
sizeof(buffer), format_str, hue,
int(saturation * 1000),
int(value * 1000));
207 color_value = buffer;
212 float saturation, value;
213 rgb_to_hsv(red, green, blue, hue, saturation, value);
215 const char *format_str = this->
color_type_lowercase_ ?
"%02x%02x%02x%04x%02x%02x" :
"%02X%02X%02X%04X%02X%02X";
216 snprintf(buffer,
sizeof(buffer), format_str,
int(red * 255),
int(green * 255),
int(blue * 255), hue,
217 int(saturation * 255),
int(value * 255));
218 color_value = buffer;
LightCall & set_color_temperature(optional< float > color_temperature)
Set the color temperature of the light in mireds for CWWW or RGBWW lights.
LightCall & set_rgb(float red, float green, float blue)
Set the RGB color of the light by RGB values.
LightCall & set_brightness(optional< float > brightness)
Set the target brightness of the light from 0.0 (fully off) to 1.0 (fully on)
LightCall & set_state(optional< bool > state)
Set the binary ON/OFF state of the light.
float state_
ON / OFF, float for transition.
This class represents the communication layer between the front-end MQTT layer and the hardware outpu...
void current_values_as_rgb(float *red, float *green, float *blue)
void current_values_as_rgbct(float *red, float *green, float *blue, float *color_temperature, float *white_brightness)
void current_values_as_ct(float *color_temperature, float *white_brightness)
void current_values_as_rgbw(float *red, float *green, float *blue, float *white)
LightColorValues current_values
The current values of the light as outputted to the light.
This class is used to represent the capabilities of a light.
void set_string_datapoint_value(uint8_t datapoint_id, const std::string &value)
void set_boolean_datapoint_value(uint8_t datapoint_id, bool value)
void register_listener(uint8_t datapoint_id, const std::function< void(TuyaDatapoint)> &func)
void set_integer_datapoint_value(uint8_t datapoint_id, uint32_t value)
optional< uint8_t > min_value_datapoint_id_
void setup_state(light::LightState *state) override
void dump_config() override
light::LightTraits get_traits() override
optional< TuyaColorType > color_type_
bool color_type_lowercase_
float cold_white_temperature_
float warm_white_temperature_
optional< uint8_t > switch_id_
optional< uint8_t > color_temperature_id_
void write_state(light::LightState *state) override
optional< uint8_t > dimmer_id_
optional< uint8_t > color_id_
uint32_t color_temperature_max_value_
light::LightState * state_
bool color_temperature_invert_
@ ON_OFF
Only on/off control.
@ BRIGHTNESS
Dimmable light.
@ RGB_WHITE
RGB color output and a separate white output.
@ RGB_COLOR_TEMPERATURE
RGB color output and a separate white output with controllable color temperature.
@ COLOR_TEMPERATURE
Controllable color temperature output.
@ WHITE
White output only (use only if the light also has another color mode such as RGB).
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).
size_t parse_hex(const char *str, size_t length, uint8_t *data, size_t count)
Parse bytes from a hex-encoded string into a byte array.
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).