14PROGMEM_STRING_TABLE(ColorModeStrings,
"onoff",
"brightness",
"white",
"color_temp",
"cwww",
"rgb",
"rgbw",
"rgbct",
24 return ColorModeStrings::get_progmem_str(bit - 1, ColorModeStrings::LAST_INDEX);
29 if (
state.supports_effects()) {
30 root[ESPHOME_F(
"effect")] =
state.get_effect_name().c_str();
31 root[ESPHOME_F(
"effect_index")] =
state.get_current_effect_index();
32 root[ESPHOME_F(
"effect_count")] =
state.get_effect_count();
35 auto values =
state.remote_values;
37 const auto color_mode = values.get_color_mode();
38 const auto *mode_str = get_color_mode_json_str(color_mode);
39 if (mode_str !=
nullptr) {
40 root[ESPHOME_F(
"color_mode")] = mode_str;
44 root[ESPHOME_F(
"state")] = (values.get_state() != 0.0f) ?
"ON" :
"OFF";
46 root[ESPHOME_F(
"brightness")] = to_uint8_scale(values.get_brightness());
48 JsonObject color = root[ESPHOME_F(
"color")].to<JsonObject>();
50 float color_brightness = values.get_color_brightness();
51 color[ESPHOME_F(
"r")] = to_uint8_scale(color_brightness * values.get_red());
52 color[ESPHOME_F(
"g")] = to_uint8_scale(color_brightness * values.get_green());
53 color[ESPHOME_F(
"b")] = to_uint8_scale(color_brightness * values.get_blue());
56 uint8_t white_val = to_uint8_scale(values.get_white());
57 color[ESPHOME_F(
"w")] = white_val;
58 root[ESPHOME_F(
"white_value")] = white_val;
62 root[ESPHOME_F(
"color_temp")] =
uint32_t(values.get_color_temperature());
65 color[ESPHOME_F(
"c")] = to_uint8_scale(values.get_cold_white());
66 color[ESPHOME_F(
"w")] = to_uint8_scale(values.get_warm_white());
71 if (root[ESPHOME_F(
"state")].is<const char *>()) {
88 if (root[ESPHOME_F(
"brightness")].is<uint8_t>()) {
89 call.
set_brightness(
float(root[ESPHOME_F(
"brightness")]) / 255.0f);
92 if (root[ESPHOME_F(
"color")].is<JsonObject>()) {
93 JsonObject color = root[ESPHOME_F(
"color")];
96 if (color[ESPHOME_F(
"r")].is<uint8_t>()) {
97 float r =
float(color[ESPHOME_F(
"r")]) / 255.0f;
98 max_rgb = fmaxf(max_rgb, r);
101 if (color[ESPHOME_F(
"g")].is<uint8_t>()) {
102 float g =
float(color[ESPHOME_F(
"g")]) / 255.0f;
103 max_rgb = fmaxf(max_rgb, g);
106 if (color[ESPHOME_F(
"b")].is<uint8_t>()) {
107 float b =
float(color[ESPHOME_F(
"b")]) / 255.0f;
108 max_rgb = fmaxf(max_rgb,
b);
111 if (color[ESPHOME_F(
"r")].is<uint8_t>() || color[ESPHOME_F(
"g")].is<uint8_t>() ||
112 color[ESPHOME_F(
"b")].is<uint8_t>()) {
116 if (color[ESPHOME_F(
"c")].is<uint8_t>()) {
119 if (color[ESPHOME_F(
"w")].is<uint8_t>()) {
122 if (color[ESPHOME_F(
"c")].is<uint8_t>()) {
125 call.
set_white(
float(color[ESPHOME_F(
"w")]) / 255.0f);
130 if (root[ESPHOME_F(
"white_value")].is<uint8_t>()) {
131 call.
set_white(
float(root[ESPHOME_F(
"white_value")]) / 255.0f);
134 if (root[ESPHOME_F(
"color_temp")].is<uint16_t>()) {
142 if (root[ESPHOME_F(
"flash")].is<uint32_t>()) {
147 if (root[ESPHOME_F(
"transition")].is<uint16_t>()) {
148 auto length =
uint32_t(
float(root[ESPHOME_F(
"transition")]) * 1000);
152 if (root[ESPHOME_F(
"effect")].is<const char *>()) {
153 const char *effect = root[ESPHOME_F(
"effect")];
157 if (root[ESPHOME_F(
"effect_index")].is<uint32_t>()) {
158 uint32_t effect_index = root[ESPHOME_F(
"effect_index")];
BedjetMode mode
BedJet operating mode.
This class represents a requested change in a light state.
LightCall & set_color_temperature(optional< float > color_temperature)
Set the color temperature of the light in mireds for CWWW or RGBWW lights.
LightCall & set_color_brightness(optional< float > brightness)
Set the color brightness of the light from 0.0 (no color) to 1.0 (fully on)
LightCall & set_effect(optional< std::string > effect)
Set the effect of the light by its name.
LightCall & set_white(optional< float > white)
Set the white value value of the light from 0.0 to 1.0 for RGBW[W] lights.
LightCall & set_green(optional< float > green)
Set the green RGB value of the light from 0.0 to 1.0.
LightCall & set_warm_white(optional< float > warm_white)
Set the warm white value of the light from 0.0 to 1.0.
LightCall & set_blue(optional< float > blue)
Set the blue RGB value of the light from 0.0 to 1.0.
LightCall & set_flash_length(optional< uint32_t > flash_length)
Start and set the flash length of this call in milliseconds.
LightCall & set_cold_white(optional< float > cold_white)
Set the cold white value of the light from 0.0 to 1.0.
LightCall & set_red(optional< float > red)
Set the red RGB value of the light from 0.0 to 1.0.
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.
LightCall & set_transition_length(optional< uint32_t > transition_length)
Set the transition length of this call in milliseconds.
static void parse_color_json(LightState &state, LightCall &call, JsonObject root)
static void parse_json(LightState &state, LightCall &call, JsonObject root)
Parse the JSON state of a light to a LightCall.
static void dump_json(LightState &state, JsonObject root)
Dump the state of a light as JSON.
This class represents the communication layer between the front-end MQTT layer and the hardware outpu...
PROGMEM_STRING_TABLE(ColorModeHumanStrings, "Unknown", "On/Off", "Brightness", "White", "Color temperature", "Cold/warm white", "RGB", "RGBW", "RGB + color temperature", "RGB + cold/warm white")
FLAG_HAS_TRANSITION float
ColorMode
Color modes are a combination of color capabilities that can be used at the same time.
@ ON_OFF
Light can be turned on/off.
@ BRIGHTNESS
Master brightness of the light can be controlled.
@ RGB
Color can be controlled using RGB format (includes a brightness control for the color).
@ COLOR_TEMPERATURE
Color temperature can be controlled.
@ WHITE
Brightness of white channel can be controlled separately from other channels.
@ COLD_WARM_WHITE
Brightness of cold and warm white output can be controlled.
ParseOnOffState parse_on_off(const char *str, const char *on, const char *off)
Parse a string that contains either on, off or toggle.
const __FlashStringHelper * ProgmemStr
static constexpr unsigned to_bit(ColorMode mode)