mirror of
https://github.com/esphome/esphome.git
synced 2026-09-28 15:30:21 +00:00
[sound_level] Use register_apply_action for sound_level.start and sound_level.stop (#19656)
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user