Compare commits

...
22 changed files with 269 additions and 88 deletions
@@ -58,6 +58,9 @@ esp_err_t AudioReader::add_sink(const std::weak_ptr<ring_buffer::RingBuffer> &ou
if (current_audio_file_ != nullptr) { if (current_audio_file_ != nullptr) {
// A transfer buffer isn't ncessary for a local file // A transfer buffer isn't ncessary for a local file
this->file_ring_buffer_ = output_ring_buffer.lock(); this->file_ring_buffer_ = output_ring_buffer.lock();
if (this->file_ring_buffer_ == nullptr) {
return ESP_ERR_INVALID_STATE;
}
return ESP_OK; return ESP_OK;
} }
@@ -51,14 +51,14 @@ void AudioTransferBuffer::increase_buffer_length(size_t bytes) { this->buffer_le
void AudioTransferBuffer::clear_buffered_data() { void AudioTransferBuffer::clear_buffered_data() {
this->buffer_length_ = 0; this->buffer_length_ = 0;
if (this->ring_buffer_.use_count() > 0) { if (this->ring_buffer_ != nullptr) {
this->ring_buffer_->reset(); this->ring_buffer_->reset();
} }
} }
void AudioSinkTransferBuffer::clear_buffered_data() { void AudioSinkTransferBuffer::clear_buffered_data() {
this->buffer_length_ = 0; this->buffer_length_ = 0;
if (this->ring_buffer_.use_count() > 0) { if (this->ring_buffer_ != nullptr) {
this->ring_buffer_->reset(); this->ring_buffer_->reset();
} }
#ifdef USE_SPEAKER #ifdef USE_SPEAKER
@@ -69,7 +69,7 @@ void AudioSinkTransferBuffer::clear_buffered_data() {
} }
bool AudioTransferBuffer::has_buffered_data() const { bool AudioTransferBuffer::has_buffered_data() const {
if (this->ring_buffer_.use_count() > 0) { if (this->ring_buffer_ != nullptr) {
return ((this->ring_buffer_->available() > 0) || (this->available() > 0)); return ((this->ring_buffer_->available() > 0) || (this->available() > 0));
} }
return (this->available() > 0); return (this->available() > 0);
@@ -144,7 +144,7 @@ size_t AudioSourceTransferBuffer::transfer_data_from_source(TickType_t ticks_to_
size_t bytes_to_read = AudioTransferBuffer::free(); size_t bytes_to_read = AudioTransferBuffer::free();
size_t bytes_read = 0; size_t bytes_read = 0;
if (bytes_to_read > 0) { if (bytes_to_read > 0) {
if (this->ring_buffer_.use_count() > 0) { if (this->ring_buffer_ != nullptr) {
bytes_read = this->ring_buffer_->read((void *) this->get_buffer_end(), bytes_to_read, ticks_to_wait); bytes_read = this->ring_buffer_->read((void *) this->get_buffer_end(), bytes_to_read, ticks_to_wait);
} }
@@ -161,7 +161,7 @@ size_t AudioSinkTransferBuffer::transfer_data_to_sink(TickType_t ticks_to_wait,
bytes_written = this->speaker_->play(this->data_start_, this->available(), ticks_to_wait); bytes_written = this->speaker_->play(this->data_start_, this->available(), ticks_to_wait);
} else } else
#endif #endif
if (this->ring_buffer_.use_count() > 0) { if (this->ring_buffer_ != nullptr) {
bytes_written = bytes_written =
this->ring_buffer_->write_without_replacement((void *) this->data_start_, this->available(), ticks_to_wait); this->ring_buffer_->write_without_replacement((void *) this->data_start_, this->available(), ticks_to_wait);
} else if (this->sink_callback_ != nullptr) { } else if (this->sink_callback_ != nullptr) {
@@ -186,7 +186,7 @@ bool AudioSinkTransferBuffer::has_buffered_data() const {
return (this->speaker_->has_buffered_data() || (this->available() > 0)); return (this->speaker_->has_buffered_data() || (this->available() > 0));
} }
#endif #endif
if (this->ring_buffer_.use_count() > 0) { if (this->ring_buffer_ != nullptr) {
return ((this->ring_buffer_->available() > 0) || (this->available() > 0)); return ((this->ring_buffer_->available() > 0) || (this->available() > 0));
} }
return (this->available() > 0); return (this->available() > 0);
@@ -41,7 +41,10 @@ const noise::NoiseContext &ESPHomeOTAComponent::noise_context_() const {
#endif #endif
static constexpr uint16_t OTA_BLOCK_SIZE = 8192; static constexpr uint16_t OTA_BLOCK_SIZE = 8192;
static constexpr uint32_t OTA_SOCKET_TIMEOUT_HANDSHAKE = 20000; // milliseconds for initial handshake static constexpr uint32_t OTA_SOCKET_TIMEOUT_HANDSHAKE = 20000; // milliseconds for initial handshake
static constexpr uint32_t OTA_SOCKET_TIMEOUT_DATA = 90000; // milliseconds for data transfer // Milliseconds for data transfer. Covers the lwIP retransmit run seen in
// practice for a lost chunk ack (1.5 + 3 + 6 + 12 + 24 + 48 s); the CLI waits
// longer (espota2.DATA_PHASE_TIMEOUT) so the device is free before it retries
static constexpr uint32_t OTA_SOCKET_TIMEOUT_DATA = 105000;
// Single-instance pointer — multi-port configs are rejected in final_validate. // Single-instance pointer — multi-port configs are rejected in final_validate.
// NOLINTNEXTLINE(cppcoreguidelines-avoid-non-const-global-variables) // NOLINTNEXTLINE(cppcoreguidelines-avoid-non-const-global-variables)
@@ -118,21 +118,24 @@ void I2SAudioSpeakerBase::loop() {
break; break;
} }
// Still starting up or winding down from a previous run
if ((this->tx_handle_ != nullptr) || (this->speaker_task_handle_ != nullptr)) {
break;
}
if (this->start_i2s_driver(this->audio_stream_info_) != ESP_OK) { if (this->start_i2s_driver(this->audio_stream_info_) != ESP_OK) {
ESP_LOGE(TAG, "Driver failed to start; retrying in 1 second"); ESP_LOGE(TAG, "Driver failed to start; retrying in 1 second");
this->status_momentary_error("driver-failure", 1000); this->status_momentary_error("driver-failure", 1000);
break; break;
} }
if (this->speaker_task_handle_ == nullptr) { xTaskCreate(I2SAudioSpeakerBase::speaker_task, "speaker_task", TASK_STACK_SIZE, (void *) this, TASK_PRIORITY,
xTaskCreate(I2SAudioSpeakerBase::speaker_task, "speaker_task", TASK_STACK_SIZE, (void *) this, TASK_PRIORITY, &this->speaker_task_handle_);
&this->speaker_task_handle_);
if (this->speaker_task_handle_ == nullptr) { if (this->speaker_task_handle_ == nullptr) {
ESP_LOGE(TAG, "Task failed to start, retrying in 1 second"); ESP_LOGE(TAG, "Task failed to start, retrying in 1 second");
this->status_momentary_error("task-failure", 1000); this->status_momentary_error("task-failure", 1000);
this->stop_i2s_driver_(); // Stops the driver to return the lock; will be reloaded in next attempt this->stop_i2s_driver_(); // Stops the driver to return the lock; will be reloaded in next attempt
}
} }
break; break;
case speaker::STATE_RUNNING: // Intentional fallthrough case speaker::STATE_RUNNING: // Intentional fallthrough
@@ -218,8 +221,8 @@ size_t I2SAudioSpeakerBase::play(const uint8_t *data, size_t length, TickType_t
} }
bool I2SAudioSpeakerBase::has_buffered_data() const { bool I2SAudioSpeakerBase::has_buffered_data() const {
if (this->audio_ring_buffer_.use_count() > 0) { std::shared_ptr<ring_buffer::RingBuffer> temp_ring_buffer = this->audio_ring_buffer_.lock();
std::shared_ptr<ring_buffer::RingBuffer> temp_ring_buffer = this->audio_ring_buffer_.lock(); if (temp_ring_buffer != nullptr) {
return temp_ring_buffer->available() > 0; return temp_ring_buffer->available() > 0;
} }
return false; return false;
@@ -129,7 +129,7 @@ void MicroWakeWord::setup() {
return; return;
} }
std::shared_ptr<ring_buffer::RingBuffer> temp_ring_buffer = this->ring_buffer_.lock(); std::shared_ptr<ring_buffer::RingBuffer> temp_ring_buffer = this->ring_buffer_.lock();
if (this->ring_buffer_.use_count() > 1) { if (temp_ring_buffer != nullptr) {
// Producer-only write: never touches consumer state. If the buffer is full, ask the inference task // Producer-only write: never touches consumer state. If the buffer is full, ask the inference task
// to drain it - reset() is a consumer operation and must run on the inference task's thread. // to drain it - reset() is a consumer operation and must run on the inference task's thread.
// Disable partial writes so audio chunks are either fully accepted or rejected and handled below. // Disable partial writes so audio chunks are either fully accepted or rejected and handled below.
@@ -446,9 +446,9 @@ void MicroWakeWord::loop() {
xEventGroupClearBits(this->event_group_, EventGroupBits::TASK_STOPPING); xEventGroupClearBits(this->event_group_, EventGroupBits::TASK_STOPPING);
} }
if ((event_group_bits & EventGroupBits::TASK_STOPPED)) { // Retries on a subsequent loop if the task is still running on the other core
if ((event_group_bits & EventGroupBits::TASK_STOPPED) && this->inference_task_.deallocate()) {
ESP_LOGD(TAG, "Inference task is finished, freeing task resources"); ESP_LOGD(TAG, "Inference task is finished, freeing task resources");
this->inference_task_.deallocate();
xEventGroupClearBits(this->event_group_, ALL_BITS); xEventGroupClearBits(this->event_group_, ALL_BITS);
xQueueReset(this->detection_queue_); xQueueReset(this->detection_queue_);
this->set_state_(State::STOPPED); this->set_state_(State::STOPPED);
@@ -48,7 +48,7 @@ class MicrophoneSource final {
template<typename F> void add_data_callback(F &&data_callback) { template<typename F> void add_data_callback(F &&data_callback) {
this->mic_->add_data_callback([this, data_callback](const std::vector<uint8_t> &data) { this->mic_->add_data_callback([this, data_callback](const std::vector<uint8_t> &data) {
if (this->enabled_ || this->passive_) { if (this->enabled_ || this->passive_) {
if (this->processed_samples_.use_count() == 0) { if (this->processed_samples_ == nullptr) {
// Create vector if its unused // Create vector if its unused
this->processed_samples_ = std::make_shared<std::vector<uint8_t>>(); this->processed_samples_ = std::make_shared<std::vector<uint8_t>>();
} }
@@ -218,7 +218,7 @@ size_t SourceSpeaker::play(const uint8_t *data, size_t length, TickType_t ticks_
} }
size_t bytes_written = 0; size_t bytes_written = 0;
std::shared_ptr<ring_buffer::RingBuffer> temp_ring_buffer = this->ring_buffer_.lock(); std::shared_ptr<ring_buffer::RingBuffer> temp_ring_buffer = this->ring_buffer_.lock();
if (temp_ring_buffer.use_count() > 0) { if (temp_ring_buffer != nullptr) {
// Only write to the ring buffer if the reference is valid // Only write to the ring buffer if the reference is valid
bytes_written = temp_ring_buffer->write_without_replacement(data, length, ticks_to_wait); bytes_written = temp_ring_buffer->write_without_replacement(data, length, ticks_to_wait);
if (bytes_written > 0) { if (bytes_written > 0) {
@@ -250,14 +250,14 @@ esp_err_t SourceSpeaker::start_() {
// avoids unnecessary single-frame splices. // avoids unnecessary single-frame splices.
const size_t ring_buffer_size = const size_t ring_buffer_size =
(this->audio_stream_info_.ms_to_bytes(this->buffer_duration_ms_) / bytes_per_frame) * bytes_per_frame; (this->audio_stream_info_.ms_to_bytes(this->buffer_duration_ms_) / bytes_per_frame) * bytes_per_frame;
if (this->audio_source_.use_count() == 0) { if (this->audio_source_ == nullptr) {
std::shared_ptr<ring_buffer::RingBuffer> temp_ring_buffer = this->ring_buffer_.lock(); std::shared_ptr<ring_buffer::RingBuffer> temp_ring_buffer = this->ring_buffer_.lock();
if (!temp_ring_buffer) { if (temp_ring_buffer == nullptr) {
temp_ring_buffer = ring_buffer::RingBuffer::create(ring_buffer_size); temp_ring_buffer = ring_buffer::RingBuffer::create(ring_buffer_size);
this->ring_buffer_ = temp_ring_buffer; this->ring_buffer_ = temp_ring_buffer;
} }
if (!temp_ring_buffer) { if (temp_ring_buffer == nullptr) {
return ESP_ERR_NO_MEM; return ESP_ERR_NO_MEM;
} }
@@ -278,7 +278,7 @@ void SourceSpeaker::stop() { this->send_command_(SOURCE_SPEAKER_COMMAND_STOP); }
void SourceSpeaker::finish() { this->send_command_(SOURCE_SPEAKER_COMMAND_FINISH); } void SourceSpeaker::finish() { this->send_command_(SOURCE_SPEAKER_COMMAND_FINISH); }
bool SourceSpeaker::has_buffered_data() const { bool SourceSpeaker::has_buffered_data() const {
return ((this->audio_source_.use_count() > 0) && this->audio_source_->has_buffered_data()); return ((this->audio_source_ != nullptr) && this->audio_source_->has_buffered_data());
} }
void SourceSpeaker::set_mute_state(bool mute_state) { void SourceSpeaker::set_mute_state(bool mute_state) {
@@ -382,8 +382,8 @@ void MixerSpeaker::loop() {
ESP_LOGV(TAG, "Stopping"); ESP_LOGV(TAG, "Stopping");
xEventGroupClearBits(this->event_group_, MIXER_TASK_STATE_STOPPING); xEventGroupClearBits(this->event_group_, MIXER_TASK_STATE_STOPPING);
} }
if (event_group_bits & MIXER_TASK_STATE_STOPPED) { // Retries on a subsequent loop if the task is still running on the other core
this->task_.deallocate(); if ((event_group_bits & MIXER_TASK_STATE_STOPPED) && this->task_.deallocate()) {
ESP_LOGD(TAG, "Stopped"); ESP_LOGD(TAG, "Stopped");
xEventGroupClearBits(this->event_group_, MIXER_TASK_ALL_BITS); xEventGroupClearBits(this->event_group_, MIXER_TASK_ALL_BITS);
this->all_stopped_since_ms_ = 0; this->all_stopped_since_ms_ = 0;
@@ -496,7 +496,7 @@ void MixerSpeaker::audio_mixer_task(void *params) {
if (speaker->is_running() && !speaker->get_pause_state()) { if (speaker->is_running() && !speaker->get_pause_state()) {
// Speaker is running and not paused, so it possibly can provide audio data // Speaker is running and not paused, so it possibly can provide audio data
std::shared_ptr<audio::RingBufferAudioSource> audio_source = speaker->get_audio_source().lock(); std::shared_ptr<audio::RingBufferAudioSource> audio_source = speaker->get_audio_source().lock();
if (audio_source.use_count() == 0) { if (audio_source == nullptr) {
// No audio source allocated, so skip processing this speaker // No audio source allocated, so skip processing this speaker
continue; continue;
} }
+2 -2
View File
@@ -88,12 +88,12 @@ def encryption_schema(config: ConfigType | None) -> ConfigType:
async def to_code(config: ConfigType) -> None: async def to_code(config: ConfigType) -> None:
cg.add_define("USE_NOISE") cg.add_define("USE_NOISE")
cg.add_library("esphome/noise-c", "0.1.24") cg.add_library("esphome/noise-c", "0.1.26")
# noise-c depends on libsodium, but declaring it here too lets the # noise-c depends on libsodium, but declaring it here too lets the
# library manager see the full set up front instead of discovering # library manager see the full set up front instead of discovering
# libsodium only after noise-c has downloaded, so the two can download # libsodium only after noise-c has downloaded, so the two can download
# in parallel. The version must match noise-c's library.json. # in parallel. The version must match noise-c's library.json.
cg.add_library("esphome/libsodium", "1.10021.6") cg.add_library("esphome/libsodium", "1.10021.8")
# Enable optimized memzero/memcmp in libsodium instead of volatile byte loops # Enable optimized memzero/memcmp in libsodium instead of volatile byte loops
cg.add_build_flag("-DHAVE_WEAK_SYMBOLS=1") cg.add_build_flag("-DHAVE_WEAK_SYMBOLS=1")
cg.add_build_flag("-DHAVE_INLINE_ASM=1") cg.add_build_flag("-DHAVE_INLINE_ASM=1")
@@ -153,8 +153,8 @@ void ResamplerSpeaker::loop() {
ESP_LOGV(TAG, "Stopping"); ESP_LOGV(TAG, "Stopping");
xEventGroupClearBits(this->event_group_, ResamplingEventGroupBits::STATE_STOPPING); xEventGroupClearBits(this->event_group_, ResamplingEventGroupBits::STATE_STOPPING);
} }
if (event_group_bits & ResamplingEventGroupBits::STATE_STOPPED) { // Retries on a subsequent loop if the task is still running on the other core
this->task_.deallocate(); if ((event_group_bits & ResamplingEventGroupBits::STATE_STOPPED) && this->task_.deallocate()) {
ESP_LOGD(TAG, "Stopped"); ESP_LOGD(TAG, "Stopped");
xEventGroupClearBits(this->event_group_, ResamplingEventGroupBits::ALL_BITS); xEventGroupClearBits(this->event_group_, ResamplingEventGroupBits::ALL_BITS);
} }
@@ -235,7 +235,7 @@ size_t ResamplerSpeaker::play(const uint8_t *data, size_t length, TickType_t tic
bytes_written = this->output_speaker_->play(data, length, ticks_to_wait); bytes_written = this->output_speaker_->play(data, length, ticks_to_wait);
} else { } else {
std::shared_ptr<ring_buffer::RingBuffer> temp_ring_buffer = this->ring_buffer_.lock(); std::shared_ptr<ring_buffer::RingBuffer> temp_ring_buffer = this->ring_buffer_.lock();
if (temp_ring_buffer) { if (temp_ring_buffer != nullptr) {
// Only write to the ring buffer if the reference is valid // Only write to the ring buffer if the reference is valid
bytes_written = temp_ring_buffer->write_without_replacement(data, length, ticks_to_wait); bytes_written = temp_ring_buffer->write_without_replacement(data, length, ticks_to_wait);
} else { } else {
@@ -299,7 +299,7 @@ bool ResamplerSpeaker::has_buffered_data() const {
bool has_ring_buffer_data = false; bool has_ring_buffer_data = false;
if (this->requires_resampling_()) { if (this->requires_resampling_()) {
std::shared_ptr<ring_buffer::RingBuffer> temp_ring_buffer = this->ring_buffer_.lock(); std::shared_ptr<ring_buffer::RingBuffer> temp_ring_buffer = this->ring_buffer_.lock();
if (temp_ring_buffer) { if (temp_ring_buffer != nullptr) {
has_ring_buffer_data = (temp_ring_buffer->available() > 0); has_ring_buffer_data = (temp_ring_buffer->available() > 0);
} }
} }
@@ -342,7 +342,7 @@ void ResamplerSpeaker::resample_task(void *params) {
std::shared_ptr<ring_buffer::RingBuffer> temp_ring_buffer = ring_buffer::RingBuffer::create( std::shared_ptr<ring_buffer::RingBuffer> temp_ring_buffer = ring_buffer::RingBuffer::create(
this_resampler->audio_stream_info_.ms_to_bytes(this_resampler->buffer_duration_ms_)); this_resampler->audio_stream_info_.ms_to_bytes(this_resampler->buffer_duration_ms_));
if (!temp_ring_buffer) { if (temp_ring_buffer == nullptr) {
err = ESP_ERR_NO_MEM; err = ESP_ERR_NO_MEM;
} else { } else {
this_resampler->ring_buffer_ = temp_ring_buffer; this_resampler->ring_buffer_ = temp_ring_buffer;
+19 -7
View File
@@ -30,6 +30,7 @@ CONF_SENDSPIN_ID = "sendspin_id"
CONF_INITIAL_STATIC_DELAY = "initial_static_delay" CONF_INITIAL_STATIC_DELAY = "initial_static_delay"
CONF_FIXED_DELAY = "fixed_delay" CONF_FIXED_DELAY = "fixed_delay"
CONF_DECODE_MEMORY = "decode_memory" CONF_DECODE_MEMORY = "decode_memory"
CONF_CODECS = "codecs"
# Matches ARTWORK_MAX_SLOTS in sendspin-cpp. # Matches ARTWORK_MAX_SLOTS in sendspin-cpp.
MAX_ARTWORK_SLOTS = 4 MAX_ARTWORK_SLOTS = 4
@@ -44,6 +45,20 @@ CODEC_FORMAT_OPUS = SendspinCodecFormat.enum("OPUS")
CODEC_FORMAT_PCM = SendspinCodecFormat.enum("PCM") CODEC_FORMAT_PCM = SendspinCodecFormat.enum("PCM")
CODEC_FORMAT_UNSUPPORTED = SendspinCodecFormat.enum("UNSUPPORTED") CODEC_FORMAT_UNSUPPORTED = SendspinCodecFormat.enum("UNSUPPORTED")
CODEC_FLAC = "flac"
CODEC_OPUS = "opus"
CODEC_PCM = "pcm"
CODECS = {
CODEC_FLAC: CODEC_FORMAT_FLAC,
CODEC_OPUS: CODEC_FORMAT_OPUS,
CODEC_PCM: CODEC_FORMAT_PCM,
}
# Opus only supports 48 kHz audio, so it is left out of the default list at other rates.
DEFAULT_CODECS = [CODEC_FLAC, CODEC_OPUS, CODEC_PCM]
OPUS_SAMPLE_RATE = 48000
SendspinImageFormat = sendspin_library_ns.enum("SendspinImageFormat", is_class=True) SendspinImageFormat = sendspin_library_ns.enum("SendspinImageFormat", is_class=True)
IMAGE_FORMAT_JPEG = SendspinImageFormat.enum("JPEG") IMAGE_FORMAT_JPEG = SendspinImageFormat.enum("JPEG")
IMAGE_FORMAT_PNG = SendspinImageFormat.enum("PNG") IMAGE_FORMAT_PNG = SendspinImageFormat.enum("PNG")
@@ -286,16 +301,13 @@ async def to_code(config: ConfigType) -> None:
if data.player_support: if data.player_support:
cg.add_define("USE_SENDSPIN_PLAYER", True) cg.add_define("USE_SENDSPIN_PLAYER", True)
# Configures the player role. We always assume support for 16 bits per sample mono and stereo FLAC, Opus, and PCM at the configured sample rate # Configures the player role. Each configured codec is advertised for 16 bits per sample
# (with Opus only supported at 48 kHz since that's the only sample rate it supports). Users can configure the specific formats via the Sendspin server # mono and stereo at the configured sample rate. The order is a preference order, both for
# the codecs themselves and for stereo over mono.
player_cfg = data.player_config player_cfg = data.player_config
sample_rate = player_cfg[CONF_SAMPLE_RATE] sample_rate = player_cfg[CONF_SAMPLE_RATE]
# OPUS only supports 48 kHz audio codecs = player_cfg[CONF_CODECS]
codecs = [CODEC_FORMAT_FLAC]
if sample_rate == 48000:
codecs.append(CODEC_FORMAT_OPUS)
codecs.append(CODEC_FORMAT_PCM)
def _audio_format(codec: MockObj, channels: int) -> cg.StructInitializer: def _audio_format(codec: MockObj, channels: int) -> cg.StructInitializer:
return cg.StructInitializer( return cg.StructInitializer(
@@ -13,11 +13,16 @@ from esphome.cpp_generator import MockObj, TemplateArgsType
from esphome.types import ConfigType from esphome.types import ConfigType
from .. import ( from .. import (
CODEC_OPUS,
CODECS,
CONF_CODECS,
CONF_DECODE_MEMORY, CONF_DECODE_MEMORY,
CONF_FIXED_DELAY, CONF_FIXED_DELAY,
CONF_INITIAL_STATIC_DELAY, CONF_INITIAL_STATIC_DELAY,
CONF_SENDSPIN_ID, CONF_SENDSPIN_ID,
DEFAULT_CODECS,
MEMORY_LOCATIONS, MEMORY_LOCATIONS,
OPUS_SAMPLE_RATE,
SendspinHub, SendspinHub,
register_player_config, register_player_config,
request_controller_support, request_controller_support,
@@ -49,10 +54,32 @@ DisableStaticDelayAdjustmentAction = sendspin_ns.class_(
) )
def _resolve_codecs(config: ConfigType) -> ConfigType:
"""Validate the codec preference list, filling in the default when it is not set."""
sample_rate = config[CONF_SAMPLE_RATE]
if (codecs := config.get(CONF_CODECS)) is None:
config[CONF_CODECS] = [
codec
for codec in DEFAULT_CODECS
if codec != CODEC_OPUS or sample_rate == OPUS_SAMPLE_RATE
]
return config
if len(set(codecs)) != len(codecs):
raise cv.Invalid("Each codec may only be listed once", path=[CONF_CODECS])
if CODEC_OPUS in codecs and sample_rate != OPUS_SAMPLE_RATE:
raise cv.Invalid(
f"Codec '{CODEC_OPUS}' requires a {CONF_SAMPLE_RATE} of {OPUS_SAMPLE_RATE}",
path=[CONF_CODECS],
)
return config
def _register(config: ConfigType) -> ConfigType: def _register(config: ConfigType) -> ConfigType:
request_controller_support() request_controller_support()
register_player_config( register_player_config(
{ {
CONF_CODECS: config[CONF_CODECS],
CONF_SAMPLE_RATE: config[CONF_SAMPLE_RATE], CONF_SAMPLE_RATE: config[CONF_SAMPLE_RATE],
CONF_BUFFER_SIZE: config[CONF_BUFFER_SIZE], CONF_BUFFER_SIZE: config[CONF_BUFFER_SIZE],
CONF_INITIAL_STATIC_DELAY: config[CONF_INITIAL_STATIC_DELAY], CONF_INITIAL_STATIC_DELAY: config[CONF_INITIAL_STATIC_DELAY],
@@ -85,9 +112,13 @@ CONFIG_SCHEMA = cv.All(
min=16000, max=96000 min=16000, max=96000
), ),
cv.Optional(CONF_DECODE_MEMORY): cv.one_of(*MEMORY_LOCATIONS, lower=True), cv.Optional(CONF_DECODE_MEMORY): cv.one_of(*MEMORY_LOCATIONS, lower=True),
cv.Optional(CONF_CODECS): cv.All(
cv.ensure_list(cv.enum(CODECS, lower=True)), cv.Length(min=1)
),
} }
), ),
cv.only_on_esp32, cv.only_on_esp32,
_resolve_codecs,
_register, _register,
) )
@@ -202,8 +202,15 @@ AudioPipelineState AudioPipeline::process_state() {
if (!this->is_playing_) { if (!this->is_playing_) {
// The tasks have been stopped for two ``process_state`` calls in a row, so delete the tasks // The tasks have been stopped for two ``process_state`` calls in a row, so delete the tasks
if (this->read_task_.is_created() || this->decode_task_.is_created()) { if (this->read_task_.is_created() || this->decode_task_.is_created()) {
this->read_task_.deallocate(); // Both are attempted every time; a task that is still running on the other core is freed by a
this->decode_task_.deallocate(); // subsequent call, and freeing an already freed task succeeds without doing anything
bool read_task_freed = this->read_task_.deallocate();
bool decode_task_freed = this->decode_task_.deallocate();
if (!read_task_freed || !decode_task_freed) {
// A task is still running on the other core, so keep the pipeline in its current state and try
// again on the next call
return AudioPipelineState::PLAYING;
}
if (this->hard_stop_) { if (this->hard_stop_) {
// Stop command was sent, so immediately end the playback // Stop command was sent, so immediately end the playback
this->speaker_->stop(); this->speaker_->stop();
@@ -315,17 +322,17 @@ void AudioPipeline::read_task(void *params) {
if (err == ESP_OK) { if (err == ESP_OK) {
size_t file_ring_buffer_size = this_pipeline->buffer_size_; size_t file_ring_buffer_size = this_pipeline->buffer_size_;
std::shared_ptr<ring_buffer::RingBuffer> temp_ring_buffer; std::shared_ptr<ring_buffer::RingBuffer> temp_ring_buffer = this_pipeline->raw_file_ring_buffer_.lock();
if (!this_pipeline->raw_file_ring_buffer_.use_count()) { if (temp_ring_buffer == nullptr) {
temp_ring_buffer = ring_buffer::RingBuffer::create(file_ring_buffer_size); temp_ring_buffer = ring_buffer::RingBuffer::create(file_ring_buffer_size);
this_pipeline->raw_file_ring_buffer_ = temp_ring_buffer; this_pipeline->raw_file_ring_buffer_ = temp_ring_buffer;
} }
if (!this_pipeline->raw_file_ring_buffer_.use_count()) { if (temp_ring_buffer == nullptr) {
err = ESP_ERR_NO_MEM; err = ESP_ERR_NO_MEM;
} else { } else {
reader->add_sink(this_pipeline->raw_file_ring_buffer_); err = reader->add_sink(temp_ring_buffer);
} }
} }
@@ -396,7 +403,9 @@ void AudioPipeline::decode_task(void *params) {
make_unique<audio::AudioDecoder>(this_pipeline->transfer_buffer_size_, this_pipeline->transfer_buffer_size_); make_unique<audio::AudioDecoder>(this_pipeline->transfer_buffer_size_, this_pipeline->transfer_buffer_size_);
esp_err_t err = decoder->start(this_pipeline->current_audio_file_type_); esp_err_t err = decoder->start(this_pipeline->current_audio_file_type_);
decoder->add_source(this_pipeline->raw_file_ring_buffer_); if (err == ESP_OK) {
err = decoder->add_source(this_pipeline->raw_file_ring_buffer_);
}
if (err != ESP_OK) { if (err != ESP_OK) {
// Send specific error message // Send specific error message
+23 -7
View File
@@ -40,16 +40,31 @@ bool StaticTask::create(TaskFunction_t fn, const char *name, uint32_t stack_size
return true; return true;
} }
void StaticTask::destroy() { bool StaticTask::destroy() {
if (this->handle_ != nullptr) { if (this->handle_ == nullptr) {
TaskHandle_t handle = this->handle_; return true;
this->handle_ = nullptr;
vTaskDelete(handle);
} }
// Suspending takes the task off the ready and event lists, so nothing can schedule it again. It only asks
// the other core to yield though, so the task may still be running on it for a moment.
vTaskSuspend(this->handle_);
if (eTaskGetState(this->handle_) != eSuspended) {
// The task is still running on the other core and using its stack. Deleting it now would only put it on
// the termination list and return, so the caller has to try again once it has been swapped out.
return false;
}
// The task cannot run again, so the delete completes right away instead of being left to the idle task.
TaskHandle_t handle = this->handle_;
this->handle_ = nullptr;
vTaskDelete(handle);
return true;
} }
void StaticTask::deallocate() { bool StaticTask::deallocate() {
this->destroy(); if (!this->destroy()) {
return false;
}
if (this->stack_buffer_ != nullptr) { if (this->stack_buffer_ != nullptr) {
RAMAllocator<StackType_t> allocator(this->use_psram_ ? RAMAllocator<StackType_t>::ALLOC_EXTERNAL RAMAllocator<StackType_t> allocator(this->use_psram_ ? RAMAllocator<StackType_t>::ALLOC_EXTERNAL
: RAMAllocator<StackType_t>::ALLOC_INTERNAL); : RAMAllocator<StackType_t>::ALLOC_INTERNAL);
@@ -57,6 +72,7 @@ void StaticTask::deallocate() {
this->stack_buffer_ = nullptr; this->stack_buffer_ = nullptr;
this->stack_size_ = 0; this->stack_size_ = 0;
} }
return true;
} }
} // namespace esphome } // namespace esphome
+12 -5
View File
@@ -11,6 +11,7 @@ namespace esphome {
/** Helper for FreeRTOS static task management. /** Helper for FreeRTOS static task management.
* Bundles TaskHandle_t, StaticTask_t, and the stack buffer into one object with create/destroy methods. * Bundles TaskHandle_t, StaticTask_t, and the stack buffer into one object with create/destroy methods.
* Call destroy() and deallocate() from another task: a task cannot free the stack it is still running on.
*/ */
class StaticTask { class StaticTask {
public: public:
@@ -23,7 +24,7 @@ class StaticTask {
/// @brief Allocate stack and create task. /// @brief Allocate stack and create task.
/// @param fn Task function /// @param fn Task function
/// @param name Task name (for debug) /// @param name Task name (for debug)
/// @param stack_size Stack size in StackType_t words /// @param stack_size Stack size in bytes (StackType_t is a byte on ESP-IDF)
/// @param param Parameter passed to task function /// @param param Parameter passed to task function
/// @param priority FreeRTOS task priority /// @param priority FreeRTOS task priority
/// @param use_psram If true, allocate stack in PSRAM; otherwise internal RAM /// @param use_psram If true, allocate stack in PSRAM; otherwise internal RAM
@@ -31,11 +32,17 @@ class StaticTask {
bool create(TaskFunction_t fn, const char *name, uint32_t stack_size, void *param, UBaseType_t priority, bool create(TaskFunction_t fn, const char *name, uint32_t stack_size, void *param, UBaseType_t priority,
bool use_psram); bool use_psram);
/// @brief Delete the task but keep the stack buffer allocated for reuse by a subsequent create() call. /// @brief Delete the task, keeping the stack buffer allocated for reuse by a subsequent create() call.
void destroy(); /// The task must have finished its work and parked itself, either suspended or blocked indefinitely: it is
/// suspended here so that it cannot be scheduled again, and it is given no chance to clean up.
/// @return true if the task was deleted; false if it is still running on another core, in which case the
/// caller should try again later.
bool destroy();
/// @brief Delete the task (if running) and free the stack buffer. /// @brief Delete the task (if created) and free the stack buffer.
void deallocate(); /// @return true if the stack buffer was freed; false if the task is still running on another core, in
/// which case the caller should try again later.
bool deallocate();
protected: protected:
TaskHandle_t handle_{nullptr}; TaskHandle_t handle_{nullptr};
+6 -3
View File
@@ -96,6 +96,10 @@ UPLOAD_BUFFER_SIZE = UPLOAD_BLOCK_SIZE * 8
# across the addresses on top of that. # across the addresses on top of that.
EXTRA_UPLOAD_ATTEMPTS = 2 EXTRA_UPLOAD_ATTEMPTS = 2
UPLOAD_RETRY_DELAY = 5.0 UPLOAD_RETRY_DELAY = 5.0
# Data phase timeout; must stay longer than the device's OTA_SOCKET_TIMEOUT_DATA
# (105 s) so a stalled session is gone before a retry, and long enough for lwIP
# to get a lost chunk ack through after the retransmit run seen in practice
DATA_PHASE_TIMEOUT = 160.0
_LOGGER = logging.getLogger(__name__) _LOGGER = logging.getLogger(__name__)
@@ -694,8 +698,7 @@ def perform_ota(
_LOGGER.info("Handshake complete") _LOGGER.info("Handshake complete")
# Timeout must match device-side OTA_SOCKET_TIMEOUT_DATA to prevent premature failures sock.settimeout(DATA_PHASE_TIMEOUT)
sock.settimeout(90.0)
if extended_proto: if extended_proto:
send_check(sock, ota_type, "ota type") send_check(sock, ota_type, "ota type")
@@ -854,7 +857,7 @@ def run_ota_impl_(
# clean up a half-open connection (its handshake watchdog runs at 20s); # clean up a half-open connection (its handshake watchdog runs at 20s);
# moving on to the next address family stays immediate. Known limitation: # moving on to the next address family stays immediate. Known limitation:
# a silent mid-transfer drop with no reset can wedge the device until its # a silent mid-transfer drop with no reset can wedge the device until its
# 90s data timeout, which outlasts this budget; the retries target the # 105s data timeout, which outlasts this budget; the retries target the
# common failures where the device resets or closes the link promptly. # common failures where the device resets or closes the link promptly.
total_attempts = len(res) + EXTRA_UPLOAD_ATTEMPTS total_attempts = len(res) + EXTRA_UPLOAD_ATTEMPTS
last_error = "" last_error = ""
+3 -3
View File
@@ -45,7 +45,7 @@ lib_deps_base =
lib_deps = lib_deps =
${common.lib_deps_base} ${common.lib_deps_base}
https://github.com/dudanov/MideaUART.git#eeea6c3e9b4474f067054592b435be1c4e466815 ; midea https://github.com/dudanov/MideaUART.git#eeea6c3e9b4474f067054592b435be1c4e466815 ; midea
esphome/noise-c@0.1.24 ; noise (api, ota) esphome/noise-c@0.1.26 ; noise (api, ota)
improv/Improv@1.2.7 ; improv_serial / esp32_improv improv/Improv@1.2.7 ; improv_serial / esp32_improv
kikuchan98/pngle@1.1.0 ; online_image kikuchan98/pngle@1.1.0 ; online_image
; Using the repository directly, otherwise ESP-IDF can't use the library ; Using the repository directly, otherwise ESP-IDF can't use the library
@@ -244,7 +244,7 @@ lib_deps =
${common:idf-component-libs.lib_deps} ${common:idf-component-libs.lib_deps}
ESP32Async/ESPAsyncWebServer@3.9.6 ; web_server_base ESP32Async/ESPAsyncWebServer@3.9.6 ; web_server_base
droscy/esp_wireguard@0.4.5 ; wireguard droscy/esp_wireguard@0.4.5 ; wireguard
esphome/noise-c@0.1.24 ; noise (api, ota) esphome/noise-c@0.1.26 ; noise (api, ota)
ESP32Async/AsyncTCP@3.4.5 ; async_tcp ESP32Async/AsyncTCP@3.4.5 ; async_tcp
DNSServer ; captive_portal DNSServer ; captive_portal
heman/AsyncMqttClient-esphome@2.0.0 ; mqtt heman/AsyncMqttClient-esphome@2.0.0 ; mqtt
@@ -641,7 +641,7 @@ build_unflags =
extends = common extends = common
platform = platformio/native platform = platformio/native
lib_deps = lib_deps =
esphome/noise-c@0.1.24 ; used by noise (api, ota) esphome/noise-c@0.1.26 ; used by noise (api, ota)
lvgl/lvgl@9.5.0 ; lvgl lvgl/lvgl@9.5.0 ; lvgl
build_flags = build_flags =
${common.build_flags} ${common.build_flags}
+1 -1
View File
@@ -10,7 +10,7 @@ tzlocal==5.4.4 # from time
tzdata>=2026.3 # from time tzdata>=2026.3 # from time
pyserial==3.5 pyserial==3.5
platformio==6.1.19 platformio==6.1.19
esptool==5.3.1 esptool==5.4.0
click==8.3.3 click==8.3.3
aioesphomeapi==46.3.0 aioesphomeapi==46.3.0
aiohappyeyeballs==2.7.1 # Happy Eyeballs for requests downloads; already pulled in by aioesphomeapi aiohappyeyeballs==2.7.1 # Happy Eyeballs for requests downloads; already pulled in by aioesphomeapi
@@ -0,0 +1,90 @@
"""Validation tests for the sendspin media_source platform.
These cover the codec preference list, whose rejection branches a compile test
cannot reach: a `test*.yaml` can only assert that a configuration is accepted.
"""
from typing import Any
import pytest
from esphome import config_validation as cv
from esphome.components.sendspin import CONF_CODECS, _get_data
from esphome.components.sendspin.media_source import CONFIG_SCHEMA
from esphome.const import PlatformFramework
from esphome.types import ConfigType
from tests.component_tests.types import SetCoreConfigCallable
def _media_source_config(**overrides: Any) -> ConfigType:
"""Build a minimal valid media source config, allowing field overrides."""
config: ConfigType = {
"id": "sendspin_media_source",
"sendspin_id": "sendspin_hub",
}
config.update(overrides)
return config
def test_default_codecs_at_48_khz(set_core_config: SetCoreConfigCallable) -> None:
"""Every codec is advertised when the sample rate suits all of them."""
set_core_config(PlatformFramework.ESP32_IDF)
config = CONFIG_SCHEMA(_media_source_config())
assert config[CONF_CODECS] == ["flac", "opus", "pcm"]
def test_default_codecs_drop_opus_at_other_rates(
set_core_config: SetCoreConfigCallable,
) -> None:
"""Opus only supports 48 kHz, so it leaves the default list at other rates."""
set_core_config(PlatformFramework.ESP32_IDF)
config = CONFIG_SCHEMA(_media_source_config(sample_rate=44100))
assert config[CONF_CODECS] == ["flac", "pcm"]
def test_configured_order_is_preserved(set_core_config: SetCoreConfigCallable) -> None:
"""The list is a preference order, so it reaches the player role as written."""
set_core_config(PlatformFramework.ESP32_IDF)
CONFIG_SCHEMA(_media_source_config(codecs=["pcm", "flac"]))
assert _get_data().player_config[CONF_CODECS] == ["pcm", "flac"]
def test_empty_codec_list_rejected(set_core_config: SetCoreConfigCallable) -> None:
"""A player with no codecs at all could never be given a stream."""
set_core_config(PlatformFramework.ESP32_IDF)
with pytest.raises(cv.Invalid, match="length of value must be at least 1"):
CONFIG_SCHEMA(_media_source_config(codecs=[]))
def test_duplicate_codec_rejected(set_core_config: SetCoreConfigCallable) -> None:
"""A repeated codec has no meaning in a preference order."""
set_core_config(PlatformFramework.ESP32_IDF)
with pytest.raises(cv.Invalid, match="may only be listed once"):
CONFIG_SCHEMA(_media_source_config(codecs=["flac", "flac"]))
def test_unknown_codec_rejected(set_core_config: SetCoreConfigCallable) -> None:
"""Only codecs the player role can decode are accepted."""
set_core_config(PlatformFramework.ESP32_IDF)
with pytest.raises(cv.Invalid, match="Unknown value"):
CONFIG_SCHEMA(_media_source_config(codecs=["mp3"]))
def test_opus_at_wrong_sample_rate_rejected(
set_core_config: SetCoreConfigCallable,
) -> None:
"""Asking for Opus at a rate it cannot handle fails rather than silently
dropping the stated preference."""
set_core_config(PlatformFramework.ESP32_IDF)
with pytest.raises(cv.Invalid, match="requires a sample_rate of 48000"):
CONFIG_SCHEMA(_media_source_config(codecs=["opus"], sample_rate=44100))
@@ -9,3 +9,4 @@ media_source:
static_delay_adjustable: true static_delay_adjustable: true
fixed_delay: 480us fixed_delay: 480us
decode_memory: internal decode_memory: internal
codecs: [pcm, opus, flac]
+17 -17
View File
@@ -35,8 +35,8 @@ def _load_script():
def test_spec_key_collapses_destinations() -> None: def test_spec_key_collapses_destinations() -> None:
"""Two specs delivering one package share a directory and one key.""" """Two specs delivering one package share a directory and one key."""
mod = _load_script() mod = _load_script()
assert mod.spec_key("esphome/noise-c @ 0.1.24") == "noise-c" assert mod.spec_key("esphome/noise-c @ 0.1.26") == "noise-c"
assert mod.spec_key("esphome/noise-c@0.1.24") == "noise-c" assert mod.spec_key("esphome/noise-c@0.1.26") == "noise-c"
assert mod.spec_key("ESP32Async/AsyncTCP @ ^3.4.10") == mod.spec_key( assert mod.spec_key("ESP32Async/AsyncTCP @ ^3.4.10") == mod.spec_key(
"esp32async/asynctcp @ 3.5.0" "esp32async/asynctcp @ 3.5.0"
) )
@@ -54,23 +54,23 @@ def test_parse_specs_and_cli_args(tmp_path: Path) -> None:
"[env:a]\n" "[env:a]\n"
"platform = fake/platform@1\n" "platform = fake/platform@1\n"
"lib_deps =\n" "lib_deps =\n"
" esphome/noise-c @ 0.1.24\n" " esphome/noise-c @ 0.1.26\n"
" ${common.lib_deps}\n" " ${common.lib_deps}\n"
" internal_lib\n" " internal_lib\n"
"[env:b]\n" "[env:b]\n"
"lib_deps =\n" "lib_deps =\n"
" esphome/noise-c @ 0.1.24\n" " esphome/noise-c @ 0.1.26\n"
) )
mod = _load_script() mod = _load_script()
args = Namespace(libraries=True, platforms=True, tools=False) args = Namespace(libraries=True, platforms=True, tools=False)
libs, platforms, tools = mod.parse_specs(str(ini), args) libs, platforms, tools = mod.parse_specs(str(ini), args)
# exact-string duplicates collapse; distinct version pins survive # exact-string duplicates collapse; distinct version pins survive
assert libs == ["esphome/noise-c @ 0.1.24"] assert libs == ["esphome/noise-c @ 0.1.26"]
assert platforms == ["fake/platform@1"] assert platforms == ["fake/platform@1"]
assert tools == [] assert tools == []
assert mod.build_cli_args(libs, platforms, tools) == [ assert mod.build_cli_args(libs, platforms, tools) == [
"-l", "-l",
"esphome/noise-c @ 0.1.24", "esphome/noise-c @ 0.1.26",
"-p", "-p",
"fake/platform@1", "fake/platform@1",
] ]
@@ -162,13 +162,13 @@ def test_parallel_install_behavior(tmp_path: Path) -> None:
mod.parallel_install( mod.parallel_install(
cls, cls,
[ [
"esphome/noise-c @ 0.1.24", "esphome/noise-c @ 0.1.26",
"esphome/noise-c @ 0.1.24", "esphome/noise-c @ 0.1.26",
"esphome/already @ 1.0", "esphome/already @ 1.0",
"https://x/framework.tar.xz", "https://x/framework.tar.xz",
], ],
) )
assert cls.calls == ["esphome/noise-c @ 0.1.24"] assert cls.calls == ["esphome/noise-c @ 0.1.26"]
assert cls.lock_events == ["lock", "unlock"] assert cls.lock_events == ["lock", "unlock"]
@@ -205,7 +205,7 @@ def test_parallel_install_runs_dependency_waves(tmp_path: Path) -> None:
mod = _load_script() mod = _load_script()
cls = _reset_fake(str(tmp_path)) cls = _reset_fake(str(tmp_path))
cls.deps = { cls.deps = {
"esphome/noise-c @ 0.1.24": [ "esphome/noise-c @ 0.1.26": [
{"owner": "esphome", "name": "libsodium", "version": "^1.0"}, {"owner": "esphome", "name": "libsodium", "version": "^1.0"},
{"name": "SPI"}, {"name": "SPI"},
], ],
@@ -213,12 +213,12 @@ def test_parallel_install_runs_dependency_waves(tmp_path: Path) -> None:
{"owner": "esphome", "name": "libsodium", "version": "^1.0"}, {"owner": "esphome", "name": "libsodium", "version": "^1.0"},
], ],
} }
mod.parallel_install(cls, ["esphome/noise-c @ 0.1.24", "esphome/wg @ 1.0"]) mod.parallel_install(cls, ["esphome/noise-c @ 0.1.26", "esphome/wg @ 1.0"])
assert len(cls.calls) == 3 # the shared dep installs exactly once assert len(cls.calls) == 3 # the shared dep installs exactly once
assert {mod.spec_key(c) for c in cls.calls} == {"noise-c", "wg", "libsodium"} assert {mod.spec_key(c) for c in cls.calls} == {"noise-c", "wg", "libsodium"}
# Wave-1 strings carry no compatibility; the dependency wave does # Wave-1 strings carry no compatibility; the dependency wave does
compats = dict(cls.compat_calls) compats = dict(cls.compat_calls)
assert compats["esphome/noise-c @ 0.1.24"] is None assert compats["esphome/noise-c @ 0.1.26"] is None
dep_compat = next(v for k, v in cls.compat_calls if "libsodium" in k) dep_compat = next(v for k, v in cls.compat_calls if "libsodium" in k)
assert dep_compat is not None # mirrors pio's install_dependency assert dep_compat is not None # mirrors pio's install_dependency
@@ -229,11 +229,11 @@ def test_dependency_wave_excludes_url_specs(tmp_path: Path) -> None:
mod = _load_script() mod = _load_script()
cls = _reset_fake(str(tmp_path)) cls = _reset_fake(str(tmp_path))
cls.deps = { cls.deps = {
"esphome/noise-c @ 0.1.24": [ "esphome/noise-c @ 0.1.26": [
{"name": "vendored", "version": "https://github.com/x/y.git"}, {"name": "vendored", "version": "https://github.com/x/y.git"},
], ],
} }
mod.parallel_install(cls, ["esphome/noise-c @ 0.1.24"]) mod.parallel_install(cls, ["esphome/noise-c @ 0.1.26"])
assert {mod.spec_key(c) for c in cls.calls} == {"noise-c"} assert {mod.spec_key(c) for c in cls.calls} == {"noise-c"}
@@ -348,13 +348,13 @@ def test_warm_store_still_walks_dependencies(tmp_path: Path) -> None:
"""Already-installed top-level packages still feed the dependency """Already-installed top-level packages still feed the dependency
wave; a warm store can be missing a transitive dep.""" wave; a warm store can be missing a transitive dep."""
mod = _load_script() mod = _load_script()
cls = _reset_fake(str(tmp_path), installed={"esphome/noise-c @ 0.1.24"}) cls = _reset_fake(str(tmp_path), installed={"esphome/noise-c @ 0.1.26"})
cls.deps = { cls.deps = {
"esphome/noise-c @ 0.1.24": [ "esphome/noise-c @ 0.1.26": [
{"owner": "esphome", "name": "libsodium", "version": "^1.0"}, {"owner": "esphome", "name": "libsodium", "version": "^1.0"},
], ],
} }
mod.parallel_install(cls, ["esphome/noise-c @ 0.1.24"]) mod.parallel_install(cls, ["esphome/noise-c @ 0.1.26"])
assert [mod.spec_key(c) for c in cls.calls] == ["libsodium"] assert [mod.spec_key(c) for c in cls.calls] == ["libsodium"]
+3
View File
@@ -416,6 +416,9 @@ def test_perform_ota_no_auth(
"Update took 14.00 seconds (prepare 2.00, upload 5.00, commit 7.00)" "Update took 14.00 seconds (prepare 2.00, upload 5.00, commit 7.00)"
in caplog.text in caplog.text
) )
# The data phase timeout must outlast the device's 105 s data timeout
mock_socket.settimeout.assert_any_call(espota2.DATA_PHASE_TIMEOUT)
assert espota2.DATA_PHASE_TIMEOUT > 105.0
@pytest.mark.usefixtures("mock_time") @pytest.mark.usefixtures("mock_time")
+2 -2
View File
@@ -1663,7 +1663,7 @@ def test_preinstall_runs_dependency_waves(tmp_path: Path) -> None:
{"name": "SPI"}, {"name": "SPI"},
] ]
m.dependency_to_spec.side_effect = lambda dep: _FakeSpec(name=dep["name"]) m.dependency_to_spec.side_effect = lambda dep: _FakeSpec(name=dep["name"])
pf._preinstall(m, [("noise-c@0.1.24", _FakeSpec(name="noise-c"))]) pf._preinstall(m, [("noise-c@0.1.26", _FakeSpec(name="noise-c"))])
assert installed == ["noise-c", "libsodium"] # dep deduped, SPI left out assert installed == ["noise-c", "libsodium"] # dep deduped, SPI left out
# The dep wave carries its compatibility so _install searches qualified # The dep wave carries its compatibility so _install searches qualified
dep_call = m._install.call_args_list[-1] dep_call = m._install.call_args_list[-1]
@@ -1683,7 +1683,7 @@ def test_preinstall_dependency_wave_skips_seen_names(tmp_path: Path) -> None:
m._install.side_effect = lambda spec, skip_dependencies, compatibility=None: ( m._install.side_effect = lambda spec, skip_dependencies, compatibility=None: (
installed.append(getattr(spec, "name", str(spec))) installed.append(getattr(spec, "name", str(spec)))
) )
pf._preinstall(m, [("noise-c@0.1.24", _FakeSpec(name="noise-c"))]) pf._preinstall(m, [("noise-c@0.1.26", _FakeSpec(name="noise-c"))])
assert installed == ["noise-c"] assert installed == ["noise-c"]