mirror of
https://github.com/esphome/esphome.git
synced 2025-01-31 10:10:56 +00:00
Dont force 0 state instead of min_power unless explicit config set (#2107)
This commit is contained in:
parent
fb24e55c8d
commit
f7311aa025
@ -17,6 +17,8 @@ from esphome.core import CORE
|
|||||||
CODEOWNERS = ["@esphome/core"]
|
CODEOWNERS = ["@esphome/core"]
|
||||||
IS_PLATFORM_COMPONENT = True
|
IS_PLATFORM_COMPONENT = True
|
||||||
|
|
||||||
|
CONF_ZERO_MEANS_ZERO = "zero_means_zero"
|
||||||
|
|
||||||
BINARY_OUTPUT_SCHEMA = cv.Schema(
|
BINARY_OUTPUT_SCHEMA = cv.Schema(
|
||||||
{
|
{
|
||||||
cv.Optional(CONF_POWER_SUPPLY): cv.use_id(power_supply.PowerSupply),
|
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_MAX_POWER): cv.percentage,
|
||||||
cv.Optional(CONF_MIN_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]))
|
cg.add(obj.set_max_power(config[CONF_MAX_POWER]))
|
||||||
if CONF_MIN_POWER in config:
|
if CONF_MIN_POWER in config:
|
||||||
cg.add(obj.set_min_power(config[CONF_MIN_POWER]))
|
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):
|
async def register_output(var, config):
|
||||||
|
@ -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
|
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_; }
|
float FloatOutput::get_min_power() const { return this->min_power_; }
|
||||||
|
|
||||||
void FloatOutput::set_level(float state) {
|
void FloatOutput::set_level(float state) {
|
||||||
@ -31,7 +33,7 @@ void FloatOutput::set_level(float state) {
|
|||||||
#endif
|
#endif
|
||||||
if (this->is_inverted())
|
if (this->is_inverted())
|
||||||
state = 1.0f - state;
|
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);
|
this->write_state(state);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -46,6 +46,12 @@ class FloatOutput : public BinaryOutput {
|
|||||||
*/
|
*/
|
||||||
void set_min_power(float min_power);
|
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.
|
/** Set the level of this float output, this is called from the front-end.
|
||||||
*
|
*
|
||||||
* @param state The new state.
|
* @param state The new state.
|
||||||
@ -76,6 +82,7 @@ class FloatOutput : public BinaryOutput {
|
|||||||
|
|
||||||
float max_power_{1.0f};
|
float max_power_{1.0f};
|
||||||
float min_power_{0.0f};
|
float min_power_{0.0f};
|
||||||
|
bool zero_means_zero_;
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace output
|
} // namespace output
|
||||||
|
Loading…
x
Reference in New Issue
Block a user