mirror of
https://github.com/esphome/esphome.git
synced 2026-09-28 15:30:21 +00:00
[fan] Use register_apply_action for fan.toggle and fan.turn_off (#19600)
This commit is contained in:
@@ -61,8 +61,6 @@ RESTORE_MODES = {
|
||||
}
|
||||
|
||||
# Actions
|
||||
TurnOffAction = fan_ns.class_("TurnOffAction", automation.Action)
|
||||
ToggleAction = fan_ns.class_("ToggleAction", automation.Action)
|
||||
CycleSpeedAction = fan_ns.class_("CycleSpeedAction", automation.Action)
|
||||
|
||||
FanStateTrigger = fan_ns.class_(
|
||||
@@ -310,21 +308,8 @@ FAN_ACTION_SCHEMA = maybe_simple_id(
|
||||
)
|
||||
|
||||
|
||||
@automation.register_action(
|
||||
"fan.toggle", ToggleAction, FAN_ACTION_SCHEMA, synchronous=True
|
||||
)
|
||||
async def fan_toggle_to_code(config, action_id, template_arg, args):
|
||||
paren = await cg.get_variable(config[CONF_ID])
|
||||
return cg.new_Pvariable(action_id, template_arg, paren)
|
||||
|
||||
|
||||
@automation.register_action(
|
||||
"fan.turn_off", TurnOffAction, FAN_ACTION_SCHEMA, synchronous=True
|
||||
)
|
||||
async def fan_turn_off_to_code(config, action_id, template_arg, args):
|
||||
paren = await cg.get_variable(config[CONF_ID])
|
||||
return cg.new_Pvariable(action_id, template_arg, paren)
|
||||
|
||||
automation.register_apply_action("fan.toggle", FAN_ACTION_SCHEMA, call="toggle")
|
||||
automation.register_apply_action("fan.turn_off", FAN_ACTION_SCHEMA, call="turn_off")
|
||||
|
||||
automation.register_apply_action(
|
||||
"fan.turn_on",
|
||||
|
||||
@@ -6,24 +6,6 @@
|
||||
|
||||
namespace esphome::fan {
|
||||
|
||||
template<typename... Ts> class TurnOffAction final : public Action<Ts...> {
|
||||
public:
|
||||
explicit TurnOffAction(Fan *state) : state_(state) {}
|
||||
|
||||
void play(const Ts &...x) override { this->state_->turn_off().perform(); }
|
||||
|
||||
Fan *state_;
|
||||
};
|
||||
|
||||
template<typename... Ts> class ToggleAction final : public Action<Ts...> {
|
||||
public:
|
||||
explicit ToggleAction(Fan *state) : state_(state) {}
|
||||
|
||||
void play(const Ts &...x) override { this->state_->toggle().perform(); }
|
||||
|
||||
Fan *state_;
|
||||
};
|
||||
|
||||
template<typename... Ts> class CycleSpeedAction final : public Action<Ts...> {
|
||||
public:
|
||||
explicit CycleSpeedAction(Fan *state) : state_(state) {}
|
||||
|
||||
@@ -104,6 +104,9 @@ button:
|
||||
fan.is_on: test_fan
|
||||
then:
|
||||
- fan.turn_off: test_fan
|
||||
- fan.toggle: test_fan
|
||||
- fan.turn_off:
|
||||
id: test_fan
|
||||
- if:
|
||||
condition:
|
||||
fan.is_off:
|
||||
|
||||
Reference in New Issue
Block a user