ESPHome 2025.8.0b1
Loading...
Searching...
No Matches
light_call.cpp
Go to the documentation of this file.
1#include <cinttypes>
2#include "light_call.h"
3#include "light_state.h"
4#include "esphome/core/log.h"
6
7namespace esphome {
8namespace light {
9
10static const char *const TAG = "light";
11
12// Helper functions to reduce code size for logging
13#if ESPHOME_LOG_LEVEL >= ESPHOME_LOG_LEVEL_WARN
14static void log_validation_warning(const char *name, const char *param_name, float val, float min, float max) {
15 ESP_LOGW(TAG, "'%s': %s value %.2f is out of range [%.1f - %.1f]", name, param_name, val, min, max);
16}
17
18static void log_feature_not_supported(const char *name, const char *feature) {
19 ESP_LOGW(TAG, "'%s': %s not supported", name, feature);
20}
21
22static void log_color_mode_not_supported(const char *name, const char *feature) {
23 ESP_LOGW(TAG, "'%s': color mode does not support setting %s", name, feature);
24}
25
26static void log_invalid_parameter(const char *name, const char *message) { ESP_LOGW(TAG, "'%s': %s", name, message); }
27#else
28#define log_validation_warning(name, param_name, val, min, max)
29#define log_feature_not_supported(name, feature)
30#define log_color_mode_not_supported(name, feature)
31#define log_invalid_parameter(name, message)
32#endif
33
34// Macro to reduce repetitive setter code
35#define IMPLEMENT_LIGHT_CALL_SETTER(name, type, flag) \
36 LightCall &LightCall::set_##name(optional<type>(name)) { \
37 if ((name).has_value()) { \
38 this->name##_ = (name).value(); \
39 } \
40 this->set_flag_(flag, (name).has_value()); \
41 return *this; \
42 } \
43 LightCall &LightCall::set_##name(type name) { \
44 this->name##_ = name; \
45 this->set_flag_(flag, true); \
46 return *this; \
47 }
48
49static const LogString *color_mode_to_human(ColorMode color_mode) {
50 if (color_mode == ColorMode::UNKNOWN)
51 return LOG_STR("Unknown");
52 if (color_mode == ColorMode::WHITE)
53 return LOG_STR("White");
54 if (color_mode == ColorMode::COLOR_TEMPERATURE)
55 return LOG_STR("Color temperature");
56 if (color_mode == ColorMode::COLD_WARM_WHITE)
57 return LOG_STR("Cold/warm white");
58 if (color_mode == ColorMode::RGB)
59 return LOG_STR("RGB");
60 if (color_mode == ColorMode::RGB_WHITE)
61 return LOG_STR("RGBW");
62 if (color_mode == ColorMode::RGB_COLD_WARM_WHITE)
63 return LOG_STR("RGB + cold/warm white");
64 if (color_mode == ColorMode::RGB_COLOR_TEMPERATURE)
65 return LOG_STR("RGB + color temperature");
66 return LOG_STR("");
67}
68
69// Helper to log percentage values
70#if ESPHOME_LOG_LEVEL >= ESPHOME_LOG_LEVEL_DEBUG
71static void log_percent(const char *name, const char *param, float value) {
72 ESP_LOGD(TAG, " %s: %.0f%%", param, value * 100.0f);
73}
74#else
75#define log_percent(name, param, value)
76#endif
77
79 const char *name = this->parent_->get_name().c_str();
80 LightColorValues v = this->validate_();
81 const bool publish = this->get_publish_();
82
83 if (publish) {
84 ESP_LOGD(TAG, "'%s' Setting:", name);
85
86 // Only print color mode when it's being changed
87 ColorMode current_color_mode = this->parent_->remote_values.get_color_mode();
88 ColorMode target_color_mode = this->has_color_mode() ? this->color_mode_ : current_color_mode;
89 if (target_color_mode != current_color_mode) {
90 ESP_LOGD(TAG, " Color mode: %s", LOG_STR_ARG(color_mode_to_human(v.get_color_mode())));
91 }
92
93 // Only print state when it's being changed
94 bool current_state = this->parent_->remote_values.is_on();
95 bool target_state = this->has_state() ? this->state_ : current_state;
96 if (target_state != current_state) {
97 ESP_LOGD(TAG, " State: %s", ONOFF(v.is_on()));
98 }
99
100 if (this->has_brightness()) {
101 log_percent(name, "Brightness", v.get_brightness());
102 }
103
104 if (this->has_color_brightness()) {
105 log_percent(name, "Color brightness", v.get_color_brightness());
106 }
107 if (this->has_red() || this->has_green() || this->has_blue()) {
108 ESP_LOGD(TAG, " Red: %.0f%%, Green: %.0f%%, Blue: %.0f%%", v.get_red() * 100.0f, v.get_green() * 100.0f,
109 v.get_blue() * 100.0f);
110 }
111
112 if (this->has_white()) {
113 log_percent(name, "White", v.get_white());
114 }
115 if (this->has_color_temperature()) {
116 ESP_LOGD(TAG, " Color temperature: %.1f mireds", v.get_color_temperature());
117 }
118
119 if (this->has_cold_white() || this->has_warm_white()) {
120 ESP_LOGD(TAG, " Cold white: %.0f%%, warm white: %.0f%%", v.get_cold_white() * 100.0f,
121 v.get_warm_white() * 100.0f);
122 }
123 }
124
125 if (this->has_flash_()) {
126 // FLASH
127 if (publish) {
128 ESP_LOGD(TAG, " Flash length: %.1fs", this->flash_length_ / 1e3f);
129 }
130
131 this->parent_->start_flash_(v, this->flash_length_, publish);
132 } else if (this->has_transition_()) {
133 // TRANSITION
134 if (publish) {
135 ESP_LOGD(TAG, " Transition length: %.1fs", this->transition_length_ / 1e3f);
136 }
137
138 // Special case: Transition and effect can be set when turning off
139 if (this->has_effect_()) {
140 if (publish) {
141 ESP_LOGD(TAG, " Effect: 'None'");
142 }
143 this->parent_->stop_effect_();
144 }
145
146 this->parent_->start_transition_(v, this->transition_length_, publish);
147
148 } else if (this->has_effect_()) {
149 // EFFECT
150 const char *effect_s;
151 if (this->effect_ == 0u) {
152 effect_s = "None";
153 } else {
154 effect_s = this->parent_->effects_[this->effect_ - 1]->get_name().c_str();
155 }
156
157 if (publish) {
158 ESP_LOGD(TAG, " Effect: '%s'", effect_s);
159 }
160
161 this->parent_->start_effect_(this->effect_);
162
163 // Also set light color values when starting an effect
164 // For example to turn off the light
165 this->parent_->set_immediately_(v, true);
166 } else {
167 // INSTANT CHANGE
168 this->parent_->set_immediately_(v, publish);
169 }
170
171 if (!this->has_transition_()) {
173 }
174 if (publish) {
175 this->parent_->publish_state();
176 }
177 if (this->get_save_()) {
179 }
180}
181
183 auto *name = this->parent_->get_name().c_str();
184 auto traits = this->parent_->get_traits();
185
186 // Color mode check
187 if (this->has_color_mode() && !traits.supports_color_mode(this->color_mode_)) {
188 ESP_LOGW(TAG, "'%s' does not support color mode %s", name, LOG_STR_ARG(color_mode_to_human(this->color_mode_)));
189 this->set_flag_(FLAG_HAS_COLOR_MODE, false);
190 }
191
192 // Ensure there is always a color mode set
193 if (!this->has_color_mode()) {
194 this->color_mode_ = this->compute_color_mode_();
195 this->set_flag_(FLAG_HAS_COLOR_MODE, true);
196 }
197 auto color_mode = this->color_mode_;
198
199 // Transform calls that use non-native parameters for the current mode.
200 this->transform_parameters_();
201
202 // Brightness exists check
203 if (this->has_brightness() && this->brightness_ > 0.0f && !(color_mode & ColorCapability::BRIGHTNESS)) {
204 log_feature_not_supported(name, "brightness");
205 this->set_flag_(FLAG_HAS_BRIGHTNESS, false);
206 }
207
208 // Transition length possible check
209 if (this->has_transition_() && this->transition_length_ != 0 && !(color_mode & ColorCapability::BRIGHTNESS)) {
210 log_feature_not_supported(name, "transitions");
211 this->set_flag_(FLAG_HAS_TRANSITION, false);
212 }
213
214 // Color brightness exists check
215 if (this->has_color_brightness() && this->color_brightness_ > 0.0f && !(color_mode & ColorCapability::RGB)) {
216 log_color_mode_not_supported(name, "RGB brightness");
218 }
219
220 // RGB exists check
221 if ((this->has_red() && this->red_ > 0.0f) || (this->has_green() && this->green_ > 0.0f) ||
222 (this->has_blue() && this->blue_ > 0.0f)) {
223 if (!(color_mode & ColorCapability::RGB)) {
224 log_color_mode_not_supported(name, "RGB color");
225 this->set_flag_(FLAG_HAS_RED, false);
226 this->set_flag_(FLAG_HAS_GREEN, false);
227 this->set_flag_(FLAG_HAS_BLUE, false);
228 }
229 }
230
231 // White value exists check
232 if (this->has_white() && this->white_ > 0.0f &&
233 !(color_mode & ColorCapability::WHITE || color_mode & ColorCapability::COLD_WARM_WHITE)) {
234 log_color_mode_not_supported(name, "white value");
235 this->set_flag_(FLAG_HAS_WHITE, false);
236 }
237
238 // Color temperature exists check
239 if (this->has_color_temperature() &&
241 log_color_mode_not_supported(name, "color temperature");
243 }
244
245 // Cold/warm white value exists check
246 if ((this->has_cold_white() && this->cold_white_ > 0.0f) || (this->has_warm_white() && this->warm_white_ > 0.0f)) {
247 if (!(color_mode & ColorCapability::COLD_WARM_WHITE)) {
248 log_color_mode_not_supported(name, "cold/warm white value");
249 this->set_flag_(FLAG_HAS_COLD_WHITE, false);
250 this->set_flag_(FLAG_HAS_WARM_WHITE, false);
251 }
252 }
253
254#define VALIDATE_RANGE_(name_, upper_name, min, max) \
255 if (this->has_##name_()) { \
256 auto val = this->name_##_; \
257 if (val < (min) || val > (max)) { \
258 log_validation_warning(name, LOG_STR_LITERAL(upper_name), val, (min), (max)); \
259 this->name_##_ = clamp(val, (min), (max)); \
260 } \
261 }
262#define VALIDATE_RANGE(name, upper_name) VALIDATE_RANGE_(name, upper_name, 0.0f, 1.0f)
263
264 // Range checks
265 VALIDATE_RANGE(brightness, "Brightness")
266 VALIDATE_RANGE(color_brightness, "Color brightness")
267 VALIDATE_RANGE(red, "Red")
268 VALIDATE_RANGE(green, "Green")
269 VALIDATE_RANGE(blue, "Blue")
270 VALIDATE_RANGE(white, "White")
271 VALIDATE_RANGE(cold_white, "Cold white")
272 VALIDATE_RANGE(warm_white, "Warm white")
273 VALIDATE_RANGE_(color_temperature, "Color temperature", traits.get_min_mireds(), traits.get_max_mireds())
274
275 // Flag whether an explicit turn off was requested, in which case we'll also stop the effect.
276 bool explicit_turn_off_request = this->has_state() && !this->state_;
277
278 // Turn off when brightness is set to zero, and reset brightness (so that it has nonzero brightness when turned on).
279 if (this->has_brightness() && this->brightness_ == 0.0f) {
280 this->state_ = false;
281 this->set_flag_(FLAG_HAS_STATE, true);
282 this->brightness_ = 1.0f;
283 }
284
285 // Set color brightness to 100% if currently zero and a color is set.
286 if (this->has_red() || this->has_green() || this->has_blue()) {
287 if (!this->has_color_brightness() && this->parent_->remote_values.get_color_brightness() == 0.0f) {
288 this->color_brightness_ = 1.0f;
290 }
291 }
292
293 // Create color values for the light with this call applied.
294 auto v = this->parent_->remote_values;
295 if (this->has_color_mode())
297 if (this->has_state())
298 v.set_state(this->state_);
299 if (this->has_brightness())
300 v.set_brightness(this->brightness_);
301 if (this->has_color_brightness())
302 v.set_color_brightness(this->color_brightness_);
303 if (this->has_red())
304 v.set_red(this->red_);
305 if (this->has_green())
306 v.set_green(this->green_);
307 if (this->has_blue())
308 v.set_blue(this->blue_);
309 if (this->has_white())
310 v.set_white(this->white_);
311 if (this->has_color_temperature())
312 v.set_color_temperature(this->color_temperature_);
313 if (this->has_cold_white())
314 v.set_cold_white(this->cold_white_);
315 if (this->has_warm_white())
316 v.set_warm_white(this->warm_white_);
317
318 v.normalize_color();
319
320 // Flash length check
321 if (this->has_flash_() && this->flash_length_ == 0) {
322 log_invalid_parameter(name, "flash length must be greater than zero");
323 this->set_flag_(FLAG_HAS_FLASH, false);
324 }
325
326 // validate transition length/flash length/effect not used at the same time
327 bool supports_transition = color_mode & ColorCapability::BRIGHTNESS;
328
329 // If effect is already active, remove effect start
330 if (this->has_effect_() && this->effect_ == this->parent_->active_effect_index_) {
331 this->set_flag_(FLAG_HAS_EFFECT, false);
332 }
333
334 // validate effect index
335 if (this->has_effect_() && this->effect_ > this->parent_->effects_.size()) {
336 ESP_LOGW(TAG, "'%s': invalid effect index %" PRIu32, name, this->effect_);
337 this->set_flag_(FLAG_HAS_EFFECT, false);
338 }
339
340 if (this->has_effect_() && (this->has_transition_() || this->has_flash_())) {
341 log_invalid_parameter(name, "effect cannot be used with transition/flash");
342 this->set_flag_(FLAG_HAS_TRANSITION, false);
343 this->set_flag_(FLAG_HAS_FLASH, false);
344 }
345
346 if (this->has_flash_() && this->has_transition_()) {
347 log_invalid_parameter(name, "flash cannot be used with transition");
348 this->set_flag_(FLAG_HAS_TRANSITION, false);
349 }
350
351 if (!this->has_transition_() && !this->has_flash_() && (!this->has_effect_() || this->effect_ == 0) &&
352 supports_transition) {
353 // nothing specified and light supports transitions, set default transition length
355 this->set_flag_(FLAG_HAS_TRANSITION, true);
356 }
357
358 if (this->has_transition_() && this->transition_length_ == 0) {
359 // 0 transition is interpreted as no transition (instant change)
360 this->set_flag_(FLAG_HAS_TRANSITION, false);
361 }
362
363 if (this->has_transition_() && !supports_transition) {
364 log_feature_not_supported(name, "transitions");
365 this->set_flag_(FLAG_HAS_TRANSITION, false);
366 }
367
368 // If not a flash and turning the light off, then disable the light
369 // Do not use light color values directly, so that effects can set 0% brightness
370 // Reason: When user turns off the light in frontend, the effect should also stop
371 bool target_state = this->has_state() ? this->state_ : v.is_on();
372 if (!this->has_flash_() && !target_state) {
373 if (this->has_effect_()) {
374 log_invalid_parameter(name, "cannot start effect when turning off");
375 this->set_flag_(FLAG_HAS_EFFECT, false);
376 } else if (this->parent_->active_effect_index_ != 0 && explicit_turn_off_request) {
377 // Auto turn off effect
378 this->effect_ = 0;
379 this->set_flag_(FLAG_HAS_EFFECT, true);
380 }
381 }
382
383 // Disable saving for flashes
384 if (this->has_flash_())
385 this->set_flag_(FLAG_SAVE, false);
386
387 return v;
388}
390 auto traits = this->parent_->get_traits();
391
392 // Allow CWWW modes to be set with a white value and/or color temperature.
393 // This is used in three cases in HA:
394 // - CW/WW lights, which set the "brightness" and "color_temperature"
395 // - RGBWW lights with color_interlock=true, which also sets "brightness" and
396 // "color_temperature" (without color_interlock, CW/WW are set directly)
397 // - Legacy Home Assistant (pre-colormode), which sets "white" and "color_temperature"
398
399 // Cache min/max mireds to avoid repeated calls
400 const float min_mireds = traits.get_min_mireds();
401 const float max_mireds = traits.get_max_mireds();
402
403 if (((this->has_white() && this->white_ > 0.0f) || this->has_color_temperature()) && //
405 !(this->color_mode_ & ColorCapability::WHITE) && //
407 min_mireds > 0.0f && max_mireds > 0.0f) {
408 ESP_LOGD(TAG, "'%s': setting cold/warm white channels using white/color temperature values",
409 this->parent_->get_name().c_str());
410 if (this->has_color_temperature()) {
411 const float color_temp = clamp(this->color_temperature_, min_mireds, max_mireds);
412 const float range = max_mireds - min_mireds;
413 const float ww_fraction = (color_temp - min_mireds) / range;
414 const float cw_fraction = 1.0f - ww_fraction;
415 const float max_cw_ww = std::max(ww_fraction, cw_fraction);
416 const float gamma = this->parent_->get_gamma_correct();
417 this->cold_white_ = gamma_uncorrect(cw_fraction / max_cw_ww, gamma);
418 this->warm_white_ = gamma_uncorrect(ww_fraction / max_cw_ww, gamma);
419 this->set_flag_(FLAG_HAS_COLD_WHITE, true);
420 this->set_flag_(FLAG_HAS_WARM_WHITE, true);
421 }
422 if (this->has_white()) {
423 this->brightness_ = this->white_;
424 this->set_flag_(FLAG_HAS_BRIGHTNESS, true);
425 }
426 }
427}
429 auto supported_modes = this->parent_->get_traits().get_supported_color_modes();
430 int supported_count = supported_modes.size();
431
432 // Some lights don't support any color modes (e.g. monochromatic light), leave it at unknown.
433 if (supported_count == 0)
434 return ColorMode::UNKNOWN;
435
436 // In the common case of lights supporting only a single mode, use that one.
437 if (supported_count == 1)
438 return *supported_modes.begin();
439
440 // Don't change if the light is being turned off.
441 ColorMode current_mode = this->parent_->remote_values.get_color_mode();
442 if (this->has_state() && !this->state_)
443 return current_mode;
444
445 // If no color mode is specified, we try to guess the color mode. This is needed for backward compatibility to
446 // pre-colormode clients and automations, but also for the MQTT API, where HA doesn't let us know which color mode
447 // was used for some reason.
448 std::set<ColorMode> suitable_modes = this->get_suitable_color_modes_();
449
450 // Don't change if the current mode is suitable.
451 if (suitable_modes.count(current_mode) > 0) {
452 ESP_LOGI(TAG, "'%s': color mode not specified; retaining %s", this->parent_->get_name().c_str(),
453 LOG_STR_ARG(color_mode_to_human(current_mode)));
454 return current_mode;
455 }
456
457 // Use the preferred suitable mode.
458 for (auto mode : suitable_modes) {
459 if (supported_modes.count(mode) == 0)
460 continue;
461
462 ESP_LOGI(TAG, "'%s': color mode not specified; using %s", this->parent_->get_name().c_str(),
463 LOG_STR_ARG(color_mode_to_human(mode)));
464 return mode;
465 }
466
467 // There's no supported mode for this call, so warn, use the current more or a mode at random and let validation strip
468 // out whatever we don't support.
469 auto color_mode = current_mode != ColorMode::UNKNOWN ? current_mode : *supported_modes.begin();
470 ESP_LOGW(TAG, "'%s': no suitable color mode supported; defaulting to %s", this->parent_->get_name().c_str(),
471 LOG_STR_ARG(color_mode_to_human(color_mode)));
472 return color_mode;
473}
475 bool has_white = this->has_white() && this->white_ > 0.0f;
476 bool has_ct = this->has_color_temperature();
477 bool has_cwww =
478 (this->has_cold_white() && this->cold_white_ > 0.0f) || (this->has_warm_white() && this->warm_white_ > 0.0f);
479 bool has_rgb = (this->has_color_brightness() && this->color_brightness_ > 0.0f) ||
480 (this->has_red() || this->has_green() || this->has_blue());
481
482// Build key from flags: [rgb][cwww][ct][white]
483#define KEY(white, ct, cwww, rgb) ((white) << 0 | (ct) << 1 | (cwww) << 2 | (rgb) << 3)
484
485 uint8_t key = KEY(has_white, has_ct, has_cwww, has_rgb);
486
487 switch (key) {
488 case KEY(true, false, false, false): // white only
491 case KEY(false, true, false, false): // ct only
494 case KEY(true, true, false, false): // white + ct
496 case KEY(false, false, true, false): // cwww only
498 case KEY(false, false, false, false): // none
501 case KEY(true, false, false, true): // rgb + white
503 case KEY(false, true, false, true): // rgb + ct
504 case KEY(true, true, false, true): // rgb + white + ct
506 case KEY(false, false, true, true): // rgb + cwww
508 case KEY(false, false, false, true): // rgb only
510 default:
511 return {}; // conflicting flags
512 }
513
514#undef KEY
515}
516
517LightCall &LightCall::set_effect(const std::string &effect) {
518 if (strcasecmp(effect.c_str(), "none") == 0) {
519 this->set_effect(0);
520 return *this;
521 }
522
523 bool found = false;
524 for (uint32_t i = 0; i < this->parent_->effects_.size(); i++) {
525 LightEffect *e = this->parent_->effects_[i];
526
527 if (strcasecmp(effect.c_str(), e->get_name().c_str()) == 0) {
528 this->set_effect(i + 1);
529 found = true;
530 break;
531 }
532 }
533 if (!found) {
534 ESP_LOGW(TAG, "'%s': no such effect '%s'", this->parent_->get_name().c_str(), effect.c_str());
535 }
536 return *this;
537}
557 this->set_transition_length(transition_length);
558 return *this;
559}
562 this->set_brightness(brightness);
563 return *this;
564}
566 if (this->parent_->get_traits().supports_color_mode(color_mode))
567 this->set_color_mode(color_mode);
568 return *this;
569}
572 this->set_color_brightness(brightness);
573 return *this;
574}
577 this->set_red(red);
578 return *this;
579}
582 this->set_green(green);
583 return *this;
584}
587 this->set_blue(blue);
588 return *this;
589}
592 this->set_white(white);
593 return *this;
594}
603 this->set_cold_white(cold_white);
604 return *this;
605}
608 this->set_warm_white(warm_white);
609 return *this;
610}
611IMPLEMENT_LIGHT_CALL_SETTER(state, bool, FLAG_HAS_STATE)
612IMPLEMENT_LIGHT_CALL_SETTER(transition_length, uint32_t, FLAG_HAS_TRANSITION)
613IMPLEMENT_LIGHT_CALL_SETTER(flash_length, uint32_t, FLAG_HAS_FLASH)
614IMPLEMENT_LIGHT_CALL_SETTER(brightness, float, FLAG_HAS_BRIGHTNESS)
615IMPLEMENT_LIGHT_CALL_SETTER(color_mode, ColorMode, FLAG_HAS_COLOR_MODE)
616IMPLEMENT_LIGHT_CALL_SETTER(color_brightness, float, FLAG_HAS_COLOR_BRIGHTNESS)
617IMPLEMENT_LIGHT_CALL_SETTER(red, float, FLAG_HAS_RED)
618IMPLEMENT_LIGHT_CALL_SETTER(green, float, FLAG_HAS_GREEN)
619IMPLEMENT_LIGHT_CALL_SETTER(blue, float, FLAG_HAS_BLUE)
620IMPLEMENT_LIGHT_CALL_SETTER(white, float, FLAG_HAS_WHITE)
621IMPLEMENT_LIGHT_CALL_SETTER(color_temperature, float, FLAG_HAS_COLOR_TEMPERATURE)
622IMPLEMENT_LIGHT_CALL_SETTER(cold_white, float, FLAG_HAS_COLD_WHITE)
623IMPLEMENT_LIGHT_CALL_SETTER(warm_white, float, FLAG_HAS_WARM_WHITE)
624LightCall &LightCall::set_effect(optional<std::string> effect) {
625 if (effect.has_value())
626 this->set_effect(*effect);
627 return *this;
628}
630 this->effect_ = effect_number;
631 this->set_flag_(FLAG_HAS_EFFECT, true);
632 return *this;
633}
635 if (effect_number.has_value()) {
636 this->effect_ = effect_number.value();
637 }
638 this->set_flag_(FLAG_HAS_EFFECT, effect_number.has_value());
639 return *this;
640}
642 this->set_flag_(FLAG_PUBLISH, publish);
643 return *this;
644}
646 this->set_flag_(FLAG_SAVE, save);
647 return *this;
648}
649LightCall &LightCall::set_rgb(float red, float green, float blue) {
650 this->set_red(red);
651 this->set_green(green);
652 this->set_blue(blue);
653 return *this;
654}
655LightCall &LightCall::set_rgbw(float red, float green, float blue, float white) {
656 this->set_rgb(red, green, blue);
657 this->set_white(white);
658 return *this;
659}
660
661} // namespace light
662} // namespace esphome
BedjetMode mode
BedJet operating mode.
const StringRef & get_name() const
constexpr const char * c_str() const
Definition string_ref.h:69
This class represents a requested change in a light state.
Definition light_call.h:18
bool has_color_mode() const
Definition light_call.h:149
bool has_color_temperature() const
Definition light_call.h:146
LightCall & set_color_mode_if_supported(ColorMode color_mode)
Set the color mode of the light, if this mode is supported.
LightCall & set_color_temperature(optional< float > color_temperature)
Set the color temperature of the light in mireds for CWWW or RGBWW lights.
LightCall & set_publish(bool publish)
Set whether this light call should trigger a publish state.
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 has_warm_white() const
Definition light_call.h:148
bool has_brightness() const
Definition light_call.h:140
LightCall & set_rgb(float red, float green, float blue)
Set the RGB color of the light by RGB values.
bool has_cold_white() const
Definition light_call.h:147
LightCall & set_transition_length_if_supported(uint32_t transition_length)
Set the transition length property if the light supports transitions.
bool has_color_brightness() const
Definition light_call.h:141
LightCall & set_red_if_supported(float red)
Set the red property if the light supports RGB.
LightCall & set_effect(optional< std::string > effect)
Set the effect of the light by its name.
std::set< ColorMode > get_suitable_color_modes_()
Get potential color modes for this light call.
LightCall & set_color_brightness_if_supported(float brightness)
Set the color brightness property if the light supports RGBW.
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_green_if_supported(float green)
Set the green property if the light supports RGB.
LightCall & set_warm_white(optional< float > warm_white)
Set the warm white value of the light from 0.0 to 1.0.
LightCall & set_rgbw(float red, float green, float blue, float white)
Set the RGBW color of the light by RGB values.
LightCall & set_save(bool save)
Set whether this light call should trigger a save state to recover them at startup....
LightCall & set_color_temperature_if_supported(float color_temperature)
Set the color_temperature property if the light supports color temperature.
LightCall & set_blue(optional< float > blue)
Set the blue RGB value of the light from 0.0 to 1.0.
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.
ColorMode get_active_color_mode_()
Get the currently targeted, or active if none set, color mode.
void set_flag_(FieldFlags flag, bool value)
Definition light_call.h:217
LightCall & set_white_if_supported(float white)
Set the white property if the light supports RGB.
LightCall & set_cold_white_if_supported(float cold_white)
Set the cold white property if the light supports cold white output.
LightCall & set_warm_white_if_supported(float warm_white)
Set the warm white property if the light supports cold white output.
LightCall & set_brightness_if_supported(float brightness)
Set the brightness property if the light supports brightness.
LightColorValues validate_()
Validate all properties and return the target light color 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_blue_if_supported(float blue)
Set the blue property if the light supports RGB.
void transform_parameters_()
Some color modes also can be set using non-native parameters, transform those calls.
LightCall & from_light_color_values(const LightColorValues &values)
LightCall & set_state(optional< bool > state)
Set the binary ON/OFF state of the light.
LightCall & set_color_mode(optional< ColorMode > color_mode)
Set the color mode of the light.
LightCall & set_transition_length(optional< uint32_t > transition_length)
Set the transition length of this call in milliseconds.
This class represents the color state for a light object.
void set_color_mode(ColorMode color_mode)
Set the color mode of these light color values.
float get_brightness() const
Get the brightness property of these light color values. In range 0.0 to 1.0.
float get_blue() const
Get the blue property of these light color values. In range 0.0 to 1.0.
float get_white() const
Get the white property of these light color values. In range 0.0 to 1.0.
float get_color_temperature() const
Get the color temperature property of these light color values in mired.
float get_cold_white() const
Get the cold white property of these light color values. In range 0.0 to 1.0.
bool is_on() const
Get the binary true/false state of these light color values.
float get_green() const
Get the green property of these light color values. In range 0.0 to 1.0.
float get_warm_white() const
Get the warm white property of these light color values. In range 0.0 to 1.0.
ColorMode get_color_mode() const
Get the color mode of these light color values.
float get_red() const
Get the red property of these light color values. In range 0.0 to 1.0.
float get_color_brightness() const
Get the color brightness property of these light color values. In range 0.0 to 1.0.
const std::string & get_name()
void start_effect_(uint32_t effect_index)
Internal method to start an effect with the given index.
void stop_effect_()
Internal method to stop the current effect (if one is active).
LightColorValues remote_values
The remote color values reported to the frontend.
void save_remote_values_()
Internal method to save the current remote_values to the preferences.
void set_immediately_(const LightColorValues &target, bool set_remote_values)
Internal method to set the color values to target immediately (with no transition).
float get_gamma_correct() const
void publish_state()
Publish the currently active state to the frontend.
uint32_t active_effect_index_
Value for storing the index of the currently active effect. 0 if no effect is active.
void start_flash_(const LightColorValues &target, uint32_t length, bool set_remote_values)
Internal method to start a flash for the specified amount of time.
std::vector< LightEffect * > effects_
List of effects for this light.
CallbackManager< void()> target_state_reached_callback_
Callback to call when the state of current_values and remote_values are equal This should be called o...
void start_transition_(const LightColorValues &target, uint32_t length, bool set_remote_values)
Internal method to start a transition to the target color with the given length.
uint32_t default_transition_length_
Default transition length for all transitions in ms.
bool supports_color_mode(ColorMode color_mode) const
const std::set< ColorMode > & get_supported_color_modes() const
bool has_value() const
Definition optional.h:92
value_type const & value() const
Definition optional.h:94
bool state
Definition fan.h:0
mopeka_std_values val[4]
Range range
Definition msa3xx.h:0
IMPLEMENT_LIGHT_CALL_SETTER(state, bool, FLAG_HAS_STATE) IMPLEMENT_LIGHT_CALL_SETTER(transition_length
ColorMode
Color modes are a combination of color capabilities that can be used at the same time.
Definition color_mode.h:49
@ RGB_COLD_WARM_WHITE
RGB color output, and separate cold and warm white outputs.
@ UNKNOWN
No color mode configured (cannot be a supported mode, only active when light is off).
@ 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.
@ RGB
RGB color output.
@ 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.
@ 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.
Definition a01nyub.cpp:7
float gamma_uncorrect(float value, float gamma)
Reverts gamma correction of gamma to value.
Definition helpers.cpp:490