8static 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");
44 ESP_LOGD(TAG,
"Light is transitioning, datapoint change ignored");
56 ESP_LOGD(TAG,
"Light is transitioning, datapoint change ignored");
60 float red, green, blue;
68 red = (*rgb >> 16) / 255.0f;
69 green = ((*rgb >> 8) & 0xff) / 255.0f;
70 blue = (*rgb & 0xff) / 255.0f;
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(
149 float red = 0.0f, green = 0.0f, blue = 0.0f;
150 float color_temperature = 0.0f, brightness = 0.0f;
158 state->current_values_as_rgb(&red, &green, &blue);
163 state->current_values_as_brightness(&brightness);
166 if (!
state->current_values.is_on() && this->switch_id_.has_value()) {
175 color_temp_int = this->color_temperature_max_value_ - color_temp_int;
181 auto brightness_int =
static_cast<uint32_t
>(brightness * this->
max_value_);
182 brightness_int = std::max(brightness_int, this->
min_value_);
189 std::string color_value;
193 sprintf(buffer,
"%02X%02X%02X",
int(red * 255),
int(green * 255),
int(blue * 255));
194 color_value = buffer;
199 float saturation, value;
200 rgb_to_hsv(red, green, blue, hue, saturation, value);
202 sprintf(buffer,
"%04X%04X%04X", hue,
int(saturation * 1000),
int(value * 1000));
203 color_value = buffer;
208 float saturation, value;
209 rgb_to_hsv(red, green, blue, hue, saturation, value);
211 sprintf(buffer,
"%02X%02X%02X%04X%02X%02X",
int(red * 255),
int(green * 255),
int(blue * 255), hue,
212 int(saturation * 255),
int(value * 255));
213 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_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_rgb(float *red, float *green, float *blue, bool color_interlock=false)
void current_values_as_rgbw(float *red, float *green, float *blue, float *white, bool color_interlock=false)
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_
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).
Providing packet encoding functions for exchanging data with a remote host.
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).