12static constexpr const char *get_color_mode_json_str(
ColorMode mode) {
39 if (
state.supports_effects())
40 root[
"effect"] =
state.get_effect_name();
42 auto values =
state.remote_values;
43 auto traits =
state.get_output()->get_traits();
45 const auto color_mode = values.get_color_mode();
46 const char *mode_str = get_color_mode_json_str(color_mode);
47 if (mode_str !=
nullptr) {
48 root[
"color_mode"] = mode_str;
52 root[
"state"] = (values.get_state() != 0.0f) ?
"ON" :
"OFF";
54 root[
"brightness"] = to_uint8_scale(values.get_brightness());
56 JsonObject color = root[
"color"].to<JsonObject>();
58 float color_brightness = values.get_color_brightness();
59 color[
"r"] = to_uint8_scale(color_brightness * values.get_red());
60 color[
"g"] = to_uint8_scale(color_brightness * values.get_green());
61 color[
"b"] = to_uint8_scale(color_brightness * values.get_blue());
64 uint8_t white_val = to_uint8_scale(values.get_white());
65 color[
"w"] = white_val;
66 root[
"white_value"] = white_val;
70 root[
"color_temp"] =
uint32_t(values.get_color_temperature());
73 color[
"c"] = to_uint8_scale(values.get_cold_white());
74 color[
"w"] = to_uint8_scale(values.get_warm_white());
79 if (root[
"state"].is<const char *>()) {
96 if (root[
"brightness"].is<uint8_t>()) {
100 if (root[
"color"].is<JsonObject>()) {
101 JsonObject color = root[
"color"];
103 float max_rgb = 0.0f;
104 if (color[
"r"].is<uint8_t>()) {
105 float r =
float(color[
"r"]) / 255.0f;
106 max_rgb = fmaxf(max_rgb, r);
109 if (color[
"g"].is<uint8_t>()) {
110 float g =
float(color[
"g"]) / 255.0f;
111 max_rgb = fmaxf(max_rgb, g);
114 if (color[
"b"].is<uint8_t>()) {
115 float b =
float(color[
"b"]) / 255.0f;
116 max_rgb = fmaxf(max_rgb, b);
119 if (color[
"r"].is<uint8_t>() || color[
"g"].is<uint8_t>() || color[
"b"].is<uint8_t>()) {
123 if (color[
"c"].is<uint8_t>()) {
126 if (color[
"w"].is<uint8_t>()) {
129 if (color[
"c"].is<uint8_t>()) {
132 call.
set_white(
float(color[
"w"]) / 255.0f);
137 if (root[
"white_value"].is<uint8_t>()) {
138 call.
set_white(
float(root[
"white_value"]) / 255.0f);
141 if (root[
"color_temp"].is<uint16_t>()) {
149 if (root[
"flash"].is<uint32_t>()) {
154 if (root[
"transition"].is<uint16_t>()) {
159 if (root[
"effect"].is<const char *>()) {
160 const char *effect = root[
"effect"];
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...
FLAG_HAS_TRANSITION float
ColorMode
Color modes are a combination of color capabilities that can be used at the same time.
@ ON_OFF
Only on/off control.
@ RGB_COLD_WARM_WHITE
RGB color output, and separate cold and warm white outputs.
@ 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).
@ COLD_WARM_WHITE
Cold and warm white output with individually controllable brightness.
@ 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.
Providing packet encoding functions for exchanging data with a remote host.
ParseOnOffState parse_on_off(const char *str, const char *on, const char *off)
Parse a string that contains either on, off or toggle.