mirror of
https://github.com/esphome/esphome.git
synced 2025-11-12 21:05:46 +00:00
Compare commits
30 Commits
2024.5.0b3
...
2024.5.3
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
d72ab25d46 | ||
|
|
af755380b7 | ||
|
|
04db724295 | ||
|
|
0ee4348777 | ||
|
|
fcdf36e991 | ||
|
|
5eb8efd8b3 | ||
|
|
cd0f557940 | ||
|
|
efde677ca9 | ||
|
|
2eebee1de7 | ||
|
|
f235dcc096 | ||
|
|
d2d3db4b8c | ||
|
|
ec6d86c8f5 | ||
|
|
7452879fb1 | ||
|
|
4fc2f2284a | ||
|
|
840f69ffe6 | ||
|
|
caa8c820de | ||
|
|
0d3adc8f0c | ||
|
|
ad0a1c5c35 | ||
|
|
5d2e3a7d8d | ||
|
|
ebc3f0fe17 | ||
|
|
bd8afa51cd | ||
|
|
db4aa0b679 | ||
|
|
28a09cc0d0 | ||
|
|
128fad57b3 | ||
|
|
142c4a87d2 | ||
|
|
1e4d6ee344 | ||
|
|
5afe0e5ec2 | ||
|
|
ba3fc4c5d0 | ||
|
|
694f75117e | ||
|
|
4ec2ef27a8 |
@@ -346,7 +346,7 @@ def upload_program(config, args, host):
|
|||||||
not is_ip_address(CORE.address) # pylint: disable=too-many-boolean-expressions
|
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 (get_port_type(host) == "MQTT" or config[CONF_MDNS][CONF_DISABLED])
|
||||||
and CONF_MQTT in config
|
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
|
from esphome import mqtt
|
||||||
|
|
||||||
|
|||||||
@@ -18,11 +18,23 @@ from esphome.components.esp32.const import (
|
|||||||
|
|
||||||
CODEOWNERS = ["@esphome/core"]
|
CODEOWNERS = ["@esphome/core"]
|
||||||
|
|
||||||
|
adc_ns = cg.esphome_ns.namespace("adc")
|
||||||
|
|
||||||
|
|
||||||
|
"""
|
||||||
|
From the below patch versions (and 5.2+) ADC_ATTEN_DB_11 is deprecated and replaced with ADC_ATTEN_DB_12.
|
||||||
|
4.4.7
|
||||||
|
5.0.5
|
||||||
|
5.1.3
|
||||||
|
5.2+
|
||||||
|
"""
|
||||||
|
|
||||||
ATTENUATION_MODES = {
|
ATTENUATION_MODES = {
|
||||||
"0db": cg.global_ns.ADC_ATTEN_DB_0,
|
"0db": cg.global_ns.ADC_ATTEN_DB_0,
|
||||||
"2.5db": cg.global_ns.ADC_ATTEN_DB_2_5,
|
"2.5db": cg.global_ns.ADC_ATTEN_DB_2_5,
|
||||||
"6db": cg.global_ns.ADC_ATTEN_DB_6,
|
"6db": cg.global_ns.ADC_ATTEN_DB_6,
|
||||||
"11db": cg.global_ns.ADC_ATTEN_DB_11,
|
"11db": adc_ns.ADC_ATTEN_DB_12_COMPAT,
|
||||||
|
"12db": adc_ns.ADC_ATTEN_DB_12_COMPAT,
|
||||||
"auto": "auto",
|
"auto": "auto",
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -62,7 +62,7 @@ extern "C"
|
|||||||
}
|
}
|
||||||
|
|
||||||
// load characteristics for each attenuation
|
// load characteristics for each attenuation
|
||||||
for (int32_t i = 0; i <= ADC_ATTEN_DB_11; i++) {
|
for (int32_t i = 0; i <= ADC_ATTEN_DB_12_COMPAT; i++) {
|
||||||
auto adc_unit = channel1_ != ADC1_CHANNEL_MAX ? ADC_UNIT_1 : ADC_UNIT_2;
|
auto adc_unit = channel1_ != ADC1_CHANNEL_MAX ? ADC_UNIT_1 : ADC_UNIT_2;
|
||||||
auto cal_value = esp_adc_cal_characterize(adc_unit, (adc_atten_t) i, ADC_WIDTH_MAX_SOC_BITS,
|
auto cal_value = esp_adc_cal_characterize(adc_unit, (adc_atten_t) i, ADC_WIDTH_MAX_SOC_BITS,
|
||||||
1100, // default vref
|
1100, // default vref
|
||||||
@@ -118,8 +118,8 @@ void ADCSensor::dump_config() {
|
|||||||
case ADC_ATTEN_DB_6:
|
case ADC_ATTEN_DB_6:
|
||||||
ESP_LOGCONFIG(TAG, " Attenuation: 6db");
|
ESP_LOGCONFIG(TAG, " Attenuation: 6db");
|
||||||
break;
|
break;
|
||||||
case ADC_ATTEN_DB_11:
|
case ADC_ATTEN_DB_12_COMPAT:
|
||||||
ESP_LOGCONFIG(TAG, " Attenuation: 11db");
|
ESP_LOGCONFIG(TAG, " Attenuation: 12db");
|
||||||
break;
|
break;
|
||||||
default: // This is to satisfy the unused ADC_ATTEN_MAX
|
default: // This is to satisfy the unused ADC_ATTEN_MAX
|
||||||
break;
|
break;
|
||||||
@@ -183,12 +183,12 @@ float ADCSensor::sample() {
|
|||||||
return mv / 1000.0f;
|
return mv / 1000.0f;
|
||||||
}
|
}
|
||||||
|
|
||||||
int raw11 = ADC_MAX, raw6 = ADC_MAX, raw2 = ADC_MAX, raw0 = ADC_MAX;
|
int raw12 = ADC_MAX, raw6 = ADC_MAX, raw2 = ADC_MAX, raw0 = ADC_MAX;
|
||||||
|
|
||||||
if (channel1_ != ADC1_CHANNEL_MAX) {
|
if (channel1_ != ADC1_CHANNEL_MAX) {
|
||||||
adc1_config_channel_atten(channel1_, ADC_ATTEN_DB_11);
|
adc1_config_channel_atten(channel1_, ADC_ATTEN_DB_12_COMPAT);
|
||||||
raw11 = adc1_get_raw(channel1_);
|
raw12 = adc1_get_raw(channel1_);
|
||||||
if (raw11 < ADC_MAX) {
|
if (raw12 < ADC_MAX) {
|
||||||
adc1_config_channel_atten(channel1_, ADC_ATTEN_DB_6);
|
adc1_config_channel_atten(channel1_, ADC_ATTEN_DB_6);
|
||||||
raw6 = adc1_get_raw(channel1_);
|
raw6 = adc1_get_raw(channel1_);
|
||||||
if (raw6 < ADC_MAX) {
|
if (raw6 < ADC_MAX) {
|
||||||
@@ -201,9 +201,9 @@ float ADCSensor::sample() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else if (channel2_ != ADC2_CHANNEL_MAX) {
|
} else if (channel2_ != ADC2_CHANNEL_MAX) {
|
||||||
adc2_config_channel_atten(channel2_, ADC_ATTEN_DB_11);
|
adc2_config_channel_atten(channel2_, ADC_ATTEN_DB_12_COMPAT);
|
||||||
adc2_get_raw(channel2_, ADC_WIDTH_MAX_SOC_BITS, &raw11);
|
adc2_get_raw(channel2_, ADC_WIDTH_MAX_SOC_BITS, &raw12);
|
||||||
if (raw11 < ADC_MAX) {
|
if (raw12 < ADC_MAX) {
|
||||||
adc2_config_channel_atten(channel2_, ADC_ATTEN_DB_6);
|
adc2_config_channel_atten(channel2_, ADC_ATTEN_DB_6);
|
||||||
adc2_get_raw(channel2_, ADC_WIDTH_MAX_SOC_BITS, &raw6);
|
adc2_get_raw(channel2_, ADC_WIDTH_MAX_SOC_BITS, &raw6);
|
||||||
if (raw6 < ADC_MAX) {
|
if (raw6 < ADC_MAX) {
|
||||||
@@ -217,25 +217,25 @@ float ADCSensor::sample() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (raw0 == -1 || raw2 == -1 || raw6 == -1 || raw11 == -1) {
|
if (raw0 == -1 || raw2 == -1 || raw6 == -1 || raw12 == -1) {
|
||||||
return NAN;
|
return NAN;
|
||||||
}
|
}
|
||||||
|
|
||||||
uint32_t mv11 = esp_adc_cal_raw_to_voltage(raw11, &cal_characteristics_[(int32_t) ADC_ATTEN_DB_11]);
|
uint32_t mv12 = esp_adc_cal_raw_to_voltage(raw12, &cal_characteristics_[(int32_t) ADC_ATTEN_DB_12_COMPAT]);
|
||||||
uint32_t mv6 = esp_adc_cal_raw_to_voltage(raw6, &cal_characteristics_[(int32_t) ADC_ATTEN_DB_6]);
|
uint32_t mv6 = esp_adc_cal_raw_to_voltage(raw6, &cal_characteristics_[(int32_t) ADC_ATTEN_DB_6]);
|
||||||
uint32_t mv2 = esp_adc_cal_raw_to_voltage(raw2, &cal_characteristics_[(int32_t) ADC_ATTEN_DB_2_5]);
|
uint32_t mv2 = esp_adc_cal_raw_to_voltage(raw2, &cal_characteristics_[(int32_t) ADC_ATTEN_DB_2_5]);
|
||||||
uint32_t mv0 = esp_adc_cal_raw_to_voltage(raw0, &cal_characteristics_[(int32_t) ADC_ATTEN_DB_0]);
|
uint32_t mv0 = esp_adc_cal_raw_to_voltage(raw0, &cal_characteristics_[(int32_t) ADC_ATTEN_DB_0]);
|
||||||
|
|
||||||
// Contribution of each value, in range 0-2048 (12 bit ADC) or 0-4096 (13 bit ADC)
|
// Contribution of each value, in range 0-2048 (12 bit ADC) or 0-4096 (13 bit ADC)
|
||||||
uint32_t c11 = std::min(raw11, ADC_HALF);
|
uint32_t c12 = std::min(raw12, ADC_HALF);
|
||||||
uint32_t c6 = ADC_HALF - std::abs(raw6 - ADC_HALF);
|
uint32_t c6 = ADC_HALF - std::abs(raw6 - ADC_HALF);
|
||||||
uint32_t c2 = ADC_HALF - std::abs(raw2 - ADC_HALF);
|
uint32_t c2 = ADC_HALF - std::abs(raw2 - ADC_HALF);
|
||||||
uint32_t c0 = std::min(ADC_MAX - raw0, ADC_HALF);
|
uint32_t c0 = std::min(ADC_MAX - raw0, ADC_HALF);
|
||||||
// max theoretical csum value is 4096*4 = 16384
|
// max theoretical csum value is 4096*4 = 16384
|
||||||
uint32_t csum = c11 + c6 + c2 + c0;
|
uint32_t csum = c12 + c6 + c2 + c0;
|
||||||
|
|
||||||
// each mv is max 3900; so max value is 3900*4096*4, fits in unsigned32
|
// each mv is max 3900; so max value is 3900*4096*4, fits in unsigned32
|
||||||
uint32_t mv_scaled = (mv11 * c11) + (mv6 * c6) + (mv2 * c2) + (mv0 * c0);
|
uint32_t mv_scaled = (mv12 * c12) + (mv6 * c6) + (mv2 * c2) + (mv0 * c0);
|
||||||
return mv_scaled / (float) (csum * 1000U);
|
return mv_scaled / (float) (csum * 1000U);
|
||||||
}
|
}
|
||||||
#endif // USE_ESP32
|
#endif // USE_ESP32
|
||||||
|
|||||||
@@ -1,19 +1,34 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "esphome/core/component.h"
|
|
||||||
#include "esphome/core/hal.h"
|
|
||||||
#include "esphome/core/defines.h"
|
|
||||||
#include "esphome/components/sensor/sensor.h"
|
#include "esphome/components/sensor/sensor.h"
|
||||||
#include "esphome/components/voltage_sampler/voltage_sampler.h"
|
#include "esphome/components/voltage_sampler/voltage_sampler.h"
|
||||||
|
#include "esphome/core/component.h"
|
||||||
|
#include "esphome/core/defines.h"
|
||||||
|
#include "esphome/core/hal.h"
|
||||||
|
|
||||||
#ifdef USE_ESP32
|
#ifdef USE_ESP32
|
||||||
#include "driver/adc.h"
|
|
||||||
#include <esp_adc_cal.h>
|
#include <esp_adc_cal.h>
|
||||||
|
#include "driver/adc.h"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
namespace esphome {
|
namespace esphome {
|
||||||
namespace adc {
|
namespace adc {
|
||||||
|
|
||||||
|
#ifdef USE_ESP32
|
||||||
|
// clang-format off
|
||||||
|
#if (ESP_IDF_VERSION_MAJOR == 4 && ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(4, 4, 7)) || \
|
||||||
|
(ESP_IDF_VERSION_MAJOR == 5 && \
|
||||||
|
((ESP_IDF_VERSION_MINOR == 0 && ESP_IDF_VERSION_PATCH >= 5) || \
|
||||||
|
(ESP_IDF_VERSION_MINOR == 1 && ESP_IDF_VERSION_PATCH >= 3) || \
|
||||||
|
(ESP_IDF_VERSION_MINOR >= 2)) \
|
||||||
|
)
|
||||||
|
// clang-format on
|
||||||
|
static const adc_atten_t ADC_ATTEN_DB_12_COMPAT = ADC_ATTEN_DB_12;
|
||||||
|
#else
|
||||||
|
static const adc_atten_t ADC_ATTEN_DB_12_COMPAT = ADC_ATTEN_DB_11;
|
||||||
|
#endif
|
||||||
|
#endif // USE_ESP32
|
||||||
|
|
||||||
class ADCSensor : public sensor::Sensor, public PollingComponent, public voltage_sampler::VoltageSampler {
|
class ADCSensor : public sensor::Sensor, public PollingComponent, public voltage_sampler::VoltageSampler {
|
||||||
public:
|
public:
|
||||||
#ifdef USE_ESP32
|
#ifdef USE_ESP32
|
||||||
|
|||||||
@@ -1,3 +1,5 @@
|
|||||||
|
import logging
|
||||||
|
|
||||||
import esphome.codegen as cg
|
import esphome.codegen as cg
|
||||||
import esphome.config_validation as cv
|
import esphome.config_validation as cv
|
||||||
import esphome.final_validate as fv
|
import esphome.final_validate as fv
|
||||||
@@ -19,16 +21,29 @@ from . import (
|
|||||||
ATTENUATION_MODES,
|
ATTENUATION_MODES,
|
||||||
ESP32_VARIANT_ADC1_PIN_TO_CHANNEL,
|
ESP32_VARIANT_ADC1_PIN_TO_CHANNEL,
|
||||||
ESP32_VARIANT_ADC2_PIN_TO_CHANNEL,
|
ESP32_VARIANT_ADC2_PIN_TO_CHANNEL,
|
||||||
|
adc_ns,
|
||||||
validate_adc_pin,
|
validate_adc_pin,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
_LOGGER = logging.getLogger(__name__)
|
||||||
|
|
||||||
AUTO_LOAD = ["voltage_sampler"]
|
AUTO_LOAD = ["voltage_sampler"]
|
||||||
|
|
||||||
|
|
||||||
|
_attenuation = cv.enum(ATTENUATION_MODES, lower=True)
|
||||||
|
|
||||||
|
|
||||||
def validate_config(config):
|
def validate_config(config):
|
||||||
if config[CONF_RAW] and config.get(CONF_ATTENUATION, None) == "auto":
|
if config[CONF_RAW] and config.get(CONF_ATTENUATION, None) == "auto":
|
||||||
raise cv.Invalid("Automatic attenuation cannot be used when raw output is set")
|
raise cv.Invalid("Automatic attenuation cannot be used when raw output is set")
|
||||||
|
|
||||||
|
if config.get(CONF_ATTENUATION) == "11db":
|
||||||
|
_LOGGER.warning(
|
||||||
|
"`attenuation: 11db` is deprecated, use `attenuation: 12db` instead"
|
||||||
|
)
|
||||||
|
# Alter value here so `config` command prints the recommended change
|
||||||
|
config[CONF_ATTENUATION] = _attenuation("12db")
|
||||||
|
|
||||||
return config
|
return config
|
||||||
|
|
||||||
|
|
||||||
@@ -47,7 +62,6 @@ def final_validate_config(config):
|
|||||||
return config
|
return config
|
||||||
|
|
||||||
|
|
||||||
adc_ns = cg.esphome_ns.namespace("adc")
|
|
||||||
ADCSensor = adc_ns.class_(
|
ADCSensor = adc_ns.class_(
|
||||||
"ADCSensor", sensor.Sensor, cg.PollingComponent, voltage_sampler.VoltageSampler
|
"ADCSensor", sensor.Sensor, cg.PollingComponent, voltage_sampler.VoltageSampler
|
||||||
)
|
)
|
||||||
@@ -65,7 +79,7 @@ CONFIG_SCHEMA = cv.All(
|
|||||||
cv.Required(CONF_PIN): validate_adc_pin,
|
cv.Required(CONF_PIN): validate_adc_pin,
|
||||||
cv.Optional(CONF_RAW, default=False): cv.boolean,
|
cv.Optional(CONF_RAW, default=False): cv.boolean,
|
||||||
cv.SplitDefault(CONF_ATTENUATION, esp32="0db"): cv.All(
|
cv.SplitDefault(CONF_ATTENUATION, esp32="0db"): cv.All(
|
||||||
cv.only_on_esp32, cv.enum(ATTENUATION_MODES, lower=True)
|
cv.only_on_esp32, _attenuation
|
||||||
),
|
),
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -1147,6 +1147,9 @@ message MediaPlayerCommandRequest {
|
|||||||
|
|
||||||
bool has_media_url = 6;
|
bool has_media_url = 6;
|
||||||
string media_url = 7;
|
string media_url = 7;
|
||||||
|
|
||||||
|
bool has_announcement = 8;
|
||||||
|
bool announcement = 9;
|
||||||
}
|
}
|
||||||
|
|
||||||
// ==================== BLUETOOTH ====================
|
// ==================== BLUETOOTH ====================
|
||||||
|
|||||||
@@ -1002,7 +1002,11 @@ bool APIConnection::send_media_player_state(media_player::MediaPlayer *media_pla
|
|||||||
|
|
||||||
MediaPlayerStateResponse resp{};
|
MediaPlayerStateResponse resp{};
|
||||||
resp.key = media_player->get_object_id_hash();
|
resp.key = media_player->get_object_id_hash();
|
||||||
resp.state = static_cast<enums::MediaPlayerState>(media_player->state);
|
|
||||||
|
media_player::MediaPlayerState report_state = media_player->state == media_player::MEDIA_PLAYER_STATE_ANNOUNCING
|
||||||
|
? media_player::MEDIA_PLAYER_STATE_PLAYING
|
||||||
|
: media_player->state;
|
||||||
|
resp.state = static_cast<enums::MediaPlayerState>(report_state);
|
||||||
resp.volume = media_player->volume;
|
resp.volume = media_player->volume;
|
||||||
resp.muted = media_player->is_muted();
|
resp.muted = media_player->is_muted();
|
||||||
return this->send_media_player_state_response(resp);
|
return this->send_media_player_state_response(resp);
|
||||||
@@ -1038,6 +1042,9 @@ void APIConnection::media_player_command(const MediaPlayerCommandRequest &msg) {
|
|||||||
if (msg.has_media_url) {
|
if (msg.has_media_url) {
|
||||||
call.set_media_url(msg.media_url);
|
call.set_media_url(msg.media_url);
|
||||||
}
|
}
|
||||||
|
if (msg.has_announcement) {
|
||||||
|
call.set_announcement(msg.announcement);
|
||||||
|
}
|
||||||
call.perform();
|
call.perform();
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -5253,6 +5253,14 @@ bool MediaPlayerCommandRequest::decode_varint(uint32_t field_id, ProtoVarInt val
|
|||||||
this->has_media_url = value.as_bool();
|
this->has_media_url = value.as_bool();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
case 8: {
|
||||||
|
this->has_announcement = value.as_bool();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
case 9: {
|
||||||
|
this->announcement = value.as_bool();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
default:
|
default:
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@@ -5289,6 +5297,8 @@ void MediaPlayerCommandRequest::encode(ProtoWriteBuffer buffer) const {
|
|||||||
buffer.encode_float(5, this->volume);
|
buffer.encode_float(5, this->volume);
|
||||||
buffer.encode_bool(6, this->has_media_url);
|
buffer.encode_bool(6, this->has_media_url);
|
||||||
buffer.encode_string(7, this->media_url);
|
buffer.encode_string(7, this->media_url);
|
||||||
|
buffer.encode_bool(8, this->has_announcement);
|
||||||
|
buffer.encode_bool(9, this->announcement);
|
||||||
}
|
}
|
||||||
#ifdef HAS_PROTO_MESSAGE_DUMP
|
#ifdef HAS_PROTO_MESSAGE_DUMP
|
||||||
void MediaPlayerCommandRequest::dump_to(std::string &out) const {
|
void MediaPlayerCommandRequest::dump_to(std::string &out) const {
|
||||||
@@ -5323,6 +5333,14 @@ void MediaPlayerCommandRequest::dump_to(std::string &out) const {
|
|||||||
out.append(" media_url: ");
|
out.append(" media_url: ");
|
||||||
out.append("'").append(this->media_url).append("'");
|
out.append("'").append(this->media_url).append("'");
|
||||||
out.append("\n");
|
out.append("\n");
|
||||||
|
|
||||||
|
out.append(" has_announcement: ");
|
||||||
|
out.append(YESNO(this->has_announcement));
|
||||||
|
out.append("\n");
|
||||||
|
|
||||||
|
out.append(" announcement: ");
|
||||||
|
out.append(YESNO(this->announcement));
|
||||||
|
out.append("\n");
|
||||||
out.append("}");
|
out.append("}");
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -1298,6 +1298,8 @@ class MediaPlayerCommandRequest : public ProtoMessage {
|
|||||||
float volume{0.0f};
|
float volume{0.0f};
|
||||||
bool has_media_url{false};
|
bool has_media_url{false};
|
||||||
std::string media_url{};
|
std::string media_url{};
|
||||||
|
bool has_announcement{false};
|
||||||
|
bool announcement{false};
|
||||||
void encode(ProtoWriteBuffer buffer) const override;
|
void encode(ProtoWriteBuffer buffer) const override;
|
||||||
#ifdef HAS_PROTO_MESSAGE_DUMP
|
#ifdef HAS_PROTO_MESSAGE_DUMP
|
||||||
void dump_to(std::string &out) const override;
|
void dump_to(std::string &out) const override;
|
||||||
|
|||||||
@@ -10,6 +10,11 @@ namespace i2s_audio {
|
|||||||
static const char *const TAG = "audio";
|
static const char *const TAG = "audio";
|
||||||
|
|
||||||
void I2SAudioMediaPlayer::control(const media_player::MediaPlayerCall &call) {
|
void I2SAudioMediaPlayer::control(const media_player::MediaPlayerCall &call) {
|
||||||
|
media_player::MediaPlayerState play_state = media_player::MEDIA_PLAYER_STATE_PLAYING;
|
||||||
|
if (call.get_announcement().has_value()) {
|
||||||
|
play_state = call.get_announcement().value() ? media_player::MEDIA_PLAYER_STATE_ANNOUNCING
|
||||||
|
: media_player::MEDIA_PLAYER_STATE_PLAYING;
|
||||||
|
}
|
||||||
if (call.get_media_url().has_value()) {
|
if (call.get_media_url().has_value()) {
|
||||||
this->current_url_ = call.get_media_url();
|
this->current_url_ = call.get_media_url();
|
||||||
if (this->i2s_state_ != I2S_STATE_STOPPED && this->audio_ != nullptr) {
|
if (this->i2s_state_ != I2S_STATE_STOPPED && this->audio_ != nullptr) {
|
||||||
@@ -17,7 +22,7 @@ void I2SAudioMediaPlayer::control(const media_player::MediaPlayerCall &call) {
|
|||||||
this->audio_->stopSong();
|
this->audio_->stopSong();
|
||||||
}
|
}
|
||||||
this->audio_->connecttohost(this->current_url_.value().c_str());
|
this->audio_->connecttohost(this->current_url_.value().c_str());
|
||||||
this->state = media_player::MEDIA_PLAYER_STATE_PLAYING;
|
this->state = play_state;
|
||||||
} else {
|
} else {
|
||||||
this->start();
|
this->start();
|
||||||
}
|
}
|
||||||
@@ -35,7 +40,7 @@ void I2SAudioMediaPlayer::control(const media_player::MediaPlayerCall &call) {
|
|||||||
case media_player::MEDIA_PLAYER_COMMAND_PLAY:
|
case media_player::MEDIA_PLAYER_COMMAND_PLAY:
|
||||||
if (!this->audio_->isRunning())
|
if (!this->audio_->isRunning())
|
||||||
this->audio_->pauseResume();
|
this->audio_->pauseResume();
|
||||||
this->state = media_player::MEDIA_PLAYER_STATE_PLAYING;
|
this->state = play_state;
|
||||||
break;
|
break;
|
||||||
case media_player::MEDIA_PLAYER_COMMAND_PAUSE:
|
case media_player::MEDIA_PLAYER_COMMAND_PAUSE:
|
||||||
if (this->audio_->isRunning())
|
if (this->audio_->isRunning())
|
||||||
@@ -126,7 +131,9 @@ void I2SAudioMediaPlayer::loop() {
|
|||||||
|
|
||||||
void I2SAudioMediaPlayer::play_() {
|
void I2SAudioMediaPlayer::play_() {
|
||||||
this->audio_->loop();
|
this->audio_->loop();
|
||||||
if (this->state == media_player::MEDIA_PLAYER_STATE_PLAYING && !this->audio_->isRunning()) {
|
if ((this->state == media_player::MEDIA_PLAYER_STATE_PLAYING ||
|
||||||
|
this->state == media_player::MEDIA_PLAYER_STATE_ANNOUNCING) &&
|
||||||
|
!this->audio_->isRunning()) {
|
||||||
this->stop();
|
this->stop();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -164,6 +171,10 @@ void I2SAudioMediaPlayer::start_() {
|
|||||||
if (this->current_url_.has_value()) {
|
if (this->current_url_.has_value()) {
|
||||||
this->audio_->connecttohost(this->current_url_.value().c_str());
|
this->audio_->connecttohost(this->current_url_.value().c_str());
|
||||||
this->state = media_player::MEDIA_PLAYER_STATE_PLAYING;
|
this->state = media_player::MEDIA_PLAYER_STATE_PLAYING;
|
||||||
|
if (this->is_announcement_.has_value()) {
|
||||||
|
this->state = this->is_announcement_.value() ? media_player::MEDIA_PLAYER_STATE_ANNOUNCING
|
||||||
|
: media_player::MEDIA_PLAYER_STATE_PLAYING;
|
||||||
|
}
|
||||||
this->publish_state();
|
this->publish_state();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -78,6 +78,7 @@ class I2SAudioMediaPlayer : public Component, public media_player::MediaPlayer,
|
|||||||
HighFrequencyLoopRequester high_freq_;
|
HighFrequencyLoopRequester high_freq_;
|
||||||
|
|
||||||
optional<std::string> current_url_{};
|
optional<std::string> current_url_{};
|
||||||
|
optional<bool> is_announcement_{};
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace i2s_audio
|
} // namespace i2s_audio
|
||||||
|
|||||||
@@ -8,6 +8,9 @@ namespace ltr390 {
|
|||||||
|
|
||||||
static const char *const TAG = "ltr390";
|
static const char *const TAG = "ltr390";
|
||||||
|
|
||||||
|
static const uint8_t LTR390_WAKEUP_TIME = 10;
|
||||||
|
static const uint8_t LTR390_SETTLE_TIME = 5;
|
||||||
|
|
||||||
static const uint8_t LTR390_MAIN_CTRL = 0x00;
|
static const uint8_t LTR390_MAIN_CTRL = 0x00;
|
||||||
static const uint8_t LTR390_MEAS_RATE = 0x04;
|
static const uint8_t LTR390_MEAS_RATE = 0x04;
|
||||||
static const uint8_t LTR390_GAIN = 0x05;
|
static const uint8_t LTR390_GAIN = 0x05;
|
||||||
@@ -101,10 +104,12 @@ void LTR390Component::read_mode_(int mode_index) {
|
|||||||
|
|
||||||
std::bitset<8> ctrl = this->reg(LTR390_MAIN_CTRL).get();
|
std::bitset<8> ctrl = this->reg(LTR390_MAIN_CTRL).get();
|
||||||
ctrl[LTR390_CTRL_MODE] = mode;
|
ctrl[LTR390_CTRL_MODE] = mode;
|
||||||
|
ctrl[LTR390_CTRL_EN] = true;
|
||||||
this->reg(LTR390_MAIN_CTRL) = ctrl.to_ulong();
|
this->reg(LTR390_MAIN_CTRL) = ctrl.to_ulong();
|
||||||
|
|
||||||
// After the sensor integration time do the following
|
// After the sensor integration time do the following
|
||||||
this->set_timeout(((uint32_t) RESOLUTIONVALUE[this->res_]) * 100, [this, mode_index]() {
|
this->set_timeout(((uint32_t) RESOLUTIONVALUE[this->res_]) * 100 + LTR390_WAKEUP_TIME + LTR390_SETTLE_TIME,
|
||||||
|
[this, mode_index]() {
|
||||||
// Read from the sensor
|
// Read from the sensor
|
||||||
std::get<1>(this->mode_funcs_[mode_index])();
|
std::get<1>(this->mode_funcs_[mode_index])();
|
||||||
|
|
||||||
@@ -113,6 +118,10 @@ void LTR390Component::read_mode_(int mode_index) {
|
|||||||
if (mode_index + 1 < (int) this->mode_funcs_.size()) {
|
if (mode_index + 1 < (int) this->mode_funcs_.size()) {
|
||||||
this->read_mode_(mode_index + 1);
|
this->read_mode_(mode_index + 1);
|
||||||
} else {
|
} else {
|
||||||
|
// put sensor in standby
|
||||||
|
std::bitset<8> ctrl = this->reg(LTR390_MAIN_CTRL).get();
|
||||||
|
ctrl[LTR390_CTRL_EN] = false;
|
||||||
|
this->reg(LTR390_MAIN_CTRL) = ctrl.to_ulong();
|
||||||
this->reading_ = false;
|
this->reading_ = false;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -51,12 +51,16 @@ VolumeSetAction = media_player_ns.class_(
|
|||||||
|
|
||||||
CONF_ON_PLAY = "on_play"
|
CONF_ON_PLAY = "on_play"
|
||||||
CONF_ON_PAUSE = "on_pause"
|
CONF_ON_PAUSE = "on_pause"
|
||||||
|
CONF_ON_ANNOUNCEMENT = "on_announcement"
|
||||||
CONF_MEDIA_URL = "media_url"
|
CONF_MEDIA_URL = "media_url"
|
||||||
|
|
||||||
StateTrigger = media_player_ns.class_("StateTrigger", automation.Trigger.template())
|
StateTrigger = media_player_ns.class_("StateTrigger", automation.Trigger.template())
|
||||||
IdleTrigger = media_player_ns.class_("IdleTrigger", automation.Trigger.template())
|
IdleTrigger = media_player_ns.class_("IdleTrigger", automation.Trigger.template())
|
||||||
PlayTrigger = media_player_ns.class_("PlayTrigger", automation.Trigger.template())
|
PlayTrigger = media_player_ns.class_("PlayTrigger", automation.Trigger.template())
|
||||||
PauseTrigger = media_player_ns.class_("PauseTrigger", automation.Trigger.template())
|
PauseTrigger = media_player_ns.class_("PauseTrigger", automation.Trigger.template())
|
||||||
|
AnnoucementTrigger = media_player_ns.class_(
|
||||||
|
"AnnouncementTrigger", automation.Trigger.template()
|
||||||
|
)
|
||||||
IsIdleCondition = media_player_ns.class_("IsIdleCondition", automation.Condition)
|
IsIdleCondition = media_player_ns.class_("IsIdleCondition", automation.Condition)
|
||||||
IsPlayingCondition = media_player_ns.class_("IsPlayingCondition", automation.Condition)
|
IsPlayingCondition = media_player_ns.class_("IsPlayingCondition", automation.Condition)
|
||||||
|
|
||||||
@@ -75,6 +79,9 @@ async def setup_media_player_core_(var, config):
|
|||||||
for conf in config.get(CONF_ON_PAUSE, []):
|
for conf in config.get(CONF_ON_PAUSE, []):
|
||||||
trigger = cg.new_Pvariable(conf[CONF_TRIGGER_ID], var)
|
trigger = cg.new_Pvariable(conf[CONF_TRIGGER_ID], var)
|
||||||
await automation.build_automation(trigger, [], conf)
|
await automation.build_automation(trigger, [], conf)
|
||||||
|
for conf in config.get(CONF_ON_ANNOUNCEMENT, []):
|
||||||
|
trigger = cg.new_Pvariable(conf[CONF_TRIGGER_ID], var)
|
||||||
|
await automation.build_automation(trigger, [], conf)
|
||||||
|
|
||||||
|
|
||||||
async def register_media_player(var, config):
|
async def register_media_player(var, config):
|
||||||
@@ -106,6 +113,11 @@ MEDIA_PLAYER_SCHEMA = cv.ENTITY_BASE_SCHEMA.extend(
|
|||||||
cv.GenerateID(CONF_TRIGGER_ID): cv.declare_id(PauseTrigger),
|
cv.GenerateID(CONF_TRIGGER_ID): cv.declare_id(PauseTrigger),
|
||||||
}
|
}
|
||||||
),
|
),
|
||||||
|
cv.Optional(CONF_ON_ANNOUNCEMENT): automation.validate_automation(
|
||||||
|
{
|
||||||
|
cv.GenerateID(CONF_TRIGGER_ID): cv.declare_id(AnnoucementTrigger),
|
||||||
|
}
|
||||||
|
),
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|||||||
@@ -52,6 +52,7 @@ class StateTrigger : public Trigger<> {
|
|||||||
MEDIA_PLAYER_SIMPLE_STATE_TRIGGER(IdleTrigger, IDLE)
|
MEDIA_PLAYER_SIMPLE_STATE_TRIGGER(IdleTrigger, IDLE)
|
||||||
MEDIA_PLAYER_SIMPLE_STATE_TRIGGER(PlayTrigger, PLAYING)
|
MEDIA_PLAYER_SIMPLE_STATE_TRIGGER(PlayTrigger, PLAYING)
|
||||||
MEDIA_PLAYER_SIMPLE_STATE_TRIGGER(PauseTrigger, PAUSED)
|
MEDIA_PLAYER_SIMPLE_STATE_TRIGGER(PauseTrigger, PAUSED)
|
||||||
|
MEDIA_PLAYER_SIMPLE_STATE_TRIGGER(AnnouncementTrigger, ANNOUNCING)
|
||||||
|
|
||||||
template<typename... Ts> class IsIdleCondition : public Condition<Ts...>, public Parented<MediaPlayer> {
|
template<typename... Ts> class IsIdleCondition : public Condition<Ts...>, public Parented<MediaPlayer> {
|
||||||
public:
|
public:
|
||||||
|
|||||||
@@ -15,6 +15,8 @@ const char *media_player_state_to_string(MediaPlayerState state) {
|
|||||||
return "PLAYING";
|
return "PLAYING";
|
||||||
case MEDIA_PLAYER_STATE_PAUSED:
|
case MEDIA_PLAYER_STATE_PAUSED:
|
||||||
return "PAUSED";
|
return "PAUSED";
|
||||||
|
case MEDIA_PLAYER_STATE_ANNOUNCING:
|
||||||
|
return "ANNOUNCING";
|
||||||
case MEDIA_PLAYER_STATE_NONE:
|
case MEDIA_PLAYER_STATE_NONE:
|
||||||
default:
|
default:
|
||||||
return "UNKNOWN";
|
return "UNKNOWN";
|
||||||
@@ -68,6 +70,9 @@ void MediaPlayerCall::perform() {
|
|||||||
if (this->volume_.has_value()) {
|
if (this->volume_.has_value()) {
|
||||||
ESP_LOGD(TAG, " Volume: %.2f", this->volume_.value());
|
ESP_LOGD(TAG, " Volume: %.2f", this->volume_.value());
|
||||||
}
|
}
|
||||||
|
if (this->announcement_.has_value()) {
|
||||||
|
ESP_LOGD(TAG, " Announcement: %s", this->announcement_.value() ? "yes" : "no");
|
||||||
|
}
|
||||||
this->parent_->control(*this);
|
this->parent_->control(*this);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -108,6 +113,11 @@ MediaPlayerCall &MediaPlayerCall::set_volume(float volume) {
|
|||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
MediaPlayerCall &MediaPlayerCall::set_announcement(bool announce) {
|
||||||
|
this->announcement_ = announce;
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
void MediaPlayer::add_on_state_callback(std::function<void()> &&callback) {
|
void MediaPlayer::add_on_state_callback(std::function<void()> &&callback) {
|
||||||
this->state_callback_.add(std::move(callback));
|
this->state_callback_.add(std::move(callback));
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -10,7 +10,8 @@ enum MediaPlayerState : uint8_t {
|
|||||||
MEDIA_PLAYER_STATE_NONE = 0,
|
MEDIA_PLAYER_STATE_NONE = 0,
|
||||||
MEDIA_PLAYER_STATE_IDLE = 1,
|
MEDIA_PLAYER_STATE_IDLE = 1,
|
||||||
MEDIA_PLAYER_STATE_PLAYING = 2,
|
MEDIA_PLAYER_STATE_PLAYING = 2,
|
||||||
MEDIA_PLAYER_STATE_PAUSED = 3
|
MEDIA_PLAYER_STATE_PAUSED = 3,
|
||||||
|
MEDIA_PLAYER_STATE_ANNOUNCING = 4
|
||||||
};
|
};
|
||||||
const char *media_player_state_to_string(MediaPlayerState state);
|
const char *media_player_state_to_string(MediaPlayerState state);
|
||||||
|
|
||||||
@@ -51,12 +52,14 @@ class MediaPlayerCall {
|
|||||||
MediaPlayerCall &set_media_url(const std::string &url);
|
MediaPlayerCall &set_media_url(const std::string &url);
|
||||||
|
|
||||||
MediaPlayerCall &set_volume(float volume);
|
MediaPlayerCall &set_volume(float volume);
|
||||||
|
MediaPlayerCall &set_announcement(bool announce);
|
||||||
|
|
||||||
void perform();
|
void perform();
|
||||||
|
|
||||||
const optional<MediaPlayerCommand> &get_command() const { return command_; }
|
const optional<MediaPlayerCommand> &get_command() const { return command_; }
|
||||||
const optional<std::string> &get_media_url() const { return media_url_; }
|
const optional<std::string> &get_media_url() const { return media_url_; }
|
||||||
const optional<float> &get_volume() const { return volume_; }
|
const optional<float> &get_volume() const { return volume_; }
|
||||||
|
const optional<bool> &get_announcement() const { return announcement_; }
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
void validate_();
|
void validate_();
|
||||||
@@ -64,6 +67,7 @@ class MediaPlayerCall {
|
|||||||
optional<MediaPlayerCommand> command_;
|
optional<MediaPlayerCommand> command_;
|
||||||
optional<std::string> media_url_;
|
optional<std::string> media_url_;
|
||||||
optional<float> volume_;
|
optional<float> volume_;
|
||||||
|
optional<bool> announcement_;
|
||||||
};
|
};
|
||||||
|
|
||||||
class MediaPlayer : public EntityBase {
|
class MediaPlayer : public EntityBase {
|
||||||
|
|||||||
@@ -63,7 +63,13 @@ def validate_tolerance(value):
|
|||||||
if "%" in str(value):
|
if "%" in str(value):
|
||||||
type_ = TYPE_PERCENTAGE
|
type_ = TYPE_PERCENTAGE
|
||||||
else:
|
else:
|
||||||
|
try:
|
||||||
|
cv.positive_time_period_microseconds(value)
|
||||||
type_ = TYPE_TIME
|
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(
|
return TOLERANCE_SCHEMA(
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -14,6 +14,9 @@ from esphome.const import (
|
|||||||
CONF_STATE,
|
CONF_STATE,
|
||||||
CONF_STOP,
|
CONF_STOP,
|
||||||
CONF_TRIGGER_ID,
|
CONF_TRIGGER_ID,
|
||||||
|
DEVICE_CLASS_EMPTY,
|
||||||
|
DEVICE_CLASS_GAS,
|
||||||
|
DEVICE_CLASS_WATER,
|
||||||
)
|
)
|
||||||
from esphome.core import CORE, coroutine_with_priority
|
from esphome.core import CORE, coroutine_with_priority
|
||||||
from esphome.cpp_helpers import setup_entity
|
from esphome.cpp_helpers import setup_entity
|
||||||
@@ -22,6 +25,12 @@ IS_PLATFORM_COMPONENT = True
|
|||||||
|
|
||||||
CODEOWNERS = ["@esphome/core"]
|
CODEOWNERS = ["@esphome/core"]
|
||||||
|
|
||||||
|
DEVICE_CLASSES = [
|
||||||
|
DEVICE_CLASS_EMPTY,
|
||||||
|
DEVICE_CLASS_GAS,
|
||||||
|
DEVICE_CLASS_WATER,
|
||||||
|
]
|
||||||
|
|
||||||
valve_ns = cg.esphome_ns.namespace("valve")
|
valve_ns = cg.esphome_ns.namespace("valve")
|
||||||
|
|
||||||
Valve = valve_ns.class_("Valve", cg.EntityBase)
|
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.GenerateID(): cv.declare_id(Valve),
|
||||||
cv.OnlyWith(CONF_MQTT_ID, "mqtt"): cv.declare_id(mqtt.MQTTValveComponent),
|
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.Optional(CONF_POSITION_COMMAND_TOPIC): cv.All(
|
||||||
cv.requires_component("mqtt"), cv.subscribe_topic
|
cv.requires_component("mqtt"), cv.subscribe_topic
|
||||||
),
|
),
|
||||||
|
|||||||
@@ -71,6 +71,12 @@ void VoiceAssistant::setup() {
|
|||||||
ESP_LOGCONFIG(TAG, "Setting up Voice Assistant...");
|
ESP_LOGCONFIG(TAG, "Setting up Voice Assistant...");
|
||||||
|
|
||||||
global_voice_assistant = this;
|
global_voice_assistant = this;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool VoiceAssistant::allocate_buffers_() {
|
||||||
|
if (this->send_buffer_ != nullptr) {
|
||||||
|
return true; // Already allocated
|
||||||
|
}
|
||||||
|
|
||||||
#ifdef USE_SPEAKER
|
#ifdef USE_SPEAKER
|
||||||
if (this->speaker_ != nullptr) {
|
if (this->speaker_ != nullptr) {
|
||||||
@@ -78,8 +84,7 @@ void VoiceAssistant::setup() {
|
|||||||
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();
|
return false;
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
@@ -88,8 +93,7 @@ void VoiceAssistant::setup() {
|
|||||||
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();
|
return false;
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef USE_ESP_ADF
|
#ifdef USE_ESP_ADF
|
||||||
@@ -99,17 +103,71 @@ void VoiceAssistant::setup() {
|
|||||||
this->ring_buffer_ = RingBuffer::create(BUFFER_SIZE * sizeof(int16_t));
|
this->ring_buffer_ = RingBuffer::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();
|
return false;
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
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();
|
return false;
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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_() {
|
int VoiceAssistant::read_microphone_() {
|
||||||
@@ -138,21 +196,20 @@ void VoiceAssistant::loop() {
|
|||||||
}
|
}
|
||||||
this->continuous_ = false;
|
this->continuous_ = false;
|
||||||
this->signal_stop_();
|
this->signal_stop_();
|
||||||
|
this->clear_buffers_();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
switch (this->state_) {
|
switch (this->state_) {
|
||||||
case State::IDLE: {
|
case State::IDLE: {
|
||||||
if (this->continuous_ && this->desired_state_ == State::IDLE) {
|
if (this->continuous_ && this->desired_state_ == State::IDLE) {
|
||||||
this->idle_trigger_->trigger();
|
this->idle_trigger_->trigger();
|
||||||
|
|
||||||
this->ring_buffer_->reset();
|
|
||||||
#ifdef USE_ESP_ADF
|
#ifdef USE_ESP_ADF
|
||||||
if (this->use_wake_word_) {
|
if (this->use_wake_word_) {
|
||||||
this->set_state_(State::START_MICROPHONE, State::WAIT_FOR_VAD);
|
this->set_state_(State::START_MICROPHONE, State::WAIT_FOR_VAD);
|
||||||
} else
|
} else
|
||||||
#endif
|
#endif
|
||||||
{
|
{
|
||||||
this->set_state_(State::START_PIPELINE, State::START_MICROPHONE);
|
this->set_state_(State::START_MICROPHONE, State::START_PIPELINE);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
this->high_freq_.stop();
|
this->high_freq_.stop();
|
||||||
@@ -161,8 +218,15 @@ void VoiceAssistant::loop() {
|
|||||||
}
|
}
|
||||||
case State::START_MICROPHONE: {
|
case State::START_MICROPHONE: {
|
||||||
ESP_LOGD(TAG, "Starting Microphone");
|
ESP_LOGD(TAG, "Starting Microphone");
|
||||||
memset(this->send_buffer_, 0, SEND_BUFFER_SIZE);
|
if (!this->allocate_buffers_()) {
|
||||||
memset(this->input_buffer_, 0, INPUT_BUFFER_SIZE * sizeof(int16_t));
|
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->mic_->start();
|
||||||
this->high_freq_.start();
|
this->high_freq_.start();
|
||||||
this->set_state_(State::STARTING_MICROPHONE);
|
this->set_state_(State::STARTING_MICROPHONE);
|
||||||
@@ -318,7 +382,7 @@ void VoiceAssistant::loop() {
|
|||||||
#endif
|
#endif
|
||||||
#ifdef USE_MEDIA_PLAYER
|
#ifdef USE_MEDIA_PLAYER
|
||||||
if (this->media_player_ != nullptr) {
|
if (this->media_player_ != nullptr) {
|
||||||
playing = (this->media_player_->state == media_player::MediaPlayerState::MEDIA_PLAYER_STATE_PLAYING);
|
playing = (this->media_player_->state == media_player::MediaPlayerState::MEDIA_PLAYER_STATE_ANNOUNCING);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
if (playing) {
|
if (playing) {
|
||||||
@@ -343,10 +407,9 @@ void VoiceAssistant::loop() {
|
|||||||
this->speaker_->stop();
|
this->speaker_->stop();
|
||||||
this->cancel_timeout("speaker-timeout");
|
this->cancel_timeout("speaker-timeout");
|
||||||
this->cancel_timeout("playing");
|
this->cancel_timeout("playing");
|
||||||
this->speaker_buffer_size_ = 0;
|
|
||||||
this->speaker_buffer_index_ = 0;
|
this->clear_buffers_();
|
||||||
this->speaker_bytes_received_ = 0;
|
|
||||||
memset(this->speaker_buffer_, 0, SPEAKER_BUFFER_SIZE);
|
|
||||||
this->wait_for_stream_end_ = false;
|
this->wait_for_stream_end_ = false;
|
||||||
this->stream_ended_ = false;
|
this->stream_ended_ = false;
|
||||||
|
|
||||||
@@ -507,14 +570,13 @@ void VoiceAssistant::request_start(bool continuous, bool silence_detection) {
|
|||||||
if (this->state_ == State::IDLE) {
|
if (this->state_ == State::IDLE) {
|
||||||
this->continuous_ = continuous;
|
this->continuous_ = continuous;
|
||||||
this->silence_detection_ = silence_detection;
|
this->silence_detection_ = silence_detection;
|
||||||
this->ring_buffer_->reset();
|
|
||||||
#ifdef USE_ESP_ADF
|
#ifdef USE_ESP_ADF
|
||||||
if (this->use_wake_word_) {
|
if (this->use_wake_word_) {
|
||||||
this->set_state_(State::START_MICROPHONE, State::WAIT_FOR_VAD);
|
this->set_state_(State::START_MICROPHONE, State::WAIT_FOR_VAD);
|
||||||
} else
|
} else
|
||||||
#endif
|
#endif
|
||||||
{
|
{
|
||||||
this->set_state_(State::START_PIPELINE, State::START_MICROPHONE);
|
this->set_state_(State::START_MICROPHONE, State::START_PIPELINE);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -640,7 +702,7 @@ void VoiceAssistant::on_event(const api::VoiceAssistantEventResponse &msg) {
|
|||||||
this->defer([this, url]() {
|
this->defer([this, url]() {
|
||||||
#ifdef USE_MEDIA_PLAYER
|
#ifdef USE_MEDIA_PLAYER
|
||||||
if (this->media_player_ != nullptr) {
|
if (this->media_player_ != nullptr) {
|
||||||
this->media_player_->make_call().set_media_url(url).perform();
|
this->media_player_->make_call().set_media_url(url).set_announcement(true).perform();
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
this->tts_end_trigger_->trigger(url);
|
this->tts_end_trigger_->trigger(url);
|
||||||
|
|||||||
@@ -94,10 +94,10 @@ class VoiceAssistant : public Component {
|
|||||||
uint32_t get_feature_flags() const {
|
uint32_t get_feature_flags() const {
|
||||||
uint32_t flags = 0;
|
uint32_t flags = 0;
|
||||||
flags |= VoiceAssistantFeature::FEATURE_VOICE_ASSISTANT;
|
flags |= VoiceAssistantFeature::FEATURE_VOICE_ASSISTANT;
|
||||||
|
flags |= VoiceAssistantFeature::FEATURE_API_AUDIO;
|
||||||
#ifdef USE_SPEAKER
|
#ifdef USE_SPEAKER
|
||||||
if (this->speaker_ != nullptr) {
|
if (this->speaker_ != nullptr) {
|
||||||
flags |= VoiceAssistantFeature::FEATURE_SPEAKER;
|
flags |= VoiceAssistantFeature::FEATURE_SPEAKER;
|
||||||
flags |= VoiceAssistantFeature::FEATURE_API_AUDIO;
|
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
return flags;
|
return flags;
|
||||||
@@ -151,6 +151,10 @@ class VoiceAssistant : public Component {
|
|||||||
void set_wake_word(const std::string &wake_word) { this->wake_word_ = wake_word; }
|
void set_wake_word(const std::string &wake_word) { this->wake_word_ = wake_word; }
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
bool allocate_buffers_();
|
||||||
|
void clear_buffers_();
|
||||||
|
void deallocate_buffers_();
|
||||||
|
|
||||||
int read_microphone_();
|
int read_microphone_();
|
||||||
void set_state_(State state);
|
void set_state_(State state);
|
||||||
void set_state_(State state, State desired_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."""
|
"""Constants used by esphome."""
|
||||||
|
|
||||||
__version__ = "2024.5.0b3"
|
__version__ = "2024.5.3"
|
||||||
|
|
||||||
ALLOWED_NAME_CHARS = "abcdefghijklmnopqrstuvwxyz0123456789-_"
|
ALLOWED_NAME_CHARS = "abcdefghijklmnopqrstuvwxyz0123456789-_"
|
||||||
VALID_SUBSTITUTIONS_CHARACTERS = (
|
VALID_SUBSTITUTIONS_CHARACTERS = (
|
||||||
|
|||||||
@@ -394,7 +394,7 @@ async def to_code(config):
|
|||||||
if project_conf := config.get(CONF_PROJECT):
|
if project_conf := config.get(CONF_PROJECT):
|
||||||
cg.add_define("ESPHOME_PROJECT_NAME", project_conf[CONF_NAME])
|
cg.add_define("ESPHOME_PROJECT_NAME", project_conf[CONF_NAME])
|
||||||
cg.add_define("ESPHOME_PROJECT_VERSION", project_conf[CONF_VERSION])
|
cg.add_define("ESPHOME_PROJECT_VERSION", project_conf[CONF_VERSION])
|
||||||
cg.add_define("ESPHOME_PROJECT_VERSION_30", project_conf[CONF_VERSION][:30])
|
cg.add_define("ESPHOME_PROJECT_VERSION_30", project_conf[CONF_VERSION][:29])
|
||||||
for conf in project_conf.get(CONF_ON_UPDATE, []):
|
for conf in project_conf.get(CONF_ON_UPDATE, []):
|
||||||
trigger = cg.new_Pvariable(conf[CONF_TRIGGER_ID])
|
trigger = cg.new_Pvariable(conf[CONF_TRIGGER_ID])
|
||||||
await cg.register_component(trigger, conf)
|
await cg.register_component(trigger, conf)
|
||||||
|
|||||||
@@ -103,7 +103,7 @@ class DashboardEntries:
|
|||||||
|
|
||||||
def all(self) -> list[DashboardEntry]:
|
def all(self) -> list[DashboardEntry]:
|
||||||
"""Return all entries."""
|
"""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]:
|
def async_all(self) -> list[DashboardEntry]:
|
||||||
"""Return all entries."""
|
"""Return all entries."""
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ tornado==6.4
|
|||||||
tzlocal==5.2 # from time
|
tzlocal==5.2 # from time
|
||||||
tzdata>=2021.1 # from time
|
tzdata>=2021.1 # from time
|
||||||
pyserial==3.5
|
pyserial==3.5
|
||||||
platformio==6.1.13 # When updating platformio, also update Dockerfile
|
platformio==6.1.15 # When updating platformio, also update Dockerfile
|
||||||
esptool==4.7.0
|
esptool==4.7.0
|
||||||
click==8.1.7
|
click==8.1.7
|
||||||
esphome-dashboard==20240412.0
|
esphome-dashboard==20240412.0
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ remote_receiver:
|
|||||||
pin: ${pin}
|
pin: ${pin}
|
||||||
rmt_channel: ${rmt_channel}
|
rmt_channel: ${rmt_channel}
|
||||||
dump: all
|
dump: all
|
||||||
|
tolerance: 25%
|
||||||
on_abbwelcome:
|
on_abbwelcome:
|
||||||
then:
|
then:
|
||||||
- logger.log:
|
- logger.log:
|
||||||
|
|||||||
Reference in New Issue
Block a user