Dont force 0 state instead of min_power unless explicit config set (#2107)

This commit is contained in:
Jesse Hills 2021-08-02 20:33:00 +12:00 committed by GitHub
parent fb24e55c8d
commit f7311aa025
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 15 additions and 1 deletions

View file

@ -17,6 +17,8 @@ from esphome.core import CORE
CODEOWNERS = ["@esphome/core"]
IS_PLATFORM_COMPONENT = True
CONF_ZERO_MEANS_ZERO = "zero_means_zero"
BINARY_OUTPUT_SCHEMA = cv.Schema(
{
cv.Optional(CONF_POWER_SUPPLY): cv.use_id(power_supply.PowerSupply),
@ -28,6 +30,7 @@ FLOAT_OUTPUT_SCHEMA = BINARY_OUTPUT_SCHEMA.extend(
{
cv.Optional(CONF_MAX_POWER): cv.percentage,
cv.Optional(CONF_MIN_POWER): cv.percentage,
cv.Optional(CONF_ZERO_MEANS_ZERO, default=False): cv.boolean,
}
)
@ -53,6 +56,8 @@ async def setup_output_platform_(obj, config):
cg.add(obj.set_max_power(config[CONF_MAX_POWER]))
if CONF_MIN_POWER in config:
cg.add(obj.set_min_power(config[CONF_MIN_POWER]))
if CONF_ZERO_MEANS_ZERO in config:
cg.add(obj.set_zero_means_zero(config[CONF_ZERO_MEANS_ZERO]))
async def register_output(var, config):

View file

@ -17,6 +17,8 @@ void FloatOutput::set_min_power(float min_power) {
this->min_power_ = clamp(min_power, 0.0f, this->max_power_); // Clamp to 0.0>=MIN>=MAX
}
void FloatOutput::set_zero_means_zero(bool zero_means_zero) { this->zero_means_zero_ = zero_means_zero; }
float FloatOutput::get_min_power() const { return this->min_power_; }
void FloatOutput::set_level(float state) {
@ -31,7 +33,7 @@ void FloatOutput::set_level(float state) {
#endif
if (this->is_inverted())
state = 1.0f - state;
if (state == 0.0f) { // regardless of min_power_, 0.0 means off
if (state == 0.0f && this->zero_means_zero_) { // regardless of min_power_, 0.0 means off
this->write_state(state);
return;
}

View file

@ -46,6 +46,12 @@ class FloatOutput : public BinaryOutput {
*/
void set_min_power(float min_power);
/** Sets this output to ignore min_power for a 0 state
*
* @param zero True if a 0 state should mean 0 and not min_power.
*/
void set_zero_means_zero(bool zero_means_zero);
/** Set the level of this float output, this is called from the front-end.
*
* @param state The new state.
@ -76,6 +82,7 @@ class FloatOutput : public BinaryOutput {
float max_power_{1.0f};
float min_power_{0.0f};
bool zero_means_zero_;
};
} // namespace output