mirror of
https://github.com/esphome/esphome.git
synced 2025-11-02 08:01:50 +00:00
Compare commits
17 Commits
2024.5.0b6
...
2024.5.3
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
d72ab25d46 | ||
|
|
af755380b7 | ||
|
|
04db724295 | ||
|
|
0ee4348777 | ||
|
|
fcdf36e991 | ||
|
|
5eb8efd8b3 | ||
|
|
cd0f557940 | ||
|
|
efde677ca9 | ||
|
|
2eebee1de7 | ||
|
|
f235dcc096 | ||
|
|
d2d3db4b8c | ||
|
|
ec6d86c8f5 | ||
|
|
7452879fb1 | ||
|
|
4fc2f2284a | ||
|
|
840f69ffe6 | ||
|
|
caa8c820de | ||
|
|
0d3adc8f0c |
@@ -346,7 +346,7 @@ def upload_program(config, args, host):
|
||||
not is_ip_address(CORE.address) # pylint: disable=too-many-boolean-expressions
|
||||
and (get_port_type(host) == "MQTT" or config[CONF_MDNS][CONF_DISABLED])
|
||||
and CONF_MQTT in config
|
||||
and (not args.device or args.device == "MQTT")
|
||||
and (not args.device or args.device in ("MQTT", "OTA"))
|
||||
):
|
||||
from esphome import mqtt
|
||||
|
||||
|
||||
@@ -63,7 +63,13 @@ def validate_tolerance(value):
|
||||
if "%" in str(value):
|
||||
type_ = TYPE_PERCENTAGE
|
||||
else:
|
||||
type_ = TYPE_TIME
|
||||
try:
|
||||
cv.positive_time_period_microseconds(value)
|
||||
type_ = TYPE_TIME
|
||||
except cv.Invalid as exc:
|
||||
raise cv.Invalid(
|
||||
"Tolerance must be a percentage or time. Configurations made before 2024.5.0 treated the value as a percentage."
|
||||
) from exc
|
||||
|
||||
return TOLERANCE_SCHEMA(
|
||||
{
|
||||
|
||||
@@ -14,6 +14,9 @@ from esphome.const import (
|
||||
CONF_STATE,
|
||||
CONF_STOP,
|
||||
CONF_TRIGGER_ID,
|
||||
DEVICE_CLASS_EMPTY,
|
||||
DEVICE_CLASS_GAS,
|
||||
DEVICE_CLASS_WATER,
|
||||
)
|
||||
from esphome.core import CORE, coroutine_with_priority
|
||||
from esphome.cpp_helpers import setup_entity
|
||||
@@ -22,6 +25,12 @@ IS_PLATFORM_COMPONENT = True
|
||||
|
||||
CODEOWNERS = ["@esphome/core"]
|
||||
|
||||
DEVICE_CLASSES = [
|
||||
DEVICE_CLASS_EMPTY,
|
||||
DEVICE_CLASS_GAS,
|
||||
DEVICE_CLASS_WATER,
|
||||
]
|
||||
|
||||
valve_ns = cg.esphome_ns.namespace("valve")
|
||||
|
||||
Valve = valve_ns.class_("Valve", cg.EntityBase)
|
||||
@@ -65,6 +74,7 @@ VALVE_SCHEMA = cv.ENTITY_BASE_SCHEMA.extend(cv.MQTT_COMMAND_COMPONENT_SCHEMA).ex
|
||||
{
|
||||
cv.GenerateID(): cv.declare_id(Valve),
|
||||
cv.OnlyWith(CONF_MQTT_ID, "mqtt"): cv.declare_id(mqtt.MQTTValveComponent),
|
||||
cv.Optional(CONF_DEVICE_CLASS): cv.one_of(*DEVICE_CLASSES, lower=True),
|
||||
cv.Optional(CONF_POSITION_COMMAND_TOPIC): cv.All(
|
||||
cv.requires_component("mqtt"), cv.subscribe_topic
|
||||
),
|
||||
|
||||
@@ -71,6 +71,12 @@ void VoiceAssistant::setup() {
|
||||
ESP_LOGCONFIG(TAG, "Setting up Voice Assistant...");
|
||||
|
||||
global_voice_assistant = this;
|
||||
}
|
||||
|
||||
bool VoiceAssistant::allocate_buffers_() {
|
||||
if (this->send_buffer_ != nullptr) {
|
||||
return true; // Already allocated
|
||||
}
|
||||
|
||||
#ifdef USE_SPEAKER
|
||||
if (this->speaker_ != nullptr) {
|
||||
@@ -78,8 +84,7 @@ void VoiceAssistant::setup() {
|
||||
this->speaker_buffer_ = speaker_allocator.allocate(SPEAKER_BUFFER_SIZE);
|
||||
if (this->speaker_buffer_ == nullptr) {
|
||||
ESP_LOGW(TAG, "Could not allocate speaker buffer");
|
||||
this->mark_failed();
|
||||
return;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
@@ -88,8 +93,7 @@ void VoiceAssistant::setup() {
|
||||
this->input_buffer_ = allocator.allocate(INPUT_BUFFER_SIZE);
|
||||
if (this->input_buffer_ == nullptr) {
|
||||
ESP_LOGW(TAG, "Could not allocate input buffer");
|
||||
this->mark_failed();
|
||||
return;
|
||||
return false;
|
||||
}
|
||||
|
||||
#ifdef USE_ESP_ADF
|
||||
@@ -99,17 +103,71 @@ void VoiceAssistant::setup() {
|
||||
this->ring_buffer_ = RingBuffer::create(BUFFER_SIZE * sizeof(int16_t));
|
||||
if (this->ring_buffer_ == nullptr) {
|
||||
ESP_LOGW(TAG, "Could not allocate ring buffer");
|
||||
this->mark_failed();
|
||||
return;
|
||||
return false;
|
||||
}
|
||||
|
||||
ExternalRAMAllocator<uint8_t> send_allocator(ExternalRAMAllocator<uint8_t>::ALLOW_FAILURE);
|
||||
this->send_buffer_ = send_allocator.allocate(SEND_BUFFER_SIZE);
|
||||
if (send_buffer_ == nullptr) {
|
||||
ESP_LOGW(TAG, "Could not allocate send buffer");
|
||||
this->mark_failed();
|
||||
return;
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void VoiceAssistant::clear_buffers_() {
|
||||
if (this->send_buffer_ != nullptr) {
|
||||
memset(this->send_buffer_, 0, SEND_BUFFER_SIZE);
|
||||
}
|
||||
|
||||
if (this->input_buffer_ != nullptr) {
|
||||
memset(this->input_buffer_, 0, INPUT_BUFFER_SIZE * sizeof(int16_t));
|
||||
}
|
||||
|
||||
if (this->ring_buffer_ != nullptr) {
|
||||
this->ring_buffer_->reset();
|
||||
}
|
||||
|
||||
#ifdef USE_SPEAKER
|
||||
if (this->speaker_buffer_ != nullptr) {
|
||||
memset(this->speaker_buffer_, 0, SPEAKER_BUFFER_SIZE);
|
||||
|
||||
this->speaker_buffer_size_ = 0;
|
||||
this->speaker_buffer_index_ = 0;
|
||||
this->speaker_bytes_received_ = 0;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
void VoiceAssistant::deallocate_buffers_() {
|
||||
ExternalRAMAllocator<uint8_t> send_deallocator(ExternalRAMAllocator<uint8_t>::ALLOW_FAILURE);
|
||||
send_deallocator.deallocate(this->send_buffer_, SEND_BUFFER_SIZE);
|
||||
this->send_buffer_ = nullptr;
|
||||
|
||||
if (this->ring_buffer_ != nullptr) {
|
||||
this->ring_buffer_.reset();
|
||||
this->ring_buffer_ = nullptr;
|
||||
}
|
||||
|
||||
#ifdef USE_ESP_ADF
|
||||
if (this->vad_instance_ != nullptr) {
|
||||
vad_destroy(this->vad_instance_);
|
||||
this->vad_instance_ = nullptr;
|
||||
}
|
||||
#endif
|
||||
|
||||
ExternalRAMAllocator<int16_t> input_deallocator(ExternalRAMAllocator<int16_t>::ALLOW_FAILURE);
|
||||
input_deallocator.deallocate(this->input_buffer_, INPUT_BUFFER_SIZE);
|
||||
this->input_buffer_ = nullptr;
|
||||
|
||||
#ifdef USE_SPEAKER
|
||||
if (this->speaker_buffer_ != nullptr) {
|
||||
ExternalRAMAllocator<uint8_t> speaker_deallocator(ExternalRAMAllocator<uint8_t>::ALLOW_FAILURE);
|
||||
speaker_deallocator.deallocate(this->speaker_buffer_, SPEAKER_BUFFER_SIZE);
|
||||
this->speaker_buffer_ = nullptr;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
int VoiceAssistant::read_microphone_() {
|
||||
@@ -138,14 +196,13 @@ void VoiceAssistant::loop() {
|
||||
}
|
||||
this->continuous_ = false;
|
||||
this->signal_stop_();
|
||||
this->clear_buffers_();
|
||||
return;
|
||||
}
|
||||
switch (this->state_) {
|
||||
case State::IDLE: {
|
||||
if (this->continuous_ && this->desired_state_ == State::IDLE) {
|
||||
this->idle_trigger_->trigger();
|
||||
|
||||
this->ring_buffer_->reset();
|
||||
#ifdef USE_ESP_ADF
|
||||
if (this->use_wake_word_) {
|
||||
this->set_state_(State::START_MICROPHONE, State::WAIT_FOR_VAD);
|
||||
@@ -161,8 +218,15 @@ void VoiceAssistant::loop() {
|
||||
}
|
||||
case State::START_MICROPHONE: {
|
||||
ESP_LOGD(TAG, "Starting Microphone");
|
||||
memset(this->send_buffer_, 0, SEND_BUFFER_SIZE);
|
||||
memset(this->input_buffer_, 0, INPUT_BUFFER_SIZE * sizeof(int16_t));
|
||||
if (!this->allocate_buffers_()) {
|
||||
this->status_set_error("Failed to allocate buffers");
|
||||
return;
|
||||
}
|
||||
if (this->status_has_error()) {
|
||||
this->status_clear_error();
|
||||
}
|
||||
this->clear_buffers_();
|
||||
|
||||
this->mic_->start();
|
||||
this->high_freq_.start();
|
||||
this->set_state_(State::STARTING_MICROPHONE);
|
||||
@@ -343,10 +407,9 @@ void VoiceAssistant::loop() {
|
||||
this->speaker_->stop();
|
||||
this->cancel_timeout("speaker-timeout");
|
||||
this->cancel_timeout("playing");
|
||||
this->speaker_buffer_size_ = 0;
|
||||
this->speaker_buffer_index_ = 0;
|
||||
this->speaker_bytes_received_ = 0;
|
||||
memset(this->speaker_buffer_, 0, SPEAKER_BUFFER_SIZE);
|
||||
|
||||
this->clear_buffers_();
|
||||
|
||||
this->wait_for_stream_end_ = false;
|
||||
this->stream_ended_ = false;
|
||||
|
||||
@@ -507,7 +570,6 @@ void VoiceAssistant::request_start(bool continuous, bool silence_detection) {
|
||||
if (this->state_ == State::IDLE) {
|
||||
this->continuous_ = continuous;
|
||||
this->silence_detection_ = silence_detection;
|
||||
this->ring_buffer_->reset();
|
||||
#ifdef USE_ESP_ADF
|
||||
if (this->use_wake_word_) {
|
||||
this->set_state_(State::START_MICROPHONE, State::WAIT_FOR_VAD);
|
||||
|
||||
@@ -151,6 +151,10 @@ class VoiceAssistant : public Component {
|
||||
void set_wake_word(const std::string &wake_word) { this->wake_word_ = wake_word; }
|
||||
|
||||
protected:
|
||||
bool allocate_buffers_();
|
||||
void clear_buffers_();
|
||||
void deallocate_buffers_();
|
||||
|
||||
int read_microphone_();
|
||||
void set_state_(State state);
|
||||
void set_state_(State state, State desired_state);
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1,6 +1,6 @@
|
||||
"""Constants used by esphome."""
|
||||
|
||||
__version__ = "2024.5.0b6"
|
||||
__version__ = "2024.5.3"
|
||||
|
||||
ALLOWED_NAME_CHARS = "abcdefghijklmnopqrstuvwxyz0123456789-_"
|
||||
VALID_SUBSTITUTIONS_CHARACTERS = (
|
||||
|
||||
@@ -103,7 +103,7 @@ class DashboardEntries:
|
||||
|
||||
def all(self) -> list[DashboardEntry]:
|
||||
"""Return all entries."""
|
||||
return asyncio.run_coroutine_threadsafe(self._async_all, self._loop).result()
|
||||
return asyncio.run_coroutine_threadsafe(self._async_all(), self._loop).result()
|
||||
|
||||
def async_all(self) -> list[DashboardEntry]:
|
||||
"""Return all entries."""
|
||||
|
||||
@@ -3,6 +3,7 @@ remote_receiver:
|
||||
pin: ${pin}
|
||||
rmt_channel: ${rmt_channel}
|
||||
dump: all
|
||||
tolerance: 25%
|
||||
on_abbwelcome:
|
||||
then:
|
||||
- logger.log:
|
||||
|
||||
Reference in New Issue
Block a user