mirror of
https://github.com/esphome/esphome.git
synced 2026-06-24 13:45:15 +00:00
[rtttl] Gate on_finished_playback callback storage behind define (#16003)
This commit is contained in:
@@ -93,7 +93,9 @@ async def to_code(config):
|
|||||||
|
|
||||||
cg.add(var.set_gain(config[CONF_GAIN]))
|
cg.add(var.set_gain(config[CONF_GAIN]))
|
||||||
|
|
||||||
await automation.build_callback_automations(var, config, _CALLBACK_AUTOMATIONS)
|
if config.get(CONF_ON_FINISHED_PLAYBACK):
|
||||||
|
cg.add_define("USE_RTTTL_FINISHED_PLAYBACK_CALLBACK")
|
||||||
|
await automation.build_callback_automations(var, config, _CALLBACK_AUTOMATIONS)
|
||||||
|
|
||||||
|
|
||||||
@automation.register_action(
|
@automation.register_action(
|
||||||
|
|||||||
@@ -424,7 +424,9 @@ void Rtttl::set_state_(State state) {
|
|||||||
// Clear loop_done when transitioning from `State::STOPPED` to any other state
|
// Clear loop_done when transitioning from `State::STOPPED` to any other state
|
||||||
if (state == State::STOPPED) {
|
if (state == State::STOPPED) {
|
||||||
this->disable_loop();
|
this->disable_loop();
|
||||||
|
#ifdef USE_RTTTL_FINISHED_PLAYBACK_CALLBACK
|
||||||
this->on_finished_playback_callback_.call();
|
this->on_finished_playback_callback_.call();
|
||||||
|
#endif
|
||||||
ESP_LOGD(TAG, "Playback finished");
|
ESP_LOGD(TAG, "Playback finished");
|
||||||
} else if (old_state == State::STOPPED) {
|
} else if (old_state == State::STOPPED) {
|
||||||
this->enable_loop();
|
this->enable_loop();
|
||||||
|
|||||||
@@ -2,6 +2,8 @@
|
|||||||
|
|
||||||
#include "esphome/core/automation.h"
|
#include "esphome/core/automation.h"
|
||||||
#include "esphome/core/component.h"
|
#include "esphome/core/component.h"
|
||||||
|
#include "esphome/core/defines.h"
|
||||||
|
#include "esphome/core/helpers.h"
|
||||||
|
|
||||||
#ifdef USE_OUTPUT
|
#ifdef USE_OUTPUT
|
||||||
#include "esphome/components/output/float_output.h"
|
#include "esphome/components/output/float_output.h"
|
||||||
@@ -45,9 +47,11 @@ class Rtttl : public Component {
|
|||||||
|
|
||||||
bool is_playing() { return this->state_ != State::STOPPED; }
|
bool is_playing() { return this->state_ != State::STOPPED; }
|
||||||
|
|
||||||
|
#ifdef USE_RTTTL_FINISHED_PLAYBACK_CALLBACK
|
||||||
template<typename F> void add_on_finished_playback_callback(F &&callback) {
|
template<typename F> void add_on_finished_playback_callback(F &&callback) {
|
||||||
this->on_finished_playback_callback_.add(std::forward<F>(callback));
|
this->on_finished_playback_callback_.add(std::forward<F>(callback));
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
inline uint16_t get_integer_() {
|
inline uint16_t get_integer_() {
|
||||||
@@ -106,8 +110,10 @@ class Rtttl : public Component {
|
|||||||
uint32_t samples_gap_{0};
|
uint32_t samples_gap_{0};
|
||||||
#endif // USE_SPEAKER
|
#endif // USE_SPEAKER
|
||||||
|
|
||||||
|
#ifdef USE_RTTTL_FINISHED_PLAYBACK_CALLBACK
|
||||||
/// The callback to call when playback is finished.
|
/// The callback to call when playback is finished.
|
||||||
CallbackManager<void()> on_finished_playback_callback_;
|
CallbackManager<void()> on_finished_playback_callback_;
|
||||||
|
#endif
|
||||||
};
|
};
|
||||||
|
|
||||||
template<typename... Ts> class PlayAction : public Action<Ts...> {
|
template<typename... Ts> class PlayAction : public Action<Ts...> {
|
||||||
|
|||||||
@@ -186,6 +186,7 @@
|
|||||||
#define USE_MQTT
|
#define USE_MQTT
|
||||||
#define USE_MQTT_COVER_JSON
|
#define USE_MQTT_COVER_JSON
|
||||||
#define USE_NETWORK
|
#define USE_NETWORK
|
||||||
|
#define USE_RTTTL_FINISHED_PLAYBACK_CALLBACK
|
||||||
#define USE_RUNTIME_IMAGE_BMP
|
#define USE_RUNTIME_IMAGE_BMP
|
||||||
#define USE_RUNTIME_IMAGE_PNG
|
#define USE_RUNTIME_IMAGE_PNG
|
||||||
#define USE_RUNTIME_IMAGE_JPEG
|
#define USE_RUNTIME_IMAGE_JPEG
|
||||||
|
|||||||
@@ -29,3 +29,8 @@ output:
|
|||||||
|
|
||||||
rtttl:
|
rtttl:
|
||||||
output: rtttl_output
|
output: rtttl_output
|
||||||
|
on_finished_playback:
|
||||||
|
- then:
|
||||||
|
- logger.log: "Playback finished 1"
|
||||||
|
- then:
|
||||||
|
- logger.log: "Playback finished 2"
|
||||||
|
|||||||
Reference in New Issue
Block a user