mirror of
https://github.com/esphome/esphome.git
synced 2024-11-23 23:48:11 +01:00
Merge branch 'dev' into dev
This commit is contained in:
commit
dd5e2a63fe
36 changed files with 332 additions and 65 deletions
4
.github/workflows/ci.yml
vendored
4
.github/workflows/ci.yml
vendored
|
@ -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
|
||||
|
|
|
@ -169,6 +169,7 @@ esphome/components/he60r/* @clydebarrow
|
|||
esphome/components/heatpumpir/* @rob-deutsch
|
||||
esphome/components/hitachi_ac424/* @sourabhjaiswal
|
||||
esphome/components/hm3301/* @freekode
|
||||
esphome/components/hmac_md5/* @dwmw2
|
||||
esphome/components/homeassistant/* @OttoWinter @esphome/core
|
||||
esphome/components/homeassistant/number/* @landonr
|
||||
esphome/components/homeassistant/switch/* @Links2004
|
||||
|
|
|
@ -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")
|
||||
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
#include "captive_portal.h"
|
||||
#ifdef USE_CAPTIVE_PORTAL
|
||||
#include "esphome/core/log.h"
|
||||
#include "esphome/core/application.h"
|
||||
#include "esphome/components/wifi/wifi_component.h"
|
||||
|
@ -91,3 +92,4 @@ CaptivePortal *global_captive_portal = nullptr; // NOLINT(cppcoreguidelines-avo
|
|||
|
||||
} // namespace captive_portal
|
||||
} // namespace esphome
|
||||
#endif
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
#pragma once
|
||||
|
||||
#include "esphome/core/defines.h"
|
||||
#ifdef USE_CAPTIVE_PORTAL
|
||||
#include <memory>
|
||||
#ifdef USE_ARDUINO
|
||||
#include <DNSServer.h>
|
||||
|
@ -71,3 +72,4 @@ extern CaptivePortal *global_captive_portal; // NOLINT(cppcoreguidelines-avoid-
|
|||
|
||||
} // namespace captive_portal
|
||||
} // namespace esphome
|
||||
#endif
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
#include "e131.h"
|
||||
#ifdef USE_NETWORK
|
||||
#include "e131_addressable_light_effect.h"
|
||||
#include "esphome/core/log.h"
|
||||
|
||||
|
@ -118,3 +119,4 @@ bool E131Component::process_(int universe, const E131Packet &packet) {
|
|||
|
||||
} // namespace e131
|
||||
} // namespace esphome
|
||||
#endif
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
#pragma once
|
||||
|
||||
#include "esphome/core/defines.h"
|
||||
#ifdef USE_NETWORK
|
||||
#include "esphome/components/socket/socket.h"
|
||||
#include "esphome/core/component.h"
|
||||
|
||||
|
@ -53,3 +54,4 @@ class E131Component : public esphome::Component {
|
|||
|
||||
} // namespace e131
|
||||
} // namespace esphome
|
||||
#endif
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
#include "e131_addressable_light_effect.h"
|
||||
#include "e131.h"
|
||||
#ifdef USE_NETWORK
|
||||
#include "esphome/core/log.h"
|
||||
|
||||
namespace esphome {
|
||||
|
@ -90,3 +91,4 @@ bool E131AddressableLightEffect::process_(int universe, const E131Packet &packet
|
|||
|
||||
} // namespace e131
|
||||
} // namespace esphome
|
||||
#endif
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
#include "esphome/core/component.h"
|
||||
#include "esphome/components/light/addressable_light_effect.h"
|
||||
|
||||
#ifdef USE_NETWORK
|
||||
namespace esphome {
|
||||
namespace e131 {
|
||||
|
||||
|
@ -42,3 +42,4 @@ class E131AddressableLightEffect : public light::AddressableLightEffect {
|
|||
|
||||
} // namespace e131
|
||||
} // namespace esphome
|
||||
#endif
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
#include <cstring>
|
||||
#include "e131.h"
|
||||
#ifdef USE_NETWORK
|
||||
#include "esphome/components/network/ip_address.h"
|
||||
#include "esphome/core/log.h"
|
||||
#include "esphome/core/util.h"
|
||||
|
@ -137,3 +138,4 @@ bool E131Component::packet_(const std::vector<uint8_t> &data, int &universe, E13
|
|||
|
||||
} // namespace e131
|
||||
} // namespace esphome
|
||||
#endif
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
#include "ota_esphome.h"
|
||||
|
||||
#ifdef USE_OTA
|
||||
#include "esphome/components/md5/md5.h"
|
||||
#include "esphome/components/network/util.h"
|
||||
#include "esphome/components/ota/ota_backend.h"
|
||||
|
@ -410,3 +410,4 @@ float ESPHomeOTAComponent::get_setup_priority() const { return setup_priority::A
|
|||
uint16_t ESPHomeOTAComponent::get_port() const { return this->port_; }
|
||||
void ESPHomeOTAComponent::set_port(uint16_t port) { this->port_ = port; }
|
||||
} // namespace esphome
|
||||
#endif
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
#pragma once
|
||||
|
||||
#include "esphome/core/defines.h"
|
||||
#ifdef USE_OTA
|
||||
#include "esphome/core/helpers.h"
|
||||
#include "esphome/core/preferences.h"
|
||||
#include "esphome/components/ota/ota_backend.h"
|
||||
|
@ -41,3 +42,4 @@ class ESPHomeOTAComponent : public ota::OTAComponent {
|
|||
};
|
||||
|
||||
} // namespace esphome
|
||||
#endif
|
||||
|
|
2
esphome/components/hmac_md5/__init__.py
Normal file
2
esphome/components/hmac_md5/__init__.py
Normal file
|
@ -0,0 +1,2 @@
|
|||
AUTO_LOAD = ["md5"]
|
||||
CODEOWNERS = ["@dwmw2"]
|
56
esphome/components/hmac_md5/hmac_md5.cpp
Normal file
56
esphome/components/hmac_md5/hmac_md5.cpp
Normal file
|
@ -0,0 +1,56 @@
|
|||
#include <cstdio>
|
||||
#include <cstring>
|
||||
#include "hmac_md5.h"
|
||||
#include "esphome/core/helpers.h"
|
||||
|
||||
namespace esphome {
|
||||
namespace hmac_md5 {
|
||||
void HmacMD5::init(const uint8_t *key, size_t len) {
|
||||
uint8_t ipad[64], opad[64];
|
||||
|
||||
memset(ipad, 0, sizeof(ipad));
|
||||
if (len > 64) {
|
||||
md5::MD5Digest keymd5;
|
||||
keymd5.init();
|
||||
keymd5.add(key, len);
|
||||
keymd5.calculate();
|
||||
keymd5.get_bytes(ipad);
|
||||
} else {
|
||||
memcpy(ipad, key, len);
|
||||
}
|
||||
memcpy(opad, ipad, sizeof(opad));
|
||||
|
||||
for (int i = 0; i < 64; i++) {
|
||||
ipad[i] ^= 0x36;
|
||||
opad[i] ^= 0x5c;
|
||||
}
|
||||
|
||||
this->ihash_.init();
|
||||
this->ihash_.add(ipad, sizeof(ipad));
|
||||
|
||||
this->ohash_.init();
|
||||
this->ohash_.add(opad, sizeof(opad));
|
||||
}
|
||||
|
||||
void HmacMD5::add(const uint8_t *data, size_t len) { this->ihash_.add(data, len); }
|
||||
|
||||
void HmacMD5::calculate() {
|
||||
uint8_t ibytes[16];
|
||||
|
||||
this->ihash_.calculate();
|
||||
this->ihash_.get_bytes(ibytes);
|
||||
|
||||
this->ohash_.add(ibytes, sizeof(ibytes));
|
||||
this->ohash_.calculate();
|
||||
}
|
||||
|
||||
void HmacMD5::get_bytes(uint8_t *output) { this->ohash_.get_bytes(output); }
|
||||
|
||||
void HmacMD5::get_hex(char *output) { this->ohash_.get_hex(output); }
|
||||
|
||||
bool HmacMD5::equals_bytes(const uint8_t *expected) { return this->ohash_.equals_bytes(expected); }
|
||||
|
||||
bool HmacMD5::equals_hex(const char *expected) { return this->ohash_.equals_hex(expected); }
|
||||
|
||||
} // namespace hmac_md5
|
||||
} // namespace esphome
|
48
esphome/components/hmac_md5/hmac_md5.h
Normal file
48
esphome/components/hmac_md5/hmac_md5.h
Normal file
|
@ -0,0 +1,48 @@
|
|||
#pragma once
|
||||
|
||||
#include "esphome/core/defines.h"
|
||||
#include "esphome/components/md5/md5.h"
|
||||
|
||||
#include <string>
|
||||
|
||||
namespace esphome {
|
||||
namespace hmac_md5 {
|
||||
|
||||
class HmacMD5 {
|
||||
public:
|
||||
HmacMD5() = default;
|
||||
~HmacMD5() = default;
|
||||
|
||||
/// Initialize a new MD5 digest computation.
|
||||
void init(const uint8_t *key, size_t len);
|
||||
void init(const char *key, size_t len) { this->init((const uint8_t *) key, len); }
|
||||
void init(const std::string &key) { this->init(key.c_str(), key.length()); }
|
||||
|
||||
/// Add bytes of data for the digest.
|
||||
void add(const uint8_t *data, size_t len);
|
||||
void add(const char *data, size_t len) { this->add((const uint8_t *) data, len); }
|
||||
|
||||
/// Compute the digest, based on the provided data.
|
||||
void calculate();
|
||||
|
||||
/// Retrieve the HMAC-MD5 digest as bytes.
|
||||
/// The output must be able to hold 16 bytes or more.
|
||||
void get_bytes(uint8_t *output);
|
||||
|
||||
/// Retrieve the HMAC-MD5 digest as hex characters.
|
||||
/// The output must be able to hold 32 bytes or more.
|
||||
void get_hex(char *output);
|
||||
|
||||
/// Compare the digest against a provided byte-encoded digest (16 bytes).
|
||||
bool equals_bytes(const uint8_t *expected);
|
||||
|
||||
/// Compare the digest against a provided hex-encoded digest (32 bytes).
|
||||
bool equals_hex(const char *expected);
|
||||
|
||||
protected:
|
||||
md5::MD5Digest ihash_;
|
||||
md5::MD5Digest ohash_;
|
||||
};
|
||||
|
||||
} // namespace hmac_md5
|
||||
} // namespace esphome
|
|
@ -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")
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
#include "improv_serial_component.h"
|
||||
|
||||
#ifdef USE_WIFI
|
||||
#include "esphome/core/application.h"
|
||||
#include "esphome/core/defines.h"
|
||||
#include "esphome/core/hal.h"
|
||||
|
@ -313,3 +313,4 @@ ImprovSerialComponent *global_improv_serial_component = // NOLINT(cppcoreguidel
|
|||
|
||||
} // namespace improv_serial
|
||||
} // namespace esphome
|
||||
#endif
|
||||
|
|
|
@ -5,7 +5,7 @@
|
|||
#include "esphome/core/component.h"
|
||||
#include "esphome/core/defines.h"
|
||||
#include "esphome/core/helpers.h"
|
||||
|
||||
#ifdef USE_WIFI
|
||||
#include <improv.h>
|
||||
#include <vector>
|
||||
|
||||
|
@ -78,3 +78,4 @@ extern ImprovSerialComponent
|
|||
|
||||
} // namespace improv_serial
|
||||
} // namespace esphome
|
||||
#endif
|
||||
|
|
|
@ -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:
|
||||
|
|
|
@ -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,
|
||||
}
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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};
|
||||
|
|
|
@ -1,19 +1,20 @@
|
|||
import re
|
||||
import ipaddress
|
||||
import re
|
||||
|
||||
from esphome import automation
|
||||
import esphome.codegen as cg
|
||||
from esphome.components import time
|
||||
from esphome.components.esp32 import CORE, add_idf_sdkconfig_option
|
||||
import esphome.config_validation as cv
|
||||
from esphome.const import (
|
||||
CONF_ID,
|
||||
CONF_TIME_ID,
|
||||
CONF_ADDRESS,
|
||||
CONF_ID,
|
||||
CONF_REBOOT_TIMEOUT,
|
||||
CONF_TIME_ID,
|
||||
KEY_CORE,
|
||||
KEY_FRAMEWORK_VERSION,
|
||||
)
|
||||
from esphome.components.esp32 import CORE, add_idf_sdkconfig_option
|
||||
from esphome.components import time
|
||||
from esphome.core import TimePeriod
|
||||
from esphome import automation
|
||||
|
||||
CONF_NETMASK = "netmask"
|
||||
CONF_PRIVATE_KEY = "private_key"
|
||||
|
@ -91,6 +92,8 @@ CONFIG_SCHEMA = cv.Schema(
|
|||
async def to_code(config):
|
||||
var = cg.new_Pvariable(config[CONF_ID])
|
||||
|
||||
cg.add_define("USE_WIREGUARD")
|
||||
|
||||
cg.add(var.set_address(str(config[CONF_ADDRESS])))
|
||||
cg.add(var.set_netmask(str(config[CONF_NETMASK])))
|
||||
cg.add(var.set_private_key(config[CONF_PRIVATE_KEY]))
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
#include "wireguard.h"
|
||||
|
||||
#ifdef USE_WIREGUARD
|
||||
#include <cinttypes>
|
||||
#include <ctime>
|
||||
#include <functional>
|
||||
|
@ -289,3 +289,4 @@ std::string mask_key(const std::string &key) { return (key.substr(0, 5) + "[...]
|
|||
|
||||
} // namespace wireguard
|
||||
} // namespace esphome
|
||||
#endif
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
#pragma once
|
||||
|
||||
#include "esphome/core/defines.h"
|
||||
#ifdef USE_WIREGUARD
|
||||
#include <ctime>
|
||||
#include <vector>
|
||||
#include <tuple>
|
||||
|
@ -170,3 +171,4 @@ template<typename... Ts> class WireguardDisableAction : public Action<Ts...>, pu
|
|||
|
||||
} // namespace wireguard
|
||||
} // namespace esphome
|
||||
#endif
|
||||
|
|
|
@ -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})
|
||||
|
||||
|
|
|
@ -75,6 +75,7 @@
|
|||
#define USE_VALVE
|
||||
#define USE_WIFI
|
||||
#define USE_WIFI_AP
|
||||
#define USE_WIREGUARD
|
||||
|
||||
// Arduino-specific feature flags
|
||||
#ifdef USE_ARDUINO
|
||||
|
|
|
@ -11,10 +11,6 @@ esphome:
|
|||
message: Button was pressed
|
||||
- homeassistant.tag_scanned: pulse
|
||||
|
||||
wifi:
|
||||
ssid: MySSID
|
||||
password: password1
|
||||
|
||||
api:
|
||||
port: 8000
|
||||
password: pwd
|
||||
|
|
|
@ -1 +1,5 @@
|
|||
<<: !include common.yaml
|
||||
|
||||
wifi:
|
||||
ssid: MySSID
|
||||
password: password1
|
||||
|
|
|
@ -1 +1,5 @@
|
|||
<<: !include common.yaml
|
||||
|
||||
wifi:
|
||||
ssid: MySSID
|
||||
password: password1
|
||||
|
|
|
@ -1 +1,5 @@
|
|||
<<: !include common.yaml
|
||||
|
||||
wifi:
|
||||
ssid: MySSID
|
||||
password: password1
|
||||
|
|
|
@ -1 +1,5 @@
|
|||
<<: !include common.yaml
|
||||
|
||||
wifi:
|
||||
ssid: MySSID
|
||||
password: password1
|
||||
|
|
|
@ -1 +1,5 @@
|
|||
<<: !include common.yaml
|
||||
|
||||
wifi:
|
||||
ssid: MySSID
|
||||
password: password1
|
||||
|
|
3
tests/components/api/test.host.yaml
Normal file
3
tests/components/api/test.host.yaml
Normal file
|
@ -0,0 +1,3 @@
|
|||
<<: !include common.yaml
|
||||
|
||||
network:
|
|
@ -1 +1,5 @@
|
|||
<<: !include common.yaml
|
||||
|
||||
wifi:
|
||||
ssid: MySSID
|
||||
password: password1
|
||||
|
|
4
tests/components/network/test-ipv6.bk72xx-ard.yaml
Normal file
4
tests/components/network/test-ipv6.bk72xx-ard.yaml
Normal file
|
@ -0,0 +1,4 @@
|
|||
substitutions:
|
||||
network_enable_ipv6: "false"
|
||||
|
||||
<<: !include common.yaml
|
Loading…
Reference in a new issue