Merge pull request #7297 from esphome/bump-2024.8.0b2

2024.8.0b2
This commit is contained in:
Jesse Hills 2024-08-17 08:07:54 +12:00 committed by GitHub
commit 28bb0ddfeb
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
19 changed files with 187 additions and 55 deletions

View File

@ -397,7 +397,7 @@ jobs:
file: ${{ fromJson(needs.list-components.outputs.components) }}
steps:
- name: Install dependencies
run: sudo apt-get install libsodium-dev libsdl2-dev
run: sudo apt-get install libsdl2-dev
- name: Check out code from GitHub
uses: actions/checkout@v4.1.7
@ -451,7 +451,7 @@ jobs:
run: echo ${{ matrix.components }}
- name: Install dependencies
run: sudo apt-get install libsodium-dev libsdl2-dev
run: sudo apt-get install libsdl2-dev
- name: Check out code from GitHub
uses: actions/checkout@v4.1.7

View File

@ -155,7 +155,7 @@ async def to_code(config):
decoded = base64.b64decode(encryption_config[CONF_KEY])
cg.add(var.set_noise_psk(list(decoded)))
cg.add_define("USE_API_NOISE")
cg.add_library("esphome/noise-c", "0.1.4")
cg.add_library("esphome/noise-c", "0.1.6")
else:
cg.add_define("USE_API_PLAINTEXT")

View File

@ -1,15 +1,14 @@
import esphome.codegen as cg
import esphome.config_validation as cv
from esphome.const import (
CONF_MAC_ADDRESS,
KEY_CORE,
KEY_FRAMEWORK_VERSION,
KEY_TARGET_FRAMEWORK,
KEY_TARGET_PLATFORM,
PLATFORM_HOST,
CONF_MAC_ADDRESS,
)
from esphome.core import CORE
from esphome.helpers import IS_MACOS
import esphome.config_validation as cv
import esphome.codegen as cg
from .const import KEY_HOST
@ -42,8 +41,5 @@ async def to_code(config):
cg.add_build_flag("-DUSE_HOST")
cg.add_define("USE_ESPHOME_HOST_MAC_ADDRESS", config[CONF_MAC_ADDRESS].parts)
cg.add_build_flag("-std=c++17")
cg.add_build_flag("-lsodium")
if IS_MACOS:
cg.add_build_flag("-L/opt/homebrew/lib")
cg.add_define("ESPHOME_BOARD", "host")
cg.add_platformio_option("platform", "platformio/native")

View File

@ -41,29 +41,29 @@ class ESPColorCorrection {
if (this->max_brightness_.red == 0 || this->local_brightness_ == 0)
return 0;
uint16_t uncorrected = this->gamma_reverse_table_[red] * 255UL;
uint8_t res = ((uncorrected / this->max_brightness_.red) * 255UL) / this->local_brightness_;
return res;
uint16_t res = ((uncorrected / this->max_brightness_.red) * 255UL) / this->local_brightness_;
return (uint8_t) std::min(res, uint16_t(255));
}
inline uint8_t color_uncorrect_green(uint8_t green) const ESPHOME_ALWAYS_INLINE {
if (this->max_brightness_.green == 0 || this->local_brightness_ == 0)
return 0;
uint16_t uncorrected = this->gamma_reverse_table_[green] * 255UL;
uint8_t res = ((uncorrected / this->max_brightness_.green) * 255UL) / this->local_brightness_;
return res;
uint16_t res = ((uncorrected / this->max_brightness_.green) * 255UL) / this->local_brightness_;
return (uint8_t) std::min(res, uint16_t(255));
}
inline uint8_t color_uncorrect_blue(uint8_t blue) const ESPHOME_ALWAYS_INLINE {
if (this->max_brightness_.blue == 0 || this->local_brightness_ == 0)
return 0;
uint16_t uncorrected = this->gamma_reverse_table_[blue] * 255UL;
uint8_t res = ((uncorrected / this->max_brightness_.blue) * 255UL) / this->local_brightness_;
return res;
uint16_t res = ((uncorrected / this->max_brightness_.blue) * 255UL) / this->local_brightness_;
return (uint8_t) std::min(res, uint16_t(255));
}
inline uint8_t color_uncorrect_white(uint8_t white) const ESPHOME_ALWAYS_INLINE {
if (this->max_brightness_.white == 0 || this->local_brightness_ == 0)
return 0;
uint16_t uncorrected = this->gamma_reverse_table_[white] * 255UL;
uint8_t res = ((uncorrected / this->max_brightness_.white) * 255UL) / this->local_brightness_;
return res;
uint16_t res = ((uncorrected / this->max_brightness_.white) * 255UL) / this->local_brightness_;
return (uint8_t) std::min(res, uint16_t(255));
}
protected:

View File

@ -24,7 +24,11 @@ CONFIG_SCHEMA = cv.Schema(
esp32=False,
rp2040=False,
): cv.All(
cv.boolean, cv.only_on([PLATFORM_ESP32, PLATFORM_ESP8266, PLATFORM_RP2040])
cv.boolean,
cv.Any(
cv.only_on([PLATFORM_ESP32, PLATFORM_ESP8266, PLATFORM_RP2040]),
cv.boolean_false,
),
),
cv.Optional(CONF_MIN_IPV6_ADDR_COUNT, default=0): cv.positive_int,
}

View File

@ -201,9 +201,6 @@ std::string ProntoProtocol::compensate_and_dump_sequence_(const RawTimings &data
out += dump_duration_(t_duration, timebase);
}
// append minimum gap
out += dump_duration_(PRONTO_DEFAULT_GAP, timebase, true);
return out;
}

View File

@ -29,6 +29,13 @@ inline double deg2rad(double degrees) {
void Rtttl::dump_config() { ESP_LOGCONFIG(TAG, "Rtttl"); }
void Rtttl::play(std::string rtttl) {
if (this->state_ != State::STATE_STOPPED && this->state_ != State::STATE_STOPPING) {
int pos = this->rtttl_.find(':');
auto name = this->rtttl_.substr(0, pos);
ESP_LOGW(TAG, "RTTL Component is already playing: %s", name.c_str());
return;
}
this->rtttl_ = std::move(rtttl);
this->default_duration_ = 4;
@ -98,13 +105,20 @@ void Rtttl::play(std::string rtttl) {
this->note_duration_ = 1;
#ifdef USE_SPEAKER
if (this->speaker_ != nullptr) {
this->set_state_(State::STATE_INIT);
this->samples_sent_ = 0;
this->samples_count_ = 0;
}
#endif
#ifdef USE_OUTPUT
if (this->output_ != nullptr) {
this->set_state_(State::STATE_RUNNING);
}
#endif
}
void Rtttl::stop() {
this->note_duration_ = 0;
#ifdef USE_OUTPUT
if (this->output_ != nullptr) {
this->output_->set_level(0.0);
@ -117,16 +131,35 @@ void Rtttl::stop() {
}
}
#endif
this->note_duration_ = 0;
this->set_state_(STATE_STOPPING);
}
void Rtttl::loop() {
if (this->note_duration_ == 0)
if (this->note_duration_ == 0 || this->state_ == State::STATE_STOPPED)
return;
#ifdef USE_SPEAKER
if (this->speaker_ != nullptr) {
if (this->state_ == State::STATE_STOPPING) {
if (this->speaker_->is_stopped()) {
this->set_state_(State::STATE_STOPPED);
}
} else if (this->state_ == State::STATE_INIT) {
if (this->speaker_->is_stopped()) {
this->speaker_->start();
this->set_state_(State::STATE_STARTING);
}
} else if (this->state_ == State::STATE_STARTING) {
if (this->speaker_->is_running()) {
this->set_state_(State::STATE_RUNNING);
}
}
if (!this->speaker_->is_running()) {
return;
}
if (this->samples_sent_ != this->samples_count_) {
SpeakerSample sample[SAMPLE_BUFFER_SIZE + 1];
SpeakerSample sample[SAMPLE_BUFFER_SIZE + 2];
int x = 0;
double rem = 0.0;
@ -136,7 +169,7 @@ void Rtttl::loop() {
if (this->samples_per_wave_ != 0 && this->samples_sent_ >= this->samples_gap_) { // Play note//
rem = ((this->samples_sent_ << 10) % this->samples_per_wave_) * (360.0 / this->samples_per_wave_);
int16_t val = (49152 * this->gain_) * sin(deg2rad(rem));
int16_t val = (127 * this->gain_) * sin(deg2rad(rem)); // 16bit = 49152
sample[x].left = val;
sample[x].right = val;
@ -153,9 +186,9 @@ void Rtttl::loop() {
x++;
}
if (x > 0) {
int send = this->speaker_->play((uint8_t *) (&sample), x * 4);
int send = this->speaker_->play((uint8_t *) (&sample), x * 2);
if (send != x * 4) {
this->samples_sent_ -= (x - (send / 4));
this->samples_sent_ -= (x - (send / 2));
}
return;
}
@ -167,14 +200,7 @@ void Rtttl::loop() {
return;
#endif
if (!this->rtttl_[position_]) {
this->note_duration_ = 0;
#ifdef USE_OUTPUT
if (this->output_ != nullptr) {
this->output_->set_level(0.0);
}
#endif
ESP_LOGD(TAG, "Playback finished");
this->on_finished_playback_callback_.call();
this->finish_();
return;
}
@ -213,6 +239,7 @@ void Rtttl::loop() {
case 'a':
note = 10;
break;
case 'h':
case 'b':
note = 12;
break;
@ -238,14 +265,21 @@ void Rtttl::loop() {
uint8_t scale = get_integer_();
if (scale == 0)
scale = this->default_octave_;
if (scale < 4 || scale > 7) {
ESP_LOGE(TAG, "Octave out of valid range. Should be between 4 and 7. (Octave: %d)", scale);
this->finish_();
return;
}
bool need_note_gap = false;
// Now play the note
if (note) {
auto note_index = (scale - 4) * 12 + note;
if (note_index < 0 || note_index >= (int) sizeof(NOTES)) {
ESP_LOGE(TAG, "Note out of valid range");
this->note_duration_ = 0;
ESP_LOGE(TAG, "Note out of valid range (note: %d, scale: %d, index: %d, max: %d)", note, scale, note_index,
(int) sizeof(NOTES));
this->finish_();
return;
}
auto freq = NOTES[note_index];
@ -285,14 +319,17 @@ void Rtttl::loop() {
this->samples_gap_ = (this->sample_rate_ * DOUBLE_NOTE_GAP_MS) / 1600; //(ms);
}
if (this->output_freq_ != 0) {
// make sure there is enough samples to add a full last sinus.
uint16_t samples_wish = this->samples_count_;
this->samples_per_wave_ = (this->sample_rate_ << 10) / this->output_freq_;
// make sure there is enough samples to add a full last sinus.
uint16_t division = ((this->samples_count_ << 10) / this->samples_per_wave_) + 1;
uint16_t x = this->samples_count_;
this->samples_count_ = (division * this->samples_per_wave_);
ESP_LOGD(TAG, "play time old: %d div: %d new: %d %d", x, division, this->samples_count_, this->samples_per_wave_);
this->samples_count_ = this->samples_count_ >> 10;
ESP_LOGVV(TAG, "- Calc play time: wish: %d gets: %d (div: %d spw: %d)", samples_wish, this->samples_count_,
division, this->samples_per_wave_);
}
// Convert from frequency in Hz to high and low samples in fixed point
}
@ -301,5 +338,53 @@ void Rtttl::loop() {
this->last_note_ = millis();
}
void Rtttl::finish_() {
#ifdef USE_OUTPUT
if (this->output_ != nullptr) {
this->output_->set_level(0.0);
}
#endif
#ifdef USE_SPEAKER
if (this->speaker_ != nullptr) {
SpeakerSample sample[2];
sample[0].left = 0;
sample[0].right = 0;
sample[1].left = 0;
sample[1].right = 0;
this->speaker_->play((uint8_t *) (&sample), 8);
this->speaker_->finish();
}
#endif
this->set_state_(State::STATE_STOPPING);
this->note_duration_ = 0;
this->on_finished_playback_callback_.call();
ESP_LOGD(TAG, "Playback finished");
}
static const LogString *state_to_string(State state) {
switch (state) {
case STATE_STOPPED:
return LOG_STR("STATE_STOPPED");
case STATE_STARTING:
return LOG_STR("STATE_STARTING");
case STATE_RUNNING:
return LOG_STR("STATE_RUNNING");
case STATE_STOPPING:
return LOG_STR("STATE_STOPPING");
case STATE_INIT:
return LOG_STR("STATE_INIT");
default:
return LOG_STR("UNKNOWN");
}
};
void Rtttl::set_state_(State state) {
State old_state = this->state_;
this->state_ = state;
ESP_LOGD(TAG, "State changed from %s to %s", LOG_STR_ARG(state_to_string(old_state)),
LOG_STR_ARG(state_to_string(state)));
}
} // namespace rtttl
} // namespace esphome

View File

@ -14,12 +14,20 @@
namespace esphome {
namespace rtttl {
enum State : uint8_t {
STATE_STOPPED = 0,
STATE_INIT,
STATE_STARTING,
STATE_RUNNING,
STATE_STOPPING,
};
#ifdef USE_SPEAKER
static const size_t SAMPLE_BUFFER_SIZE = 512;
static const size_t SAMPLE_BUFFER_SIZE = 2048;
struct SpeakerSample {
int16_t left{0};
int16_t right{0};
int8_t left{0};
int8_t right{0};
};
#endif
@ -42,7 +50,7 @@ class Rtttl : public Component {
void stop();
void dump_config() override;
bool is_playing() { return this->note_duration_ != 0; }
bool is_playing() { return this->state_ != State::STATE_STOPPED; }
void loop() override;
void add_on_finished_playback_callback(std::function<void()> callback) {
@ -57,6 +65,8 @@ class Rtttl : public Component {
}
return ret;
}
void finish_();
void set_state_(State state);
std::string rtttl_{""};
size_t position_{0};
@ -68,13 +78,12 @@ class Rtttl : public Component {
uint32_t output_freq_;
float gain_{0.6f};
State state_{State::STATE_STOPPED};
#ifdef USE_OUTPUT
output::FloatOutput *output_;
#endif
void play_output_();
#ifdef USE_SPEAKER
speaker::Speaker *speaker_{nullptr};
int sample_rate_{16000};

View File

@ -370,6 +370,20 @@ def boolean(value):
)
def boolean_false(value):
"""Validate the given config option to be a boolean, set to False.
This option allows a bunch of different ways of expressing boolean values:
- instance of boolean
- 'true'/'false'
- 'yes'/'no'
- 'enable'/disable
"""
if boolean(value):
raise Invalid("Expected boolean value to be false")
return False
@schema_extractor_list
def ensure_list(*validators):
"""Validate this configuration option to be a list.
@ -1850,7 +1864,7 @@ def maybe_simple_value(*validators, **kwargs):
if value == SCHEMA_EXTRACT:
return (validator, key)
if isinstance(value, dict) and key in value:
if isinstance(value, dict):
return validator(value)
return validator({key: value})

View File

@ -1,6 +1,6 @@
"""Constants used by esphome."""
__version__ = "2024.8.0b1"
__version__ = "2024.8.0b2"
ALLOWED_NAME_CHARS = "abcdefghijklmnopqrstuvwxyz0123456789-_"
VALID_SUBSTITUTIONS_CHARACTERS = (

View File

@ -11,10 +11,6 @@ esphome:
message: Button was pressed
- homeassistant.tag_scanned: pulse
wifi:
ssid: MySSID
password: password1
api:
port: 8000
password: pwd

View File

@ -1 +1,5 @@
<<: !include common.yaml
wifi:
ssid: MySSID
password: password1

View File

@ -1 +1,5 @@
<<: !include common.yaml
wifi:
ssid: MySSID
password: password1

View File

@ -1 +1,5 @@
<<: !include common.yaml
wifi:
ssid: MySSID
password: password1

View File

@ -1 +1,5 @@
<<: !include common.yaml
wifi:
ssid: MySSID
password: password1

View File

@ -1 +1,5 @@
<<: !include common.yaml
wifi:
ssid: MySSID
password: password1

View File

@ -0,0 +1,3 @@
<<: !include common.yaml
network:

View File

@ -1 +1,5 @@
<<: !include common.yaml
wifi:
ssid: MySSID
password: password1

View File

@ -0,0 +1,4 @@
substitutions:
network_enable_ipv6: "false"
<<: !include common.yaml