[sound_level] Use register_apply_action for sound_level.start and sound_level.stop (#19656)

This commit is contained in:
J. Nick Koston
2026-09-25 18:56:32 +00:00
committed by GitHub
parent 1edc327835
commit 14bd50d469
2 changed files with 4 additions and 25 deletions
+4 -14
View File
@@ -25,8 +25,6 @@ CONF_RMS = "rms"
sound_level_ns = cg.esphome_ns.namespace("sound_level")
SoundLevelComponent = sound_level_ns.class_("SoundLevelComponent", cg.Component)
StartAction = sound_level_ns.class_("StartAction", automation.Action)
StopAction = sound_level_ns.class_("StopAction", automation.Action)
CONFIG_SCHEMA = cv.All(
cv.Schema(
@@ -90,17 +88,9 @@ SOUND_LEVEL_ACTION_SCHEMA = automation.maybe_simple_id(
)
automation.register_parented_action(
"sound_level.start",
StartAction,
SOUND_LEVEL_ACTION_SCHEMA,
synchronous=True,
automation.register_apply_action(
"sound_level.start", SOUND_LEVEL_ACTION_SCHEMA, automation.ApplyCall("start()")
)
automation.register_parented_action(
"sound_level.stop",
StopAction,
SOUND_LEVEL_ACTION_SCHEMA,
synchronous=True,
automation.register_apply_action(
"sound_level.stop", SOUND_LEVEL_ACTION_SCHEMA, automation.ApplyCall("stop()")
)
@@ -7,7 +7,6 @@
#include "esphome/components/ring_buffer/ring_buffer.h"
#include "esphome/components/sensor/sensor.h"
#include "esphome/core/automation.h"
#include "esphome/core/component.h"
namespace esphome::sound_level {
@@ -59,16 +58,6 @@ class SoundLevelComponent final : public Component {
uint32_t measurement_duration_ms_;
};
template<typename... Ts> class StartAction final : public Action<Ts...>, public Parented<SoundLevelComponent> {
public:
void play(const Ts &...x) override { this->parent_->start(); }
};
template<typename... Ts> class StopAction final : public Action<Ts...>, public Parented<SoundLevelComponent> {
public:
void play(const Ts &...x) override { this->parent_->stop(); }
};
} // namespace esphome::sound_level
#endif