[hbridge] Use register_apply_action for fan.hbridge.brake (#19649)

This commit is contained in:
J. Nick Koston
2026-09-25 14:30:30 -04:00
committed by GitHub
parent 340e105a76
commit 9ae83f2830
4 changed files with 17 additions and 16 deletions
+2 -6
View File
@@ -27,9 +27,6 @@ DECAY_MODE_OPTIONS = {
"FAST": DecayMode.DECAY_MODE_FAST,
}
# Actions
BrakeAction = hbridge_ns.class_("BrakeAction", automation.Action)
CONFIG_SCHEMA = (
fan.fan_schema(HBridgeFan)
.extend(
@@ -48,11 +45,10 @@ CONFIG_SCHEMA = (
)
automation.register_simple_action(
automation.register_apply_action(
"fan.hbridge.brake",
BrakeAction,
maybe_simple_id({cv.GenerateID(): cv.use_id(HBridgeFan)}),
synchronous=True,
automation.ApplyCall("brake()"),
)
@@ -1,6 +1,5 @@
#pragma once
#include "esphome/core/automation.h"
#include "esphome/components/output/binary_output.h"
#include "esphome/components/output/float_output.h"
#include "esphome/components/fan/fan.h"
@@ -46,13 +45,4 @@ class HBridgeFan final : public Component, public fan::Fan {
void set_hbridge_levels_(float a_level, float b_level, float enable);
};
template<typename... Ts> class BrakeAction final : public Action<Ts...> {
public:
explicit BrakeAction(HBridgeFan *parent) : parent_(parent) {}
void play(const Ts &...x) override { this->parent_->brake(); }
HBridgeFan *parent_;
};
} // namespace esphome::hbridge
@@ -0,0 +1,5 @@
button:
- platform: template
name: Brake the fan
on_press:
- fan.hbridge.brake: fan_hbridge
@@ -0,0 +1,10 @@
substitutions:
pwm_platform: "esp8266_pwm"
output1_pin: "4"
output2_pin: "5"
output3_pin: "12"
output4_pin: "13"
packages:
hbridge: !include common.yaml
actions: !include common-actions.yaml