mirror of
				https://github.com/esphome/esphome.git
				synced 2025-10-30 22:53:59 +00:00 
			
		
		
		
	Float output: Fix min_power and max_power adjusting when output is inverted (#1250)
This patch fixes faulty behaviour when both, invert and min_power/max_power are set for a float output (e.g. PWM). The current code scales the output level to the range [min_power, max_power] and subsequently inverts the value. This leads to values that are outside the range [min_power, max_power]. This patch fixes the problem by inverting the requested level first and then scaling it to the interval [min_power, max_power]. Co-authored-by: Thomas Niederprüm <niederp@physik.uni-kl.de>
This commit is contained in:
		| @@ -29,10 +29,9 @@ void FloatOutput::set_level(float state) { | |||||||
|     this->power_.unrequest(); |     this->power_.unrequest(); | ||||||
|   } |   } | ||||||
| #endif | #endif | ||||||
|  |  | ||||||
|   float adjusted_value = (state * (this->max_power_ - this->min_power_)) + this->min_power_; |  | ||||||
|   if (this->is_inverted()) |   if (this->is_inverted()) | ||||||
|     adjusted_value = 1.0f - adjusted_value; |     state = 1.0f - state; | ||||||
|  |   float adjusted_value = (state * (this->max_power_ - this->min_power_)) + this->min_power_; | ||||||
|   this->write_state(adjusted_value); |   this->write_state(adjusted_value); | ||||||
| } | } | ||||||
|  |  | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user