mirror of
				https://github.com/esphome/esphome.git
				synced 2025-10-30 22:53:59 +00:00 
			
		
		
		
	[cover] Reduce flash usage by optimizing validation messages (#10130)
This commit is contained in:
		| @@ -99,43 +99,39 @@ const optional<float> &CoverCall::get_tilt() const { return this->tilt_; } | |||||||
| const optional<bool> &CoverCall::get_toggle() const { return this->toggle_; } | const optional<bool> &CoverCall::get_toggle() const { return this->toggle_; } | ||||||
| void CoverCall::validate_() { | void CoverCall::validate_() { | ||||||
|   auto traits = this->parent_->get_traits(); |   auto traits = this->parent_->get_traits(); | ||||||
|  |   const char *name = this->parent_->get_name().c_str(); | ||||||
|  |  | ||||||
|   if (this->position_.has_value()) { |   if (this->position_.has_value()) { | ||||||
|     auto pos = *this->position_; |     auto pos = *this->position_; | ||||||
|     if (!traits.get_supports_position() && pos != COVER_OPEN && pos != COVER_CLOSED) { |     if (!traits.get_supports_position() && pos != COVER_OPEN && pos != COVER_CLOSED) { | ||||||
|       ESP_LOGW(TAG, "'%s' - This cover device does not support setting position!", this->parent_->get_name().c_str()); |       ESP_LOGW(TAG, "'%s': position unsupported", name); | ||||||
|       this->position_.reset(); |       this->position_.reset(); | ||||||
|     } else if (pos < 0.0f || pos > 1.0f) { |     } else if (pos < 0.0f || pos > 1.0f) { | ||||||
|       ESP_LOGW(TAG, "'%s' - Position %.2f is out of range [0.0 - 1.0]", this->parent_->get_name().c_str(), pos); |       ESP_LOGW(TAG, "'%s': position %.2f out of range", name, pos); | ||||||
|       this->position_ = clamp(pos, 0.0f, 1.0f); |       this->position_ = clamp(pos, 0.0f, 1.0f); | ||||||
|     } |     } | ||||||
|   } |   } | ||||||
|   if (this->tilt_.has_value()) { |   if (this->tilt_.has_value()) { | ||||||
|     auto tilt = *this->tilt_; |     auto tilt = *this->tilt_; | ||||||
|     if (!traits.get_supports_tilt()) { |     if (!traits.get_supports_tilt()) { | ||||||
|       ESP_LOGW(TAG, "'%s' - This cover device does not support tilt!", this->parent_->get_name().c_str()); |       ESP_LOGW(TAG, "'%s': tilt unsupported", name); | ||||||
|       this->tilt_.reset(); |       this->tilt_.reset(); | ||||||
|     } else if (tilt < 0.0f || tilt > 1.0f) { |     } else if (tilt < 0.0f || tilt > 1.0f) { | ||||||
|       ESP_LOGW(TAG, "'%s' - Tilt %.2f is out of range [0.0 - 1.0]", this->parent_->get_name().c_str(), tilt); |       ESP_LOGW(TAG, "'%s': tilt %.2f out of range", name, tilt); | ||||||
|       this->tilt_ = clamp(tilt, 0.0f, 1.0f); |       this->tilt_ = clamp(tilt, 0.0f, 1.0f); | ||||||
|     } |     } | ||||||
|   } |   } | ||||||
|   if (this->toggle_.has_value()) { |   if (this->toggle_.has_value()) { | ||||||
|     if (!traits.get_supports_toggle()) { |     if (!traits.get_supports_toggle()) { | ||||||
|       ESP_LOGW(TAG, "'%s' - This cover device does not support toggle!", this->parent_->get_name().c_str()); |       ESP_LOGW(TAG, "'%s': toggle unsupported", name); | ||||||
|       this->toggle_.reset(); |       this->toggle_.reset(); | ||||||
|     } |     } | ||||||
|   } |   } | ||||||
|   if (this->stop_) { |   if (this->stop_) { | ||||||
|     if (this->position_.has_value()) { |     if (this->position_.has_value() || this->tilt_.has_value() || this->toggle_.has_value()) { | ||||||
|       ESP_LOGW(TAG, "Cannot set position when stopping a cover!"); |       ESP_LOGW(TAG, "'%s': cannot position/tilt/toggle when stopping", name); | ||||||
|       this->position_.reset(); |       this->position_.reset(); | ||||||
|     } |  | ||||||
|     if (this->tilt_.has_value()) { |  | ||||||
|       ESP_LOGW(TAG, "Cannot set tilt when stopping a cover!"); |  | ||||||
|       this->tilt_.reset(); |       this->tilt_.reset(); | ||||||
|     } |  | ||||||
|     if (this->toggle_.has_value()) { |  | ||||||
|       ESP_LOGW(TAG, "Cannot set toggle when stopping a cover!"); |  | ||||||
|       this->toggle_.reset(); |       this->toggle_.reset(); | ||||||
|     } |     } | ||||||
|   } |   } | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user