18 switch (values.get_color_mode()) {
22 root[
"color_mode"] =
"onoff";
25 root[
"color_mode"] =
"brightness";
28 root[
"color_mode"] =
"white";
31 root[
"color_mode"] =
"color_temp";
34 root[
"color_mode"] =
"cwww";
37 root[
"color_mode"] =
"rgb";
40 root[
"color_mode"] =
"rgbw";
43 root[
"color_mode"] =
"rgbct";
46 root[
"color_mode"] =
"rgbww";
51 root[
"state"] = (values.get_state() != 0.0f) ?
"ON" :
"OFF";
53 root[
"brightness"] = uint8_t(values.get_brightness() * 255);
55 JsonObject color = root.createNestedObject(
"color");
57 color[
"r"] = uint8_t(values.get_color_brightness() * values.get_red() * 255);
58 color[
"g"] = uint8_t(values.get_color_brightness() * values.get_green() * 255);
59 color[
"b"] = uint8_t(values.get_color_brightness() * values.get_blue() * 255);
62 color[
"w"] = uint8_t(values.get_white() * 255);
63 root[
"white_value"] = uint8_t(values.get_white() * 255);
67 root[
"color_temp"] = uint32_t(values.get_color_temperature());
70 color[
"c"] = uint8_t(values.get_cold_white() * 255);
71 color[
"w"] = uint8_t(values.get_warm_white() * 255);
76 if (root.containsKey(
"state")) {
93 if (root.containsKey(
"brightness")) {
97 if (root.containsKey(
"color")) {
98 JsonObject color = root[
"color"];
100 float max_rgb = 0.0f;
101 if (color.containsKey(
"r")) {
102 float r = float(color[
"r"]) / 255.0f;
103 max_rgb = fmaxf(max_rgb, r);
106 if (color.containsKey(
"g")) {
107 float g = float(color[
"g"]) / 255.0f;
108 max_rgb = fmaxf(max_rgb, g);
111 if (color.containsKey(
"b")) {
112 float b = float(color[
"b"]) / 255.0f;
113 max_rgb = fmaxf(max_rgb, b);
116 if (color.containsKey(
"r") || color.containsKey(
"g") || color.containsKey(
"b")) {
120 if (color.containsKey(
"c")) {
123 if (color.containsKey(
"w")) {
126 if (color.containsKey(
"c")) {
129 call.
set_white(
float(color[
"w"]) / 255.0f);
134 if (root.containsKey(
"white_value")) {
135 call.
set_white(
float(root[
"white_value"]) / 255.0f);
138 if (root.containsKey(
"color_temp")) {
146 if (root.containsKey(
"flash")) {
147 auto length = uint32_t(
float(root[
"flash"]) * 1000);
151 if (root.containsKey(
"transition")) {
152 auto length = uint32_t(
float(root[
"transition"]) * 1000);
156 if (root.containsKey(
"effect")) {
157 const char *effect = root[
"effect"];
This class represents the communication layer between the front-end MQTT layer and the hardware outpu...
LightCall & set_color_brightness(optional< float > brightness)
Set the color brightness of the light from 0.0 (no color) to 1.0 (fully on)
bool is_on() const
Get the binary true/false state of these light color values.
LightCall & set_red(optional< float > red)
Set the red RGB value of the light from 0.0 to 1.0.
LightCall & set_color_temperature(optional< float > color_temperature)
Set the color temperature of the light in mireds for CWWW or RGBWW lights.
LightCall & set_cold_white(optional< float > cold_white)
Set the cold white value of the light from 0.0 to 1.0.
std::string get_effect_name()
Return the name of the current effect, or if no effect is active "None".
LightOutput * get_output() const
Get the light output associated with this object.
RGB color output and a separate white output.
bool supports_effects()
Return whether the light has any effects that meet the trait requirements.
Color temperature can be controlled.
LightCall & set_transition_length(optional< uint32_t > transition_length)
Set the transition length of this call in milliseconds.
ParseOnOffState parse_on_off(const char *str, const char *on, const char *off)
Parse a string that contains either on, off or toggle.
RGB color output, and separate cold and warm white outputs.
Brightness of cold and warm white output can be controlled.
static void parse_json(LightState &state, LightCall &call, JsonObject root)
Parse the JSON state of a light to a LightCall.
Brightness of white channel can be controlled separately from other channels.
Light can be turned on/off.
RGB color output and a separate white output with controllable color temperature. ...
This class represents a requested change in a light state.
LightCall & set_state(optional< bool > state)
Set the binary ON/OFF state of the light.
Master brightness of the light can be controlled.
static void dump_json(LightState &state, JsonObject root)
Dump the state of a light as JSON.
static void parse_color_json(LightState &state, LightCall &call, JsonObject root)
White output only (use only if the light also has another color mode such as RGB).
LightCall & set_warm_white(optional< float > warm_white)
Set the warm white value of the light from 0.0 to 1.0.
No color mode configured (cannot be a supported mode, only active when light is off).
LightCall & set_effect(optional< std::string > effect)
Set the effect of the light by its name.
LightCall & set_flash_length(optional< uint32_t > flash_length)
Start and set the flash length of this call in milliseconds.
LightCall & set_green(optional< float > green)
Set the green RGB value of the light from 0.0 to 1.0.
Implementation of SPI Controller mode.
Color can be controlled using RGB format (includes a brightness control for the color).
LightColorValues remote_values
The remote color values reported to the frontend.
virtual LightTraits get_traits()=0
Return the LightTraits of this LightOutput.
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_brightness(optional< float > brightness)
Set the target brightness of the light from 0.0 (fully off) to 1.0 (fully on)
LightCall & set_blue(optional< float > blue)
Set the blue RGB value of the light from 0.0 to 1.0.