mirror of
https://github.com/esphome/esphome.git
synced 2025-11-09 19:41:49 +00:00
Compare commits
18 Commits
2023.11.0b
...
2023.11.1
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
1e061582d3 | ||
|
|
445b13dbc6 | ||
|
|
255483de63 | ||
|
|
4ac49907ca | ||
|
|
c536c976b7 | ||
|
|
0c18872888 | ||
|
|
197b6b4275 | ||
|
|
4e8bdc2155 | ||
|
|
f1e8622187 | ||
|
|
e0c7a02fbc | ||
|
|
2a20a5fc11 | ||
|
|
7100d073f8 | ||
|
|
1ac6cf2ff9 | ||
|
|
2ee089c9d5 | ||
|
|
bd568eecf5 | ||
|
|
3e2b83acb0 | ||
|
|
c1eb5bd675 | ||
|
|
a9772ebf3f |
@@ -386,10 +386,21 @@ FRAMEWORK_SCHEMA = cv.typed_schema(
|
|||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
FLASH_SIZES = [
|
||||||
|
"4MB",
|
||||||
|
"8MB",
|
||||||
|
"16MB",
|
||||||
|
"32MB",
|
||||||
|
]
|
||||||
|
|
||||||
|
CONF_FLASH_SIZE = "flash_size"
|
||||||
CONFIG_SCHEMA = cv.All(
|
CONFIG_SCHEMA = cv.All(
|
||||||
cv.Schema(
|
cv.Schema(
|
||||||
{
|
{
|
||||||
cv.Required(CONF_BOARD): cv.string_strict,
|
cv.Required(CONF_BOARD): cv.string_strict,
|
||||||
|
cv.Optional(CONF_FLASH_SIZE, default="4MB"): cv.one_of(
|
||||||
|
*FLASH_SIZES, upper=True
|
||||||
|
),
|
||||||
cv.Optional(CONF_VARIANT): cv.one_of(*VARIANTS, upper=True),
|
cv.Optional(CONF_VARIANT): cv.one_of(*VARIANTS, upper=True),
|
||||||
cv.Optional(CONF_FRAMEWORK, default={}): FRAMEWORK_SCHEMA,
|
cv.Optional(CONF_FRAMEWORK, default={}): FRAMEWORK_SCHEMA,
|
||||||
}
|
}
|
||||||
@@ -401,6 +412,7 @@ CONFIG_SCHEMA = cv.All(
|
|||||||
|
|
||||||
async def to_code(config):
|
async def to_code(config):
|
||||||
cg.add_platformio_option("board", config[CONF_BOARD])
|
cg.add_platformio_option("board", config[CONF_BOARD])
|
||||||
|
cg.add_platformio_option("board_upload.flash_size", config[CONF_FLASH_SIZE])
|
||||||
cg.add_build_flag("-DUSE_ESP32")
|
cg.add_build_flag("-DUSE_ESP32")
|
||||||
cg.add_define("ESPHOME_BOARD", config[CONF_BOARD])
|
cg.add_define("ESPHOME_BOARD", config[CONF_BOARD])
|
||||||
cg.add_build_flag(f"-DUSE_ESP32_VARIANT_{config[CONF_VARIANT]}")
|
cg.add_build_flag(f"-DUSE_ESP32_VARIANT_{config[CONF_VARIANT]}")
|
||||||
@@ -505,24 +517,46 @@ async def to_code(config):
|
|||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
ARDUINO_PARTITIONS_CSV = """\
|
APP_PARTITION_SIZES = {
|
||||||
nvs, data, nvs, 0x009000, 0x005000,
|
"4MB": 0x1C0000, # 1792 KB
|
||||||
otadata, data, ota, 0x00e000, 0x002000,
|
"8MB": 0x3C0000, # 3840 KB
|
||||||
app0, app, ota_0, 0x010000, 0x1C0000,
|
"16MB": 0x7C0000, # 7936 KB
|
||||||
app1, app, ota_1, 0x1D0000, 0x1C0000,
|
"32MB": 0xFC0000, # 16128 KB
|
||||||
eeprom, data, 0x99, 0x390000, 0x001000,
|
}
|
||||||
spiffs, data, spiffs, 0x391000, 0x00F000
|
|
||||||
|
|
||||||
|
def get_arduino_partition_csv(flash_size):
|
||||||
|
app_partition_size = APP_PARTITION_SIZES[flash_size]
|
||||||
|
eeprom_partition_size = 0x1000 # 4 KB
|
||||||
|
spiffs_partition_size = 0xF000 # 60 KB
|
||||||
|
|
||||||
|
app0_partition_start = 0x010000 # 64 KB
|
||||||
|
app1_partition_start = app0_partition_start + app_partition_size
|
||||||
|
eeprom_partition_start = app1_partition_start + app_partition_size
|
||||||
|
spiffs_partition_start = eeprom_partition_start + eeprom_partition_size
|
||||||
|
|
||||||
|
partition_csv = f"""\
|
||||||
|
nvs, data, nvs, 0x9000, 0x5000,
|
||||||
|
otadata, data, ota, 0xE000, 0x2000,
|
||||||
|
app0, app, ota_0, 0x{app0_partition_start:X}, 0x{app_partition_size:X},
|
||||||
|
app1, app, ota_1, 0x{app1_partition_start:X}, 0x{app_partition_size:X},
|
||||||
|
eeprom, data, 0x99, 0x{eeprom_partition_start:X}, 0x{eeprom_partition_size:X},
|
||||||
|
spiffs, data, spiffs, 0x{spiffs_partition_start:X}, 0x{spiffs_partition_size:X}
|
||||||
"""
|
"""
|
||||||
|
return partition_csv
|
||||||
|
|
||||||
|
|
||||||
IDF_PARTITIONS_CSV = """\
|
def get_idf_partition_csv(flash_size):
|
||||||
# Name, Type, SubType, Offset, Size, Flags
|
app_partition_size = APP_PARTITION_SIZES[flash_size]
|
||||||
|
|
||||||
|
partition_csv = f"""\
|
||||||
otadata, data, ota, , 0x2000,
|
otadata, data, ota, , 0x2000,
|
||||||
phy_init, data, phy, , 0x1000,
|
phy_init, data, phy, , 0x1000,
|
||||||
app0, app, ota_0, , 0x1C0000,
|
app0, app, ota_0, , 0x{app_partition_size:X},
|
||||||
app1, app, ota_1, , 0x1C0000,
|
app1, app, ota_1, , 0x{app_partition_size:X},
|
||||||
nvs, data, nvs, , 0x6d000,
|
nvs, data, nvs, , 0x6D000,
|
||||||
"""
|
"""
|
||||||
|
return partition_csv
|
||||||
|
|
||||||
|
|
||||||
def _format_sdkconfig_val(value: SdkconfigValueType) -> str:
|
def _format_sdkconfig_val(value: SdkconfigValueType) -> str:
|
||||||
@@ -565,13 +599,17 @@ def copy_files():
|
|||||||
if CORE.using_arduino:
|
if CORE.using_arduino:
|
||||||
write_file_if_changed(
|
write_file_if_changed(
|
||||||
CORE.relative_build_path("partitions.csv"),
|
CORE.relative_build_path("partitions.csv"),
|
||||||
ARDUINO_PARTITIONS_CSV,
|
get_arduino_partition_csv(
|
||||||
|
CORE.platformio_options.get("board_upload.flash_size")
|
||||||
|
),
|
||||||
)
|
)
|
||||||
if CORE.using_esp_idf:
|
if CORE.using_esp_idf:
|
||||||
_write_sdkconfig()
|
_write_sdkconfig()
|
||||||
write_file_if_changed(
|
write_file_if_changed(
|
||||||
CORE.relative_build_path("partitions.csv"),
|
CORE.relative_build_path("partitions.csv"),
|
||||||
IDF_PARTITIONS_CSV,
|
get_idf_partition_csv(
|
||||||
|
CORE.platformio_options.get("board_upload.flash_size")
|
||||||
|
),
|
||||||
)
|
)
|
||||||
# IDF build scripts look for version string to put in the build.
|
# IDF build scripts look for version string to put in the build.
|
||||||
# However, if the build path does not have an initialized git repo,
|
# However, if the build path does not have an initialized git repo,
|
||||||
|
|||||||
@@ -147,7 +147,7 @@ void MQTTClientComponent::dump_config() {
|
|||||||
ESP_LOGCONFIG(TAG, " Availability: '%s'", this->availability_.topic.c_str());
|
ESP_LOGCONFIG(TAG, " Availability: '%s'", this->availability_.topic.c_str());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
bool MQTTClientComponent::can_proceed() { return this->is_connected(); }
|
bool MQTTClientComponent::can_proceed() { return network::is_disabled() || this->is_connected(); }
|
||||||
|
|
||||||
void MQTTClientComponent::start_dnslookup_() {
|
void MQTTClientComponent::start_dnslookup_() {
|
||||||
for (auto &subscription : this->subscriptions_) {
|
for (auto &subscription : this->subscriptions_) {
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
#include "my9231.h"
|
#include "my9231.h"
|
||||||
#include "esphome/core/log.h"
|
#include "esphome/core/log.h"
|
||||||
|
#include "esphome/core/helpers.h"
|
||||||
|
|
||||||
namespace esphome {
|
namespace esphome {
|
||||||
namespace my9231 {
|
namespace my9231 {
|
||||||
@@ -51,7 +52,11 @@ void MY9231OutputComponent::setup() {
|
|||||||
MY9231_CMD_SCATTER_APDM | MY9231_CMD_FREQUENCY_DIVIDE_1 | MY9231_CMD_REACTION_FAST | MY9231_CMD_ONE_SHOT_DISABLE;
|
MY9231_CMD_SCATTER_APDM | MY9231_CMD_FREQUENCY_DIVIDE_1 | MY9231_CMD_REACTION_FAST | MY9231_CMD_ONE_SHOT_DISABLE;
|
||||||
ESP_LOGV(TAG, " Command: 0x%02X", command);
|
ESP_LOGV(TAG, " Command: 0x%02X", command);
|
||||||
|
|
||||||
this->init_chips_(command);
|
{
|
||||||
|
InterruptLock lock;
|
||||||
|
this->send_dcki_pulses_(32 * this->num_chips_);
|
||||||
|
this->init_chips_(command);
|
||||||
|
}
|
||||||
ESP_LOGV(TAG, " Chips initialized.");
|
ESP_LOGV(TAG, " Chips initialized.");
|
||||||
}
|
}
|
||||||
void MY9231OutputComponent::dump_config() {
|
void MY9231OutputComponent::dump_config() {
|
||||||
@@ -66,11 +71,14 @@ void MY9231OutputComponent::loop() {
|
|||||||
if (!this->update_)
|
if (!this->update_)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
for (auto pwm_amount : this->pwm_amounts_) {
|
{
|
||||||
this->write_word_(pwm_amount, this->bit_depth_);
|
InterruptLock lock;
|
||||||
|
for (auto pwm_amount : this->pwm_amounts_) {
|
||||||
|
this->write_word_(pwm_amount, this->bit_depth_);
|
||||||
|
}
|
||||||
|
// Send 8 DI pulses. After 8 falling edges, the duty data are store.
|
||||||
|
this->send_di_pulses_(8);
|
||||||
}
|
}
|
||||||
// Send 8 DI pulses. After 8 falling edges, the duty data are store.
|
|
||||||
this->send_di_pulses_(8);
|
|
||||||
this->update_ = false;
|
this->update_ = false;
|
||||||
}
|
}
|
||||||
void MY9231OutputComponent::set_channel_value_(uint8_t channel, uint16_t value) {
|
void MY9231OutputComponent::set_channel_value_(uint8_t channel, uint16_t value) {
|
||||||
@@ -92,6 +100,7 @@ void MY9231OutputComponent::init_chips_(uint8_t command) {
|
|||||||
// Send 16 DI pulse. After 14 falling edges, the command data are
|
// Send 16 DI pulse. After 14 falling edges, the command data are
|
||||||
// stored and after 16 falling edges the duty mode is activated.
|
// stored and after 16 falling edges the duty mode is activated.
|
||||||
this->send_di_pulses_(16);
|
this->send_di_pulses_(16);
|
||||||
|
delayMicroseconds(12);
|
||||||
}
|
}
|
||||||
void MY9231OutputComponent::write_word_(uint16_t value, uint8_t bits) {
|
void MY9231OutputComponent::write_word_(uint16_t value, uint8_t bits) {
|
||||||
for (uint8_t i = bits; i > 0; i--) {
|
for (uint8_t i = bits; i > 0; i--) {
|
||||||
@@ -106,6 +115,13 @@ void MY9231OutputComponent::send_di_pulses_(uint8_t count) {
|
|||||||
this->pin_di_->digital_write(false);
|
this->pin_di_->digital_write(false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
void MY9231OutputComponent::send_dcki_pulses_(uint8_t count) {
|
||||||
|
delayMicroseconds(12);
|
||||||
|
for (uint8_t i = 0; i < count; i++) {
|
||||||
|
this->pin_dcki_->digital_write(true);
|
||||||
|
this->pin_dcki_->digital_write(false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace my9231
|
} // namespace my9231
|
||||||
} // namespace esphome
|
} // namespace esphome
|
||||||
|
|||||||
@@ -49,6 +49,7 @@ class MY9231OutputComponent : public Component {
|
|||||||
void init_chips_(uint8_t command);
|
void init_chips_(uint8_t command);
|
||||||
void write_word_(uint16_t value, uint8_t bits);
|
void write_word_(uint16_t value, uint8_t bits);
|
||||||
void send_di_pulses_(uint8_t count);
|
void send_di_pulses_(uint8_t count);
|
||||||
|
void send_dcki_pulses_(uint8_t count);
|
||||||
|
|
||||||
GPIOPin *pin_di_;
|
GPIOPin *pin_di_;
|
||||||
GPIOPin *pin_dcki_;
|
GPIOPin *pin_dcki_;
|
||||||
|
|||||||
@@ -29,6 +29,14 @@ bool is_connected() {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool is_disabled() {
|
||||||
|
#ifdef USE_WIFI
|
||||||
|
if (wifi::global_wifi_component != nullptr)
|
||||||
|
return wifi::global_wifi_component->is_disabled();
|
||||||
|
#endif
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
network::IPAddress get_ip_address() {
|
network::IPAddress get_ip_address() {
|
||||||
#ifdef USE_ETHERNET
|
#ifdef USE_ETHERNET
|
||||||
if (ethernet::global_eth_component != nullptr)
|
if (ethernet::global_eth_component != nullptr)
|
||||||
|
|||||||
@@ -8,6 +8,8 @@ namespace network {
|
|||||||
|
|
||||||
/// Return whether the node is connected to the network (through wifi, eth, ...)
|
/// Return whether the node is connected to the network (through wifi, eth, ...)
|
||||||
bool is_connected();
|
bool is_connected();
|
||||||
|
/// Return whether the network is disabled (only wifi for now)
|
||||||
|
bool is_disabled();
|
||||||
/// Get the active network hostname
|
/// Get the active network hostname
|
||||||
std::string get_use_address();
|
std::string get_use_address();
|
||||||
IPAddress get_ip_address();
|
IPAddress get_ip_address();
|
||||||
|
|||||||
@@ -18,20 +18,25 @@ DEPENDENCIES = ["api", "microphone"]
|
|||||||
|
|
||||||
CODEOWNERS = ["@jesserockz"]
|
CODEOWNERS = ["@jesserockz"]
|
||||||
|
|
||||||
CONF_SILENCE_DETECTION = "silence_detection"
|
|
||||||
CONF_ON_LISTENING = "on_listening"
|
|
||||||
CONF_ON_START = "on_start"
|
|
||||||
CONF_ON_WAKE_WORD_DETECTED = "on_wake_word_detected"
|
|
||||||
CONF_ON_STT_END = "on_stt_end"
|
|
||||||
CONF_ON_TTS_START = "on_tts_start"
|
|
||||||
CONF_ON_TTS_END = "on_tts_end"
|
|
||||||
CONF_ON_END = "on_end"
|
CONF_ON_END = "on_end"
|
||||||
CONF_ON_ERROR = "on_error"
|
CONF_ON_ERROR = "on_error"
|
||||||
|
CONF_ON_INTENT_END = "on_intent_end"
|
||||||
|
CONF_ON_INTENT_START = "on_intent_start"
|
||||||
|
CONF_ON_LISTENING = "on_listening"
|
||||||
|
CONF_ON_START = "on_start"
|
||||||
|
CONF_ON_STT_END = "on_stt_end"
|
||||||
|
CONF_ON_STT_VAD_END = "on_stt_vad_end"
|
||||||
|
CONF_ON_STT_VAD_START = "on_stt_vad_start"
|
||||||
|
CONF_ON_TTS_END = "on_tts_end"
|
||||||
|
CONF_ON_TTS_START = "on_tts_start"
|
||||||
|
CONF_ON_WAKE_WORD_DETECTED = "on_wake_word_detected"
|
||||||
|
|
||||||
|
CONF_SILENCE_DETECTION = "silence_detection"
|
||||||
CONF_USE_WAKE_WORD = "use_wake_word"
|
CONF_USE_WAKE_WORD = "use_wake_word"
|
||||||
CONF_VAD_THRESHOLD = "vad_threshold"
|
CONF_VAD_THRESHOLD = "vad_threshold"
|
||||||
|
|
||||||
CONF_NOISE_SUPPRESSION_LEVEL = "noise_suppression_level"
|
|
||||||
CONF_AUTO_GAIN = "auto_gain"
|
CONF_AUTO_GAIN = "auto_gain"
|
||||||
|
CONF_NOISE_SUPPRESSION_LEVEL = "noise_suppression_level"
|
||||||
CONF_VOLUME_MULTIPLIER = "volume_multiplier"
|
CONF_VOLUME_MULTIPLIER = "volume_multiplier"
|
||||||
|
|
||||||
|
|
||||||
@@ -88,6 +93,18 @@ CONFIG_SCHEMA = cv.All(
|
|||||||
cv.Optional(CONF_ON_CLIENT_DISCONNECTED): automation.validate_automation(
|
cv.Optional(CONF_ON_CLIENT_DISCONNECTED): automation.validate_automation(
|
||||||
single=True
|
single=True
|
||||||
),
|
),
|
||||||
|
cv.Optional(CONF_ON_INTENT_START): automation.validate_automation(
|
||||||
|
single=True
|
||||||
|
),
|
||||||
|
cv.Optional(CONF_ON_INTENT_END): automation.validate_automation(
|
||||||
|
single=True
|
||||||
|
),
|
||||||
|
cv.Optional(CONF_ON_STT_VAD_START): automation.validate_automation(
|
||||||
|
single=True
|
||||||
|
),
|
||||||
|
cv.Optional(CONF_ON_STT_VAD_END): automation.validate_automation(
|
||||||
|
single=True
|
||||||
|
),
|
||||||
}
|
}
|
||||||
).extend(cv.COMPONENT_SCHEMA),
|
).extend(cv.COMPONENT_SCHEMA),
|
||||||
)
|
)
|
||||||
@@ -177,6 +194,34 @@ async def to_code(config):
|
|||||||
config[CONF_ON_CLIENT_DISCONNECTED],
|
config[CONF_ON_CLIENT_DISCONNECTED],
|
||||||
)
|
)
|
||||||
|
|
||||||
|
if CONF_ON_INTENT_START in config:
|
||||||
|
await automation.build_automation(
|
||||||
|
var.get_intent_start_trigger(),
|
||||||
|
[],
|
||||||
|
config[CONF_ON_INTENT_START],
|
||||||
|
)
|
||||||
|
|
||||||
|
if CONF_ON_INTENT_END in config:
|
||||||
|
await automation.build_automation(
|
||||||
|
var.get_intent_end_trigger(),
|
||||||
|
[],
|
||||||
|
config[CONF_ON_INTENT_END],
|
||||||
|
)
|
||||||
|
|
||||||
|
if CONF_ON_STT_VAD_START in config:
|
||||||
|
await automation.build_automation(
|
||||||
|
var.get_stt_vad_start_trigger(),
|
||||||
|
[],
|
||||||
|
config[CONF_ON_STT_VAD_START],
|
||||||
|
)
|
||||||
|
|
||||||
|
if CONF_ON_STT_VAD_END in config:
|
||||||
|
await automation.build_automation(
|
||||||
|
var.get_stt_vad_end_trigger(),
|
||||||
|
[],
|
||||||
|
config[CONF_ON_STT_VAD_END],
|
||||||
|
)
|
||||||
|
|
||||||
cg.add_define("USE_VOICE_ASSISTANT")
|
cg.add_define("USE_VOICE_ASSISTANT")
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -31,7 +31,7 @@ void VoiceAssistant::setup() {
|
|||||||
|
|
||||||
this->socket_ = socket::socket(AF_INET, SOCK_DGRAM, IPPROTO_IP);
|
this->socket_ = socket::socket(AF_INET, SOCK_DGRAM, IPPROTO_IP);
|
||||||
if (socket_ == nullptr) {
|
if (socket_ == nullptr) {
|
||||||
ESP_LOGW(TAG, "Could not create socket.");
|
ESP_LOGW(TAG, "Could not create socket");
|
||||||
this->mark_failed();
|
this->mark_failed();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -69,7 +69,7 @@ void VoiceAssistant::setup() {
|
|||||||
ExternalRAMAllocator<uint8_t> speaker_allocator(ExternalRAMAllocator<uint8_t>::ALLOW_FAILURE);
|
ExternalRAMAllocator<uint8_t> speaker_allocator(ExternalRAMAllocator<uint8_t>::ALLOW_FAILURE);
|
||||||
this->speaker_buffer_ = speaker_allocator.allocate(SPEAKER_BUFFER_SIZE);
|
this->speaker_buffer_ = speaker_allocator.allocate(SPEAKER_BUFFER_SIZE);
|
||||||
if (this->speaker_buffer_ == nullptr) {
|
if (this->speaker_buffer_ == nullptr) {
|
||||||
ESP_LOGW(TAG, "Could not allocate speaker buffer.");
|
ESP_LOGW(TAG, "Could not allocate speaker buffer");
|
||||||
this->mark_failed();
|
this->mark_failed();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -79,7 +79,7 @@ void VoiceAssistant::setup() {
|
|||||||
ExternalRAMAllocator<int16_t> allocator(ExternalRAMAllocator<int16_t>::ALLOW_FAILURE);
|
ExternalRAMAllocator<int16_t> allocator(ExternalRAMAllocator<int16_t>::ALLOW_FAILURE);
|
||||||
this->input_buffer_ = allocator.allocate(INPUT_BUFFER_SIZE);
|
this->input_buffer_ = allocator.allocate(INPUT_BUFFER_SIZE);
|
||||||
if (this->input_buffer_ == nullptr) {
|
if (this->input_buffer_ == nullptr) {
|
||||||
ESP_LOGW(TAG, "Could not allocate input buffer.");
|
ESP_LOGW(TAG, "Could not allocate input buffer");
|
||||||
this->mark_failed();
|
this->mark_failed();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -89,7 +89,7 @@ void VoiceAssistant::setup() {
|
|||||||
|
|
||||||
this->ring_buffer_ = rb_create(BUFFER_SIZE, sizeof(int16_t));
|
this->ring_buffer_ = rb_create(BUFFER_SIZE, sizeof(int16_t));
|
||||||
if (this->ring_buffer_ == nullptr) {
|
if (this->ring_buffer_ == nullptr) {
|
||||||
ESP_LOGW(TAG, "Could not allocate ring buffer.");
|
ESP_LOGW(TAG, "Could not allocate ring buffer");
|
||||||
this->mark_failed();
|
this->mark_failed();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -98,7 +98,7 @@ void VoiceAssistant::setup() {
|
|||||||
ExternalRAMAllocator<uint8_t> send_allocator(ExternalRAMAllocator<uint8_t>::ALLOW_FAILURE);
|
ExternalRAMAllocator<uint8_t> send_allocator(ExternalRAMAllocator<uint8_t>::ALLOW_FAILURE);
|
||||||
this->send_buffer_ = send_allocator.allocate(SEND_BUFFER_SIZE);
|
this->send_buffer_ = send_allocator.allocate(SEND_BUFFER_SIZE);
|
||||||
if (send_buffer_ == nullptr) {
|
if (send_buffer_ == nullptr) {
|
||||||
ESP_LOGW(TAG, "Could not allocate send buffer.");
|
ESP_LOGW(TAG, "Could not allocate send buffer");
|
||||||
this->mark_failed();
|
this->mark_failed();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -221,8 +221,8 @@ void VoiceAssistant::loop() {
|
|||||||
msg.audio_settings = audio_settings;
|
msg.audio_settings = audio_settings;
|
||||||
|
|
||||||
if (this->api_client_ == nullptr || !this->api_client_->send_voice_assistant_request(msg)) {
|
if (this->api_client_ == nullptr || !this->api_client_->send_voice_assistant_request(msg)) {
|
||||||
ESP_LOGW(TAG, "Could not request start.");
|
ESP_LOGW(TAG, "Could not request start");
|
||||||
this->error_trigger_->trigger("not-connected", "Could not request start.");
|
this->error_trigger_->trigger("not-connected", "Could not request start");
|
||||||
this->continuous_ = false;
|
this->continuous_ = false;
|
||||||
this->set_state_(State::IDLE, State::IDLE);
|
this->set_state_(State::IDLE, State::IDLE);
|
||||||
break;
|
break;
|
||||||
@@ -280,7 +280,7 @@ void VoiceAssistant::loop() {
|
|||||||
this->speaker_buffer_size_ += len;
|
this->speaker_buffer_size_ += len;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
ESP_LOGW(TAG, "Receive buffer full.");
|
ESP_LOGW(TAG, "Receive buffer full");
|
||||||
}
|
}
|
||||||
if (this->speaker_buffer_size_ > 0) {
|
if (this->speaker_buffer_size_ > 0) {
|
||||||
size_t written = this->speaker_->play(this->speaker_buffer_, this->speaker_buffer_size_);
|
size_t written = this->speaker_->play(this->speaker_buffer_, this->speaker_buffer_size_);
|
||||||
@@ -290,7 +290,7 @@ void VoiceAssistant::loop() {
|
|||||||
this->speaker_buffer_index_ -= written;
|
this->speaker_buffer_index_ -= written;
|
||||||
this->set_timeout("speaker-timeout", 2000, [this]() { this->speaker_->stop(); });
|
this->set_timeout("speaker-timeout", 2000, [this]() { this->speaker_->stop(); });
|
||||||
} else {
|
} else {
|
||||||
ESP_LOGW(TAG, "Speaker buffer full.");
|
ESP_LOGW(TAG, "Speaker buffer full");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (this->wait_for_stream_end_) {
|
if (this->wait_for_stream_end_) {
|
||||||
@@ -513,7 +513,7 @@ void VoiceAssistant::on_event(const api::VoiceAssistantEventResponse &msg) {
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case api::enums::VOICE_ASSISTANT_STT_START:
|
case api::enums::VOICE_ASSISTANT_STT_START:
|
||||||
ESP_LOGD(TAG, "STT Started");
|
ESP_LOGD(TAG, "STT started");
|
||||||
this->listening_trigger_->trigger();
|
this->listening_trigger_->trigger();
|
||||||
break;
|
break;
|
||||||
case api::enums::VOICE_ASSISTANT_STT_END: {
|
case api::enums::VOICE_ASSISTANT_STT_END: {
|
||||||
@@ -525,19 +525,24 @@ void VoiceAssistant::on_event(const api::VoiceAssistantEventResponse &msg) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (text.empty()) {
|
if (text.empty()) {
|
||||||
ESP_LOGW(TAG, "No text in STT_END event.");
|
ESP_LOGW(TAG, "No text in STT_END event");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
ESP_LOGD(TAG, "Speech recognised as: \"%s\"", text.c_str());
|
ESP_LOGD(TAG, "Speech recognised as: \"%s\"", text.c_str());
|
||||||
this->stt_end_trigger_->trigger(text);
|
this->stt_end_trigger_->trigger(text);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
case api::enums::VOICE_ASSISTANT_INTENT_START:
|
||||||
|
ESP_LOGD(TAG, "Intent started");
|
||||||
|
this->intent_start_trigger_->trigger();
|
||||||
|
break;
|
||||||
case api::enums::VOICE_ASSISTANT_INTENT_END: {
|
case api::enums::VOICE_ASSISTANT_INTENT_END: {
|
||||||
for (auto arg : msg.data) {
|
for (auto arg : msg.data) {
|
||||||
if (arg.name == "conversation_id") {
|
if (arg.name == "conversation_id") {
|
||||||
this->conversation_id_ = std::move(arg.value);
|
this->conversation_id_ = std::move(arg.value);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
this->intent_end_trigger_->trigger();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case api::enums::VOICE_ASSISTANT_TTS_START: {
|
case api::enums::VOICE_ASSISTANT_TTS_START: {
|
||||||
@@ -548,7 +553,7 @@ void VoiceAssistant::on_event(const api::VoiceAssistantEventResponse &msg) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (text.empty()) {
|
if (text.empty()) {
|
||||||
ESP_LOGW(TAG, "No text in TTS_START event.");
|
ESP_LOGW(TAG, "No text in TTS_START event");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
ESP_LOGD(TAG, "Response: \"%s\"", text.c_str());
|
ESP_LOGD(TAG, "Response: \"%s\"", text.c_str());
|
||||||
@@ -566,7 +571,7 @@ void VoiceAssistant::on_event(const api::VoiceAssistantEventResponse &msg) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (url.empty()) {
|
if (url.empty()) {
|
||||||
ESP_LOGW(TAG, "No url in TTS_END event.");
|
ESP_LOGW(TAG, "No url in TTS_END event");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
ESP_LOGD(TAG, "Response URL: \"%s\"", url.c_str());
|
ESP_LOGD(TAG, "Response URL: \"%s\"", url.c_str());
|
||||||
@@ -610,6 +615,11 @@ void VoiceAssistant::on_event(const api::VoiceAssistantEventResponse &msg) {
|
|||||||
if (code == "wake-word-timeout" || code == "wake_word_detection_aborted") {
|
if (code == "wake-word-timeout" || code == "wake_word_detection_aborted") {
|
||||||
// Don't change state here since either the "tts-end" or "run-end" events will do it.
|
// Don't change state here since either the "tts-end" or "run-end" events will do it.
|
||||||
return;
|
return;
|
||||||
|
} else if (code == "wake-provider-missing" || code == "wake-engine-missing") {
|
||||||
|
// Wake word is not set up or not ready on Home Assistant so stop and do not retry until user starts again.
|
||||||
|
this->request_stop();
|
||||||
|
this->error_trigger_->trigger(code, message);
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
ESP_LOGE(TAG, "Error: %s - %s", code.c_str(), message.c_str());
|
ESP_LOGE(TAG, "Error: %s - %s", code.c_str(), message.c_str());
|
||||||
if (this->state_ != State::IDLE) {
|
if (this->state_ != State::IDLE) {
|
||||||
@@ -629,6 +639,14 @@ void VoiceAssistant::on_event(const api::VoiceAssistantEventResponse &msg) {
|
|||||||
this->set_state_(State::RESPONSE_FINISHED, State::IDLE);
|
this->set_state_(State::RESPONSE_FINISHED, State::IDLE);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
case api::enums::VOICE_ASSISTANT_STT_VAD_START:
|
||||||
|
ESP_LOGD(TAG, "Starting STT by VAD");
|
||||||
|
this->stt_vad_start_trigger_->trigger();
|
||||||
|
break;
|
||||||
|
case api::enums::VOICE_ASSISTANT_STT_VAD_END:
|
||||||
|
ESP_LOGD(TAG, "STT by VAD end");
|
||||||
|
this->stt_vad_end_trigger_->trigger();
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
ESP_LOGD(TAG, "Unhandled event type: %d", msg.event_type);
|
ESP_LOGD(TAG, "Unhandled event type: %d", msg.event_type);
|
||||||
break;
|
break;
|
||||||
|
|||||||
@@ -100,13 +100,17 @@ class VoiceAssistant : public Component {
|
|||||||
void set_auto_gain(uint8_t auto_gain) { this->auto_gain_ = auto_gain; }
|
void set_auto_gain(uint8_t auto_gain) { this->auto_gain_ = auto_gain; }
|
||||||
void set_volume_multiplier(float volume_multiplier) { this->volume_multiplier_ = volume_multiplier; }
|
void set_volume_multiplier(float volume_multiplier) { this->volume_multiplier_ = volume_multiplier; }
|
||||||
|
|
||||||
|
Trigger<> *get_intent_end_trigger() const { return this->intent_end_trigger_; }
|
||||||
|
Trigger<> *get_intent_start_trigger() const { return this->intent_start_trigger_; }
|
||||||
Trigger<> *get_listening_trigger() const { return this->listening_trigger_; }
|
Trigger<> *get_listening_trigger() const { return this->listening_trigger_; }
|
||||||
|
Trigger<> *get_end_trigger() const { return this->end_trigger_; }
|
||||||
Trigger<> *get_start_trigger() const { return this->start_trigger_; }
|
Trigger<> *get_start_trigger() const { return this->start_trigger_; }
|
||||||
|
Trigger<> *get_stt_vad_end_trigger() const { return this->stt_vad_end_trigger_; }
|
||||||
|
Trigger<> *get_stt_vad_start_trigger() const { return this->stt_vad_start_trigger_; }
|
||||||
Trigger<> *get_wake_word_detected_trigger() const { return this->wake_word_detected_trigger_; }
|
Trigger<> *get_wake_word_detected_trigger() const { return this->wake_word_detected_trigger_; }
|
||||||
Trigger<std::string> *get_stt_end_trigger() const { return this->stt_end_trigger_; }
|
Trigger<std::string> *get_stt_end_trigger() const { return this->stt_end_trigger_; }
|
||||||
Trigger<std::string> *get_tts_start_trigger() const { return this->tts_start_trigger_; }
|
|
||||||
Trigger<std::string> *get_tts_end_trigger() const { return this->tts_end_trigger_; }
|
Trigger<std::string> *get_tts_end_trigger() const { return this->tts_end_trigger_; }
|
||||||
Trigger<> *get_end_trigger() const { return this->end_trigger_; }
|
Trigger<std::string> *get_tts_start_trigger() const { return this->tts_start_trigger_; }
|
||||||
Trigger<std::string, std::string> *get_error_trigger() const { return this->error_trigger_; }
|
Trigger<std::string, std::string> *get_error_trigger() const { return this->error_trigger_; }
|
||||||
|
|
||||||
Trigger<> *get_client_connected_trigger() const { return this->client_connected_trigger_; }
|
Trigger<> *get_client_connected_trigger() const { return this->client_connected_trigger_; }
|
||||||
@@ -124,13 +128,17 @@ class VoiceAssistant : public Component {
|
|||||||
std::unique_ptr<socket::Socket> socket_ = nullptr;
|
std::unique_ptr<socket::Socket> socket_ = nullptr;
|
||||||
struct sockaddr_storage dest_addr_;
|
struct sockaddr_storage dest_addr_;
|
||||||
|
|
||||||
|
Trigger<> *intent_end_trigger_ = new Trigger<>();
|
||||||
|
Trigger<> *intent_start_trigger_ = new Trigger<>();
|
||||||
Trigger<> *listening_trigger_ = new Trigger<>();
|
Trigger<> *listening_trigger_ = new Trigger<>();
|
||||||
|
Trigger<> *end_trigger_ = new Trigger<>();
|
||||||
Trigger<> *start_trigger_ = new Trigger<>();
|
Trigger<> *start_trigger_ = new Trigger<>();
|
||||||
|
Trigger<> *stt_vad_start_trigger_ = new Trigger<>();
|
||||||
|
Trigger<> *stt_vad_end_trigger_ = new Trigger<>();
|
||||||
Trigger<> *wake_word_detected_trigger_ = new Trigger<>();
|
Trigger<> *wake_word_detected_trigger_ = new Trigger<>();
|
||||||
Trigger<std::string> *stt_end_trigger_ = new Trigger<std::string>();
|
Trigger<std::string> *stt_end_trigger_ = new Trigger<std::string>();
|
||||||
Trigger<std::string> *tts_start_trigger_ = new Trigger<std::string>();
|
|
||||||
Trigger<std::string> *tts_end_trigger_ = new Trigger<std::string>();
|
Trigger<std::string> *tts_end_trigger_ = new Trigger<std::string>();
|
||||||
Trigger<> *end_trigger_ = new Trigger<>();
|
Trigger<std::string> *tts_start_trigger_ = new Trigger<std::string>();
|
||||||
Trigger<std::string, std::string> *error_trigger_ = new Trigger<std::string, std::string>();
|
Trigger<std::string, std::string> *error_trigger_ = new Trigger<std::string, std::string>();
|
||||||
|
|
||||||
Trigger<> *client_connected_trigger_ = new Trigger<>();
|
Trigger<> *client_connected_trigger_ = new Trigger<>();
|
||||||
|
|||||||
@@ -389,6 +389,10 @@ void WiFiComponent::print_connect_params_() {
|
|||||||
bssid_t bssid = wifi_bssid();
|
bssid_t bssid = wifi_bssid();
|
||||||
|
|
||||||
ESP_LOGCONFIG(TAG, " Local MAC: %s", get_mac_address_pretty().c_str());
|
ESP_LOGCONFIG(TAG, " Local MAC: %s", get_mac_address_pretty().c_str());
|
||||||
|
if (this->is_disabled()) {
|
||||||
|
ESP_LOGCONFIG(TAG, " WiFi is disabled!");
|
||||||
|
return;
|
||||||
|
}
|
||||||
ESP_LOGCONFIG(TAG, " SSID: " LOG_SECRET("'%s'"), wifi_ssid().c_str());
|
ESP_LOGCONFIG(TAG, " SSID: " LOG_SECRET("'%s'"), wifi_ssid().c_str());
|
||||||
ESP_LOGCONFIG(TAG, " IP Address: %s", wifi_sta_ip().str().c_str());
|
ESP_LOGCONFIG(TAG, " IP Address: %s", wifi_sta_ip().str().c_str());
|
||||||
ESP_LOGCONFIG(TAG, " BSSID: " LOG_SECRET("%02X:%02X:%02X:%02X:%02X:%02X"), bssid[0], bssid[1], bssid[2], bssid[3],
|
ESP_LOGCONFIG(TAG, " BSSID: " LOG_SECRET("%02X:%02X:%02X:%02X:%02X:%02X"), bssid[0], bssid[1], bssid[2], bssid[3],
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
"""Constants used by esphome."""
|
"""Constants used by esphome."""
|
||||||
|
|
||||||
__version__ = "2023.11.0b4"
|
__version__ = "2023.11.1"
|
||||||
|
|
||||||
ALLOWED_NAME_CHARS = "abcdefghijklmnopqrstuvwxyz0123456789-_"
|
ALLOWED_NAME_CHARS = "abcdefghijklmnopqrstuvwxyz0123456789-_"
|
||||||
VALID_SUBSTITUTIONS_CHARACTERS = (
|
VALID_SUBSTITUTIONS_CHARACTERS = (
|
||||||
|
|||||||
@@ -1,8 +1,8 @@
|
|||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
|
||||||
|
import asyncio
|
||||||
import base64
|
import base64
|
||||||
import binascii
|
import binascii
|
||||||
import codecs
|
|
||||||
import collections
|
import collections
|
||||||
import datetime
|
import datetime
|
||||||
import functools
|
import functools
|
||||||
@@ -339,8 +339,8 @@ class EsphomeCommandWebSocket(tornado.websocket.WebSocketHandler):
|
|||||||
def handle_stdin(self, json_message):
|
def handle_stdin(self, json_message):
|
||||||
if not self.is_process_active:
|
if not self.is_process_active:
|
||||||
return
|
return
|
||||||
data = json_message["data"]
|
text: str = json_message["data"]
|
||||||
data = codecs.encode(data, "utf8", "replace")
|
data = text.encode("utf-8", "replace")
|
||||||
_LOGGER.debug("< stdin: %s", data)
|
_LOGGER.debug("< stdin: %s", data)
|
||||||
self._proc.stdin.write(data)
|
self._proc.stdin.write(data)
|
||||||
|
|
||||||
@@ -351,18 +351,18 @@ class EsphomeCommandWebSocket(tornado.websocket.WebSocketHandler):
|
|||||||
while True:
|
while True:
|
||||||
try:
|
try:
|
||||||
if self._use_popen:
|
if self._use_popen:
|
||||||
data = yield self._queue.get()
|
data: bytes = yield self._queue.get()
|
||||||
if data is None:
|
if data is None:
|
||||||
self._proc_on_exit(self._proc.poll())
|
self._proc_on_exit(self._proc.poll())
|
||||||
break
|
break
|
||||||
else:
|
else:
|
||||||
data = yield self._proc.stdout.read_until_regex(reg)
|
data: bytes = yield self._proc.stdout.read_until_regex(reg)
|
||||||
except tornado.iostream.StreamClosedError:
|
except tornado.iostream.StreamClosedError:
|
||||||
break
|
break
|
||||||
data = codecs.decode(data, "utf8", "replace")
|
|
||||||
|
|
||||||
_LOGGER.debug("> stdout: %s", data)
|
text = data.decode("utf-8", "replace")
|
||||||
self.write_message({"event": "line", "data": data})
|
_LOGGER.debug("> stdout: %s", text)
|
||||||
|
self.write_message({"event": "line", "data": text})
|
||||||
|
|
||||||
def _stdout_thread(self):
|
def _stdout_thread(self):
|
||||||
if not self._use_popen:
|
if not self._use_popen:
|
||||||
@@ -509,8 +509,8 @@ class EsphomeUpdateAllHandler(EsphomeCommandWebSocket):
|
|||||||
|
|
||||||
class SerialPortRequestHandler(BaseHandler):
|
class SerialPortRequestHandler(BaseHandler):
|
||||||
@authenticated
|
@authenticated
|
||||||
def get(self):
|
async def get(self):
|
||||||
ports = get_serial_ports()
|
ports = await asyncio.get_running_loop().run_in_executor(None, get_serial_ports)
|
||||||
data = []
|
data = []
|
||||||
for port in ports:
|
for port in ports:
|
||||||
desc = port.description
|
desc = port.description
|
||||||
|
|||||||
Reference in New Issue
Block a user