mirror of
https://github.com/esphome/esphome.git
synced 2025-07-29 14:46:40 +00:00
[output] Add set_min_power
& set_max_power
actions for FloatOutput
(#8934)
Co-authored-by: Jesse Hills <3060199+jesserockz@users.noreply.github.com>
This commit is contained in:
parent
4ff3137c0d
commit
6d30269565
@ -43,6 +43,8 @@ FloatOutputPtr = FloatOutput.operator("ptr")
|
||||
TurnOffAction = output_ns.class_("TurnOffAction", automation.Action)
|
||||
TurnOnAction = output_ns.class_("TurnOnAction", automation.Action)
|
||||
SetLevelAction = output_ns.class_("SetLevelAction", automation.Action)
|
||||
SetMinPowerAction = output_ns.class_("SetMinPowerAction", automation.Action)
|
||||
SetMaxPowerAction = output_ns.class_("SetMaxPowerAction", automation.Action)
|
||||
|
||||
|
||||
async def setup_output_platform_(obj, config):
|
||||
@ -104,6 +106,42 @@ async def output_set_level_to_code(config, action_id, template_arg, args):
|
||||
return var
|
||||
|
||||
|
||||
@automation.register_action(
|
||||
"output.set_min_power",
|
||||
SetMinPowerAction,
|
||||
cv.Schema(
|
||||
{
|
||||
cv.Required(CONF_ID): cv.use_id(FloatOutput),
|
||||
cv.Required(CONF_MIN_POWER): cv.templatable(cv.percentage),
|
||||
}
|
||||
),
|
||||
)
|
||||
async def output_set_min_power_to_code(config, action_id, template_arg, args):
|
||||
paren = await cg.get_variable(config[CONF_ID])
|
||||
var = cg.new_Pvariable(action_id, template_arg, paren)
|
||||
template_ = await cg.templatable(config[CONF_MIN_POWER], args, float)
|
||||
cg.add(var.set_min_power(template_))
|
||||
return var
|
||||
|
||||
|
||||
@automation.register_action(
|
||||
"output.set_max_power",
|
||||
SetMaxPowerAction,
|
||||
cv.Schema(
|
||||
{
|
||||
cv.Required(CONF_ID): cv.use_id(FloatOutput),
|
||||
cv.Required(CONF_MAX_POWER): cv.templatable(cv.percentage),
|
||||
}
|
||||
),
|
||||
)
|
||||
async def output_set_max_power_to_code(config, action_id, template_arg, args):
|
||||
paren = await cg.get_variable(config[CONF_ID])
|
||||
var = cg.new_Pvariable(action_id, template_arg, paren)
|
||||
template_ = await cg.templatable(config[CONF_MAX_POWER], args, float)
|
||||
cg.add(var.set_max_power(template_))
|
||||
return var
|
||||
|
||||
|
||||
async def to_code(config):
|
||||
cg.add_define("USE_OUTPUT")
|
||||
cg.add_global(output_ns.using)
|
||||
|
@ -40,5 +40,29 @@ template<typename... Ts> class SetLevelAction : public Action<Ts...> {
|
||||
FloatOutput *output_;
|
||||
};
|
||||
|
||||
template<typename... Ts> class SetMinPowerAction : public Action<Ts...> {
|
||||
public:
|
||||
SetMinPowerAction(FloatOutput *output) : output_(output) {}
|
||||
|
||||
TEMPLATABLE_VALUE(float, min_power)
|
||||
|
||||
void play(Ts... x) override { this->output_->set_min_power(this->min_power_.value(x...)); }
|
||||
|
||||
protected:
|
||||
FloatOutput *output_;
|
||||
};
|
||||
|
||||
template<typename... Ts> class SetMaxPowerAction : public Action<Ts...> {
|
||||
public:
|
||||
SetMaxPowerAction(FloatOutput *output) : output_(output) {}
|
||||
|
||||
TEMPLATABLE_VALUE(float, max_power)
|
||||
|
||||
void play(Ts... x) override { this->output_->set_max_power(this->max_power_.value(x...)); }
|
||||
|
||||
protected:
|
||||
FloatOutput *output_;
|
||||
};
|
||||
|
||||
} // namespace output
|
||||
} // namespace esphome
|
||||
|
@ -6,6 +6,12 @@ esphome:
|
||||
- output.set_level:
|
||||
id: light_output_1
|
||||
level: 50%
|
||||
- output.set_min_power:
|
||||
id: light_output_1
|
||||
min_power: 20%
|
||||
- output.set_max_power:
|
||||
id: light_output_1
|
||||
max_power: 80%
|
||||
|
||||
output:
|
||||
- platform: ${output_platform}
|
||||
|
Loading…
x
Reference in New Issue
Block a user