From 9ae83f28301decb9dcad1a49472d8cfb679aa981 Mon Sep 17 00:00:00 2001 From: "J. Nick Koston" Date: Fri, 25 Sep 2026 19:30:30 +0100 Subject: [PATCH] [hbridge] Use register_apply_action for fan.hbridge.brake (#19649) --- esphome/components/hbridge/fan/__init__.py | 8 ++------ esphome/components/hbridge/fan/hbridge_fan.h | 10 ---------- tests/components/hbridge/common-actions.yaml | 5 +++++ tests/components/hbridge/test-actions.esp8266-ard.yaml | 10 ++++++++++ 4 files changed, 17 insertions(+), 16 deletions(-) create mode 100644 tests/components/hbridge/common-actions.yaml create mode 100644 tests/components/hbridge/test-actions.esp8266-ard.yaml diff --git a/esphome/components/hbridge/fan/__init__.py b/esphome/components/hbridge/fan/__init__.py index cd47d100be..e862760e6a 100644 --- a/esphome/components/hbridge/fan/__init__.py +++ b/esphome/components/hbridge/fan/__init__.py @@ -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()"), ) diff --git a/esphome/components/hbridge/fan/hbridge_fan.h b/esphome/components/hbridge/fan/hbridge_fan.h index 187b6d2a97..c786f60674 100644 --- a/esphome/components/hbridge/fan/hbridge_fan.h +++ b/esphome/components/hbridge/fan/hbridge_fan.h @@ -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 class BrakeAction final : public Action { - public: - explicit BrakeAction(HBridgeFan *parent) : parent_(parent) {} - - void play(const Ts &...x) override { this->parent_->brake(); } - - HBridgeFan *parent_; -}; - } // namespace esphome::hbridge diff --git a/tests/components/hbridge/common-actions.yaml b/tests/components/hbridge/common-actions.yaml new file mode 100644 index 0000000000..e0638c49c0 --- /dev/null +++ b/tests/components/hbridge/common-actions.yaml @@ -0,0 +1,5 @@ +button: + - platform: template + name: Brake the fan + on_press: + - fan.hbridge.brake: fan_hbridge diff --git a/tests/components/hbridge/test-actions.esp8266-ard.yaml b/tests/components/hbridge/test-actions.esp8266-ard.yaml new file mode 100644 index 0000000000..752ab72bf9 --- /dev/null +++ b/tests/components/hbridge/test-actions.esp8266-ard.yaml @@ -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