mirror of
https://github.com/esphome/esphome.git
synced 2026-09-09 22:38:48 +00:00
Compare commits
33
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
58ca345684 | ||
|
|
fd598057ef | ||
|
|
ef7279341f | ||
|
|
69f2a7d556 | ||
|
|
008677298a | ||
|
|
d2bc056f0a | ||
|
|
42fffd16fe | ||
|
|
9c16aba6f7 | ||
|
|
ac79173f4a | ||
|
|
0a1e2acbcb | ||
|
|
9b6facb20d | ||
|
|
f89b9e704c | ||
|
|
f8b2e53609 | ||
|
|
7660dd7fa7 | ||
|
|
c3ce07755f | ||
|
|
f8a4cfa945 | ||
|
|
866ddb6e57 | ||
|
|
ca864c22b4 | ||
|
|
c9729244af | ||
|
|
442e4a1ec2 | ||
|
|
199acdf522 | ||
|
|
9340863652 | ||
|
|
d5cff6e9df | ||
|
|
e7f45a0d31 | ||
|
|
628ebe23ec | ||
|
|
823d79c948 | ||
|
|
b947094f45 | ||
|
|
6c5ab89d5f | ||
|
|
8f511a365a | ||
|
|
006f31af93 | ||
|
|
5bb112f407 | ||
|
|
4ab9298ab3 | ||
|
|
3926612281 |
@@ -6,6 +6,7 @@
|
|||||||
#include "esphome/components/network/util.h"
|
#include "esphome/components/network/util.h"
|
||||||
#include "esphome/core/log.h"
|
#include "esphome/core/log.h"
|
||||||
#include <cerrno>
|
#include <cerrno>
|
||||||
|
#include <sys/select.h>
|
||||||
|
|
||||||
namespace esphome::async_tcp {
|
namespace esphome::async_tcp {
|
||||||
|
|
||||||
@@ -41,15 +42,7 @@ bool AsyncClient::connect(const char *host, uint16_t port) {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (socket_->setblocking(false) != 0) {
|
socket_->setblocking(false);
|
||||||
// Capture before the log and close() clobber errno
|
|
||||||
const int saved_errno = errno;
|
|
||||||
ESP_LOGE(TAG, "Failed to set nonblocking: errno %d", saved_errno);
|
|
||||||
close();
|
|
||||||
if (error_cb_)
|
|
||||||
error_cb_(error_arg_, this, saved_errno);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
int err = socket_->connect((struct sockaddr *) &addr, addrlen);
|
int err = socket_->connect((struct sockaddr *) &addr, addrlen);
|
||||||
if (err == 0) {
|
if (err == 0) {
|
||||||
@@ -104,22 +97,45 @@ void AsyncClient::loop() {
|
|||||||
return;
|
return;
|
||||||
|
|
||||||
if (connecting_) {
|
if (connecting_) {
|
||||||
int err = 0;
|
// For connecting, we need to check writability, not readability
|
||||||
switch (socket::poll_connect(*socket_, err)) {
|
// The Application's select() only monitors read FDs, so we do our own check here
|
||||||
case socket::ConnectPollResult::CONNECT_POLL_RESULT_PENDING:
|
// For ESP platforms lwip_select() might be faster, but this code isn't used
|
||||||
break;
|
// on those platforms anyway. If it was, we'd fix the Application select()
|
||||||
case socket::ConnectPollResult::CONNECT_POLL_RESULT_CONNECTED:
|
// to report writability instead of doing it this way.
|
||||||
|
int fd = socket_->get_fd();
|
||||||
|
if (fd < 0) {
|
||||||
|
ESP_LOGW(TAG, "Invalid socket fd");
|
||||||
|
close();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
fd_set writefds;
|
||||||
|
FD_ZERO(&writefds);
|
||||||
|
FD_SET(fd, &writefds);
|
||||||
|
|
||||||
|
struct timeval tv = {0, 0};
|
||||||
|
int ret = select(fd + 1, nullptr, &writefds, nullptr, &tv);
|
||||||
|
|
||||||
|
if (ret > 0 && FD_ISSET(fd, &writefds)) {
|
||||||
|
int error = 0;
|
||||||
|
socklen_t len = sizeof(error);
|
||||||
|
if (socket_->getsockopt(SOL_SOCKET, SO_ERROR, &error, &len) == 0 && error == 0) {
|
||||||
connecting_ = false;
|
connecting_ = false;
|
||||||
connected_ = true;
|
connected_ = true;
|
||||||
if (connect_cb_)
|
if (connect_cb_)
|
||||||
connect_cb_(connect_arg_, this);
|
connect_cb_(connect_arg_, this);
|
||||||
break;
|
} else {
|
||||||
case socket::ConnectPollResult::CONNECT_POLL_RESULT_ERROR:
|
ESP_LOGW(TAG, "Connection failed: %d", error);
|
||||||
ESP_LOGW(TAG, "Connection failed: %d", err);
|
|
||||||
close();
|
close();
|
||||||
if (error_cb_)
|
if (error_cb_)
|
||||||
error_cb_(error_arg_, this, err);
|
error_cb_(error_arg_, this, error);
|
||||||
break;
|
}
|
||||||
|
} else if (ret < 0) {
|
||||||
|
const int err = errno;
|
||||||
|
ESP_LOGE(TAG, "Select error: %d", err);
|
||||||
|
close();
|
||||||
|
if (error_cb_)
|
||||||
|
error_cb_(error_arg_, this, err);
|
||||||
}
|
}
|
||||||
} else if (connected_) {
|
} else if (connected_) {
|
||||||
// For connected sockets, use the Application's select() results
|
// For connected sockets, use the Application's select() results
|
||||||
|
|||||||
@@ -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)
|
||||||
@@ -444,10 +447,7 @@ void ESPHomeOTAComponent::handle_data_() {
|
|||||||
tv.tv_usec = 0;
|
tv.tv_usec = 0;
|
||||||
this->client_->setsockopt(SOL_SOCKET, SO_RCVTIMEO, &tv, sizeof(tv));
|
this->client_->setsockopt(SOL_SOCKET, SO_RCVTIMEO, &tv, sizeof(tv));
|
||||||
this->client_->setsockopt(SOL_SOCKET, SO_SNDTIMEO, &tv, sizeof(tv));
|
this->client_->setsockopt(SOL_SOCKET, SO_SNDTIMEO, &tv, sizeof(tv));
|
||||||
if (this->client_->setblocking(true) != 0) {
|
this->client_->setblocking(true);
|
||||||
this->log_socket_error_(LOG_STR("blocking"));
|
|
||||||
goto error; // NOLINT(cppcoreguidelines-avoid-goto)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Acknowledge auth OK - 1 byte
|
// Acknowledge auth OK - 1 byte
|
||||||
this->data_write_byte_(ota::OTA_RESPONSE_AUTH_OK);
|
this->data_write_byte_(ota::OTA_RESPONSE_AUTH_OK);
|
||||||
|
|||||||
@@ -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;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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;
|
||||||
|
|||||||
@@ -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 = [CODECS[codec] for codec in 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,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|||||||
@@ -59,15 +59,13 @@ int BSDSocketImpl::close() {
|
|||||||
|
|
||||||
int BSDSocketImpl::setblocking(bool blocking) {
|
int BSDSocketImpl::setblocking(bool blocking) {
|
||||||
int fl = ::fcntl(this->fd_, F_GETFL, 0);
|
int fl = ::fcntl(this->fd_, F_GETFL, 0);
|
||||||
if (fl < 0) {
|
|
||||||
return fl;
|
|
||||||
}
|
|
||||||
if (blocking) {
|
if (blocking) {
|
||||||
fl &= ~O_NONBLOCK;
|
fl &= ~O_NONBLOCK;
|
||||||
} else {
|
} else {
|
||||||
fl |= O_NONBLOCK;
|
fl |= O_NONBLOCK;
|
||||||
}
|
}
|
||||||
return ::fcntl(this->fd_, F_SETFL, fl);
|
::fcntl(this->fd_, F_SETFL, fl);
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t BSDSocketImpl::getpeername_to(std::span<char, SOCKADDR_STR_LEN> buf) {
|
size_t BSDSocketImpl::getpeername_to(std::span<char, SOCKADDR_STR_LEN> buf) {
|
||||||
|
|||||||
@@ -205,13 +205,6 @@ static constexpr size_t SOCKADDR_STR_LEN = 46; // INET6_ADDRSTRLEN
|
|||||||
static constexpr size_t SOCKADDR_STR_LEN = 16; // INET_ADDRSTRLEN
|
static constexpr size_t SOCKADDR_STR_LEN = 16; // INET_ADDRSTRLEN
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/// Outcome of polling a non-blocking connect(); see socket::poll_connect().
|
|
||||||
enum class ConnectPollResult : uint8_t {
|
|
||||||
CONNECT_POLL_RESULT_PENDING,
|
|
||||||
CONNECT_POLL_RESULT_CONNECTED,
|
|
||||||
CONNECT_POLL_RESULT_ERROR,
|
|
||||||
};
|
|
||||||
|
|
||||||
} // namespace esphome::socket
|
} // namespace esphome::socket
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -48,33 +48,8 @@ static const char *const TAG = "socket";
|
|||||||
#ifdef USE_ESP8266
|
#ifdef USE_ESP8266
|
||||||
// optimistic_yield() rate limit in microseconds of CONT time; cheap when hot.
|
// optimistic_yield() rate limit in microseconds of CONT time; cheap when hot.
|
||||||
static constexpr uint32_t ESP8266_YIELD_INTERVAL_US = 1000;
|
static constexpr uint32_t ESP8266_YIELD_INTERVAL_US = 1000;
|
||||||
// Let SYS run so queued WiFi traffic reaches lwip; CONT and SYS are cooperative
|
|
||||||
static inline void yield_to_sys() { optimistic_yield(ESP8266_YIELD_INTERVAL_US); }
|
|
||||||
#else
|
|
||||||
static inline void yield_to_sys() {}
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// errno for a failed tcp_* call
|
|
||||||
static int lwip_err_to_errno(err_t err) {
|
|
||||||
switch (err) {
|
|
||||||
case ERR_MEM:
|
|
||||||
return ENOMEM;
|
|
||||||
case ERR_BUF:
|
|
||||||
return EAGAIN; // transient, e.g. no free local port
|
|
||||||
case ERR_RTE:
|
|
||||||
return EHOSTUNREACH; // no route, e.g. no address yet
|
|
||||||
case ERR_VAL:
|
|
||||||
case ERR_ARG:
|
|
||||||
return EINVAL;
|
|
||||||
case ERR_USE:
|
|
||||||
return EADDRINUSE;
|
|
||||||
case ERR_ISCONN:
|
|
||||||
return EISCONN;
|
|
||||||
default:
|
|
||||||
return EIO;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// set to 1 to enable verbose lwip logging
|
// set to 1 to enable verbose lwip logging
|
||||||
#if 0 // NOLINT(readability-avoid-unconditional-preprocessor-if)
|
#if 0 // NOLINT(readability-avoid-unconditional-preprocessor-if)
|
||||||
#define LWIP_LOG(msg, ...) ESP_LOGVV(TAG, "socket %p: " msg, this, ##__VA_ARGS__)
|
#define LWIP_LOG(msg, ...) ESP_LOGVV(TAG, "socket %p: " msg, this, ##__VA_ARGS__)
|
||||||
@@ -87,8 +62,8 @@ static int lwip_err_to_errno(err_t err) {
|
|||||||
// Must be called before destroying the object that tcp_arg points to —
|
// Must be called before destroying the object that tcp_arg points to —
|
||||||
// tcp_abort() triggers the err callback synchronously, which would
|
// tcp_abort() triggers the err callback synchronously, which would
|
||||||
// otherwise call back into a partially-destroyed object.
|
// otherwise call back into a partially-destroyed object.
|
||||||
// tcp_sent/tcp_poll are never registered and the connect callback cannot
|
// tcp_sent/tcp_poll are not cleared because this implementation
|
||||||
// fire after abort or close, so neither is cleared.
|
// never registers them.
|
||||||
static void pcb_detach_abort(struct tcp_pcb *pcb) {
|
static void pcb_detach_abort(struct tcp_pcb *pcb) {
|
||||||
tcp_arg(pcb, nullptr);
|
tcp_arg(pcb, nullptr);
|
||||||
tcp_recv(pcb, nullptr);
|
tcp_recv(pcb, nullptr);
|
||||||
@@ -101,7 +76,8 @@ static void pcb_detach_abort(struct tcp_pcb *pcb) {
|
|||||||
// After tcp_close(), the PCB remains alive during the TCP close handshake
|
// After tcp_close(), the PCB remains alive during the TCP close handshake
|
||||||
// (FIN_WAIT, TIME_WAIT states). Without clearing callbacks first, LWIP
|
// (FIN_WAIT, TIME_WAIT states). Without clearing callbacks first, LWIP
|
||||||
// would call recv/err on a destroyed socket object, corrupting the heap.
|
// would call recv/err on a destroyed socket object, corrupting the heap.
|
||||||
// Callbacks are left as in pcb_detach_abort().
|
// tcp_sent/tcp_poll are not cleared because this implementation
|
||||||
|
// never registers them.
|
||||||
// Returns ERR_OK on success; on failure the PCB is aborted instead.
|
// Returns ERR_OK on success; on failure the PCB is aborted instead.
|
||||||
static err_t pcb_detach_close(struct tcp_pcb *pcb) {
|
static err_t pcb_detach_close(struct tcp_pcb *pcb) {
|
||||||
tcp_arg(pcb, nullptr);
|
tcp_arg(pcb, nullptr);
|
||||||
@@ -125,51 +101,67 @@ LWIPRawCommon::~LWIPRawCommon() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool LWIPRawCommon::sockaddr2ip_(const struct sockaddr *name, socklen_t addrlen, ip_addr_t *ip, uint16_t *port) const {
|
|
||||||
if (name == nullptr) {
|
|
||||||
errno = EINVAL;
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
#if LWIP_IPV6
|
|
||||||
if (this->family_ == AF_INET6) {
|
|
||||||
if (addrlen < sizeof(sockaddr_in6)) {
|
|
||||||
errno = EINVAL;
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
auto *addr6 = reinterpret_cast<const sockaddr_in6 *>(name);
|
|
||||||
*port = ntohs(addr6->sin6_port);
|
|
||||||
inet6_addr_to_ip6addr(ip_2_ip6(ip), &addr6->sin6_addr);
|
|
||||||
// ANY lets bind() accept both families; connect() picks the concrete type
|
|
||||||
IP_SET_TYPE_VAL(*ip, IPADDR_TYPE_ANY);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
if (this->family_ != AF_INET || addrlen < sizeof(sockaddr_in)) {
|
|
||||||
errno = EINVAL;
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
auto *addr4 = reinterpret_cast<const sockaddr_in *>(name);
|
|
||||||
*port = ntohs(addr4->sin_port);
|
|
||||||
ip_addr_set_ip4_u32(ip, addr4->sin_addr.s_addr);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
int LWIPRawCommon::bind(const struct sockaddr *name, socklen_t addrlen) {
|
int LWIPRawCommon::bind(const struct sockaddr *name, socklen_t addrlen) {
|
||||||
LWIP_LOCK();
|
LWIP_LOCK();
|
||||||
if (this->pcb_ == nullptr) {
|
if (this->pcb_ == nullptr) {
|
||||||
errno = EBADF;
|
errno = EBADF;
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
ip_addr_t ip;
|
if (name == nullptr) {
|
||||||
uint16_t port;
|
errno = EINVAL;
|
||||||
if (!this->sockaddr2ip_(name, addrlen, &ip, &port)) {
|
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
LWIP_LOG("tcp_bind(%p ip=%s port=%u)", this->pcb_, ipaddr_ntoa(&ip), port);
|
ip_addr_t ip;
|
||||||
|
in_port_t port;
|
||||||
|
#if LWIP_IPV6
|
||||||
|
if (this->family_ == AF_INET) {
|
||||||
|
if (addrlen < sizeof(sockaddr_in)) {
|
||||||
|
errno = EINVAL;
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
auto *addr4 = reinterpret_cast<const sockaddr_in *>(name);
|
||||||
|
port = ntohs(addr4->sin_port);
|
||||||
|
ip.type = IPADDR_TYPE_V4;
|
||||||
|
ip.u_addr.ip4.addr = addr4->sin_addr.s_addr;
|
||||||
|
LWIP_LOG("tcp_bind(%p ip=%s port=%u)", this->pcb_, ip4addr_ntoa(&ip.u_addr.ip4), port);
|
||||||
|
} else if (this->family_ == AF_INET6) {
|
||||||
|
if (addrlen < sizeof(sockaddr_in6)) {
|
||||||
|
errno = EINVAL;
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
auto *addr6 = reinterpret_cast<const sockaddr_in6 *>(name);
|
||||||
|
port = ntohs(addr6->sin6_port);
|
||||||
|
ip.type = IPADDR_TYPE_ANY;
|
||||||
|
memcpy(&ip.u_addr.ip6.addr, &addr6->sin6_addr.un.u8_addr, 16);
|
||||||
|
LWIP_LOG("tcp_bind(%p ip=%s port=%u)", this->pcb_, ip6addr_ntoa(&ip.u_addr.ip6), port);
|
||||||
|
} else {
|
||||||
|
errno = EINVAL;
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
#else
|
||||||
|
if (this->family_ != AF_INET) {
|
||||||
|
errno = EINVAL;
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
auto *addr4 = reinterpret_cast<const sockaddr_in *>(name);
|
||||||
|
port = ntohs(addr4->sin_port);
|
||||||
|
ip.addr = addr4->sin_addr.s_addr;
|
||||||
|
LWIP_LOG("tcp_bind(%p ip=%u port=%u)", this->pcb_, ip.addr, port);
|
||||||
|
#endif
|
||||||
err_t err = tcp_bind(this->pcb_, &ip, port);
|
err_t err = tcp_bind(this->pcb_, &ip, port);
|
||||||
|
if (err == ERR_USE) {
|
||||||
|
LWIP_LOG(" -> err ERR_USE");
|
||||||
|
errno = EADDRINUSE;
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
if (err == ERR_VAL) {
|
||||||
|
LWIP_LOG(" -> err ERR_VAL");
|
||||||
|
errno = EINVAL;
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
if (err != ERR_OK) {
|
if (err != ERR_OK) {
|
||||||
LWIP_LOG(" -> err %d", err);
|
LWIP_LOG(" -> err %d", err);
|
||||||
errno = lwip_err_to_errno(err);
|
errno = EIO;
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
@@ -186,7 +178,7 @@ int LWIPRawCommon::close() {
|
|||||||
this->pcb_ = nullptr;
|
this->pcb_ = nullptr;
|
||||||
if (err != ERR_OK) {
|
if (err != ERR_OK) {
|
||||||
LWIP_LOG(" -> err %d", err);
|
LWIP_LOG(" -> err %d", err);
|
||||||
errno = lwip_err_to_errno(err);
|
errno = err == ERR_MEM ? ENOMEM : EIO;
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
@@ -213,7 +205,7 @@ int LWIPRawCommon::shutdown(int how) {
|
|||||||
err_t err = tcp_shutdown(this->pcb_, shut_rx, shut_tx);
|
err_t err = tcp_shutdown(this->pcb_, shut_rx, shut_tx);
|
||||||
if (err != ERR_OK) {
|
if (err != ERR_OK) {
|
||||||
LWIP_LOG(" -> err %d", err);
|
LWIP_LOG(" -> err %d", err);
|
||||||
errno = lwip_err_to_errno(err);
|
errno = err == ERR_MEM ? ENOMEM : EIO;
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
@@ -433,82 +425,7 @@ void LWIPRawImpl::s_err_fn(void *arg, err_t err) {
|
|||||||
// ERR_ABRT: aborted through tcp_abort or TCP timer
|
// ERR_ABRT: aborted through tcp_abort or TCP timer
|
||||||
auto *arg_this = reinterpret_cast<LWIPRawImpl *>(arg);
|
auto *arg_this = reinterpret_cast<LWIPRawImpl *>(arg);
|
||||||
ESP_LOGVV(TAG, "socket %p: err(err=%d)", arg_this, err);
|
ESP_LOGVV(TAG, "socket %p: err(err=%d)", arg_this, err);
|
||||||
if (arg_this->connect_err_ == EINPROGRESS) {
|
|
||||||
// Refused (RST) or SYN retries exhausted; written before pcb_ so
|
|
||||||
// poll_connect() never sees a dead pcb without its reason
|
|
||||||
arg_this->connect_err_ = err == ERR_RST ? ECONNREFUSED : ETIMEDOUT;
|
|
||||||
}
|
|
||||||
arg_this->pcb_ = nullptr;
|
arg_this->pcb_ = nullptr;
|
||||||
esphome::wake_loop_any_context();
|
|
||||||
}
|
|
||||||
|
|
||||||
err_t LWIPRawImpl::s_connected_fn(void *arg, struct tcp_pcb *pcb, err_t err) {
|
|
||||||
// LWIP CALLBACK, same constraints as s_err_fn; err is always ERR_OK
|
|
||||||
auto *arg_this = reinterpret_cast<LWIPRawImpl *>(arg);
|
|
||||||
arg_this->connect_err_ = EISCONN;
|
|
||||||
esphome::wake_loop_any_context();
|
|
||||||
return ERR_OK;
|
|
||||||
}
|
|
||||||
|
|
||||||
int LWIPRawImpl::connect(const struct sockaddr *addr, socklen_t addrlen) {
|
|
||||||
LWIP_LOCK();
|
|
||||||
if (this->pcb_ == nullptr) {
|
|
||||||
errno = EBADF;
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
if (this->connect_err_ == EINPROGRESS || this->connect_err_ == EISCONN) {
|
|
||||||
errno = this->connect_err_ == EINPROGRESS ? EALREADY : EISCONN;
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
ip_addr_t ip;
|
|
||||||
uint16_t port;
|
|
||||||
if (!this->sockaddr2ip_(addr, addrlen, &ip, &port)) {
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
#if LWIP_IPV6
|
|
||||||
// tcp_connect needs a concrete type; a remembered IPv4 peer arrives v4-mapped
|
|
||||||
if (IP_IS_ANY_TYPE_VAL(ip)) {
|
|
||||||
if (ip6_addr_isipv4mappedipv6(ip_2_ip6(&ip))) {
|
|
||||||
unmap_ipv4_mapped_ipv6(ip_2_ip4(&ip), ip_2_ip6(&ip));
|
|
||||||
IP_SET_TYPE_VAL(ip, IPADDR_TYPE_V4);
|
|
||||||
} else {
|
|
||||||
IP_SET_TYPE_VAL(ip, IPADDR_TYPE_V6);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
LWIP_LOG("tcp_connect(%p ip=%s port=%u)", this->pcb_, ipaddr_ntoa(&ip), port);
|
|
||||||
err_t err = tcp_connect(this->pcb_, &ip, port, LWIPRawImpl::s_connected_fn);
|
|
||||||
if (err != ERR_OK) {
|
|
||||||
LWIP_LOG(" -> err %d", err);
|
|
||||||
errno = lwip_err_to_errno(err);
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
this->connect_err_ = EINPROGRESS;
|
|
||||||
errno = EINPROGRESS;
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
ConnectPollResult LWIPRawImpl::poll_connect(int &err_out) const {
|
|
||||||
// pcb_ first; see the ordering note on the declaration
|
|
||||||
if (this->pcb_ == nullptr) {
|
|
||||||
// Only a recorded connect failure carries its own reason
|
|
||||||
const bool failed = this->connect_err_ == ECONNREFUSED || this->connect_err_ == ETIMEDOUT;
|
|
||||||
err_out = failed ? this->connect_err_ : ECONNRESET;
|
|
||||||
return ConnectPollResult::CONNECT_POLL_RESULT_ERROR;
|
|
||||||
}
|
|
||||||
switch (this->connect_err_) {
|
|
||||||
case EINPROGRESS:
|
|
||||||
yield_to_sys(); // so the SYN-ACK is processed between polls
|
|
||||||
return ConnectPollResult::CONNECT_POLL_RESULT_PENDING;
|
|
||||||
case EISCONN:
|
|
||||||
return ConnectPollResult::CONNECT_POLL_RESULT_CONNECTED;
|
|
||||||
case 0:
|
|
||||||
err_out = EINVAL; // no connect was started
|
|
||||||
return ConnectPollResult::CONNECT_POLL_RESULT_ERROR;
|
|
||||||
default:
|
|
||||||
err_out = this->connect_err_;
|
|
||||||
return ConnectPollResult::CONNECT_POLL_RESULT_ERROR;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
err_t LWIPRawImpl::s_recv_fn(void *arg, struct tcp_pcb *pcb, struct pbuf *pb, err_t err) {
|
err_t LWIPRawImpl::s_recv_fn(void *arg, struct tcp_pcb *pcb, struct pbuf *pb, err_t err) {
|
||||||
@@ -623,11 +540,14 @@ ssize_t LWIPRawImpl::read_locked_(void *buf, size_t len) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
ssize_t LWIPRawImpl::read(void *buf, size_t len) {
|
ssize_t LWIPRawImpl::read(void *buf, size_t len) {
|
||||||
// Let queued WiFi RX reach lwip first; otherwise inbound segments can
|
#ifdef USE_ESP8266
|
||||||
// sit unprocessed for seconds while the main loop polls
|
// Would block: yield to SYS so queued WiFi RX reaches lwip and this read
|
||||||
|
// may succeed. Without this, inbound segments can sit unprocessed for
|
||||||
|
// seconds while the main loop polls (CONT/SYS are cooperative on ESP8266).
|
||||||
if (this->waiting_for_data_()) {
|
if (this->waiting_for_data_()) {
|
||||||
yield_to_sys();
|
optimistic_yield(ESP8266_YIELD_INTERVAL_US);
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
// See waiting_for_data_() for safety of unlocked reads.
|
// See waiting_for_data_() for safety of unlocked reads.
|
||||||
if (this->recv_timeout_cs_ > 0 && this->waiting_for_data_()) {
|
if (this->recv_timeout_cs_ > 0 && this->waiting_for_data_()) {
|
||||||
this->wait_for_data_();
|
this->wait_for_data_();
|
||||||
@@ -716,10 +636,12 @@ int LWIPRawImpl::internal_output_() {
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
#ifdef USE_ESP8266
|
||||||
// Flushed: yield to SYS so the queued segments reach the WiFi driver
|
// Flushed: yield to SYS so the queued segments reach the WiFi driver
|
||||||
// instead of waiting seconds for an unrelated SYS slot. Callers only get
|
// instead of waiting seconds for an unrelated SYS slot. Callers only get
|
||||||
// here after a successful tcp_write, so idle paths never yield.
|
// here after a successful tcp_write, so idle paths never yield.
|
||||||
yield_to_sys();
|
optimistic_yield(ESP8266_YIELD_INTERVAL_US);
|
||||||
|
#endif
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -50,8 +50,6 @@ class LWIPRawCommon {
|
|||||||
|
|
||||||
protected:
|
protected:
|
||||||
int ip2sockaddr_(ip_addr_t *ip, uint16_t port, struct sockaddr *name, socklen_t *addrlen);
|
int ip2sockaddr_(ip_addr_t *ip, uint16_t port, struct sockaddr *name, socklen_t *addrlen);
|
||||||
/// sockaddr of this socket's family to lwip address and port; false with errno on mismatch
|
|
||||||
bool sockaddr2ip_(const struct sockaddr *name, socklen_t addrlen, ip_addr_t *ip, uint16_t *port) const;
|
|
||||||
|
|
||||||
// Member ordering optimized to minimize padding on 32-bit systems
|
// Member ordering optimized to minimize padding on 32-bit systems
|
||||||
struct tcp_pcb *pcb_;
|
struct tcp_pcb *pcb_;
|
||||||
@@ -60,14 +58,7 @@ class LWIPRawCommon {
|
|||||||
bool nodelay_ = false;
|
bool nodelay_ = false;
|
||||||
sa_family_t family_ = 0;
|
sa_family_t family_ = 0;
|
||||||
uint8_t recv_timeout_cs_ = 0; // SO_RCVTIMEO in centiseconds (0 = no timeout, max 2.55s)
|
uint8_t recv_timeout_cs_ = 0; // SO_RCVTIMEO in centiseconds (0 = no timeout, max 2.55s)
|
||||||
// 0 before connect(), EINPROGRESS while pending, EISCONN once established,
|
|
||||||
// else the failure errno the callbacks recorded; fills the padding byte
|
|
||||||
uint8_t connect_err_ = 0;
|
|
||||||
static_assert(EINPROGRESS < 256 && EISCONN < 256 && ECONNREFUSED < 256 && ECONNRESET < 256 && ETIMEDOUT < 256,
|
|
||||||
"connect_err_ stores errno values in a byte");
|
|
||||||
};
|
};
|
||||||
// The connect state must stay in the padding so no socket pays RAM for it
|
|
||||||
static_assert(sizeof(LWIPRawCommon) == sizeof(struct tcp_pcb *) + 4, "LWIPRawCommon grew past one word of flags");
|
|
||||||
|
|
||||||
/// Connected socket implementation for LWIP raw TCP.
|
/// Connected socket implementation for LWIP raw TCP.
|
||||||
/// No virtual methods — callers always use the concrete type.
|
/// No virtual methods — callers always use the concrete type.
|
||||||
@@ -92,12 +83,6 @@ class LWIPRawImpl : public LWIPRawCommon {
|
|||||||
errno = EOPNOTSUPP;
|
errno = EOPNOTSUPP;
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
/// Non-blocking: returns -1/EINPROGRESS once the SYN is queued, see poll_connect().
|
|
||||||
/// addr must match the socket family; an IPv4 peer on AF_INET6 arrives v4-mapped.
|
|
||||||
int connect(const struct sockaddr *addr, socklen_t addrlen);
|
|
||||||
// Unlocked like ready(): the callbacks write the error byte before pcb_,
|
|
||||||
// so a torn read only costs one extra poll
|
|
||||||
ConnectPollResult poll_connect(int &err_out) const;
|
|
||||||
ssize_t read(void *buf, size_t len);
|
ssize_t read(void *buf, size_t len);
|
||||||
ssize_t readv(const struct iovec *iov, int iovcnt);
|
ssize_t readv(const struct iovec *iov, int iovcnt);
|
||||||
ssize_t recvfrom(void *, size_t, sockaddr *, socklen_t *) {
|
ssize_t recvfrom(void *, size_t, sockaddr *, socklen_t *) {
|
||||||
@@ -135,7 +120,6 @@ class LWIPRawImpl : public LWIPRawCommon {
|
|||||||
|
|
||||||
static void s_err_fn(void *arg, err_t err);
|
static void s_err_fn(void *arg, err_t err);
|
||||||
static err_t s_recv_fn(void *arg, struct tcp_pcb *pcb, struct pbuf *pb, err_t err);
|
static err_t s_recv_fn(void *arg, struct tcp_pcb *pcb, struct pbuf *pb, err_t err);
|
||||||
static err_t s_connected_fn(void *arg, struct tcp_pcb *pcb, err_t err);
|
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
// True when the socket could receive data but none has arrived yet.
|
// True when the socket could receive data but none has arrived yet.
|
||||||
@@ -153,9 +137,6 @@ class LWIPRawImpl : public LWIPRawCommon {
|
|||||||
size_t rx_buf_offset_ = 0;
|
size_t rx_buf_offset_ = 0;
|
||||||
bool rx_closed_ = false;
|
bool rx_closed_ = false;
|
||||||
};
|
};
|
||||||
// rx_buf_, rx_buf_offset_, then rx_closed_ padded to a word
|
|
||||||
static_assert(sizeof(LWIPRawImpl) == sizeof(LWIPRawCommon) + sizeof(pbuf *) + sizeof(size_t) + 4,
|
|
||||||
"LWIPRawImpl layout changed");
|
|
||||||
|
|
||||||
/// Listening socket implementation for LWIP raw TCP.
|
/// Listening socket implementation for LWIP raw TCP.
|
||||||
/// Separate from LWIPRawImpl — no virtual dispatch needed.
|
/// Separate from LWIPRawImpl — no virtual dispatch needed.
|
||||||
|
|||||||
@@ -49,15 +49,13 @@ int LwIPSocketImpl::close() {
|
|||||||
|
|
||||||
int LwIPSocketImpl::setblocking(bool blocking) {
|
int LwIPSocketImpl::setblocking(bool blocking) {
|
||||||
int fl = lwip_fcntl(this->fd_, F_GETFL, 0);
|
int fl = lwip_fcntl(this->fd_, F_GETFL, 0);
|
||||||
if (fl < 0) {
|
|
||||||
return fl;
|
|
||||||
}
|
|
||||||
if (blocking) {
|
if (blocking) {
|
||||||
fl &= ~O_NONBLOCK;
|
fl &= ~O_NONBLOCK;
|
||||||
} else {
|
} else {
|
||||||
fl |= O_NONBLOCK;
|
fl |= O_NONBLOCK;
|
||||||
}
|
}
|
||||||
return lwip_fcntl(this->fd_, F_SETFL, fl);
|
lwip_fcntl(this->fd_, F_SETFL, fl);
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t LwIPSocketImpl::getpeername_to(std::span<char, SOCKADDR_STR_LEN> buf) {
|
size_t LwIPSocketImpl::getpeername_to(std::span<char, SOCKADDR_STR_LEN> buf) {
|
||||||
|
|||||||
@@ -2,9 +2,6 @@
|
|||||||
#if defined(USE_SOCKET_IMPL_LWIP_TCP) || defined(USE_SOCKET_IMPL_LWIP_SOCKETS) || defined(USE_SOCKET_IMPL_BSD_SOCKETS)
|
#if defined(USE_SOCKET_IMPL_LWIP_TCP) || defined(USE_SOCKET_IMPL_LWIP_SOCKETS) || defined(USE_SOCKET_IMPL_BSD_SOCKETS)
|
||||||
#include <cerrno>
|
#include <cerrno>
|
||||||
#include <cstring>
|
#include <cstring>
|
||||||
#ifdef USE_SOCKET_IMPL_BSD_SOCKETS
|
|
||||||
#include <sys/select.h>
|
|
||||||
#endif
|
|
||||||
#include <string>
|
#include <string>
|
||||||
#include "esphome/core/log.h"
|
#include "esphome/core/log.h"
|
||||||
#include "esphome/core/application.h"
|
#include "esphome/core/application.h"
|
||||||
@@ -168,10 +165,7 @@ socklen_t set_sockaddr(struct sockaddr *addr, socklen_t addrlen, const char *ip_
|
|||||||
#else
|
#else
|
||||||
// Use LWIP-specific functions
|
// Use LWIP-specific functions
|
||||||
ip6_addr_t ip6;
|
ip6_addr_t ip6;
|
||||||
if (inet6_aton(ip_address, &ip6) == 0) {
|
inet6_aton(ip_address, &ip6);
|
||||||
errno = EINVAL;
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
memcpy(server->sin6_addr.un.u32_addr, ip6.addr, sizeof(ip6.addr));
|
memcpy(server->sin6_addr.un.u32_addr, ip6.addr, sizeof(ip6.addr));
|
||||||
#endif
|
#endif
|
||||||
return sizeof(sockaddr_in6);
|
return sizeof(sockaddr_in6);
|
||||||
@@ -191,58 +185,12 @@ socklen_t set_sockaddr(struct sockaddr *addr, socklen_t addrlen, const char *ip_
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
// Unlike inet_addr(), inet_aton() can signal failure while still
|
server->sin_addr.s_addr = inet_addr(ip_address);
|
||||||
// accepting the broadcast address 255.255.255.255
|
|
||||||
if (inet_aton(ip_address, &server->sin_addr) == 0) {
|
|
||||||
errno = EINVAL;
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
#endif
|
#endif
|
||||||
server->sin_port = htons(port);
|
server->sin_port = htons(port);
|
||||||
return sizeof(sockaddr_in);
|
return sizeof(sockaddr_in);
|
||||||
}
|
}
|
||||||
|
|
||||||
#if defined(USE_SOCKET_IMPL_BSD_SOCKETS) || defined(USE_SOCKET_IMPL_LWIP_SOCKETS)
|
|
||||||
ConnectPollResult poll_connect(Socket &sock, int &err_out) {
|
|
||||||
int fd = sock.get_fd();
|
|
||||||
if (fd < 0 || fd >= FD_SETSIZE) {
|
|
||||||
// FD_SET on either is undefined behavior
|
|
||||||
err_out = EBADF;
|
|
||||||
return ConnectPollResult::CONNECT_POLL_RESULT_ERROR;
|
|
||||||
}
|
|
||||||
// Connect completion is a write event; the main loop only selects on reads
|
|
||||||
fd_set writefds;
|
|
||||||
FD_ZERO(&writefds);
|
|
||||||
FD_SET(fd, &writefds);
|
|
||||||
struct timeval tv = {0, 0};
|
|
||||||
#ifdef USE_SOCKET_IMPL_LWIP_SOCKETS
|
|
||||||
// LWIP_COMPAT_SOCKETS may be off (LibreTiny), so use the lwip symbol directly
|
|
||||||
int ret = lwip_select(fd + 1, nullptr, &writefds, nullptr, &tv);
|
|
||||||
#else
|
|
||||||
// Global-scope select: the entity namespace esphome::select shadows it here
|
|
||||||
int ret = ::select(fd + 1, nullptr, &writefds, nullptr, &tv);
|
|
||||||
#endif
|
|
||||||
if (ret < 0) {
|
|
||||||
err_out = errno;
|
|
||||||
return ConnectPollResult::CONNECT_POLL_RESULT_ERROR;
|
|
||||||
}
|
|
||||||
if (ret == 0) {
|
|
||||||
return ConnectPollResult::CONNECT_POLL_RESULT_PENDING;
|
|
||||||
}
|
|
||||||
int error = 0;
|
|
||||||
socklen_t len = sizeof(error);
|
|
||||||
if (sock.getsockopt(SOL_SOCKET, SO_ERROR, &error, &len) != 0) {
|
|
||||||
err_out = errno;
|
|
||||||
return ConnectPollResult::CONNECT_POLL_RESULT_ERROR;
|
|
||||||
}
|
|
||||||
if (error != 0) {
|
|
||||||
err_out = error;
|
|
||||||
return ConnectPollResult::CONNECT_POLL_RESULT_ERROR;
|
|
||||||
}
|
|
||||||
return ConnectPollResult::CONNECT_POLL_RESULT_CONNECTED;
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
socklen_t set_sockaddr_any(struct sockaddr *addr, socklen_t addrlen, uint16_t port) {
|
socklen_t set_sockaddr_any(struct sockaddr *addr, socklen_t addrlen, uint16_t port) {
|
||||||
#if USE_NETWORK_IPV6
|
#if USE_NETWORK_IPV6
|
||||||
if (addrlen < sizeof(sockaddr_in6)) {
|
if (addrlen < sizeof(sockaddr_in6)) {
|
||||||
|
|||||||
@@ -145,14 +145,6 @@ inline socklen_t set_sockaddr(struct sockaddr *addr, socklen_t addrlen, const st
|
|||||||
/// Set a sockaddr to the any address and specified port for the IP version used by socket_ip().
|
/// Set a sockaddr to the any address and specified port for the IP version used by socket_ip().
|
||||||
socklen_t set_sockaddr_any(struct sockaddr *addr, socklen_t addrlen, uint16_t port);
|
socklen_t set_sockaddr_any(struct sockaddr *addr, socklen_t addrlen, uint16_t port);
|
||||||
|
|
||||||
/// Poll a connect() that returned EINPROGRESS. On error, err_out is SO_ERROR (or
|
|
||||||
/// errno) on fd implementations and the failure the callbacks recorded on raw lwip.
|
|
||||||
#ifdef USE_SOCKET_IMPL_LWIP_TCP
|
|
||||||
inline ConnectPollResult poll_connect(Socket &sock, int &err_out) { return sock.poll_connect(err_out); }
|
|
||||||
#else
|
|
||||||
ConnectPollResult poll_connect(Socket &sock, int &err_out);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/// Format sockaddr into caller-provided buffer, returns length written (excluding null)
|
/// Format sockaddr into caller-provided buffer, returns length written (excluding null)
|
||||||
size_t format_sockaddr_to(const struct sockaddr *addr_ptr, socklen_t len, std::span<char, SOCKADDR_STR_LEN> buf);
|
size_t format_sockaddr_to(const struct sockaddr *addr_ptr, socklen_t len, std::span<char, SOCKADDR_STR_LEN> buf);
|
||||||
|
|
||||||
|
|||||||
@@ -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
|
||||||
|
|||||||
@@ -13,12 +13,7 @@ void UDPComponent::setup() {
|
|||||||
#if defined(USE_SOCKET_IMPL_BSD_SOCKETS) || defined(USE_SOCKET_IMPL_LWIP_SOCKETS)
|
#if defined(USE_SOCKET_IMPL_BSD_SOCKETS) || defined(USE_SOCKET_IMPL_LWIP_SOCKETS)
|
||||||
for (const auto &address : this->addresses_) {
|
for (const auto &address : this->addresses_) {
|
||||||
struct sockaddr saddr {};
|
struct sockaddr saddr {};
|
||||||
if (socket::set_sockaddr(&saddr, sizeof(saddr), address, this->broadcast_port_) == 0) {
|
socket::set_sockaddr(&saddr, sizeof(saddr), address, this->broadcast_port_);
|
||||||
ESP_LOGW(TAG, "Invalid address %s", address);
|
|
||||||
// A dropped address silently receives nothing; surface the misconfiguration
|
|
||||||
this->status_set_warning(LOG_STR("invalid address"));
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
this->sockaddrs_.push_back(saddr);
|
this->sockaddrs_.push_back(saddr);
|
||||||
}
|
}
|
||||||
// set up broadcast socket
|
// set up broadcast socket
|
||||||
@@ -99,11 +94,7 @@ void UDPComponent::setup() {
|
|||||||
// 8266 and RP2040 `Duino
|
// 8266 and RP2040 `Duino
|
||||||
for (const auto &address : this->addresses_) {
|
for (const auto &address : this->addresses_) {
|
||||||
auto ipaddr = IPAddress();
|
auto ipaddr = IPAddress();
|
||||||
if (!ipaddr.fromString(address)) {
|
ipaddr.fromString(address);
|
||||||
ESP_LOGW(TAG, "Invalid address %s", address);
|
|
||||||
this->status_set_warning(LOG_STR("invalid address"));
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
this->ipaddrs_.push_back(ipaddr);
|
this->ipaddrs_.push_back(ipaddr);
|
||||||
}
|
}
|
||||||
if (this->should_listen_)
|
if (this->should_listen_)
|
||||||
|
|||||||
@@ -34,10 +34,6 @@ void WakeOnLanButton::press_action() {
|
|||||||
struct sockaddr_storage saddr {};
|
struct sockaddr_storage saddr {};
|
||||||
auto addr_len =
|
auto addr_len =
|
||||||
socket::set_sockaddr(reinterpret_cast<sockaddr *>(&saddr), sizeof(saddr), "255.255.255.255", this->port_);
|
socket::set_sockaddr(reinterpret_cast<sockaddr *>(&saddr), sizeof(saddr), "255.255.255.255", this->port_);
|
||||||
if (addr_len == 0) {
|
|
||||||
ESP_LOGW(TAG, "Invalid broadcast address");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
uint8_t buffer[6 + sizeof this->macaddr_ * 16];
|
uint8_t buffer[6 + sizeof this->macaddr_ * 16];
|
||||||
memcpy(buffer, PREFIX, sizeof(PREFIX));
|
memcpy(buffer, PREFIX, sizeof(PREFIX));
|
||||||
for (size_t i = 0; i != 16; i++) {
|
for (size_t i = 0; i != 16; i++) {
|
||||||
|
|||||||
@@ -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
|
||||||
|
|||||||
@@ -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
@@ -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
@@ -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
@@ -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))
|
||||||
@@ -1,4 +0,0 @@
|
|||||||
substitutions:
|
|
||||||
network_enable_ipv6: "true"
|
|
||||||
|
|
||||||
<<: !include common.yaml
|
|
||||||
@@ -1,17 +0,0 @@
|
|||||||
esphome:
|
|
||||||
name: socket-set-sockaddr
|
|
||||||
on_boot:
|
|
||||||
then:
|
|
||||||
- lambda: |-
|
|
||||||
// 0 for text that is not an address, the length otherwise, broadcast included
|
|
||||||
struct sockaddr_storage addr;
|
|
||||||
auto *sa = reinterpret_cast<struct sockaddr *>(&addr);
|
|
||||||
ESP_LOGI("test", "SET_SOCKADDR invalid=%u valid=%u broadcast=%u",
|
|
||||||
(unsigned) socket::set_sockaddr(sa, sizeof(addr), "not an address", 1234),
|
|
||||||
(unsigned) socket::set_sockaddr(sa, sizeof(addr), "192.0.2.1", 1234),
|
|
||||||
(unsigned) socket::set_sockaddr(sa, sizeof(addr), "255.255.255.255", 1234));
|
|
||||||
|
|
||||||
host:
|
|
||||||
api:
|
|
||||||
logger:
|
|
||||||
level: INFO
|
|
||||||
@@ -1,143 +1,154 @@
|
|||||||
{
|
{
|
||||||
"tests/integration/test_action_concurrent_reentry.py": 57.91,
|
"tests/integration/test_action_concurrent_reentry.py": 30.48,
|
||||||
"tests/integration/test_addressable_light_transition.py": 21.25,
|
"tests/integration/test_addressable_light_transition.py": 42.1,
|
||||||
"tests/integration/test_alarm_control_panel_state_transitions.py": 70.71,
|
"tests/integration/test_alarm_control_panel_state_transitions.py": 35.76,
|
||||||
"tests/integration/test_api_action_metadata.py": 66.6,
|
"tests/integration/test_api_action_metadata.py": 22.35,
|
||||||
"tests/integration/test_api_action_responses.py": 36.1,
|
"tests/integration/test_api_action_responses.py": 30.31,
|
||||||
"tests/integration/test_api_action_timeout.py": 68.86,
|
"tests/integration/test_api_action_timeout.py": 34.73,
|
||||||
"tests/integration/test_api_conditional_memory.py": 15.48,
|
"tests/integration/test_api_conditional_memory.py": 18.35,
|
||||||
"tests/integration/test_api_custom_services.py": 18.77,
|
"tests/integration/test_api_custom_services.py": 15.99,
|
||||||
"tests/integration/test_api_get_time_response_timezone.py": 21.08,
|
"tests/integration/test_api_get_time_response_timezone.py": 24.21,
|
||||||
"tests/integration/test_api_homeassistant.py": 65.59,
|
"tests/integration/test_api_homeassistant.py": 33.77,
|
||||||
"tests/integration/test_api_homeassistant_action_no_subscriber.py": 18.44,
|
"tests/integration/test_api_homeassistant_action_no_subscriber.py": 20.8,
|
||||||
"tests/integration/test_api_homeassistant_binary_sensor_initial_state.py": 15.05,
|
"tests/integration/test_api_homeassistant_binary_sensor_initial_state.py": 23.55,
|
||||||
"tests/integration/test_api_list_entities_backpressure.py": 13.88,
|
"tests/integration/test_api_list_entities_backpressure.py": 23.04,
|
||||||
"tests/integration/test_api_message_size_batching.py": 29.98,
|
"tests/integration/test_api_message_size_batching.py": 27.31,
|
||||||
"tests/integration/test_api_reboot_timeout.py": 16.05,
|
"tests/integration/test_api_reboot_timeout.py": 29.32,
|
||||||
"tests/integration/test_api_string_lambda.py": 15.31,
|
"tests/integration/test_api_string_lambda.py": 14.9,
|
||||||
"tests/integration/test_api_vv_logging.py": 19.28,
|
"tests/integration/test_api_vv_logging.py": 26.25,
|
||||||
"tests/integration/test_api_zero_psk_provisioning.py": 31.5,
|
"tests/integration/test_api_zero_psk_provisioning.py": 38.19,
|
||||||
"tests/integration/test_areas_and_devices.py": 24.95,
|
"tests/integration/test_areas_and_devices.py": 27.52,
|
||||||
"tests/integration/test_automation_wait_actions.py": 20.92,
|
"tests/integration/test_automation_wait_actions.py": 24.25,
|
||||||
"tests/integration/test_automations.py": 35.19,
|
"tests/integration/test_automations.py": 36.02,
|
||||||
"tests/integration/test_batch_delay_zero_rapid_transitions.py": 17.99,
|
"tests/integration/test_batch_delay_zero_rapid_transitions.py": 18.46,
|
||||||
"tests/integration/test_binary_sensor_autorepeat_filter.py": 20.39,
|
"tests/integration/test_binary_sensor_autorepeat_filter.py": 17.47,
|
||||||
"tests/integration/test_binary_sensor_invalidate_state.py": 18.41,
|
"tests/integration/test_binary_sensor_invalidate_state.py": 14.79,
|
||||||
"tests/integration/test_blocking_warning_log_time_not_charged_to_next_operation.py": 24.69,
|
"tests/integration/test_blocking_warning_log_time_not_charged_to_next_operation.py": 21.52,
|
||||||
"tests/integration/test_build_info.py": 18.7,
|
"tests/integration/test_build_info.py": 21.42,
|
||||||
"tests/integration/test_camera_mock.py": 16.23,
|
"tests/integration/test_camera_mock.py": 17.02,
|
||||||
"tests/integration/test_climate_control_action.py": 21.14,
|
"tests/integration/test_climate_control_action.py": 26.56,
|
||||||
"tests/integration/test_climate_custom_modes.py": 20.74,
|
"tests/integration/test_climate_custom_modes.py": 18.82,
|
||||||
"tests/integration/test_continuation_actions.py": 16.81,
|
"tests/integration/test_continuation_actions.py": 20.39,
|
||||||
"tests/integration/test_cover_control_action.py": 20.34,
|
"tests/integration/test_cover_control_action.py": 19.91,
|
||||||
"tests/integration/test_crc8_helper.py": 9.36,
|
"tests/integration/test_crc8_helper.py": 16.73,
|
||||||
"tests/integration/test_device_id_in_state.py": 44.67,
|
"tests/integration/test_device_id_in_state.py": 58.41,
|
||||||
"tests/integration/test_duplicate_entities.py": 23.58,
|
"tests/integration/test_duplicate_entities.py": 30.76,
|
||||||
"tests/integration/test_entity_icon.py": 34.35,
|
"tests/integration/test_entity_icon.py": 25.34,
|
||||||
"tests/integration/test_fan_turn_on_action.py": 24.23,
|
"tests/integration/test_fan_turn_on_action.py": 23.64,
|
||||||
"tests/integration/test_fnv1_hash_object_id.py": 16.21,
|
"tests/integration/test_fnv1_hash_object_id.py": 25.44,
|
||||||
"tests/integration/test_fnv1a_hash.py": 13.38,
|
"tests/integration/test_fnv1a_hash.py": 20.85,
|
||||||
"tests/integration/test_gpio_expander_cache.py": 13.06,
|
"tests/integration/test_gpio_expander_cache.py": 14.42,
|
||||||
"tests/integration/test_host_logger_thread_safety.py": 23.66,
|
"tests/integration/test_host_logger_thread_safety.py": 21.31,
|
||||||
"tests/integration/test_host_mode_basic.py": 8.01,
|
"tests/integration/test_host_mode_basic.py": 2.65,
|
||||||
"tests/integration/test_host_mode_batch_delay.py": 21.0,
|
"tests/integration/test_host_mode_batch_delay.py": 22.21,
|
||||||
"tests/integration/test_host_mode_climate_basic_state.py": 22.14,
|
"tests/integration/test_host_mode_climate_basic_state.py": 27.12,
|
||||||
"tests/integration/test_host_mode_climate_control.py": 19.39,
|
"tests/integration/test_host_mode_climate_control.py": 21.57,
|
||||||
"tests/integration/test_host_mode_empty_string_options.py": 21.76,
|
"tests/integration/test_host_mode_empty_string_options.py": 27.17,
|
||||||
"tests/integration/test_host_mode_entity_fields.py": 29.61,
|
"tests/integration/test_host_mode_entity_fields.py": 30.1,
|
||||||
"tests/integration/test_host_mode_fan_preset.py": 20.01,
|
"tests/integration/test_host_mode_fan_preset.py": 17.55,
|
||||||
"tests/integration/test_host_mode_many_entities.py": 39.08,
|
"tests/integration/test_host_mode_many_entities.py": 38.98,
|
||||||
"tests/integration/test_host_mode_many_entities_multiple_connections.py": 23.92,
|
"tests/integration/test_host_mode_many_entities_multiple_connections.py": 23.82,
|
||||||
"tests/integration/test_host_mode_noise_encryption.py": 42.42,
|
"tests/integration/test_host_mode_noise_encryption.py": 39.84,
|
||||||
"tests/integration/test_host_mode_reconnect.py": 3.41,
|
"tests/integration/test_host_mode_reconnect.py": 13.1,
|
||||||
"tests/integration/test_host_mode_sensor.py": 22.96,
|
"tests/integration/test_host_mode_sensor.py": 22.17,
|
||||||
"tests/integration/test_host_ota.py": 29.5,
|
"tests/integration/test_host_ota.py": 92.05,
|
||||||
"tests/integration/test_host_preferences.py": 16.06,
|
"tests/integration/test_host_preferences.py": 20.29,
|
||||||
"tests/integration/test_host_preferences_suspend_resume.py": 18.71,
|
"tests/integration/test_host_preferences_suspend_resume.py": 15.02,
|
||||||
"tests/integration/test_improv_serial_uart.py": 20.22,
|
"tests/integration/test_improv_serial_uart.py": 30.15,
|
||||||
"tests/integration/test_large_message_batching.py": 26.56,
|
"tests/integration/test_large_message_batching.py": 25.84,
|
||||||
"tests/integration/test_legacy_area.py": 22.72,
|
"tests/integration/test_legacy_area.py": 21.24,
|
||||||
"tests/integration/test_legacy_climate_compat.py": 14.13,
|
"tests/integration/test_legacy_climate_compat.py": 17.34,
|
||||||
"tests/integration/test_legacy_fan_compat.py": 14.33,
|
"tests/integration/test_legacy_fan_compat.py": 22.6,
|
||||||
"tests/integration/test_light_automations.py": 18.81,
|
"tests/integration/test_light_automations.py": 29.13,
|
||||||
"tests/integration/test_light_binary_effect_off_phase.py": 8.38,
|
"tests/integration/test_light_binary_effect_off_phase.py": 33.99,
|
||||||
"tests/integration/test_light_calls.py": 21.88,
|
"tests/integration/test_light_calls.py": 26.81,
|
||||||
"tests/integration/test_light_constant_brightness.py": 59.45,
|
"tests/integration/test_light_constant_brightness.py": 25.0,
|
||||||
"tests/integration/test_light_control_action.py": 31.91,
|
"tests/integration/test_light_control_action.py": 25.57,
|
||||||
"tests/integration/test_light_dim_relative_action.py": 14.43,
|
"tests/integration/test_light_dim_relative_action.py": 21.4,
|
||||||
"tests/integration/test_light_effect_zero_brightness.py": 25.05,
|
"tests/integration/test_light_effect_zero_brightness.py": 19.65,
|
||||||
"tests/integration/test_light_initial_state.py": 18.97,
|
"tests/integration/test_light_initial_state.py": 17.58,
|
||||||
"tests/integration/test_light_toggle_action.py": 17.44,
|
"tests/integration/test_light_toggle_action.py": 28.28,
|
||||||
"tests/integration/test_lock_automations.py": 18.9,
|
"tests/integration/test_lock_automations.py": 23.3,
|
||||||
"tests/integration/test_logger_buffered_recursion_guard.py": 18.2,
|
"tests/integration/test_logger_buffered_recursion_guard.py": 22.96,
|
||||||
"tests/integration/test_loop_disable_enable.py": 63.35,
|
"tests/integration/test_loop_disable_enable.py": 16.18,
|
||||||
"tests/integration/test_loop_interval_decoupling.py": 17.7,
|
"tests/integration/test_loop_interval_decoupling.py": 25.19,
|
||||||
"tests/integration/test_loop_interval_default_not_pulled_forward.py": 21.56,
|
"tests/integration/test_loop_interval_default_not_pulled_forward.py": 20.59,
|
||||||
"tests/integration/test_micros_to_millis.py": 15.89,
|
"tests/integration/test_lvgl_headless_render.py": 87.78,
|
||||||
"tests/integration/test_multi_click_trigger.py": 17.23,
|
"tests/integration/test_micros_to_millis.py": 18.73,
|
||||||
"tests/integration/test_multi_device_preferences.py": 19.4,
|
"tests/integration/test_multi_click_trigger.py": 24.2,
|
||||||
"tests/integration/test_noise_encryption_key_protection.py": 72.59,
|
"tests/integration/test_multi_device_preferences.py": 20.52,
|
||||||
"tests/integration/test_object_id_api_verification.py": 19.22,
|
"tests/integration/test_noise_encryption_key_protection.py": 19.1,
|
||||||
"tests/integration/test_object_id_friendly_name_no_mac_suffix.py": 16.77,
|
"tests/integration/test_object_id_api_verification.py": 26.24,
|
||||||
"tests/integration/test_object_id_no_friendly_name.py": 45.8,
|
"tests/integration/test_object_id_friendly_name_no_mac_suffix.py": 14.88,
|
||||||
"tests/integration/test_online_image_auto_detects_image_bmp_mime.py": 86.73,
|
"tests/integration/test_object_id_no_friendly_name.py": 61.27,
|
||||||
"tests/integration/test_online_image_auto_detects_redirected_image_bmp_mime.py": 40.4,
|
"tests/integration/test_online_image_auto_detects_image_bmp_mime.py": 82.32,
|
||||||
"tests/integration/test_online_image_bmp.py": 37.24,
|
"tests/integration/test_online_image_auto_detects_redirected_image_bmp_mime.py": 46.03,
|
||||||
"tests/integration/test_oversized_payloads.py": 55.75,
|
"tests/integration/test_online_image_bmp.py": 34.21,
|
||||||
"tests/integration/test_preference_key_stability.py": 25.49,
|
"tests/integration/test_oversized_payloads.py": 62.75,
|
||||||
"tests/integration/test_runtime_stats.py": 29.81,
|
"tests/integration/test_preference_key_stability.py": 26.8,
|
||||||
"tests/integration/test_safe_mode_loop_runs.py": 6.26,
|
"tests/integration/test_runtime_stats.py": 28.26,
|
||||||
"tests/integration/test_scheduler_blocking_warning.py": 37.98,
|
"tests/integration/test_safe_mode_loop_runs.py": 18.14,
|
||||||
"tests/integration/test_scheduler_bulk_cleanup.py": 18.67,
|
"tests/integration/test_scheduler_blocking_warning.py": 28.7,
|
||||||
"tests/integration/test_scheduler_defer_cancel.py": 18.46,
|
"tests/integration/test_scheduler_bulk_cleanup.py": 20.73,
|
||||||
"tests/integration/test_scheduler_defer_cancel_regular.py": 16.34,
|
"tests/integration/test_scheduler_defer_cancel.py": 22.99,
|
||||||
"tests/integration/test_scheduler_defer_fifo_simple.py": 18.26,
|
"tests/integration/test_scheduler_defer_cancel_regular.py": 21.97,
|
||||||
"tests/integration/test_scheduler_defer_stress.py": 17.74,
|
"tests/integration/test_scheduler_defer_fifo_simple.py": 24.15,
|
||||||
"tests/integration/test_scheduler_heap_stress.py": 3.89,
|
"tests/integration/test_scheduler_defer_stress.py": 23.11,
|
||||||
"tests/integration/test_scheduler_internal_id_no_collision.py": 20.01,
|
"tests/integration/test_scheduler_heap_stress.py": 20.2,
|
||||||
"tests/integration/test_scheduler_interval_reschedule.py": 16.29,
|
"tests/integration/test_scheduler_internal_id_no_collision.py": 23.75,
|
||||||
"tests/integration/test_scheduler_interval_zero_coerced.py": 16.09,
|
"tests/integration/test_scheduler_interval_reschedule.py": 15.32,
|
||||||
"tests/integration/test_scheduler_null_name.py": 14.69,
|
"tests/integration/test_scheduler_interval_zero_coerced.py": 20.1,
|
||||||
"tests/integration/test_scheduler_numeric_id_test.py": 17.08,
|
"tests/integration/test_scheduler_null_name.py": 17.43,
|
||||||
"tests/integration/test_scheduler_pool.py": 19.88,
|
"tests/integration/test_scheduler_numeric_id_test.py": 25.51,
|
||||||
"tests/integration/test_scheduler_rapid_cancellation.py": 4.42,
|
"tests/integration/test_scheduler_pool.py": 24.22,
|
||||||
"tests/integration/test_scheduler_recursive_timeout.py": 4.3,
|
"tests/integration/test_scheduler_rapid_cancellation.py": 24.01,
|
||||||
"tests/integration/test_scheduler_removed_item_race.py": 15.49,
|
"tests/integration/test_scheduler_recursive_timeout.py": 22.94,
|
||||||
"tests/integration/test_scheduler_self_keyed.py": 25.77,
|
"tests/integration/test_scheduler_removed_item_race.py": 23.07,
|
||||||
"tests/integration/test_scheduler_simultaneous_callbacks.py": 14.84,
|
"tests/integration/test_scheduler_self_keyed.py": 18.43,
|
||||||
"tests/integration/test_scheduler_string_test.py": 15.42,
|
"tests/integration/test_scheduler_simultaneous_callbacks.py": 21.99,
|
||||||
"tests/integration/test_script_array_params.py": 12.73,
|
"tests/integration/test_scheduler_string_test.py": 17.27,
|
||||||
"tests/integration/test_script_delay_params.py": 12.69,
|
"tests/integration/test_script_array_params.py": 4.59,
|
||||||
"tests/integration/test_script_queued.py": 20.38,
|
"tests/integration/test_script_delay_params.py": 22.46,
|
||||||
"tests/integration/test_script_queued_idle_loop.py": 25.06,
|
"tests/integration/test_script_queued.py": 25.24,
|
||||||
"tests/integration/test_script_wait_on_boot.py": 15.67,
|
"tests/integration/test_script_queued_idle_loop.py": 5.04,
|
||||||
"tests/integration/test_select_stringref_trigger.py": 19.48,
|
"tests/integration/test_script_wait_on_boot.py": 21.77,
|
||||||
"tests/integration/test_sensor_filters_delta.py": 27.62,
|
"tests/integration/test_sdl_headless_screenshot.py": 19.23,
|
||||||
"tests/integration/test_sensor_filters_ring_buffer.py": 20.27,
|
"tests/integration/test_select_stringref_trigger.py": 19.31,
|
||||||
"tests/integration/test_sensor_filters_sliding_window.py": 56.28,
|
"tests/integration/test_sensor_filters_delta.py": 25.92,
|
||||||
"tests/integration/test_sensor_filters_value_list.py": 20.6,
|
"tests/integration/test_sensor_filters_ring_buffer.py": 22.39,
|
||||||
"tests/integration/test_sensor_timeout_filter.py": 22.21,
|
"tests/integration/test_sensor_filters_sliding_window.py": 57.93,
|
||||||
"tests/integration/test_socket_wake_gate_tcp.py": 16.37,
|
"tests/integration/test_sensor_filters_value_list.py": 20.32,
|
||||||
"tests/integration/test_status_flags.py": 29.68,
|
"tests/integration/test_sensor_timeout_filter.py": 25.35,
|
||||||
"tests/integration/test_strftime_to.py": 17.42,
|
"tests/integration/test_snapshot_display.py": 19.7,
|
||||||
"tests/integration/test_syslog.py": 18.39,
|
"tests/integration/test_socket_wake_gate_tcp.py": 14.5,
|
||||||
"tests/integration/test_template_alarm_control_panel_many_sensors.py": 25.61,
|
"tests/integration/test_status_flags.py": 33.83,
|
||||||
"tests/integration/test_template_text_save.py": 19.16,
|
"tests/integration/test_strftime_to.py": 17.64,
|
||||||
"tests/integration/test_text_command.py": 16.43,
|
"tests/integration/test_syslog.py": 24.49,
|
||||||
"tests/integration/test_text_sensor_raw_state.py": 17.19,
|
"tests/integration/test_template_alarm_control_panel_many_sensors.py": 24.81,
|
||||||
"tests/integration/test_uart_mock_ld2410.py": 37.0,
|
"tests/integration/test_template_climate_basic.py": 15.28,
|
||||||
"tests/integration/test_uart_mock_ld2412.py": 40.82,
|
"tests/integration/test_template_climate_custom_modes.py": 25.07,
|
||||||
"tests/integration/test_uart_mock_ld2420.py": 32.7,
|
"tests/integration/test_template_climate_nonoptimistic.py": 24.25,
|
||||||
"tests/integration/test_uart_mock_ld2450.py": 32.84,
|
"tests/integration/test_template_climate_on_control_ordering.py": 24.09,
|
||||||
"tests/integration/test_uart_mock_modbus.py": 548.87,
|
"tests/integration/test_template_climate_publish_all_fields.py": 17.78,
|
||||||
"tests/integration/test_udp.py": 16.67,
|
"tests/integration/test_template_climate_sensor_push.py": 17.42,
|
||||||
"tests/integration/test_use_address_runtime.py": 27.26,
|
"tests/integration/test_template_climate_set_actions.py": 23.63,
|
||||||
"tests/integration/test_valve_control_action.py": 24.58,
|
"tests/integration/test_template_climate_two_point_temperature.py": 25.19,
|
||||||
"tests/integration/test_varint_five_byte_device_id.py": 22.5,
|
"tests/integration/test_template_text_save.py": 17.88,
|
||||||
"tests/integration/test_wait_until_mid_loop_timing.py": 22.05,
|
"tests/integration/test_text_command.py": 22.71,
|
||||||
"tests/integration/test_wait_until_on_boot.py": 10.37,
|
"tests/integration/test_text_sensor_raw_state.py": 25.17,
|
||||||
"tests/integration/test_wait_until_ordering.py": 18.23,
|
"tests/integration/test_uart_mock_ld2410.py": 58.15,
|
||||||
"tests/integration/test_wait_until_reentrant_restart.py": 19.35,
|
"tests/integration/test_uart_mock_ld2412.py": 61.14,
|
||||||
"tests/integration/test_wake_loop_forces_phase_b.py": 17.83,
|
"tests/integration/test_uart_mock_ld2420.py": 33.87,
|
||||||
"tests/integration/test_water_heater_template.py": 25.7
|
"tests/integration/test_uart_mock_ld2450.py": 26.06,
|
||||||
|
"tests/integration/test_uart_mock_modbus.py": 391.79,
|
||||||
|
"tests/integration/test_udp.py": 7.38,
|
||||||
|
"tests/integration/test_use_address_runtime.py": 24.09,
|
||||||
|
"tests/integration/test_valve_control_action.py": 23.22,
|
||||||
|
"tests/integration/test_varint_five_byte_device_id.py": 17.93,
|
||||||
|
"tests/integration/test_wait_until_mid_loop_timing.py": 22.26,
|
||||||
|
"tests/integration/test_wait_until_on_boot.py": 17.46,
|
||||||
|
"tests/integration/test_wait_until_ordering.py": 11.89,
|
||||||
|
"tests/integration/test_wait_until_reentrant_restart.py": 22.88,
|
||||||
|
"tests/integration/test_wake_loop_forces_phase_b.py": 16.6,
|
||||||
|
"tests/integration/test_water_heater_template.py": 19.66
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,40 +0,0 @@
|
|||||||
"""Integration test for the socket::set_sockaddr failure contract."""
|
|
||||||
|
|
||||||
import asyncio
|
|
||||||
import re
|
|
||||||
|
|
||||||
import pytest
|
|
||||||
|
|
||||||
from .types import APIClientConnectedFactory, RunCompiledFunction
|
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.asyncio
|
|
||||||
async def test_socket_set_sockaddr(
|
|
||||||
yaml_config: str,
|
|
||||||
run_compiled: RunCompiledFunction,
|
|
||||||
api_client_connected: APIClientConnectedFactory,
|
|
||||||
) -> None:
|
|
||||||
"""set_sockaddr reports an invalid address with 0 and accepts broadcast."""
|
|
||||||
loop = asyncio.get_running_loop()
|
|
||||||
result: asyncio.Future[tuple[int, int, int]] = loop.create_future()
|
|
||||||
|
|
||||||
def on_log_line(line: str) -> None:
|
|
||||||
match = re.search(
|
|
||||||
r"SET_SOCKADDR invalid=(\d+) valid=(\d+) broadcast=(\d+)", line
|
|
||||||
)
|
|
||||||
if match and not result.done():
|
|
||||||
result.set_result(tuple(int(g) for g in match.groups()))
|
|
||||||
|
|
||||||
async with (
|
|
||||||
run_compiled(yaml_config, line_callback=on_log_line),
|
|
||||||
api_client_connected() as client,
|
|
||||||
):
|
|
||||||
assert (await client.device_info()).name == "socket-set-sockaddr"
|
|
||||||
try:
|
|
||||||
invalid, valid, broadcast = await asyncio.wait_for(result, timeout=10.0)
|
|
||||||
except TimeoutError:
|
|
||||||
pytest.fail("SET_SOCKADDR marker never appeared")
|
|
||||||
|
|
||||||
assert invalid == 0
|
|
||||||
assert valid > 0
|
|
||||||
assert broadcast == valid
|
|
||||||
@@ -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"]
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -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")
|
||||||
|
|||||||
@@ -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"]
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user