mirror of
https://github.com/esphome/esphome.git
synced 2024-11-27 09:18:00 +01:00
first pass at renaming
This commit is contained in:
parent
7d35a2a185
commit
7011043eff
16 changed files with 82 additions and 82 deletions
|
@ -1,4 +1,4 @@
|
|||
"""Nabu Media Player Setup."""
|
||||
"""Speaker Media Player Setup."""
|
||||
|
||||
import hashlib
|
||||
import logging
|
||||
|
@ -47,17 +47,17 @@ CONF_ON_MUTE = "on_mute"
|
|||
CONF_ON_UNMUTE = "on_unmute"
|
||||
CONF_ON_VOLUME = "on_volume"
|
||||
|
||||
nabu_ns = cg.esphome_ns.namespace("nabu")
|
||||
NabuMediaPlayer = nabu_ns.class_("NabuMediaPlayer")
|
||||
NabuMediaPlayer = nabu_ns.class_(
|
||||
"NabuMediaPlayer",
|
||||
NabuMediaPlayer,
|
||||
speaker_ns = cg.esphome_ns.namespace("speaker")
|
||||
SpeakerMediaPlayer = speaker_ns.class_("SpeakerMediaPlayer")
|
||||
SpeakerMediaPlayer = speaker_ns.class_(
|
||||
"SpeakerMediaPlayer",
|
||||
SpeakerMediaPlayer,
|
||||
media_player.MediaPlayer,
|
||||
cg.Component,
|
||||
)
|
||||
|
||||
MediaFile = nabu_ns.struct("MediaFile")
|
||||
MediaFileType = nabu_ns.enum("MediaFileType", is_class=True)
|
||||
MediaFile = speaker_ns.struct("MediaFile")
|
||||
MediaFileType = speaker_ns.enum("MediaFileType", is_class=True)
|
||||
MEDIA_FILE_TYPE_ENUM = {
|
||||
"NONE": MediaFileType.NONE,
|
||||
"WAV": MediaFileType.WAV,
|
||||
|
@ -65,20 +65,20 @@ MEDIA_FILE_TYPE_ENUM = {
|
|||
"FLAC": MediaFileType.FLAC,
|
||||
}
|
||||
|
||||
PipelineType = nabu_ns.enum("AudioPipelineType", is_class=True)
|
||||
PipelineType = speaker_ns.enum("AudioPipelineType", is_class=True)
|
||||
PIPELINE_TYPE_ENUM = {
|
||||
"MEDIA": PipelineType.MEDIA,
|
||||
"ANNOUNCEMENT": PipelineType.ANNOUNCEMENT,
|
||||
}
|
||||
|
||||
PlayLocalMediaAction = nabu_ns.class_(
|
||||
"PlayLocalMediaAction", automation.Action, cg.Parented.template(NabuMediaPlayer)
|
||||
PlayLocalMediaAction = speaker_ns.class_(
|
||||
"PlayLocalMediaAction", automation.Action, cg.Parented.template(SpeakerMediaPlayer)
|
||||
)
|
||||
StopPipelineAction = nabu_ns.class_(
|
||||
"StopPipelineAction", automation.Action, cg.Parented.template(NabuMediaPlayer)
|
||||
StopPipelineAction = speaker_ns.class_(
|
||||
"StopPipelineAction", automation.Action, cg.Parented.template(SpeakerMediaPlayer)
|
||||
)
|
||||
DuckingSetAction = nabu_ns.class_(
|
||||
"DuckingSetAction", automation.Action, cg.Parented.template(NabuMediaPlayer)
|
||||
DuckingSetAction = speaker_ns.class_(
|
||||
"DuckingSetAction", automation.Action, cg.Parented.template(SpeakerMediaPlayer)
|
||||
)
|
||||
|
||||
|
||||
|
@ -205,7 +205,7 @@ MEDIA_FILE_TYPE_SCHEMA = cv.Schema(
|
|||
CONFIG_SCHEMA = cv.All(
|
||||
media_player.MEDIA_PLAYER_SCHEMA.extend(
|
||||
{
|
||||
cv.GenerateID(): cv.declare_id(NabuMediaPlayer),
|
||||
cv.GenerateID(): cv.declare_id(SpeakerMediaPlayer),
|
||||
cv.Required(CONF_SPEAKER): cv.use_id(speaker.Speaker),
|
||||
cv.Optional(CONF_SAMPLE_RATE, default=16000): cv.int_range(min=1),
|
||||
cv.Optional(CONF_VOLUME_INCREMENT, default=0.05): cv.percentage,
|
||||
|
@ -317,18 +317,18 @@ async def to_code(config):
|
|||
|
||||
|
||||
@automation.register_action(
|
||||
"nabu.play_local_media_file",
|
||||
"speaker_media_player.play_local_media_file",
|
||||
PlayLocalMediaAction,
|
||||
cv.maybe_simple_value(
|
||||
{
|
||||
cv.GenerateID(): cv.use_id(NabuMediaPlayer),
|
||||
cv.GenerateID(): cv.use_id(SpeakerMediaPlayer),
|
||||
cv.Required(CONF_MEDIA_FILE): cv.use_id(MediaFile),
|
||||
cv.Optional(CONF_ANNOUNCEMENT, default=False): cv.boolean,
|
||||
},
|
||||
key=CONF_MEDIA_FILE,
|
||||
),
|
||||
)
|
||||
async def nabu_play_local_media_media_action(config, action_id, template_arg, args):
|
||||
async def play_local_media_media_action(config, action_id, template_arg, args):
|
||||
var = cg.new_Pvariable(action_id, template_arg)
|
||||
await cg.register_parented(var, config[CONF_ID])
|
||||
media_file = await cg.get_variable(config[CONF_MEDIA_FILE])
|
||||
|
@ -338,17 +338,17 @@ async def nabu_play_local_media_media_action(config, action_id, template_arg, ar
|
|||
|
||||
|
||||
@automation.register_action(
|
||||
"nabu.stop_pipeline",
|
||||
"speaker_media_player.stop_pipeline",
|
||||
StopPipelineAction,
|
||||
cv.maybe_simple_value(
|
||||
{
|
||||
cv.GenerateID(): cv.use_id(NabuMediaPlayer),
|
||||
cv.GenerateID(): cv.use_id(SpeakerMediaPlayer),
|
||||
cv.Required(CONF_PIPELINE): cv.enum(PIPELINE_TYPE_ENUM, upper=True),
|
||||
},
|
||||
key=CONF_PIPELINE,
|
||||
),
|
||||
)
|
||||
async def nabu_stop_pipeline_action(config, action_id, template_arg, args):
|
||||
async def stop_pipeline_action(config, action_id, template_arg, args):
|
||||
var = cg.new_Pvariable(action_id, template_arg)
|
||||
await cg.register_parented(var, config[CONF_ID])
|
||||
cg.add(var.set_pipeline_type(config[CONF_PIPELINE]))
|
||||
|
@ -356,11 +356,11 @@ async def nabu_stop_pipeline_action(config, action_id, template_arg, args):
|
|||
|
||||
|
||||
@automation.register_action(
|
||||
"nabu.set_ducking",
|
||||
"speaker_media_player.set_ducking",
|
||||
DuckingSetAction,
|
||||
cv.Schema(
|
||||
{
|
||||
cv.GenerateID(): cv.use_id(NabuMediaPlayer),
|
||||
cv.GenerateID(): cv.use_id(SpeakerMediaPlayer),
|
||||
cv.Required(CONF_DECIBEL_REDUCTION): cv.templatable(
|
||||
cv.int_range(min=0, max=51)
|
||||
),
|
|
@ -7,7 +7,7 @@
|
|||
#include "esphome/core/ring_buffer.h"
|
||||
|
||||
namespace esphome {
|
||||
namespace nabu {
|
||||
namespace speaker {
|
||||
|
||||
static const size_t READ_WRITE_TIMEOUT_MS = 20;
|
||||
|
||||
|
@ -378,7 +378,7 @@ FileDecoderState AudioDecoder::decode_wav_() {
|
|||
return FileDecoderState::END_OF_FILE;
|
||||
}
|
||||
|
||||
} // namespace nabu
|
||||
} // namespace speaker
|
||||
} // namespace esphome
|
||||
|
||||
#endif
|
|
@ -6,14 +6,14 @@
|
|||
#include <wav_decoder.h>
|
||||
#include <mp3_decoder.h>
|
||||
|
||||
#include "nabu_media_helpers.h"
|
||||
#include "speaker_media_helpers.h"
|
||||
#include "esphome/components/audio/audio.h"
|
||||
|
||||
#include "esphome/core/helpers.h"
|
||||
#include "esphome/core/ring_buffer.h"
|
||||
|
||||
namespace esphome {
|
||||
namespace nabu {
|
||||
namespace speaker {
|
||||
|
||||
enum class AudioDecoderState : uint8_t {
|
||||
INITIALIZED = 0,
|
||||
|
@ -75,7 +75,7 @@ class AudioDecoder {
|
|||
size_t potentially_failed_count_{0};
|
||||
bool end_of_file_{false};
|
||||
};
|
||||
} // namespace nabu
|
||||
} // namespace speaker
|
||||
} // namespace esphome
|
||||
|
||||
#endif
|
|
@ -8,7 +8,7 @@
|
|||
#include "esphome/core/helpers.h"
|
||||
|
||||
namespace esphome {
|
||||
namespace nabu {
|
||||
namespace speaker {
|
||||
|
||||
static const size_t INPUT_RING_BUFFER_SAMPLES = 24000;
|
||||
static const size_t OUTPUT_BUFFER_SAMPLES = 8192;
|
||||
|
@ -20,7 +20,7 @@ static const size_t TASK_DELAY_MS = 25;
|
|||
static const int16_t MAX_AUDIO_SAMPLE_VALUE = INT16_MAX;
|
||||
static const int16_t MIN_AUDIO_SAMPLE_VALUE = INT16_MIN;
|
||||
|
||||
esp_err_t AudioMixer::start(speaker::Speaker *speaker, const std::string &task_name, UBaseType_t priority) {
|
||||
esp_err_t AudioMixer::start(Speaker *speaker, const std::string &task_name, UBaseType_t priority) {
|
||||
esp_err_t err = this->allocate_buffers_();
|
||||
|
||||
if (err != ESP_OK) {
|
||||
|
@ -377,6 +377,6 @@ void AudioMixer::scale_audio_samples_(int16_t *audio_samples, int16_t *output_bu
|
|||
dsps_mulc_s16(audio_samples, output_buffer, samples_to_scale, scale_factor, 1, 1);
|
||||
}
|
||||
|
||||
} // namespace nabu
|
||||
} // namespace speaker
|
||||
} // namespace esphome
|
||||
#endif
|
|
@ -13,7 +13,7 @@
|
|||
#include <freertos/queue.h>
|
||||
|
||||
namespace esphome {
|
||||
namespace nabu {
|
||||
namespace speaker {
|
||||
|
||||
// Mixes two incoming audio streams together
|
||||
// - The media stream intended for music playback
|
||||
|
@ -95,7 +95,7 @@ class AudioMixer {
|
|||
/// @param task_name FreeRTOS task name
|
||||
/// @param priority FreeRTOS task priority. Defaults to 1
|
||||
/// @return ESP_OK if successful, and error otherwise
|
||||
esp_err_t start(speaker::Speaker *speaker, const std::string &task_name, UBaseType_t priority = 1);
|
||||
esp_err_t start(Speaker *speaker, const std::string &task_name, UBaseType_t priority = 1);
|
||||
|
||||
/// @brief Stops the mixer task and clears the queues
|
||||
void stop();
|
||||
|
@ -148,12 +148,12 @@ class AudioMixer {
|
|||
// Stores commands to send the mixer task
|
||||
QueueHandle_t command_queue_;
|
||||
|
||||
speaker::Speaker *speaker_{nullptr};
|
||||
Speaker *speaker_{nullptr};
|
||||
|
||||
std::unique_ptr<RingBuffer> media_ring_buffer_;
|
||||
std::unique_ptr<RingBuffer> announcement_ring_buffer_;
|
||||
};
|
||||
} // namespace nabu
|
||||
} // namespace speaker
|
||||
} // namespace esphome
|
||||
|
||||
#endif
|
|
@ -6,7 +6,7 @@
|
|||
#include "esphome/core/log.h"
|
||||
|
||||
namespace esphome {
|
||||
namespace nabu {
|
||||
namespace speaker {
|
||||
|
||||
static const size_t FILE_BUFFER_SIZE = 32 * 1024;
|
||||
static const size_t FILE_RING_BUFFER_SIZE = 64 * 1024;
|
||||
|
@ -19,7 +19,7 @@ static const uint32_t RESAMPLER_TASK_STACK_SIZE = 3 * 1024;
|
|||
|
||||
static const size_t INFO_ERROR_QUEUE_COUNT = 5;
|
||||
|
||||
static const char *const TAG = "nabu_media_player.pipeline";
|
||||
static const char *const TAG = "speaker_media_player.pipeline";
|
||||
|
||||
enum EventGroupBits : uint32_t {
|
||||
// The stop() function clears all unfinished bits
|
||||
|
@ -535,6 +535,6 @@ void AudioPipeline::resample_task(void *params) {
|
|||
}
|
||||
}
|
||||
|
||||
} // namespace nabu
|
||||
} // namespace speaker
|
||||
} // namespace esphome
|
||||
#endif
|
|
@ -6,7 +6,7 @@
|
|||
#include "audio_decoder.h"
|
||||
#include "audio_resampler.h"
|
||||
#include "audio_mixer.h"
|
||||
#include "nabu_media_helpers.h"
|
||||
#include "speaker_media_helpers.h"
|
||||
|
||||
#include "esphome/components/audio/audio.h"
|
||||
|
||||
|
@ -19,7 +19,7 @@
|
|||
#include <freertos/queue.h>
|
||||
|
||||
namespace esphome {
|
||||
namespace nabu {
|
||||
namespace speaker {
|
||||
|
||||
enum class AudioPipelineType : uint8_t {
|
||||
MEDIA,
|
||||
|
@ -147,7 +147,7 @@ class AudioPipeline {
|
|||
StackType_t *resample_task_stack_buffer_{nullptr};
|
||||
};
|
||||
|
||||
} // namespace nabu
|
||||
} // namespace speaker
|
||||
} // namespace esphome
|
||||
|
||||
#endif
|
|
@ -10,7 +10,7 @@
|
|||
#endif
|
||||
|
||||
namespace esphome {
|
||||
namespace nabu {
|
||||
namespace speaker {
|
||||
|
||||
static const size_t READ_WRITE_TIMEOUT_MS = 20;
|
||||
|
||||
|
@ -204,7 +204,7 @@ void AudioReader::cleanup_connection_() {
|
|||
}
|
||||
}
|
||||
|
||||
} // namespace nabu
|
||||
} // namespace speaker
|
||||
} // namespace esphome
|
||||
|
||||
#endif
|
|
@ -2,13 +2,13 @@
|
|||
|
||||
#ifdef USE_ESP_IDF
|
||||
|
||||
#include "nabu_media_helpers.h"
|
||||
#include "speaker_media_helpers.h"
|
||||
#include "esphome/core/ring_buffer.h"
|
||||
|
||||
#include <esp_http_client.h>
|
||||
|
||||
namespace esphome {
|
||||
namespace nabu {
|
||||
namespace speaker {
|
||||
|
||||
enum class AudioReaderState : uint8_t {
|
||||
READING = 0,
|
||||
|
@ -48,7 +48,7 @@ class AudioReader {
|
|||
|
||||
MediaFile *current_media_file_{nullptr};
|
||||
};
|
||||
} // namespace nabu
|
||||
} // namespace speaker
|
||||
} // namespace esphome
|
||||
|
||||
#endif
|
|
@ -6,7 +6,7 @@
|
|||
#include "esphome/core/helpers.h"
|
||||
|
||||
namespace esphome {
|
||||
namespace nabu {
|
||||
namespace speaker {
|
||||
|
||||
static const size_t NUM_TAPS = 32;
|
||||
static const size_t NUM_FILTERS = 32;
|
||||
|
@ -311,7 +311,7 @@ AudioResamplerState AudioResampler::resample(bool stop_gracefully) {
|
|||
return AudioResamplerState::RESAMPLING;
|
||||
}
|
||||
|
||||
} // namespace nabu
|
||||
} // namespace speaker
|
||||
} // namespace esphome
|
||||
|
||||
#endif
|
|
@ -9,7 +9,7 @@
|
|||
#include "esphome/core/ring_buffer.h"
|
||||
|
||||
namespace esphome {
|
||||
namespace nabu {
|
||||
namespace speaker {
|
||||
|
||||
enum class AudioResamplerState : uint8_t {
|
||||
INITIALIZED = 0,
|
||||
|
@ -76,7 +76,7 @@ class AudioResampler {
|
|||
bool post_filter_{false};
|
||||
};
|
||||
|
||||
} // namespace nabu
|
||||
} // namespace speaker
|
||||
} // namespace esphome
|
||||
|
||||
#endif
|
|
@ -3,12 +3,12 @@
|
|||
#ifdef USE_ESP_IDF
|
||||
|
||||
#include "esphome/core/automation.h"
|
||||
#include "nabu_media_player.h"
|
||||
#include "speaker_media_player.h"
|
||||
|
||||
namespace esphome {
|
||||
namespace nabu {
|
||||
namespace speaker {
|
||||
|
||||
template<typename... Ts> class DuckingSetAction : public Action<Ts...>, public Parented<NabuMediaPlayer> {
|
||||
template<typename... Ts> class DuckingSetAction : public Action<Ts...>, public Parented<SpeakerMediaPlayer> {
|
||||
TEMPLATABLE_VALUE(uint8_t, decibel_reduction)
|
||||
TEMPLATABLE_VALUE(float, duration)
|
||||
void play(Ts... x) override {
|
||||
|
@ -16,7 +16,7 @@ template<typename... Ts> class DuckingSetAction : public Action<Ts...>, public P
|
|||
}
|
||||
};
|
||||
|
||||
template<typename... Ts> class PlayLocalMediaAction : public Action<Ts...>, public Parented<NabuMediaPlayer> {
|
||||
template<typename... Ts> class PlayLocalMediaAction : public Action<Ts...>, public Parented<SpeakerMediaPlayer> {
|
||||
TEMPLATABLE_VALUE(MediaFile *, media_file)
|
||||
TEMPLATABLE_VALUE(bool, announcement)
|
||||
void play(Ts... x) override {
|
||||
|
@ -24,7 +24,7 @@ template<typename... Ts> class PlayLocalMediaAction : public Action<Ts...>, publ
|
|||
}
|
||||
};
|
||||
|
||||
template<typename... Ts> class StopPipelineAction : public Action<Ts...>, public Parented<NabuMediaPlayer> {
|
||||
template<typename... Ts> class StopPipelineAction : public Action<Ts...>, public Parented<SpeakerMediaPlayer> {
|
||||
TEMPLATABLE_VALUE(AudioPipelineType, pipeline_type)
|
||||
void play(Ts... x) override {
|
||||
bool announcement = false;
|
||||
|
@ -38,7 +38,7 @@ template<typename... Ts> class StopPipelineAction : public Action<Ts...>, public
|
|||
}
|
||||
};
|
||||
|
||||
} // namespace nabu
|
||||
} // namespace speaker
|
||||
} // namespace esphome
|
||||
|
||||
#endif
|
|
@ -6,7 +6,7 @@
|
|||
#include <cstddef>
|
||||
|
||||
namespace esphome {
|
||||
namespace nabu {
|
||||
namespace speaker {
|
||||
|
||||
enum class MediaFileType : uint8_t {
|
||||
NONE = 0,
|
||||
|
@ -22,7 +22,7 @@ struct MediaFile {
|
|||
MediaFileType file_type;
|
||||
};
|
||||
|
||||
} // namespace nabu
|
||||
} // namespace speaker
|
||||
} // namespace esphome
|
||||
|
||||
#endif
|
|
@ -1,6 +1,6 @@
|
|||
#ifdef USE_ESP_IDF
|
||||
|
||||
#include "nabu_media_player.h"
|
||||
#include "speaker_media_player.h"
|
||||
|
||||
#include "esphome/components/audio/audio.h"
|
||||
|
||||
|
@ -12,7 +12,7 @@
|
|||
#endif
|
||||
|
||||
namespace esphome {
|
||||
namespace nabu {
|
||||
namespace speaker {
|
||||
|
||||
// Framework:
|
||||
// - Media player that can handle two streams; one for media and one for announcements
|
||||
|
@ -65,7 +65,7 @@ static const size_t TASK_DELAY_MS = 10;
|
|||
|
||||
static const float FIRST_BOOT_DEFAULT_VOLUME = 0.5f;
|
||||
|
||||
static const char *const TAG = "nabu_media_player";
|
||||
static const char *const TAG = "speaker_media_player";
|
||||
|
||||
const char *media_player_file_type_to_string(MediaFileType file_type) {
|
||||
switch (file_type) {
|
||||
|
@ -80,7 +80,7 @@ const char *media_player_file_type_to_string(MediaFileType file_type) {
|
|||
}
|
||||
}
|
||||
|
||||
void NabuMediaPlayer::setup() {
|
||||
void SpeakerMediaPlayer::setup() {
|
||||
state = media_player::MEDIA_PLAYER_STATE_IDLE;
|
||||
|
||||
this->media_control_command_queue_ = xQueueCreate(QUEUE_LENGTH, sizeof(MediaCallCommand));
|
||||
|
@ -123,10 +123,10 @@ void NabuMediaPlayer::setup() {
|
|||
});
|
||||
#endif
|
||||
|
||||
ESP_LOGI(TAG, "Set up nabu media player");
|
||||
ESP_LOGI(TAG, "Set up speaker media player");
|
||||
}
|
||||
|
||||
esp_err_t NabuMediaPlayer::start_pipeline_(AudioPipelineType type, bool url) {
|
||||
esp_err_t SpeakerMediaPlayer::start_pipeline_(AudioPipelineType type, bool url) {
|
||||
esp_err_t err = ESP_OK;
|
||||
|
||||
if (this->speaker_ != nullptr) {
|
||||
|
@ -182,7 +182,7 @@ esp_err_t NabuMediaPlayer::start_pipeline_(AudioPipelineType type, bool url) {
|
|||
return err;
|
||||
}
|
||||
|
||||
void NabuMediaPlayer::watch_media_commands_() {
|
||||
void SpeakerMediaPlayer::watch_media_commands_() {
|
||||
MediaCallCommand media_command;
|
||||
CommandEvent command_event;
|
||||
esp_err_t err = ESP_OK;
|
||||
|
@ -280,7 +280,7 @@ void NabuMediaPlayer::watch_media_commands_() {
|
|||
}
|
||||
}
|
||||
|
||||
void NabuMediaPlayer::watch_mixer_() {
|
||||
void SpeakerMediaPlayer::watch_mixer_() {
|
||||
TaskEvent event;
|
||||
if (this->audio_mixer_ != nullptr) {
|
||||
while (this->audio_mixer_->read_event(&event)) {
|
||||
|
@ -292,7 +292,7 @@ void NabuMediaPlayer::watch_mixer_() {
|
|||
}
|
||||
}
|
||||
|
||||
void NabuMediaPlayer::loop() {
|
||||
void SpeakerMediaPlayer::loop() {
|
||||
this->watch_media_commands_();
|
||||
this->watch_mixer_();
|
||||
|
||||
|
@ -338,7 +338,7 @@ void NabuMediaPlayer::loop() {
|
|||
}
|
||||
}
|
||||
|
||||
void NabuMediaPlayer::set_ducking_reduction(uint8_t decibel_reduction, float duration) {
|
||||
void SpeakerMediaPlayer::set_ducking_reduction(uint8_t decibel_reduction, float duration) {
|
||||
if (this->audio_mixer_ != nullptr) {
|
||||
CommandEvent command_event;
|
||||
command_event.command = CommandEventType::DUCK;
|
||||
|
@ -350,7 +350,7 @@ void NabuMediaPlayer::set_ducking_reduction(uint8_t decibel_reduction, float dur
|
|||
}
|
||||
}
|
||||
|
||||
void NabuMediaPlayer::play_file(MediaFile *media_file, bool announcement) {
|
||||
void SpeakerMediaPlayer::play_file(MediaFile *media_file, bool announcement) {
|
||||
if (!this->is_ready()) {
|
||||
// Ignore any commands sent before the media player is setup
|
||||
return;
|
||||
|
@ -369,7 +369,7 @@ void NabuMediaPlayer::play_file(MediaFile *media_file, bool announcement) {
|
|||
xQueueSend(this->media_control_command_queue_, &media_command, portMAX_DELAY);
|
||||
}
|
||||
|
||||
void NabuMediaPlayer::control(const media_player::MediaPlayerCall &call) {
|
||||
void SpeakerMediaPlayer::control(const media_player::MediaPlayerCall &call) {
|
||||
if (!this->is_ready()) {
|
||||
// Ignore any commands sent before the media player is setup
|
||||
return;
|
||||
|
@ -415,7 +415,7 @@ void NabuMediaPlayer::control(const media_player::MediaPlayerCall &call) {
|
|||
}
|
||||
}
|
||||
|
||||
media_player::MediaPlayerTraits NabuMediaPlayer::get_traits() {
|
||||
media_player::MediaPlayerTraits SpeakerMediaPlayer::get_traits() {
|
||||
auto traits = media_player::MediaPlayerTraits();
|
||||
traits.set_supports_pause(true);
|
||||
traits.get_supported_formats().push_back(
|
||||
|
@ -433,14 +433,14 @@ media_player::MediaPlayerTraits NabuMediaPlayer::get_traits() {
|
|||
return traits;
|
||||
};
|
||||
|
||||
void NabuMediaPlayer::save_volume_restore_state_() {
|
||||
void SpeakerMediaPlayer::save_volume_restore_state_() {
|
||||
VolumeRestoreState volume_restore_state;
|
||||
volume_restore_state.volume = this->volume;
|
||||
volume_restore_state.is_muted = this->is_muted_;
|
||||
this->pref_.save(&volume_restore_state);
|
||||
}
|
||||
|
||||
void NabuMediaPlayer::set_mute_state_(bool mute_state) {
|
||||
void SpeakerMediaPlayer::set_mute_state_(bool mute_state) {
|
||||
this->speaker_->set_mute_state(mute_state);
|
||||
|
||||
bool old_mute_state = this->is_muted_;
|
||||
|
@ -457,7 +457,7 @@ void NabuMediaPlayer::set_mute_state_(bool mute_state) {
|
|||
}
|
||||
}
|
||||
|
||||
void NabuMediaPlayer::set_volume_(float volume, bool publish) {
|
||||
void SpeakerMediaPlayer::set_volume_(float volume, bool publish) {
|
||||
// Remap the volume to fit with in the configured limits
|
||||
float bounded_volume = remap<float, float>(volume, 0.0f, 1.0f, this->volume_min_, this->volume_max_);
|
||||
|
||||
|
@ -471,6 +471,6 @@ void NabuMediaPlayer::set_volume_(float volume, bool publish) {
|
|||
this->defer([this, volume]() { this->volume_trigger_->trigger(volume); });
|
||||
}
|
||||
|
||||
} // namespace nabu
|
||||
} // namespace speaker
|
||||
} // namespace esphome
|
||||
#endif
|
|
@ -5,7 +5,7 @@
|
|||
#include "audio_mixer.h"
|
||||
#include "audio_pipeline.h"
|
||||
|
||||
#include "nabu_media_helpers.h"
|
||||
#include "speaker_media_helpers.h"
|
||||
|
||||
#include "esphome/components/media_player/media_player.h"
|
||||
#include "esphome/components/speaker/speaker.h"
|
||||
|
@ -20,7 +20,7 @@
|
|||
#include <esp_http_client.h>
|
||||
|
||||
namespace esphome {
|
||||
namespace nabu {
|
||||
namespace speaker {
|
||||
|
||||
struct MediaCallCommand {
|
||||
optional<media_player::MediaPlayerCommand> command;
|
||||
|
@ -35,7 +35,7 @@ struct VolumeRestoreState {
|
|||
bool is_muted;
|
||||
};
|
||||
|
||||
class NabuMediaPlayer : public Component, public media_player::MediaPlayer {
|
||||
class SpeakerMediaPlayer : public Component, public media_player::MediaPlayer {
|
||||
public:
|
||||
float get_setup_priority() const override { return esphome::setup_priority::LATE; }
|
||||
void setup() override;
|
||||
|
@ -58,7 +58,7 @@ class NabuMediaPlayer : public Component, public media_player::MediaPlayer {
|
|||
void set_volume_max(float volume_max) { this->volume_max_ = volume_max; }
|
||||
void set_volume_min(float volume_min) { this->volume_min_ = volume_min; }
|
||||
|
||||
void set_speaker(speaker::Speaker *speaker) { this->speaker_ = speaker; }
|
||||
void set_speaker(Speaker *speaker) { this->speaker_ = speaker; }
|
||||
|
||||
Trigger<> *get_mute_trigger() const { return this->mute_trigger_; }
|
||||
Trigger<> *get_unmute_trigger() const { return this->unmute_trigger_; }
|
||||
|
@ -89,7 +89,7 @@ class NabuMediaPlayer : public Component, public media_player::MediaPlayer {
|
|||
std::unique_ptr<AudioPipeline> announcement_pipeline_;
|
||||
std::unique_ptr<AudioMixer> audio_mixer_;
|
||||
|
||||
speaker::Speaker *speaker_{nullptr};
|
||||
Speaker *speaker_{nullptr};
|
||||
|
||||
// Monitors the mixer task
|
||||
void watch_mixer_();
|
||||
|
@ -127,7 +127,7 @@ class NabuMediaPlayer : public Component, public media_player::MediaPlayer {
|
|||
Trigger<float> *volume_trigger_ = new Trigger<float>();
|
||||
};
|
||||
|
||||
} // namespace nabu
|
||||
} // namespace speaker
|
||||
} // namespace esphome
|
||||
|
||||
#endif
|
Loading…
Reference in a new issue