mirror of
				https://github.com/esphome/esphome.git
				synced 2025-10-31 07:03:55 +00:00 
			
		
		
		
	fix
This commit is contained in:
		| @@ -183,18 +183,6 @@ LightColorValues LightCall::validate_() { | |||||||
|   auto *name = this->parent_->get_name().c_str(); |   auto *name = this->parent_->get_name().c_str(); | ||||||
|   auto traits = this->parent_->get_traits(); |   auto traits = this->parent_->get_traits(); | ||||||
|  |  | ||||||
|   // Cache frequently used flags |  | ||||||
|   const bool has_state_flag = this->has_state(); |  | ||||||
|   const bool has_brightness_flag = this->has_brightness(); |  | ||||||
|   const bool has_color_brightness_flag = this->has_color_brightness(); |  | ||||||
|   const bool has_red_flag = this->has_red(); |  | ||||||
|   const bool has_green_flag = this->has_green(); |  | ||||||
|   const bool has_blue_flag = this->has_blue(); |  | ||||||
|   const bool has_white_flag = this->has_white(); |  | ||||||
|   const bool has_color_temperature_flag = this->has_color_temperature(); |  | ||||||
|   const bool has_cold_white_flag = this->has_cold_white(); |  | ||||||
|   const bool has_warm_white_flag = this->has_warm_white(); |  | ||||||
|  |  | ||||||
|   // Color mode check |   // Color mode check | ||||||
|   if (this->has_color_mode() && !traits.supports_color_mode(this->color_mode_)) { |   if (this->has_color_mode() && !traits.supports_color_mode(this->color_mode_)) { | ||||||
|     ESP_LOGW(TAG, "'%s' does not support color mode %s", name, LOG_STR_ARG(color_mode_to_human(this->color_mode_))); |     ESP_LOGW(TAG, "'%s' does not support color mode %s", name, LOG_STR_ARG(color_mode_to_human(this->color_mode_))); | ||||||
| @@ -212,7 +200,7 @@ LightColorValues LightCall::validate_() { | |||||||
|   this->transform_parameters_(); |   this->transform_parameters_(); | ||||||
|  |  | ||||||
|   // Brightness exists check |   // Brightness exists check | ||||||
|   if (has_brightness_flag && this->brightness_ > 0.0f && !(color_mode & ColorCapability::BRIGHTNESS)) { |   if (this->has_brightness() && this->brightness_ > 0.0f && !(color_mode & ColorCapability::BRIGHTNESS)) { | ||||||
|     log_feature_not_supported(name, "brightness"); |     log_feature_not_supported(name, "brightness"); | ||||||
|     this->set_flag_(FLAG_HAS_BRIGHTNESS, false); |     this->set_flag_(FLAG_HAS_BRIGHTNESS, false); | ||||||
|   } |   } | ||||||
| @@ -224,14 +212,14 @@ LightColorValues LightCall::validate_() { | |||||||
|   } |   } | ||||||
|  |  | ||||||
|   // Color brightness exists check |   // Color brightness exists check | ||||||
|   if (has_color_brightness_flag && this->color_brightness_ > 0.0f && !(color_mode & ColorCapability::RGB)) { |   if (this->has_color_brightness() && this->color_brightness_ > 0.0f && !(color_mode & ColorCapability::RGB)) { | ||||||
|     log_color_mode_not_supported(name, "RGB brightness"); |     log_color_mode_not_supported(name, "RGB brightness"); | ||||||
|     this->set_flag_(FLAG_HAS_COLOR_BRIGHTNESS, false); |     this->set_flag_(FLAG_HAS_COLOR_BRIGHTNESS, false); | ||||||
|   } |   } | ||||||
|  |  | ||||||
|   // RGB exists check |   // RGB exists check | ||||||
|   if ((has_red_flag && this->red_ > 0.0f) || (has_green_flag && this->green_ > 0.0f) || |   if ((this->has_red() && this->red_ > 0.0f) || (this->has_green() && this->green_ > 0.0f) || | ||||||
|       (has_blue_flag && this->blue_ > 0.0f)) { |       (this->has_blue() && this->blue_ > 0.0f)) { | ||||||
|     if (!(color_mode & ColorCapability::RGB)) { |     if (!(color_mode & ColorCapability::RGB)) { | ||||||
|       log_color_mode_not_supported(name, "RGB color"); |       log_color_mode_not_supported(name, "RGB color"); | ||||||
|       this->set_flag_(FLAG_HAS_RED, false); |       this->set_flag_(FLAG_HAS_RED, false); | ||||||
| @@ -241,21 +229,21 @@ LightColorValues LightCall::validate_() { | |||||||
|   } |   } | ||||||
|  |  | ||||||
|   // White value exists check |   // White value exists check | ||||||
|   if (has_white_flag && this->white_ > 0.0f && |   if (this->has_white() && this->white_ > 0.0f && | ||||||
|       !(color_mode & ColorCapability::WHITE || color_mode & ColorCapability::COLD_WARM_WHITE)) { |       !(color_mode & ColorCapability::WHITE || color_mode & ColorCapability::COLD_WARM_WHITE)) { | ||||||
|     log_color_mode_not_supported(name, "white value"); |     log_color_mode_not_supported(name, "white value"); | ||||||
|     this->set_flag_(FLAG_HAS_WHITE, false); |     this->set_flag_(FLAG_HAS_WHITE, false); | ||||||
|   } |   } | ||||||
|  |  | ||||||
|   // Color temperature exists check |   // Color temperature exists check | ||||||
|   if (has_color_temperature_flag && |   if (this->has_color_temperature() && | ||||||
|       !(color_mode & ColorCapability::COLOR_TEMPERATURE || color_mode & ColorCapability::COLD_WARM_WHITE)) { |       !(color_mode & ColorCapability::COLOR_TEMPERATURE || color_mode & ColorCapability::COLD_WARM_WHITE)) { | ||||||
|     log_color_mode_not_supported(name, "color temperature"); |     log_color_mode_not_supported(name, "color temperature"); | ||||||
|     this->set_flag_(FLAG_HAS_COLOR_TEMPERATURE, false); |     this->set_flag_(FLAG_HAS_COLOR_TEMPERATURE, false); | ||||||
|   } |   } | ||||||
|  |  | ||||||
|   // Cold/warm white value exists check |   // Cold/warm white value exists check | ||||||
|   if ((has_cold_white_flag && this->cold_white_ > 0.0f) || (has_warm_white_flag && this->warm_white_ > 0.0f)) { |   if ((this->has_cold_white() && this->cold_white_ > 0.0f) || (this->has_warm_white() && this->warm_white_ > 0.0f)) { | ||||||
|     if (!(color_mode & ColorCapability::COLD_WARM_WHITE)) { |     if (!(color_mode & ColorCapability::COLD_WARM_WHITE)) { | ||||||
|       log_color_mode_not_supported(name, "cold/warm white value"); |       log_color_mode_not_supported(name, "cold/warm white value"); | ||||||
|       this->set_flag_(FLAG_HAS_COLD_WHITE, false); |       this->set_flag_(FLAG_HAS_COLD_WHITE, false); | ||||||
| @@ -285,18 +273,18 @@ LightColorValues LightCall::validate_() { | |||||||
|   VALIDATE_RANGE_(color_temperature, "Color temperature", traits.get_min_mireds(), traits.get_max_mireds()) |   VALIDATE_RANGE_(color_temperature, "Color temperature", traits.get_min_mireds(), traits.get_max_mireds()) | ||||||
|  |  | ||||||
|   // Flag whether an explicit turn off was requested, in which case we'll also stop the effect. |   // Flag whether an explicit turn off was requested, in which case we'll also stop the effect. | ||||||
|   bool explicit_turn_off_request = has_state_flag && !this->state_; |   bool explicit_turn_off_request = this->has_state() && !this->state_; | ||||||
|  |  | ||||||
|   // Turn off when brightness is set to zero, and reset brightness (so that it has nonzero brightness when turned on). |   // Turn off when brightness is set to zero, and reset brightness (so that it has nonzero brightness when turned on). | ||||||
|   if (has_brightness_flag && this->brightness_ == 0.0f) { |   if (this->has_brightness() && this->brightness_ == 0.0f) { | ||||||
|     this->state_ = false; |     this->state_ = false; | ||||||
|     this->set_flag_(FLAG_HAS_STATE, true); |     this->set_flag_(FLAG_HAS_STATE, true); | ||||||
|     this->brightness_ = 1.0f; |     this->brightness_ = 1.0f; | ||||||
|   } |   } | ||||||
|  |  | ||||||
|   // Set color brightness to 100% if currently zero and a color is set. |   // Set color brightness to 100% if currently zero and a color is set. | ||||||
|   if (has_red_flag || has_green_flag || has_blue_flag) { |   if (this->has_red() || this->has_green() || this->has_blue()) { | ||||||
|     if (!has_color_brightness_flag && this->parent_->remote_values.get_color_brightness() == 0.0f) { |     if (!this->has_color_brightness() && this->parent_->remote_values.get_color_brightness() == 0.0f) { | ||||||
|       this->color_brightness_ = 1.0f; |       this->color_brightness_ = 1.0f; | ||||||
|       this->set_flag_(FLAG_HAS_COLOR_BRIGHTNESS, true); |       this->set_flag_(FLAG_HAS_COLOR_BRIGHTNESS, true); | ||||||
|     } |     } | ||||||
| @@ -306,25 +294,25 @@ LightColorValues LightCall::validate_() { | |||||||
|   auto v = this->parent_->remote_values; |   auto v = this->parent_->remote_values; | ||||||
|   if (this->has_color_mode()) |   if (this->has_color_mode()) | ||||||
|     v.set_color_mode(this->color_mode_); |     v.set_color_mode(this->color_mode_); | ||||||
|   if (has_state_flag) |   if (this->has_state()) | ||||||
|     v.set_state(this->state_); |     v.set_state(this->state_); | ||||||
|   if (has_brightness_flag) |   if (this->has_brightness()) | ||||||
|     v.set_brightness(this->brightness_); |     v.set_brightness(this->brightness_); | ||||||
|   if (has_color_brightness_flag) |   if (this->has_color_brightness()) | ||||||
|     v.set_color_brightness(this->color_brightness_); |     v.set_color_brightness(this->color_brightness_); | ||||||
|   if (has_red_flag) |   if (this->has_red()) | ||||||
|     v.set_red(this->red_); |     v.set_red(this->red_); | ||||||
|   if (has_green_flag) |   if (this->has_green()) | ||||||
|     v.set_green(this->green_); |     v.set_green(this->green_); | ||||||
|   if (has_blue_flag) |   if (this->has_blue()) | ||||||
|     v.set_blue(this->blue_); |     v.set_blue(this->blue_); | ||||||
|   if (has_white_flag) |   if (this->has_white()) | ||||||
|     v.set_white(this->white_); |     v.set_white(this->white_); | ||||||
|   if (has_color_temperature_flag) |   if (this->has_color_temperature()) | ||||||
|     v.set_color_temperature(this->color_temperature_); |     v.set_color_temperature(this->color_temperature_); | ||||||
|   if (has_cold_white_flag) |   if (this->has_cold_white()) | ||||||
|     v.set_cold_white(this->cold_white_); |     v.set_cold_white(this->cold_white_); | ||||||
|   if (has_warm_white_flag) |   if (this->has_warm_white()) | ||||||
|     v.set_warm_white(this->warm_white_); |     v.set_warm_white(this->warm_white_); | ||||||
|  |  | ||||||
|   v.normalize_color(); |   v.normalize_color(); | ||||||
| @@ -380,7 +368,7 @@ LightColorValues LightCall::validate_() { | |||||||
|   // If not a flash and turning the light off, then disable the light |   // If not a flash and turning the light off, then disable the light | ||||||
|   // Do not use light color values directly, so that effects can set 0% brightness |   // Do not use light color values directly, so that effects can set 0% brightness | ||||||
|   // Reason: When user turns off the light in frontend, the effect should also stop |   // Reason: When user turns off the light in frontend, the effect should also stop | ||||||
|   bool target_state = has_state_flag ? this->state_ : v.is_on(); |   bool target_state = this->has_state() ? this->state_ : v.is_on(); | ||||||
|   if (!this->has_flash_() && !target_state) { |   if (!this->has_flash_() && !target_state) { | ||||||
|     if (this->has_effect_()) { |     if (this->has_effect_()) { | ||||||
|       log_invalid_parameter(name, "cannot start effect when turning off"); |       log_invalid_parameter(name, "cannot start effect when turning off"); | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user