1
0
mirror of https://github.com/esphome/esphome.git synced 2025-11-20 08:46:01 +00:00

Compare commits

..

40 Commits

Author SHA1 Message Date
J. Nick Koston
317a6082a1 [select] Modernize namespace declarations to C++17 syntax 2025-11-19 20:53:27 -06:00
Jonathan Swoboda
bbd6d019e5 Merge branch 'release' into dev 2025-11-19 17:37:58 -05:00
Jonathan Swoboda
625172e07d Merge pull request #12004 from esphome/bump-2025.11.0
2025.11.0
2025-11-19 17:37:42 -05:00
Jonathan Swoboda
1e9c7d3c6d Bump version to 2025.11.0 2025-11-19 16:02:52 -05:00
Jonathan Swoboda
4cdab4e2d8 Merge branch 'beta' into dev 2025-11-19 15:06:55 -05:00
Jonathan Swoboda
c2bc7b3cdc Merge pull request #12003 from esphome/bump-2025.11.0b5
2025.11.0b5
2025-11-19 15:06:44 -05:00
dependabot[bot]
2c3417062a Bump pyupgrade from 3.21.1 to 3.21.2 (#12002)
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2025-11-19 13:47:40 -06:00
Jonathan Swoboda
c75abfb894 Bump version to 2025.11.0b5 2025-11-19 14:17:03 -05:00
Jesse Hills
1157b4aee8 [epaper_spi] Add basic 7.3in-Spectra-E6 model (#12001) 2025-11-19 14:17:03 -05:00
J. Nick Koston
71dc2d374d [web_server_idf] Fix pbuf_free crash by moving shutdown before close (#11995) 2025-11-19 14:17:03 -05:00
Jonathan Swoboda
0a224f919b [wifi] Fix positive RSSI values on 8266 (#11994) 2025-11-19 14:17:03 -05:00
Jonathan Swoboda
7ef4b4f3d9 [text_sensor] Fix infinite loop in substitute filter (#11989)
Co-authored-by: J. Nick Koston <nick@koston.org>
2025-11-19 14:17:03 -05:00
J. Nick Koston
13b875c763 [tests] Fix SNTP time ID conflicts in component tests for grouped testing (#11990) 2025-11-19 14:17:03 -05:00
Jesse Hills
b02b07ffaf [epaper_spi] Add basic 7.3in-Spectra-E6 model (#12001) 2025-11-19 14:11:45 -05:00
J. Nick Koston
8804bc2815 [web_server_idf] Fix pbuf_free crash by moving shutdown before close (#11995) 2025-11-20 07:58:33 +13:00
Jonathan Swoboda
61cef0a75c [api] Fix format warnings in dump (#11999) 2025-11-19 12:58:47 -05:00
Jonathan Swoboda
73bc5252a1 [wifi] Fix positive RSSI values on 8266 (#11994) 2025-11-19 10:12:57 -05:00
Jonathan Swoboda
f2b10ad132 [text_sensor] Fix infinite loop in substitute filter (#11989)
Co-authored-by: J. Nick Koston <nick@koston.org>
2025-11-19 10:12:34 -05:00
J. Nick Koston
100ea46f03 [tests] Fix SNTP time ID conflicts in component tests for grouped testing (#11990) 2025-11-18 23:19:54 -06:00
J. Nick Koston
b3ef05e5e1 [ld24xx] Modernize namespace declarations to C++17 syntax (#11988) 2025-11-19 04:00:39 +00:00
J. Nick Koston
45c994e4de [light] Modernize namespace declarations to C++17 syntax (#11986) 2025-11-18 21:56:23 -06:00
Jesse Hills
a72545639d Merge branch 'beta' into dev 2025-11-19 13:43:25 +13:00
Jesse Hills
dfd614c00c Merge pull request #11980 from esphome/bump-2025.11.0b4
2025.11.0b4
2025-11-19 13:22:09 +13:00
J. Nick Koston
29374837c6 [wifi, captive_portal, web_server, wifi_info] Use stack allocation for MAC address formatting (#11963) 2025-11-18 17:06:34 -06:00
Jesse Hills
2681a14d05 Bump version to 2025.11.0b4 2025-11-19 09:17:33 +13:00
J. Nick Koston
f436f6ee2e [wifi] Fix captive portal unusable when WiFi credentials are wrong (#11965) 2025-11-19 09:17:33 +13:00
Jonathan Swoboda
f18bc62690 [sfa30] Fix negative temperature values (#11973) 2025-11-19 09:17:33 +13:00
J. Nick Koston
6db73df649 [scheduler] Add defensive nullptr checks and explicit locking requirements (#11974) 2025-11-19 09:17:33 +13:00
Jonathan Swoboda
93215f1737 [esp32] Fix Arduino build on some ESP32 S2 boards (#11972) 2025-11-19 09:17:33 +13:00
Clyde Stubbs
70aa94b8a4 [lvgl] Apply scale to spinbox value (#11946) 2025-11-19 09:17:33 +13:00
strange_v
e8998a79c7 [mipi_rgb] Fix GUITION-4848S040 colors (#11709) 2025-11-19 09:17:33 +13:00
Jonathan Swoboda
3b25fdbc5f [core] Add support for setting environment variables (#11953) 2025-11-19 09:17:33 +13:00
J. Nick Koston
6c8577678c [captive_portal] Warn when enabled without WiFi AP configured (#11856) 2025-11-19 09:17:33 +13:00
J. Nick Koston
70ed9c7c4d [wifi] Fix captive portal unusable when WiFi credentials are wrong (#11965) 2025-11-19 08:17:21 +13:00
dependabot[bot]
81fe5deaa9 Bump github/codeql-action from 4.31.3 to 4.31.4 (#11977)
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2025-11-19 08:12:42 +13:00
Jonathan Swoboda
72e4b16a5b [sfa30] Fix negative temperature values (#11973) 2025-11-18 13:29:40 -05:00
Jonathan Swoboda
fe2befcec2 [bme68x] Print error when no sensors are configured (#11976) 2025-11-18 13:18:09 -05:00
J. Nick Koston
1888f5ffd5 [scheduler] Add defensive nullptr checks and explicit locking requirements (#11974) 2025-11-18 18:16:18 +00:00
Jonathan Swoboda
c59af22217 [esp32] Fix Arduino build on some ESP32 S2 boards (#11972) 2025-11-18 12:40:31 -05:00
J. Nick Koston
33983b051b [ld24xx] Use stack allocation for MAC and version formatting (#11961) 2025-11-18 10:51:47 -06:00
166 changed files with 547 additions and 1714 deletions

View File

@@ -58,7 +58,7 @@ jobs:
# Initializes the CodeQL tools for scanning.
- name: Initialize CodeQL
uses: github/codeql-action/init@014f16e7ab1402f30e7c3329d33797e7948572db # v4.31.3
uses: github/codeql-action/init@e12f0178983d466f2f6028f5cc7a6d786fd97f4b # v4.31.4
with:
languages: ${{ matrix.language }}
build-mode: ${{ matrix.build-mode }}
@@ -86,6 +86,6 @@ jobs:
exit 1
- name: Perform CodeQL Analysis
uses: github/codeql-action/analyze@014f16e7ab1402f30e7c3329d33797e7948572db # v4.31.3
uses: github/codeql-action/analyze@e12f0178983d466f2f6028f5cc7a6d786fd97f4b # v4.31.4
with:
category: "/language:${{matrix.language}}"

View File

@@ -66,7 +66,7 @@ static void dump_field(std::string &out, const char *field_name, float value, in
static void dump_field(std::string &out, const char *field_name, uint64_t value, int indent = 2) {
char buffer[64];
append_field_prefix(out, field_name, indent);
snprintf(buffer, 64, "%llu", value);
snprintf(buffer, 64, "%" PRIu64, value);
append_with_newline(out, buffer);
}

View File

@@ -1,29 +0,0 @@
"""AXP2101 Power Management IC component for ESPHome."""
import esphome.codegen as cg
import esphome.config_validation as cv
from esphome.components import i2c
from esphome.const import CONF_ID
CODEOWNERS = ["@esphome/core"]
DEPENDENCIES = ["i2c"]
MULTI_CONF = True
axp2101_ns = cg.esphome_ns.namespace("axp2101")
AXP2101Component = axp2101_ns.class_("AXP2101Component", cg.PollingComponent, i2c.I2CDevice)
CONFIG_SCHEMA = (
cv.Schema(
{
cv.GenerateID(): cv.declare_id(AXP2101Component),
}
)
.extend(cv.polling_component_schema("60s"))
.extend(i2c.i2c_device_schema(0x34))
)
async def to_code(config):
"""Generate code for the AXP2101 component."""
var = cg.new_Pvariable(config[CONF_ID])
await cg.register_component(var, config)
await i2c.register_i2c_device(var, config)

View File

@@ -1,369 +0,0 @@
/**
* @file axp2101.cpp
* @brief Implementation of AXP2101 Power Management IC Component
*/
#include "axp2101.h"
#include "esphome/core/log.h"
#include "esphome/core/hal.h"
namespace esphome {
namespace axp2101 {
static const char *const TAG = "axp2101";
// Temperature conversion constant (from datasheet)
static const float TEMP_CONVERSION_FACTOR = 0.1f;
static const float TEMP_OFFSET = -267.15f;
void AXP2101Component::setup() {
ESP_LOGCONFIG(TAG, "Setting up AXP2101...");
// Read chip ID to verify communication
uint8_t chip_id;
if (!this->read_byte(AXP2101_IC_TYPE, &chip_id)) {
ESP_LOGE(TAG, "Failed to read chip ID");
this->mark_failed();
return;
}
ESP_LOGD(TAG, "Chip ID: 0x%02X", chip_id);
// Enable ADC channels for monitoring
// Enable battery voltage, VBUS, VSYS, and temperature measurements
uint8_t adc_ctrl = 0xFF; // Enable all ADC channels
if (!this->write_byte(AXP2101_ADC_CHANNEL_CTRL, adc_ctrl)) {
ESP_LOGW(TAG, "Failed to configure ADC channels");
}
ESP_LOGCONFIG(TAG, "AXP2101 setup complete");
}
void AXP2101Component::dump_config() {
ESP_LOGCONFIG(TAG, "AXP2101:");
LOG_I2C_DEVICE(this);
if (this->is_failed()) {
ESP_LOGE(TAG, "Communication with AXP2101 failed!");
return;
}
#ifdef USE_SENSOR
// Log sensor configuration
LOG_SENSOR(" ", "Battery Voltage", this->battery_voltage_sensor_);
LOG_SENSOR(" ", "Battery Level", this->battery_level_sensor_);
LOG_SENSOR(" ", "VBUS Voltage", this->vbus_voltage_sensor_);
LOG_SENSOR(" ", "VSYS Voltage", this->vsys_voltage_sensor_);
LOG_SENSOR(" ", "Die Temperature", this->die_temperature_sensor_);
#endif
}
void AXP2101Component::update() {
#ifdef USE_SENSOR
if (this->battery_voltage_sensor_ != nullptr) {
this->battery_voltage_sensor_->publish_state(this->read_battery_voltage() / 1000.0f);
}
if (this->battery_level_sensor_ != nullptr) {
this->battery_level_sensor_->publish_state(this->read_battery_level());
}
if (this->vbus_voltage_sensor_ != nullptr) {
this->vbus_voltage_sensor_->publish_state(this->read_vbus_voltage() / 1000.0f);
}
if (this->vsys_voltage_sensor_ != nullptr) {
this->vsys_voltage_sensor_->publish_state(this->read_vsys_voltage() / 1000.0f);
}
if (this->die_temperature_sensor_ != nullptr) {
this->die_temperature_sensor_->publish_state(this->read_die_temperature());
}
#endif
}
bool AXP2101Component::set_register_bit(uint8_t reg, uint8_t bit) {
uint8_t value;
if (!this->read_byte(reg, &value)) {
return false;
}
value |= (1 << bit);
return this->write_byte(reg, value);
}
bool AXP2101Component::clear_register_bit(uint8_t reg, uint8_t bit) {
uint8_t value;
if (!this->read_byte(reg, &value)) {
return false;
}
value &= ~(1 << bit);
return this->write_byte(reg, value);
}
bool AXP2101Component::get_register_bit(uint8_t reg, uint8_t bit) {
uint8_t value;
if (!this->read_byte(reg, &value)) {
return false;
}
return (value & (1 << bit)) != 0;
}
uint16_t AXP2101Component::read_register_h5l8(uint8_t high_reg, uint8_t low_reg) {
uint8_t high, low;
if (!this->read_byte(high_reg, &high) || !this->read_byte(low_reg, &low)) {
return 0;
}
return ((high & 0x1F) << 8) | low;
}
uint16_t AXP2101Component::read_register_h6l8(uint8_t high_reg, uint8_t low_reg) {
uint8_t high, low;
if (!this->read_byte(high_reg, &high) || !this->read_byte(low_reg, &low)) {
return 0;
}
return ((high & 0x3F) << 8) | low;
}
bool AXP2101Component::get_rail_enable_info(PowerRail rail, uint8_t &reg, uint8_t &bit) {
// DCDC rails are controlled by DC_ONOFF_DVM_CTRL register
if (rail >= DCDC1 && rail <= DCDC5) {
reg = AXP2101_DC_ONOFF_DVM_CTRL;
bit = static_cast<uint8_t>(rail); // DCDC1=bit0, DCDC2=bit1, etc.
return true;
}
// LDO rails are controlled by LDO_ONOFF_CTRL0 and LDO_ONOFF_CTRL1
if (rail >= ALDO1 && rail <= DLDO2) {
if (rail <= BLDO2) {
reg = AXP2101_LDO_ONOFF_CTRL0;
bit = static_cast<uint8_t>(rail - ALDO1); // ALDO1=bit0, ALDO2=bit1, etc.
} else {
reg = AXP2101_LDO_ONOFF_CTRL1;
bit = static_cast<uint8_t>(rail - CPUSLDO); // CPUSLDO=bit0, DLDO1=bit1, DLDO2=bit2
}
return true;
}
return false;
}
bool AXP2101Component::get_rail_voltage_info(PowerRail rail, uint8_t &reg, uint16_t &min_mv, uint16_t &max_mv,
uint16_t &step_mv) {
switch (rail) {
case DCDC1:
reg = AXP2101_DC_VOL0_CTRL;
min_mv = 1500;
max_mv = 3400;
step_mv = 100;
return true;
case DCDC2:
case DCDC3:
case DCDC4:
// These have dual ranges, handle in calculate methods
reg = AXP2101_DC_VOL1_CTRL + (rail - DCDC2);
min_mv = 500;
max_mv = 1540;
step_mv = 10;
return true;
case DCDC5:
reg = AXP2101_DC_VOL4_CTRL;
min_mv = 1400;
max_mv = 3700;
step_mv = 100;
return true;
case ALDO1:
case ALDO2:
case ALDO3:
case ALDO4:
reg = AXP2101_ALDO1_VOL_CTRL + (rail - ALDO1);
min_mv = 500;
max_mv = 3500;
step_mv = 100;
return true;
case BLDO1:
case BLDO2:
reg = AXP2101_BLDO1_VOL_CTRL + (rail - BLDO1);
min_mv = 500;
max_mv = 3500;
step_mv = 100;
return true;
case CPUSLDO:
reg = AXP2101_CPUSLDO_VOL_CTRL;
min_mv = 500;
max_mv = 1400;
step_mv = 50;
return true;
case DLDO1:
case DLDO2:
reg = AXP2101_DLDO1_VOL_CTRL + (rail - DLDO1);
min_mv = 500;
max_mv = 3400;
step_mv = 100;
return true;
default:
return false;
}
}
uint8_t AXP2101Component::calculate_voltage_register_value(PowerRail rail, uint16_t millivolts) {
// Special handling for DCDC2, DCDC3, DCDC4 with dual ranges
if (rail == DCDC2 || rail == DCDC3 || rail == DCDC4) {
if (millivolts >= 500 && millivolts <= 1200) {
// Range 1: 500-1200mV in 10mV steps
return static_cast<uint8_t>((millivolts - 500) / 10);
} else if (millivolts >= 1220 && millivolts <= 1540) {
// Range 2: 1220-1540mV in 20mV steps
return static_cast<uint8_t>(70 + (millivolts - 1220) / 20);
} else if (rail == DCDC3 && millivolts >= 1600 && millivolts <= 3400) {
// DCDC3 has an extended range
return static_cast<uint8_t>(87 + (millivolts - 1600) / 100);
}
return 0; // Invalid voltage
}
// Special handling for DCDC4 extended range
if (rail == DCDC4 && millivolts >= 1600 && millivolts <= 1840) {
return static_cast<uint8_t>(87 + (millivolts - 1600) / 20);
}
// Standard calculation for other rails
uint8_t reg;
uint16_t min_mv, max_mv, step_mv;
if (!this->get_rail_voltage_info(rail, reg, min_mv, max_mv, step_mv)) {
return 0;
}
if (millivolts < min_mv || millivolts > max_mv) {
return 0; // Out of range
}
if ((millivolts - min_mv) % step_mv != 0) {
return 0; // Not aligned to step size
}
return static_cast<uint8_t>((millivolts - min_mv) / step_mv);
}
uint16_t AXP2101Component::calculate_millivolts_from_register(PowerRail rail, uint8_t reg_value) {
// Special handling for DCDC2, DCDC3, DCDC4 with dual ranges
if (rail == DCDC2 || rail == DCDC3 || rail == DCDC4) {
if (reg_value <= 70) {
// Range 1: 500-1200mV in 10mV steps
return 500 + (reg_value * 10);
} else if (reg_value <= 86) {
// Range 2: 1220-1540mV in 20mV steps
return 1220 + ((reg_value - 70) * 20);
} else if (rail == DCDC3 && reg_value <= 105) {
// DCDC3 extended range: 1600-3400mV in 100mV steps
return 1600 + ((reg_value - 87) * 100);
} else if (rail == DCDC4 && reg_value <= 99) {
// DCDC4 extended range: 1600-1840mV in 20mV steps
return 1600 + ((reg_value - 87) * 20);
}
return 0; // Invalid
}
// Standard calculation for other rails
uint8_t reg;
uint16_t min_mv, max_mv, step_mv;
if (!this->get_rail_voltage_info(rail, reg, min_mv, max_mv, step_mv)) {
return 0;
}
return min_mv + (reg_value * step_mv);
}
bool AXP2101Component::enable_power_rail(PowerRail rail) {
uint8_t reg, bit;
if (!this->get_rail_enable_info(rail, reg, bit)) {
return false;
}
return this->set_register_bit(reg, bit);
}
bool AXP2101Component::disable_power_rail(PowerRail rail) {
uint8_t reg, bit;
if (!this->get_rail_enable_info(rail, reg, bit)) {
return false;
}
return this->clear_register_bit(reg, bit);
}
bool AXP2101Component::is_power_rail_enabled(PowerRail rail) {
uint8_t reg, bit;
if (!this->get_rail_enable_info(rail, reg, bit)) {
return false;
}
return this->get_register_bit(reg, bit);
}
bool AXP2101Component::set_rail_voltage(PowerRail rail, uint16_t millivolts) {
uint8_t reg;
uint16_t min_mv, max_mv, step_mv;
if (!this->get_rail_voltage_info(rail, reg, min_mv, max_mv, step_mv)) {
ESP_LOGE(TAG, "Invalid power rail");
return false;
}
uint8_t value = this->calculate_voltage_register_value(rail, millivolts);
if (value == 0 && millivolts != 0) {
ESP_LOGE(TAG, "Invalid voltage %u mV for rail", millivolts);
return false;
}
return this->write_byte(reg, value);
}
uint16_t AXP2101Component::get_rail_voltage(PowerRail rail) {
uint8_t reg;
uint16_t min_mv, max_mv, step_mv;
if (!this->get_rail_voltage_info(rail, reg, min_mv, max_mv, step_mv)) {
return 0;
}
uint8_t value;
if (!this->read_byte(reg, &value)) {
return 0;
}
return this->calculate_millivolts_from_register(rail, value & 0x7F);
}
uint16_t AXP2101Component::read_battery_voltage() {
// 1 LSB = 1mV
return this->read_register_h5l8(AXP2101_ADC_DATA_RELUST0, AXP2101_ADC_DATA_RELUST1);
}
uint16_t AXP2101Component::read_vbus_voltage() {
// 1 LSB = 1mV
return this->read_register_h5l8(AXP2101_ADC_DATA_RELUST4, AXP2101_ADC_DATA_RELUST5);
}
uint16_t AXP2101Component::read_vsys_voltage() {
// 1 LSB = 1mV
return this->read_register_h6l8(AXP2101_ADC_DATA_RELUST6, AXP2101_ADC_DATA_RELUST7);
}
float AXP2101Component::read_die_temperature() {
// Temperature conversion: T = raw * 0.1 - 267.15
return (this->read_register_h6l8(AXP2101_ADC_DATA_RELUST8, AXP2101_ADC_DATA_RELUST9) * TEMP_CONVERSION_FACTOR) +
TEMP_OFFSET;
}
uint8_t AXP2101Component::read_battery_level() {
uint8_t level;
if (!this->read_byte(AXP2101_BAT_PERCENT_DATA, &level)) {
return 0;
}
return level > 100 ? 100 : level;
}
} // namespace axp2101
} // namespace esphome

View File

@@ -1,175 +0,0 @@
/**
* @file axp2101.h
* @brief AXP2101 Power Management IC Component
*
* This component provides access to the AXP2101 PMIC which includes:
* - 5 DCDC regulators (DCDC1-5)
* - 11 LDO regulators (ALDO1-4, BLDO1-2, CPUSLDO, DLDO1-2)
* - Battery management and charging
* - ADC monitoring (battery voltage, current, temperature, etc.)
*/
#pragma once
#include "esphome/core/component.h"
#include "esphome/components/i2c/i2c.h"
#include "esphome/components/sensor/sensor.h"
namespace esphome {
namespace axp2101 {
// Register addresses
static const uint8_t AXP2101_STATUS1 = 0x00;
static const uint8_t AXP2101_STATUS2 = 0x01;
static const uint8_t AXP2101_IC_TYPE = 0x03;
static const uint8_t AXP2101_COMMON_CONFIG = 0x10;
static const uint8_t AXP2101_BATFET_CTRL = 0x12;
static const uint8_t AXP2101_MIN_SYS_VOL_CTRL = 0x14;
static const uint8_t AXP2101_INPUT_VOL_LIMIT_CTRL = 0x15;
static const uint8_t AXP2101_INPUT_CUR_LIMIT_CTRL = 0x16;
static const uint8_t AXP2101_PWRON_STATUS = 0x20;
static const uint8_t AXP2101_PWROFF_STATUS = 0x21;
static const uint8_t AXP2101_PWROFF_EN = 0x22;
// ADC control and data registers
static const uint8_t AXP2101_ADC_CHANNEL_CTRL = 0x30;
static const uint8_t AXP2101_ADC_DATA_RELUST0 = 0x34; // Battery voltage high
static const uint8_t AXP2101_ADC_DATA_RELUST1 = 0x35; // Battery voltage low
static const uint8_t AXP2101_ADC_DATA_RELUST2 = 0x36; // TS voltage high
static const uint8_t AXP2101_ADC_DATA_RELUST3 = 0x37; // TS voltage low
static const uint8_t AXP2101_ADC_DATA_RELUST4 = 0x38; // VBUS voltage high
static const uint8_t AXP2101_ADC_DATA_RELUST5 = 0x39; // VBUS voltage low
static const uint8_t AXP2101_ADC_DATA_RELUST6 = 0x3A; // VSYS voltage high
static const uint8_t AXP2101_ADC_DATA_RELUST7 = 0x3B; // VSYS voltage low
static const uint8_t AXP2101_ADC_DATA_RELUST8 = 0x3C; // Die temperature high
static const uint8_t AXP2101_ADC_DATA_RELUST9 = 0x3D; // Die temperature low
// Interrupt registers
static const uint8_t AXP2101_INTEN1 = 0x40;
static const uint8_t AXP2101_INTEN2 = 0x41;
static const uint8_t AXP2101_INTEN3 = 0x42;
static const uint8_t AXP2101_INTSTS1 = 0x48;
static const uint8_t AXP2101_INTSTS2 = 0x49;
static const uint8_t AXP2101_INTSTS3 = 0x4A;
// Charging configuration registers
static const uint8_t AXP2101_CHARGE_GAUGE_WDT_CTRL = 0x18;
static const uint8_t AXP2101_IPRECHG_SET = 0x61;
static const uint8_t AXP2101_ICC_CHG_SET = 0x62;
static const uint8_t AXP2101_ITERM_CHG_SET_CTRL = 0x63;
static const uint8_t AXP2101_CV_CHG_VOL_SET = 0x64;
static const uint8_t AXP2101_CHARGE_TIMEOUT_SET_CTRL = 0x67;
static const uint8_t AXP2101_BAT_DET_CTRL = 0x68;
static const uint8_t AXP2101_CHGLED_SET_CTRL = 0x69;
static const uint8_t AXP2101_BTN_BAT_CHG_VOL_SET = 0x6A;
// DCDC control registers
static const uint8_t AXP2101_DC_ONOFF_DVM_CTRL = 0x80;
static const uint8_t AXP2101_DC_VOL0_CTRL = 0x82; // DCDC1
static const uint8_t AXP2101_DC_VOL1_CTRL = 0x83; // DCDC2
static const uint8_t AXP2101_DC_VOL2_CTRL = 0x84; // DCDC3
static const uint8_t AXP2101_DC_VOL3_CTRL = 0x85; // DCDC4
static const uint8_t AXP2101_DC_VOL4_CTRL = 0x86; // DCDC5
// LDO control registers
static const uint8_t AXP2101_LDO_ONOFF_CTRL0 = 0x90;
static const uint8_t AXP2101_LDO_ONOFF_CTRL1 = 0x91;
static const uint8_t AXP2101_ALDO1_VOL_CTRL = 0x92;
static const uint8_t AXP2101_ALDO2_VOL_CTRL = 0x93;
static const uint8_t AXP2101_ALDO3_VOL_CTRL = 0x94;
static const uint8_t AXP2101_ALDO4_VOL_CTRL = 0x95;
static const uint8_t AXP2101_BLDO1_VOL_CTRL = 0x96;
static const uint8_t AXP2101_BLDO2_VOL_CTRL = 0x97;
static const uint8_t AXP2101_CPUSLDO_VOL_CTRL = 0x98;
static const uint8_t AXP2101_DLDO1_VOL_CTRL = 0x99;
static const uint8_t AXP2101_DLDO2_VOL_CTRL = 0x9A;
// Battery gauge registers
static const uint8_t AXP2101_BAT_PARAMS = 0xA1;
static const uint8_t AXP2101_BAT_GAUGE_CTRL = 0xA2;
static const uint8_t AXP2101_BAT_PERCENT_DATA = 0xA4;
// Power rail identifiers
enum PowerRail {
DCDC1 = 0,
DCDC2,
DCDC3,
DCDC4,
DCDC5,
ALDO1,
ALDO2,
ALDO3,
ALDO4,
BLDO1,
BLDO2,
CPUSLDO,
DLDO1,
DLDO2,
};
/**
* @brief Main AXP2101 component class
*
* This component handles communication with the AXP2101 PMIC via I2C.
* It provides methods for power rail control, voltage adjustment,
* and monitoring of various parameters.
*/
class AXP2101Component : public PollingComponent, public i2c::I2CDevice {
public:
void setup() override;
void dump_config() override;
void update() override;
float get_setup_priority() const override { return setup_priority::HARDWARE; }
#ifdef USE_SENSOR
// Sensor setters
void set_battery_voltage_sensor(sensor::Sensor *sensor) { this->battery_voltage_sensor_ = sensor; }
void set_battery_current_sensor(sensor::Sensor *sensor) { this->battery_current_sensor_ = sensor; }
void set_battery_level_sensor(sensor::Sensor *sensor) { this->battery_level_sensor_ = sensor; }
void set_vbus_voltage_sensor(sensor::Sensor *sensor) { this->vbus_voltage_sensor_ = sensor; }
void set_vsys_voltage_sensor(sensor::Sensor *sensor) { this->vsys_voltage_sensor_ = sensor; }
void set_die_temperature_sensor(sensor::Sensor *sensor) { this->die_temperature_sensor_ = sensor; }
#endif
// Power rail control methods
bool enable_power_rail(PowerRail rail);
bool disable_power_rail(PowerRail rail);
bool is_power_rail_enabled(PowerRail rail);
// Voltage control methods
bool set_rail_voltage(PowerRail rail, uint16_t millivolts);
uint16_t get_rail_voltage(PowerRail rail);
// ADC reading methods
uint16_t read_battery_voltage();
uint16_t read_vbus_voltage();
uint16_t read_vsys_voltage();
float read_die_temperature();
uint8_t read_battery_level();
protected:
// Helper methods for register access
bool set_register_bit(uint8_t reg, uint8_t bit);
bool clear_register_bit(uint8_t reg, uint8_t bit);
bool get_register_bit(uint8_t reg, uint8_t bit);
uint16_t read_register_h5l8(uint8_t high_reg, uint8_t low_reg);
uint16_t read_register_h6l8(uint8_t high_reg, uint8_t low_reg);
// Power rail helper methods
bool get_rail_enable_info(PowerRail rail, uint8_t &reg, uint8_t &bit);
bool get_rail_voltage_info(PowerRail rail, uint8_t &reg, uint16_t &min_mv, uint16_t &max_mv, uint16_t &step_mv);
uint8_t calculate_voltage_register_value(PowerRail rail, uint16_t millivolts);
uint16_t calculate_millivolts_from_register(PowerRail rail, uint8_t reg_value);
#ifdef USE_SENSOR
// Sensor pointers (optional)
sensor::Sensor *battery_voltage_sensor_{nullptr};
sensor::Sensor *battery_current_sensor_{nullptr};
sensor::Sensor *battery_level_sensor_{nullptr};
sensor::Sensor *vbus_voltage_sensor_{nullptr};
sensor::Sensor *vsys_voltage_sensor_{nullptr};
sensor::Sensor *die_temperature_sensor_{nullptr};
#endif
};
} // namespace axp2101
} // namespace esphome

View File

@@ -1,90 +0,0 @@
"""Number support for AXP2101 voltage control."""
import esphome.codegen as cg
import esphome.config_validation as cv
from esphome.components import number
from esphome.const import CONF_ID, UNIT_VOLT
from .. import AXP2101Component, axp2101_ns
CODEOWNERS = ["@esphome/core"]
DEPENDENCIES = ["axp2101"]
CONF_AXP2101_ID = "axp2101_id"
CONF_POWER_RAIL = "power_rail"
AXP2101Number = axp2101_ns.class_("AXP2101Number", number.Number, cg.Component)
# Power rail enum matching the PowerRail enum in C++
PowerRail = axp2101_ns.enum("PowerRail")
POWER_RAILS = {
"DCDC1": PowerRail.DCDC1,
"DCDC2": PowerRail.DCDC2,
"DCDC3": PowerRail.DCDC3,
"DCDC4": PowerRail.DCDC4,
"DCDC5": PowerRail.DCDC5,
"ALDO1": PowerRail.ALDO1,
"ALDO2": PowerRail.ALDO2,
"ALDO3": PowerRail.ALDO3,
"ALDO4": PowerRail.ALDO4,
"BLDO1": PowerRail.BLDO1,
"BLDO2": PowerRail.BLDO2,
"CPUSLDO": PowerRail.CPUSLDO,
"DLDO1": PowerRail.DLDO1,
"DLDO2": PowerRail.DLDO2,
}
# Voltage ranges for each power rail (in millivolts)
VOLTAGE_RANGES = {
"DCDC1": {"min": 1500, "max": 3400, "step": 100},
"DCDC2": {"min": 500, "max": 1540, "step": 10},
"DCDC3": {"min": 500, "max": 3400, "step": 10},
"DCDC4": {"min": 500, "max": 1840, "step": 10},
"DCDC5": {"min": 1400, "max": 3700, "step": 100},
"ALDO1": {"min": 500, "max": 3500, "step": 100},
"ALDO2": {"min": 500, "max": 3500, "step": 100},
"ALDO3": {"min": 500, "max": 3500, "step": 100},
"ALDO4": {"min": 500, "max": 3500, "step": 100},
"BLDO1": {"min": 500, "max": 3500, "step": 100},
"BLDO2": {"min": 500, "max": 3500, "step": 100},
"CPUSLDO": {"min": 500, "max": 1400, "step": 50},
"DLDO1": {"min": 500, "max": 3400, "step": 100},
"DLDO2": {"min": 500, "max": 3400, "step": 100},
}
def validate_voltage_range(config):
"""Validate that voltage is within the allowed range for the power rail."""
rail = config[CONF_POWER_RAIL]
ranges = VOLTAGE_RANGES[rail]
# Update the number schema with the correct min/max/step
return config
CONFIG_SCHEMA = cv.All(
number.number_schema(
AXP2101Number,
unit_of_measurement=UNIT_VOLT,
).extend(
{
cv.GenerateID(CONF_AXP2101_ID): cv.use_id(AXP2101Component),
cv.Required(CONF_POWER_RAIL): cv.enum(POWER_RAILS, upper=True),
}
),
validate_voltage_range,
)
async def to_code(config):
"""Generate code for AXP2101 number."""
paren = await cg.get_variable(config[CONF_AXP2101_ID])
var = await number.new_number(config, min_value=0.5, max_value=3.7, step=0.01)
await cg.register_component(var, config)
cg.add(var.set_parent(paren))
cg.add(var.set_power_rail(config[CONF_POWER_RAIL]))
# Set rail-specific voltage range
rail = config[CONF_POWER_RAIL]
ranges = VOLTAGE_RANGES[rail]
cg.add(var.set_voltage_range(ranges["min"], ranges["max"], ranges["step"]))

View File

@@ -1,101 +0,0 @@
/**
* @file axp2101_number.cpp
* @brief Implementation of AXP2101 number component
*/
#include "axp2101_number.h"
#include "esphome/core/log.h"
namespace esphome {
namespace axp2101 {
static const char *const TAG = "axp2101.number";
static const char *power_rail_to_string(PowerRail rail) {
switch (rail) {
case DCDC1:
return "DCDC1";
case DCDC2:
return "DCDC2";
case DCDC3:
return "DCDC3";
case DCDC4:
return "DCDC4";
case DCDC5:
return "DCDC5";
case ALDO1:
return "ALDO1";
case ALDO2:
return "ALDO2";
case ALDO3:
return "ALDO3";
case ALDO4:
return "ALDO4";
case BLDO1:
return "BLDO1";
case BLDO2:
return "BLDO2";
case CPUSLDO:
return "CPUSLDO";
case DLDO1:
return "DLDO1";
case DLDO2:
return "DLDO2";
default:
return "UNKNOWN";
}
}
void AXP2101Number::setup() {
if (this->parent_ == nullptr) {
ESP_LOGE(TAG, "Parent not set!");
this->mark_failed();
return;
}
// Read current voltage and publish initial state
uint16_t current_mv = this->parent_->get_rail_voltage(this->rail_);
if (current_mv > 0) {
float current_v = current_mv / 1000.0f;
this->publish_state(current_v);
}
}
void AXP2101Number::dump_config() {
LOG_NUMBER("", "AXP2101 Number", this);
ESP_LOGCONFIG(TAG, " Power Rail: %s", power_rail_to_string(this->rail_));
ESP_LOGCONFIG(TAG, " Voltage Range: %.2f-%.2fV (step: %.3fV)", this->min_mv_ / 1000.0f, this->max_mv_ / 1000.0f,
this->step_mv_ / 1000.0f);
}
void AXP2101Number::control(float value) {
if (this->parent_ == nullptr) {
ESP_LOGE(TAG, "Parent not set!");
return;
}
// Convert volts to millivolts
uint16_t millivolts = static_cast<uint16_t>(value * 1000.0f);
// Validate range
if (millivolts < this->min_mv_ || millivolts > this->max_mv_) {
ESP_LOGW(TAG, "Voltage %.3fV out of range for %s (%.2f-%.2fV)", value, power_rail_to_string(this->rail_),
this->min_mv_ / 1000.0f, this->max_mv_ / 1000.0f);
return;
}
// Round to nearest step
uint16_t offset = millivolts - this->min_mv_;
uint16_t steps = (offset + this->step_mv_ / 2) / this->step_mv_;
millivolts = this->min_mv_ + (steps * this->step_mv_);
if (this->parent_->set_rail_voltage(this->rail_, millivolts)) {
float actual_v = millivolts / 1000.0f;
this->publish_state(actual_v);
ESP_LOGD(TAG, "Set %s voltage to %.3fV", power_rail_to_string(this->rail_), actual_v);
} else {
ESP_LOGE(TAG, "Failed to set %s voltage to %.3fV", power_rail_to_string(this->rail_), value);
}
}
} // namespace axp2101
} // namespace esphome

View File

@@ -1,44 +0,0 @@
/**
* @file axp2101_number.h
* @brief Number component for AXP2101 voltage control
*/
#pragma once
#include "esphome/core/component.h"
#include "esphome/components/number/number.h"
#include "../axp2101.h"
namespace esphome {
namespace axp2101 {
/**
* @brief Number component for controlling AXP2101 power rail voltages
*
* This number component allows setting the output voltage of individual
* power rails (DCDCs and LDOs).
*/
class AXP2101Number : public number::Number, public Component {
public:
void set_parent(AXP2101Component *parent) { this->parent_ = parent; }
void set_power_rail(PowerRail rail) { this->rail_ = rail; }
void set_voltage_range(uint16_t min_mv, uint16_t max_mv, uint16_t step_mv) {
this->min_mv_ = min_mv;
this->max_mv_ = max_mv;
this->step_mv_ = step_mv;
}
void setup() override;
void dump_config() override;
protected:
void control(float value) override;
AXP2101Component *parent_;
PowerRail rail_;
uint16_t min_mv_{500};
uint16_t max_mv_{3500};
uint16_t step_mv_{100};
};
} // namespace axp2101
} // namespace esphome

View File

@@ -1,86 +0,0 @@
"""Sensor support for AXP2101."""
import esphome.codegen as cg
import esphome.config_validation as cv
from esphome.components import sensor
from esphome.const import (
CONF_BATTERY_LEVEL,
CONF_BATTERY_VOLTAGE,
CONF_ID,
CONF_TEMPERATURE,
DEVICE_CLASS_BATTERY,
DEVICE_CLASS_TEMPERATURE,
DEVICE_CLASS_VOLTAGE,
STATE_CLASS_MEASUREMENT,
UNIT_CELSIUS,
UNIT_PERCENT,
UNIT_VOLT,
)
from . import AXP2101Component, axp2101_ns
DEPENDENCIES = ["axp2101"]
CONF_AXP2101_ID = "axp2101_id"
CONF_VBUS_VOLTAGE = "vbus_voltage"
CONF_VSYS_VOLTAGE = "vsys_voltage"
CONFIG_SCHEMA = cv.Schema(
{
cv.GenerateID(CONF_AXP2101_ID): cv.use_id(AXP2101Component),
cv.Optional(CONF_BATTERY_VOLTAGE): sensor.sensor_schema(
unit_of_measurement=UNIT_VOLT,
accuracy_decimals=3,
device_class=DEVICE_CLASS_VOLTAGE,
state_class=STATE_CLASS_MEASUREMENT,
),
cv.Optional(CONF_BATTERY_LEVEL): sensor.sensor_schema(
unit_of_measurement=UNIT_PERCENT,
accuracy_decimals=0,
device_class=DEVICE_CLASS_BATTERY,
state_class=STATE_CLASS_MEASUREMENT,
),
cv.Optional(CONF_VBUS_VOLTAGE): sensor.sensor_schema(
unit_of_measurement=UNIT_VOLT,
accuracy_decimals=3,
device_class=DEVICE_CLASS_VOLTAGE,
state_class=STATE_CLASS_MEASUREMENT,
),
cv.Optional(CONF_VSYS_VOLTAGE): sensor.sensor_schema(
unit_of_measurement=UNIT_VOLT,
accuracy_decimals=3,
device_class=DEVICE_CLASS_VOLTAGE,
state_class=STATE_CLASS_MEASUREMENT,
),
cv.Optional(CONF_TEMPERATURE): sensor.sensor_schema(
unit_of_measurement=UNIT_CELSIUS,
accuracy_decimals=1,
device_class=DEVICE_CLASS_TEMPERATURE,
state_class=STATE_CLASS_MEASUREMENT,
),
}
)
async def to_code(config):
"""Generate code for AXP2101 sensors."""
paren = await cg.get_variable(config[CONF_AXP2101_ID])
if conf := config.get(CONF_BATTERY_VOLTAGE):
sens = await sensor.new_sensor(conf)
cg.add(paren.set_battery_voltage_sensor(sens))
if conf := config.get(CONF_BATTERY_LEVEL):
sens = await sensor.new_sensor(conf)
cg.add(paren.set_battery_level_sensor(sens))
if conf := config.get(CONF_VBUS_VOLTAGE):
sens = await sensor.new_sensor(conf)
cg.add(paren.set_vbus_voltage_sensor(sens))
if conf := config.get(CONF_VSYS_VOLTAGE):
sens = await sensor.new_sensor(conf)
cg.add(paren.set_vsys_voltage_sensor(sens))
if conf := config.get(CONF_TEMPERATURE):
sens = await sensor.new_sensor(conf)
cg.add(paren.set_die_temperature_sensor(sens))

View File

@@ -1,52 +0,0 @@
"""Switch support for AXP2101 power rail control."""
import esphome.codegen as cg
import esphome.config_validation as cv
from esphome.components import switch
from esphome.const import CONF_ID
from .. import AXP2101Component, axp2101_ns
CODEOWNERS = ["@esphome/core"]
DEPENDENCIES = ["axp2101"]
CONF_AXP2101_ID = "axp2101_id"
CONF_POWER_RAIL = "power_rail"
AXP2101Switch = axp2101_ns.class_("AXP2101Switch", switch.Switch, cg.Component)
# Power rail enum matching the PowerRail enum in C++
PowerRail = axp2101_ns.enum("PowerRail")
POWER_RAILS = {
"DCDC1": PowerRail.DCDC1,
"DCDC2": PowerRail.DCDC2,
"DCDC3": PowerRail.DCDC3,
"DCDC4": PowerRail.DCDC4,
"DCDC5": PowerRail.DCDC5,
"ALDO1": PowerRail.ALDO1,
"ALDO2": PowerRail.ALDO2,
"ALDO3": PowerRail.ALDO3,
"ALDO4": PowerRail.ALDO4,
"BLDO1": PowerRail.BLDO1,
"BLDO2": PowerRail.BLDO2,
"CPUSLDO": PowerRail.CPUSLDO,
"DLDO1": PowerRail.DLDO1,
"DLDO2": PowerRail.DLDO2,
}
CONFIG_SCHEMA = switch.switch_schema(AXP2101Switch).extend(
{
cv.GenerateID(CONF_AXP2101_ID): cv.use_id(AXP2101Component),
cv.Required(CONF_POWER_RAIL): cv.enum(POWER_RAILS, upper=True),
}
)
async def to_code(config):
"""Generate code for AXP2101 switch."""
paren = await cg.get_variable(config[CONF_AXP2101_ID])
var = await switch.new_switch(config)
await cg.register_component(var, config)
cg.add(var.set_parent(paren))
cg.add(var.set_power_rail(config[CONF_POWER_RAIL]))

View File

@@ -1,74 +0,0 @@
/**
* @file axp2101_switch.cpp
* @brief Implementation of AXP2101 switch component
*/
#include "axp2101_switch.h"
#include "esphome/core/log.h"
namespace esphome {
namespace axp2101 {
static const char *const TAG = "axp2101.switch";
static const char *power_rail_to_string(PowerRail rail) {
switch (rail) {
case DCDC1:
return "DCDC1";
case DCDC2:
return "DCDC2";
case DCDC3:
return "DCDC3";
case DCDC4:
return "DCDC4";
case DCDC5:
return "DCDC5";
case ALDO1:
return "ALDO1";
case ALDO2:
return "ALDO2";
case ALDO3:
return "ALDO3";
case ALDO4:
return "ALDO4";
case BLDO1:
return "BLDO1";
case BLDO2:
return "BLDO2";
case CPUSLDO:
return "CPUSLDO";
case DLDO1:
return "DLDO1";
case DLDO2:
return "DLDO2";
default:
return "UNKNOWN";
}
}
void AXP2101Switch::dump_config() {
LOG_SWITCH("", "AXP2101 Switch", this);
ESP_LOGCONFIG(TAG, " Power Rail: %s", power_rail_to_string(this->rail_));
}
void AXP2101Switch::write_state(bool state) {
if (this->parent_ == nullptr) {
ESP_LOGE(TAG, "Parent not set!");
return;
}
bool success;
if (state) {
success = this->parent_->enable_power_rail(this->rail_);
} else {
success = this->parent_->disable_power_rail(this->rail_);
}
if (success) {
this->publish_state(state);
} else {
ESP_LOGE(TAG, "Failed to %s power rail %s", state ? "enable" : "disable", power_rail_to_string(this->rail_));
}
}
} // namespace axp2101
} // namespace esphome

View File

@@ -1,34 +0,0 @@
/**
* @file axp2101_switch.h
* @brief Switch component for AXP2101 power rail control
*/
#pragma once
#include "esphome/core/component.h"
#include "esphome/components/switch/switch.h"
#include "../axp2101.h"
namespace esphome {
namespace axp2101 {
/**
* @brief Switch component for controlling AXP2101 power rails
*
* This switch allows enabling/disabling individual power rails (DCDCs and LDOs).
*/
class AXP2101Switch : public switch_::Switch, public Component {
public:
void set_parent(AXP2101Component *parent) { this->parent_ = parent; }
void set_power_rail(PowerRail rail) { this->rail_ = rail; }
void dump_config() override;
protected:
void write_state(bool state) override;
AXP2101Component *parent_;
PowerRail rail_;
};
} // namespace axp2101
} // namespace esphome

View File

@@ -70,6 +70,9 @@ void BME68xBSEC2Component::dump_config() {
if (this->is_failed()) {
ESP_LOGE(TAG, "Communication failed (BSEC2 status: %d, BME68X status: %d)", this->bsec_status_,
this->bme68x_status_);
if (this->bsec_status_ == BSEC_I_SU_SUBSCRIBEDOUTPUTGATES) {
ESP_LOGE(TAG, "No sensors, add at least one sensor to the config");
}
}
if (this->algorithm_output_ != ALGORITHM_OUTPUT_IAQ) {

View File

@@ -72,6 +72,16 @@ def _final_validate(config: ConfigType) -> ConfigType:
"Add 'ap:' to your WiFi configuration to enable the captive portal."
)
# Register socket needs for DNS server and additional HTTP connections
# - 1 UDP socket for DNS server
# - 3 additional TCP sockets for captive portal detection probes + configuration requests
# OS captive portal detection makes multiple probe requests that stay in TIME_WAIT.
# Need headroom for actual user configuration requests.
# LRU purging will reclaim idle sockets to prevent exhaustion from repeated attempts.
from esphome.components import socket
socket.consume_sockets(4, "captive_portal")(config)
return config

View File

@@ -13,14 +13,16 @@ static const char *const TAG = "captive_portal";
void CaptivePortal::handle_config(AsyncWebServerRequest *request) {
AsyncResponseStream *stream = request->beginResponseStream(ESPHOME_F("application/json"));
stream->addHeader(ESPHOME_F("cache-control"), ESPHOME_F("public, max-age=0, must-revalidate"));
char mac_s[18];
const char *mac_str = get_mac_address_pretty_into_buffer(mac_s);
#ifdef USE_ESP8266
stream->print(ESPHOME_F("{\"mac\":\""));
stream->print(get_mac_address_pretty().c_str());
stream->print(mac_str);
stream->print(ESPHOME_F("\",\"name\":\""));
stream->print(App.get_name().c_str());
stream->print(ESPHOME_F("\",\"aps\":[{}"));
#else
stream->printf(R"({"mac":"%s","name":"%s","aps":[{})", get_mac_address_pretty().c_str(), App.get_name().c_str());
stream->printf(R"({"mac":"%s","name":"%s","aps":[{})", mac_str, App.get_name().c_str());
#endif
for (auto &scan : wifi::global_wifi_component->get_scan_result()) {
@@ -50,8 +52,8 @@ void CaptivePortal::handle_wifisave(AsyncWebServerRequest *request) {
ESP_LOGI(TAG, "Requested WiFi Settings Change:");
ESP_LOGI(TAG, " SSID='%s'", ssid.c_str());
ESP_LOGI(TAG, " Password=" LOG_SECRET("'%s'"), psk.c_str());
wifi::global_wifi_component->save_wifi_sta(ssid, psk);
wifi::global_wifi_component->start_scanning();
// Defer save to main loop thread to avoid NVS operations from HTTP thread
this->defer([ssid, psk]() { wifi::global_wifi_component->save_wifi_sta(ssid, psk); });
request->redirect(ESPHOME_F("/?save"));
}
@@ -63,6 +65,12 @@ void CaptivePortal::start() {
this->base_->init();
if (!this->initialized_) {
this->base_->add_handler(this);
#ifdef USE_ESP32
// Enable LRU socket purging to handle captive portal detection probe bursts
// OS captive portal detection makes many simultaneous HTTP requests which can
// exhaust sockets. LRU purging automatically closes oldest idle connections.
this->base_->get_server()->set_lru_purge_enable(true);
#endif
}
network::IPAddress ip = wifi::global_wifi_component->wifi_soft_ap_ip();

View File

@@ -40,6 +40,10 @@ class CaptivePortal : public AsyncWebHandler, public Component {
void end() {
this->active_ = false;
this->disable_loop(); // Stop processing DNS requests
#ifdef USE_ESP32
// Disable LRU socket purging now that captive portal is done
this->base_->get_server()->set_lru_purge_enable(false);
#endif
this->base_->deinit();
if (this->dns_server_ != nullptr) {
this->dns_server_->stop();

View File

@@ -102,7 +102,7 @@ def customise_schema(config):
"""
config = cv.Schema(
{
cv.Required(CONF_MODEL): cv.one_of(*MODELS, upper=True),
cv.Required(CONF_MODEL): cv.one_of(*MODELS, upper=True, space="-"),
},
extra=cv.ALLOW_EXTRA,
)(config)

View File

@@ -32,11 +32,15 @@ class SpectraE6(EpaperModel):
spectra_e6 = SpectraE6("spectra-e6")
spectra_e6.extend(
"Seeed-reTerminal-E1002",
spectra_e6_7p3 = spectra_e6.extend(
"7.3in-Spectra-E6",
width=800,
height=480,
data_rate="20MHz",
)
spectra_e6_7p3.extend(
"Seeed-reTerminal-E1002",
cs_pin=10,
dc_pin=11,
reset_pin=12,

View File

@@ -931,6 +931,12 @@ async def to_code(config):
add_idf_sdkconfig_option("CONFIG_MBEDTLS_CERTIFICATE_BUNDLE", True)
add_idf_sdkconfig_option("CONFIG_ESP_PHY_REDUCE_TX_POWER", True)
# ESP32-S2 Arduino: Disable USB Serial on boot to avoid TinyUSB dependency
if get_esp32_variant() == VARIANT_ESP32S2:
cg.add_build_unflag("-DARDUINO_USB_CDC_ON_BOOT=1")
cg.add_build_unflag("-DARDUINO_USB_CDC_ON_BOOT=0")
cg.add_build_flag("-DARDUINO_USB_CDC_ON_BOOT=0")
cg.add_build_flag("-Wno-nonnull-compare")
add_idf_sdkconfig_option(f"CONFIG_IDF_TARGET_{variant}", True)

View File

@@ -20,6 +20,10 @@ CONF_ON_STOP = "on_stop"
CONF_STATUS_INDICATOR = "status_indicator"
CONF_WIFI_TIMEOUT = "wifi_timeout"
# Default WiFi timeout - aligned with WiFi component ap_timeout
# Allows sufficient time to try all BSSIDs before starting provisioning mode
DEFAULT_WIFI_TIMEOUT = "90s"
improv_ns = cg.esphome_ns.namespace("improv")
Error = improv_ns.enum("Error")
@@ -59,7 +63,7 @@ CONFIG_SCHEMA = (
CONF_AUTHORIZED_DURATION, default="1min"
): cv.positive_time_period_milliseconds,
cv.Optional(
CONF_WIFI_TIMEOUT, default="1min"
CONF_WIFI_TIMEOUT, default=DEFAULT_WIFI_TIMEOUT
): cv.positive_time_period_milliseconds,
cv.Optional(CONF_ON_PROVISIONED): automation.validate_automation(
{

View File

@@ -127,6 +127,7 @@ void ESP32ImprovComponent::loop() {
// Set initial state based on whether we have an authorizer
this->set_state_(this->get_initial_state_(), false);
this->set_error_(improv::ERROR_NONE);
this->should_start_ = false; // Clear flag after starting
ESP_LOGD(TAG, "Service started!");
}
}

View File

@@ -45,6 +45,7 @@ class ESP32ImprovComponent : public Component, public improv_base::ImprovBase {
void start();
void stop();
bool is_active() const { return this->state_ != improv::STATE_STOPPED; }
bool should_start() const { return this->should_start_; }
#ifdef USE_ESP32_IMPROV_STATE_CALLBACK
void add_on_state_callback(std::function<void(improv::State, improv::Error)> &&callback) {

View File

@@ -4,8 +4,7 @@
#include "esphome/core/component.h"
#include "ld2410.h"
namespace esphome {
namespace ld2410 {
namespace esphome::ld2410 {
template<typename... Ts> class BluetoothPasswordSetAction : public Action<Ts...> {
public:
@@ -18,5 +17,4 @@ template<typename... Ts> class BluetoothPasswordSetAction : public Action<Ts...>
LD2410Component *ld2410_comp_;
};
} // namespace ld2410
} // namespace esphome
} // namespace esphome::ld2410

View File

@@ -1,9 +1,7 @@
#include "factory_reset_button.h"
namespace esphome {
namespace ld2410 {
namespace esphome::ld2410 {
void FactoryResetButton::press_action() { this->parent_->factory_reset(); }
} // namespace ld2410
} // namespace esphome
} // namespace esphome::ld2410

View File

@@ -3,8 +3,7 @@
#include "esphome/components/button/button.h"
#include "../ld2410.h"
namespace esphome {
namespace ld2410 {
namespace esphome::ld2410 {
class FactoryResetButton : public button::Button, public Parented<LD2410Component> {
public:
@@ -14,5 +13,4 @@ class FactoryResetButton : public button::Button, public Parented<LD2410Componen
void press_action() override;
};
} // namespace ld2410
} // namespace esphome
} // namespace esphome::ld2410

View File

@@ -1,9 +1,7 @@
#include "query_button.h"
namespace esphome {
namespace ld2410 {
namespace esphome::ld2410 {
void QueryButton::press_action() { this->parent_->read_all_info(); }
} // namespace ld2410
} // namespace esphome
} // namespace esphome::ld2410

View File

@@ -3,8 +3,7 @@
#include "esphome/components/button/button.h"
#include "../ld2410.h"
namespace esphome {
namespace ld2410 {
namespace esphome::ld2410 {
class QueryButton : public button::Button, public Parented<LD2410Component> {
public:
@@ -14,5 +13,4 @@ class QueryButton : public button::Button, public Parented<LD2410Component> {
void press_action() override;
};
} // namespace ld2410
} // namespace esphome
} // namespace esphome::ld2410

View File

@@ -1,9 +1,7 @@
#include "restart_button.h"
namespace esphome {
namespace ld2410 {
namespace esphome::ld2410 {
void RestartButton::press_action() { this->parent_->restart_and_read_all_info(); }
} // namespace ld2410
} // namespace esphome
} // namespace esphome::ld2410

View File

@@ -3,8 +3,7 @@
#include "esphome/components/button/button.h"
#include "../ld2410.h"
namespace esphome {
namespace ld2410 {
namespace esphome::ld2410 {
class RestartButton : public button::Button, public Parented<LD2410Component> {
public:
@@ -14,5 +13,4 @@ class RestartButton : public button::Button, public Parented<LD2410Component> {
void press_action() override;
};
} // namespace ld2410
} // namespace esphome
} // namespace esphome::ld2410

View File

@@ -9,12 +9,9 @@
#include "esphome/core/application.h"
namespace esphome {
namespace ld2410 {
namespace esphome::ld2410 {
static const char *const TAG = "ld2410";
static const char *const UNKNOWN_MAC = "unknown";
static const char *const VERSION_FMT = "%u.%02X.%02X%02X%02X%02X";
enum BaudRate : uint8_t {
BAUD_RATE_9600 = 1,
@@ -181,15 +178,15 @@ static inline bool validate_header_footer(const uint8_t *header_footer, const ui
}
void LD2410Component::dump_config() {
std::string mac_str =
mac_address_is_valid(this->mac_address_) ? format_mac_address_pretty(this->mac_address_) : UNKNOWN_MAC;
std::string version = str_sprintf(VERSION_FMT, this->version_[1], this->version_[0], this->version_[5],
this->version_[4], this->version_[3], this->version_[2]);
char mac_s[18];
char version_s[20];
const char *mac_str = ld24xx::format_mac_str(this->mac_address_, mac_s);
ld24xx::format_version_str(this->version_, version_s);
ESP_LOGCONFIG(TAG,
"LD2410:\n"
" Firmware version: %s\n"
" MAC address: %s",
version.c_str(), mac_str.c_str());
version_s, mac_str);
#ifdef USE_BINARY_SENSOR
ESP_LOGCONFIG(TAG, "Binary Sensors:");
LOG_BINARY_SENSOR(" ", "Target", this->target_binary_sensor_);
@@ -448,12 +445,12 @@ bool LD2410Component::handle_ack_data_() {
case CMD_QUERY_VERSION: {
std::memcpy(this->version_, &this->buffer_data_[12], sizeof(this->version_));
std::string version = str_sprintf(VERSION_FMT, this->version_[1], this->version_[0], this->version_[5],
this->version_[4], this->version_[3], this->version_[2]);
ESP_LOGV(TAG, "Firmware version: %s", version.c_str());
char version_s[20];
ld24xx::format_version_str(this->version_, version_s);
ESP_LOGV(TAG, "Firmware version: %s", version_s);
#ifdef USE_TEXT_SENSOR
if (this->version_text_sensor_ != nullptr) {
this->version_text_sensor_->publish_state(version);
this->version_text_sensor_->publish_state(version_s);
}
#endif
break;
@@ -506,9 +503,9 @@ bool LD2410Component::handle_ack_data_() {
std::memcpy(this->mac_address_, &this->buffer_data_[10], sizeof(this->mac_address_));
}
std::string mac_str =
mac_address_is_valid(this->mac_address_) ? format_mac_address_pretty(this->mac_address_) : UNKNOWN_MAC;
ESP_LOGV(TAG, "MAC address: %s", mac_str.c_str());
char mac_s[18];
const char *mac_str = ld24xx::format_mac_str(this->mac_address_, mac_s);
ESP_LOGV(TAG, "MAC address: %s", mac_str);
#ifdef USE_TEXT_SENSOR
if (this->mac_text_sensor_ != nullptr) {
this->mac_text_sensor_->publish_state(mac_str);
@@ -784,5 +781,4 @@ void LD2410Component::set_gate_still_sensor(uint8_t gate, sensor::Sensor *s) {
}
#endif
} // namespace ld2410
} // namespace esphome
} // namespace esphome::ld2410

View File

@@ -29,8 +29,7 @@
#include <array>
namespace esphome {
namespace ld2410 {
namespace esphome::ld2410 {
using namespace ld24xx;
@@ -133,5 +132,4 @@ class LD2410Component : public Component, public uart::UARTDevice {
#endif
};
} // namespace ld2410
} // namespace esphome
} // namespace esphome::ld2410

View File

@@ -1,7 +1,6 @@
#include "gate_threshold_number.h"
namespace esphome {
namespace ld2410 {
namespace esphome::ld2410 {
GateThresholdNumber::GateThresholdNumber(uint8_t gate) : gate_(gate) {}
@@ -10,5 +9,4 @@ void GateThresholdNumber::control(float value) {
this->parent_->set_gate_threshold(this->gate_);
}
} // namespace ld2410
} // namespace esphome
} // namespace esphome::ld2410

View File

@@ -3,8 +3,7 @@
#include "esphome/components/number/number.h"
#include "../ld2410.h"
namespace esphome {
namespace ld2410 {
namespace esphome::ld2410 {
class GateThresholdNumber : public number::Number, public Parented<LD2410Component> {
public:
@@ -15,5 +14,4 @@ class GateThresholdNumber : public number::Number, public Parented<LD2410Compone
void control(float value) override;
};
} // namespace ld2410
} // namespace esphome
} // namespace esphome::ld2410

View File

@@ -1,12 +1,10 @@
#include "light_threshold_number.h"
namespace esphome {
namespace ld2410 {
namespace esphome::ld2410 {
void LightThresholdNumber::control(float value) {
this->publish_state(value);
this->parent_->set_light_out_control();
}
} // namespace ld2410
} // namespace esphome
} // namespace esphome::ld2410

View File

@@ -3,8 +3,7 @@
#include "esphome/components/number/number.h"
#include "../ld2410.h"
namespace esphome {
namespace ld2410 {
namespace esphome::ld2410 {
class LightThresholdNumber : public number::Number, public Parented<LD2410Component> {
public:
@@ -14,5 +13,4 @@ class LightThresholdNumber : public number::Number, public Parented<LD2410Compon
void control(float value) override;
};
} // namespace ld2410
} // namespace esphome
} // namespace esphome::ld2410

View File

@@ -1,12 +1,10 @@
#include "max_distance_timeout_number.h"
namespace esphome {
namespace ld2410 {
namespace esphome::ld2410 {
void MaxDistanceTimeoutNumber::control(float value) {
this->publish_state(value);
this->parent_->set_max_distances_timeout();
}
} // namespace ld2410
} // namespace esphome
} // namespace esphome::ld2410

View File

@@ -3,8 +3,7 @@
#include "esphome/components/number/number.h"
#include "../ld2410.h"
namespace esphome {
namespace ld2410 {
namespace esphome::ld2410 {
class MaxDistanceTimeoutNumber : public number::Number, public Parented<LD2410Component> {
public:
@@ -14,5 +13,4 @@ class MaxDistanceTimeoutNumber : public number::Number, public Parented<LD2410Co
void control(float value) override;
};
} // namespace ld2410
} // namespace esphome
} // namespace esphome::ld2410

View File

@@ -1,12 +1,10 @@
#include "baud_rate_select.h"
namespace esphome {
namespace ld2410 {
namespace esphome::ld2410 {
void BaudRateSelect::control(size_t index) {
this->publish_state(index);
this->parent_->set_baud_rate(this->option_at(index));
}
} // namespace ld2410
} // namespace esphome
} // namespace esphome::ld2410

View File

@@ -3,8 +3,7 @@
#include "esphome/components/select/select.h"
#include "../ld2410.h"
namespace esphome {
namespace ld2410 {
namespace esphome::ld2410 {
class BaudRateSelect : public select::Select, public Parented<LD2410Component> {
public:
@@ -14,5 +13,4 @@ class BaudRateSelect : public select::Select, public Parented<LD2410Component> {
void control(size_t index) override;
};
} // namespace ld2410
} // namespace esphome
} // namespace esphome::ld2410

View File

@@ -1,12 +1,10 @@
#include "distance_resolution_select.h"
namespace esphome {
namespace ld2410 {
namespace esphome::ld2410 {
void DistanceResolutionSelect::control(size_t index) {
this->publish_state(index);
this->parent_->set_distance_resolution(this->option_at(index));
}
} // namespace ld2410
} // namespace esphome
} // namespace esphome::ld2410

View File

@@ -3,8 +3,7 @@
#include "esphome/components/select/select.h"
#include "../ld2410.h"
namespace esphome {
namespace ld2410 {
namespace esphome::ld2410 {
class DistanceResolutionSelect : public select::Select, public Parented<LD2410Component> {
public:
@@ -14,5 +13,4 @@ class DistanceResolutionSelect : public select::Select, public Parented<LD2410Co
void control(size_t index) override;
};
} // namespace ld2410
} // namespace esphome
} // namespace esphome::ld2410

View File

@@ -1,12 +1,10 @@
#include "light_out_control_select.h"
namespace esphome {
namespace ld2410 {
namespace esphome::ld2410 {
void LightOutControlSelect::control(size_t index) {
this->publish_state(index);
this->parent_->set_light_out_control();
}
} // namespace ld2410
} // namespace esphome
} // namespace esphome::ld2410

View File

@@ -3,8 +3,7 @@
#include "esphome/components/select/select.h"
#include "../ld2410.h"
namespace esphome {
namespace ld2410 {
namespace esphome::ld2410 {
class LightOutControlSelect : public select::Select, public Parented<LD2410Component> {
public:
@@ -14,5 +13,4 @@ class LightOutControlSelect : public select::Select, public Parented<LD2410Compo
void control(size_t index) override;
};
} // namespace ld2410
} // namespace esphome
} // namespace esphome::ld2410

View File

@@ -1,12 +1,10 @@
#include "bluetooth_switch.h"
namespace esphome {
namespace ld2410 {
namespace esphome::ld2410 {
void BluetoothSwitch::write_state(bool state) {
this->publish_state(state);
this->parent_->set_bluetooth(state);
}
} // namespace ld2410
} // namespace esphome
} // namespace esphome::ld2410

View File

@@ -3,8 +3,7 @@
#include "esphome/components/switch/switch.h"
#include "../ld2410.h"
namespace esphome {
namespace ld2410 {
namespace esphome::ld2410 {
class BluetoothSwitch : public switch_::Switch, public Parented<LD2410Component> {
public:
@@ -14,5 +13,4 @@ class BluetoothSwitch : public switch_::Switch, public Parented<LD2410Component>
void write_state(bool state) override;
};
} // namespace ld2410
} // namespace esphome
} // namespace esphome::ld2410

View File

@@ -1,12 +1,10 @@
#include "engineering_mode_switch.h"
namespace esphome {
namespace ld2410 {
namespace esphome::ld2410 {
void EngineeringModeSwitch::write_state(bool state) {
this->publish_state(state);
this->parent_->set_engineering_mode(state);
}
} // namespace ld2410
} // namespace esphome
} // namespace esphome::ld2410

View File

@@ -3,8 +3,7 @@
#include "esphome/components/switch/switch.h"
#include "../ld2410.h"
namespace esphome {
namespace ld2410 {
namespace esphome::ld2410 {
class EngineeringModeSwitch : public switch_::Switch, public Parented<LD2410Component> {
public:
@@ -14,5 +13,4 @@ class EngineeringModeSwitch : public switch_::Switch, public Parented<LD2410Comp
void write_state(bool state) override;
};
} // namespace ld2410
} // namespace esphome
} // namespace esphome::ld2410

View File

@@ -1,9 +1,7 @@
#include "factory_reset_button.h"
namespace esphome {
namespace ld2412 {
namespace esphome::ld2412 {
void FactoryResetButton::press_action() { this->parent_->factory_reset(); }
} // namespace ld2412
} // namespace esphome
} // namespace esphome::ld2412

View File

@@ -3,8 +3,7 @@
#include "esphome/components/button/button.h"
#include "../ld2412.h"
namespace esphome {
namespace ld2412 {
namespace esphome::ld2412 {
class FactoryResetButton : public button::Button, public Parented<LD2412Component> {
public:
@@ -14,5 +13,4 @@ class FactoryResetButton : public button::Button, public Parented<LD2412Componen
void press_action() override;
};
} // namespace ld2412
} // namespace esphome
} // namespace esphome::ld2412

View File

@@ -1,9 +1,7 @@
#include "query_button.h"
namespace esphome {
namespace ld2412 {
namespace esphome::ld2412 {
void QueryButton::press_action() { this->parent_->read_all_info(); }
} // namespace ld2412
} // namespace esphome
} // namespace esphome::ld2412

View File

@@ -3,8 +3,7 @@
#include "esphome/components/button/button.h"
#include "../ld2412.h"
namespace esphome {
namespace ld2412 {
namespace esphome::ld2412 {
class QueryButton : public button::Button, public Parented<LD2412Component> {
public:
@@ -14,5 +13,4 @@ class QueryButton : public button::Button, public Parented<LD2412Component> {
void press_action() override;
};
} // namespace ld2412
} // namespace esphome
} // namespace esphome::ld2412

View File

@@ -1,9 +1,7 @@
#include "restart_button.h"
namespace esphome {
namespace ld2412 {
namespace esphome::ld2412 {
void RestartButton::press_action() { this->parent_->restart_and_read_all_info(); }
} // namespace ld2412
} // namespace esphome
} // namespace esphome::ld2412

View File

@@ -3,8 +3,7 @@
#include "esphome/components/button/button.h"
#include "../ld2412.h"
namespace esphome {
namespace ld2412 {
namespace esphome::ld2412 {
class RestartButton : public button::Button, public Parented<LD2412Component> {
public:
@@ -14,5 +13,4 @@ class RestartButton : public button::Button, public Parented<LD2412Component> {
void press_action() override;
};
} // namespace ld2412
} // namespace esphome
} // namespace esphome::ld2412

View File

@@ -2,10 +2,8 @@
#include "restart_button.h"
namespace esphome {
namespace ld2412 {
namespace esphome::ld2412 {
void StartDynamicBackgroundCorrectionButton::press_action() { this->parent_->start_dynamic_background_correction(); }
} // namespace ld2412
} // namespace esphome
} // namespace esphome::ld2412

View File

@@ -3,8 +3,7 @@
#include "esphome/components/button/button.h"
#include "../ld2412.h"
namespace esphome {
namespace ld2412 {
namespace esphome::ld2412 {
class StartDynamicBackgroundCorrectionButton : public button::Button, public Parented<LD2412Component> {
public:
@@ -14,5 +13,4 @@ class StartDynamicBackgroundCorrectionButton : public button::Button, public Par
void press_action() override;
};
} // namespace ld2412
} // namespace esphome
} // namespace esphome::ld2412

View File

@@ -10,12 +10,9 @@
#include "esphome/core/application.h"
#include "esphome/core/helpers.h"
namespace esphome {
namespace ld2412 {
namespace esphome::ld2412 {
static const char *const TAG = "ld2412";
static const char *const UNKNOWN_MAC = "unknown";
static const char *const VERSION_FMT = "%u.%02X.%02X%02X%02X%02X";
enum BaudRate : uint8_t {
BAUD_RATE_9600 = 1,
@@ -200,15 +197,15 @@ static inline bool validate_header_footer(const uint8_t *header_footer, const ui
}
void LD2412Component::dump_config() {
std::string mac_str =
mac_address_is_valid(this->mac_address_) ? format_mac_address_pretty(this->mac_address_) : UNKNOWN_MAC;
std::string version = str_sprintf(VERSION_FMT, this->version_[1], this->version_[0], this->version_[5],
this->version_[4], this->version_[3], this->version_[2]);
char mac_s[18];
char version_s[20];
const char *mac_str = ld24xx::format_mac_str(this->mac_address_, mac_s);
ld24xx::format_version_str(this->version_, version_s);
ESP_LOGCONFIG(TAG,
"LD2412:\n"
" Firmware version: %s\n"
" MAC address: %s",
version.c_str(), mac_str.c_str());
version_s, mac_str);
#ifdef USE_BINARY_SENSOR
ESP_LOGCONFIG(TAG, "Binary Sensors:");
LOG_BINARY_SENSOR(" ", "DynamicBackgroundCorrectionStatus",
@@ -492,12 +489,12 @@ bool LD2412Component::handle_ack_data_() {
case CMD_QUERY_VERSION: {
std::memcpy(this->version_, &this->buffer_data_[12], sizeof(this->version_));
std::string version = str_sprintf(VERSION_FMT, this->version_[1], this->version_[0], this->version_[5],
this->version_[4], this->version_[3], this->version_[2]);
ESP_LOGV(TAG, "Firmware version: %s", version.c_str());
char version_s[20];
ld24xx::format_version_str(this->version_, version_s);
ESP_LOGV(TAG, "Firmware version: %s", version_s);
#ifdef USE_TEXT_SENSOR
if (this->version_text_sensor_ != nullptr) {
this->version_text_sensor_->publish_state(version);
this->version_text_sensor_->publish_state(version_s);
}
#endif
break;
@@ -544,9 +541,9 @@ bool LD2412Component::handle_ack_data_() {
std::memcpy(this->mac_address_, &this->buffer_data_[10], sizeof(this->mac_address_));
}
std::string mac_str =
mac_address_is_valid(this->mac_address_) ? format_mac_address_pretty(this->mac_address_) : UNKNOWN_MAC;
ESP_LOGV(TAG, "MAC address: %s", mac_str.c_str());
char mac_s[18];
const char *mac_str = ld24xx::format_mac_str(this->mac_address_, mac_s);
ESP_LOGV(TAG, "MAC address: %s", mac_str);
#ifdef USE_TEXT_SENSOR
if (this->mac_text_sensor_ != nullptr) {
this->mac_text_sensor_->publish_state(mac_str);
@@ -857,5 +854,4 @@ void LD2412Component::set_gate_still_sensor(uint8_t gate, sensor::Sensor *s) {
}
#endif
} // namespace ld2412
} // namespace esphome
} // namespace esphome::ld2412

View File

@@ -29,8 +29,7 @@
#include <array>
namespace esphome {
namespace ld2412 {
namespace esphome::ld2412 {
using namespace ld24xx;
@@ -137,5 +136,4 @@ class LD2412Component : public Component, public uart::UARTDevice {
#endif
};
} // namespace ld2412
} // namespace esphome
} // namespace esphome::ld2412

View File

@@ -1,7 +1,6 @@
#include "gate_threshold_number.h"
namespace esphome {
namespace ld2412 {
namespace esphome::ld2412 {
GateThresholdNumber::GateThresholdNumber(uint8_t gate) : gate_(gate) {}
@@ -10,5 +9,4 @@ void GateThresholdNumber::control(float value) {
this->parent_->set_gate_threshold();
}
} // namespace ld2412
} // namespace esphome
} // namespace esphome::ld2412

View File

@@ -3,8 +3,7 @@
#include "esphome/components/number/number.h"
#include "../ld2412.h"
namespace esphome {
namespace ld2412 {
namespace esphome::ld2412 {
class GateThresholdNumber : public number::Number, public Parented<LD2412Component> {
public:
@@ -15,5 +14,4 @@ class GateThresholdNumber : public number::Number, public Parented<LD2412Compone
void control(float value) override;
};
} // namespace ld2412
} // namespace esphome
} // namespace esphome::ld2412

View File

@@ -1,12 +1,10 @@
#include "light_threshold_number.h"
namespace esphome {
namespace ld2412 {
namespace esphome::ld2412 {
void LightThresholdNumber::control(float value) {
this->publish_state(value);
this->parent_->set_light_out_control();
}
} // namespace ld2412
} // namespace esphome
} // namespace esphome::ld2412

View File

@@ -3,8 +3,7 @@
#include "esphome/components/number/number.h"
#include "../ld2412.h"
namespace esphome {
namespace ld2412 {
namespace esphome::ld2412 {
class LightThresholdNumber : public number::Number, public Parented<LD2412Component> {
public:
@@ -14,5 +13,4 @@ class LightThresholdNumber : public number::Number, public Parented<LD2412Compon
void control(float value) override;
};
} // namespace ld2412
} // namespace esphome
} // namespace esphome::ld2412

View File

@@ -1,12 +1,10 @@
#include "max_distance_timeout_number.h"
namespace esphome {
namespace ld2412 {
namespace esphome::ld2412 {
void MaxDistanceTimeoutNumber::control(float value) {
this->publish_state(value);
this->parent_->set_basic_config();
}
} // namespace ld2412
} // namespace esphome
} // namespace esphome::ld2412

View File

@@ -3,8 +3,7 @@
#include "esphome/components/number/number.h"
#include "../ld2412.h"
namespace esphome {
namespace ld2412 {
namespace esphome::ld2412 {
class MaxDistanceTimeoutNumber : public number::Number, public Parented<LD2412Component> {
public:
@@ -14,5 +13,4 @@ class MaxDistanceTimeoutNumber : public number::Number, public Parented<LD2412Co
void control(float value) override;
};
} // namespace ld2412
} // namespace esphome
} // namespace esphome::ld2412

View File

@@ -1,12 +1,10 @@
#include "baud_rate_select.h"
namespace esphome {
namespace ld2412 {
namespace esphome::ld2412 {
void BaudRateSelect::control(size_t index) {
this->publish_state(index);
this->parent_->set_baud_rate(this->option_at(index));
}
} // namespace ld2412
} // namespace esphome
} // namespace esphome::ld2412

View File

@@ -3,8 +3,7 @@
#include "esphome/components/select/select.h"
#include "../ld2412.h"
namespace esphome {
namespace ld2412 {
namespace esphome::ld2412 {
class BaudRateSelect : public select::Select, public Parented<LD2412Component> {
public:
@@ -14,5 +13,4 @@ class BaudRateSelect : public select::Select, public Parented<LD2412Component> {
void control(size_t index) override;
};
} // namespace ld2412
} // namespace esphome
} // namespace esphome::ld2412

View File

@@ -1,12 +1,10 @@
#include "distance_resolution_select.h"
namespace esphome {
namespace ld2412 {
namespace esphome::ld2412 {
void DistanceResolutionSelect::control(size_t index) {
this->publish_state(index);
this->parent_->set_distance_resolution(this->option_at(index));
}
} // namespace ld2412
} // namespace esphome
} // namespace esphome::ld2412

View File

@@ -3,8 +3,7 @@
#include "esphome/components/select/select.h"
#include "../ld2412.h"
namespace esphome {
namespace ld2412 {
namespace esphome::ld2412 {
class DistanceResolutionSelect : public select::Select, public Parented<LD2412Component> {
public:
@@ -14,5 +13,4 @@ class DistanceResolutionSelect : public select::Select, public Parented<LD2412Co
void control(size_t index) override;
};
} // namespace ld2412
} // namespace esphome
} // namespace esphome::ld2412

View File

@@ -1,12 +1,10 @@
#include "light_out_control_select.h"
namespace esphome {
namespace ld2412 {
namespace esphome::ld2412 {
void LightOutControlSelect::control(size_t index) {
this->publish_state(index);
this->parent_->set_light_out_control();
}
} // namespace ld2412
} // namespace esphome
} // namespace esphome::ld2412

View File

@@ -3,8 +3,7 @@
#include "esphome/components/select/select.h"
#include "../ld2412.h"
namespace esphome {
namespace ld2412 {
namespace esphome::ld2412 {
class LightOutControlSelect : public select::Select, public Parented<LD2412Component> {
public:
@@ -14,5 +13,4 @@ class LightOutControlSelect : public select::Select, public Parented<LD2412Compo
void control(size_t index) override;
};
} // namespace ld2412
} // namespace esphome
} // namespace esphome::ld2412

View File

@@ -1,12 +1,10 @@
#include "bluetooth_switch.h"
namespace esphome {
namespace ld2412 {
namespace esphome::ld2412 {
void BluetoothSwitch::write_state(bool state) {
this->publish_state(state);
this->parent_->set_bluetooth(state);
}
} // namespace ld2412
} // namespace esphome
} // namespace esphome::ld2412

View File

@@ -3,8 +3,7 @@
#include "esphome/components/switch/switch.h"
#include "../ld2412.h"
namespace esphome {
namespace ld2412 {
namespace esphome::ld2412 {
class BluetoothSwitch : public switch_::Switch, public Parented<LD2412Component> {
public:
@@ -14,5 +13,4 @@ class BluetoothSwitch : public switch_::Switch, public Parented<LD2412Component>
void write_state(bool state) override;
};
} // namespace ld2412
} // namespace esphome
} // namespace esphome::ld2412

View File

@@ -1,12 +1,10 @@
#include "engineering_mode_switch.h"
namespace esphome {
namespace ld2412 {
namespace esphome::ld2412 {
void EngineeringModeSwitch::write_state(bool state) {
this->publish_state(state);
this->parent_->set_engineering_mode(state);
}
} // namespace ld2412
} // namespace esphome
} // namespace esphome::ld2412

View File

@@ -3,8 +3,7 @@
#include "esphome/components/switch/switch.h"
#include "../ld2412.h"
namespace esphome {
namespace ld2412 {
namespace esphome::ld2412 {
class EngineeringModeSwitch : public switch_::Switch, public Parented<LD2412Component> {
public:
@@ -14,5 +13,4 @@ class EngineeringModeSwitch : public switch_::Switch, public Parented<LD2412Comp
void write_state(bool state) override;
};
} // namespace ld2412
} // namespace esphome
} // namespace esphome::ld2412

View File

@@ -2,8 +2,7 @@
#include "esphome/core/helpers.h"
#include "esphome/core/log.h"
namespace esphome {
namespace ld2420 {
namespace esphome::ld2420 {
static const char *const TAG = "ld2420.binary_sensor";
@@ -12,5 +11,4 @@ void LD2420BinarySensor::dump_config() {
LOG_BINARY_SENSOR(" ", "Presence", this->presence_bsensor_);
}
} // namespace ld2420
} // namespace esphome
} // namespace esphome::ld2420

View File

@@ -3,8 +3,7 @@
#include "../ld2420.h"
#include "esphome/components/binary_sensor/binary_sensor.h"
namespace esphome {
namespace ld2420 {
namespace esphome::ld2420 {
class LD2420BinarySensor : public LD2420Listener, public Component, binary_sensor::BinarySensor {
public:
@@ -21,5 +20,4 @@ class LD2420BinarySensor : public LD2420Listener, public Component, binary_senso
binary_sensor::BinarySensor *presence_bsensor_{nullptr};
};
} // namespace ld2420
} // namespace esphome
} // namespace esphome::ld2420

View File

@@ -4,13 +4,11 @@
static const char *const TAG = "ld2420.button";
namespace esphome {
namespace ld2420 {
namespace esphome::ld2420 {
void LD2420ApplyConfigButton::press_action() { this->parent_->apply_config_action(); }
void LD2420RevertConfigButton::press_action() { this->parent_->revert_config_action(); }
void LD2420RestartModuleButton::press_action() { this->parent_->restart_module_action(); }
void LD2420FactoryResetButton::press_action() { this->parent_->factory_reset_action(); }
} // namespace ld2420
} // namespace esphome
} // namespace esphome::ld2420

View File

@@ -3,8 +3,7 @@
#include "esphome/components/button/button.h"
#include "../ld2420.h"
namespace esphome {
namespace ld2420 {
namespace esphome::ld2420 {
class LD2420ApplyConfigButton : public button::Button, public Parented<LD2420Component> {
public:
@@ -38,5 +37,4 @@ class LD2420FactoryResetButton : public button::Button, public Parented<LD2420Co
void press_action() override;
};
} // namespace ld2420
} // namespace esphome
} // namespace esphome::ld2420

View File

@@ -58,8 +58,7 @@ Gate 0 high thresh = 10 00 uint16_t 0x0010, Threshold value = 60 EA 00 00 uint32
Gate 0 low thresh = 20 00 uint16_t 0x0020, Threshold value = 60 EA 00 00 uint32_t 0x0000EA60
*/
namespace esphome {
namespace ld2420 {
namespace esphome::ld2420 {
static const char *const TAG = "ld2420";
@@ -880,5 +879,4 @@ void LD2420Component::refresh_gate_config_numbers() {
#endif
} // namespace ld2420
} // namespace esphome
} // namespace esphome::ld2420

View File

@@ -17,8 +17,7 @@
#include "esphome/components/button/button.h"
#endif
namespace esphome {
namespace ld2420 {
namespace esphome::ld2420 {
static const uint8_t CALIBRATE_SAMPLES = 64;
static const uint8_t MAX_LINE_LENGTH = 46; // Max characters for serial buffer
@@ -193,5 +192,4 @@ class LD2420Component : public Component, public uart::UARTDevice {
std::vector<LD2420Listener *> listeners_{};
};
} // namespace ld2420
} // namespace esphome
} // namespace esphome::ld2420

View File

@@ -4,8 +4,7 @@
static const char *const TAG = "ld2420.number";
namespace esphome {
namespace ld2420 {
namespace esphome::ld2420 {
void LD2420TimeoutNumber::control(float timeout) {
this->publish_state(timeout);
@@ -69,5 +68,4 @@ void LD2420StillThresholdNumbers::control(float still_threshold) {
}
}
} // namespace ld2420
} // namespace esphome
} // namespace esphome::ld2420

View File

@@ -3,8 +3,7 @@
#include "esphome/components/number/number.h"
#include "../ld2420.h"
namespace esphome {
namespace ld2420 {
namespace esphome::ld2420 {
class LD2420TimeoutNumber : public number::Number, public Parented<LD2420Component> {
public:
@@ -74,5 +73,4 @@ class LD2420MoveThresholdNumbers : public number::Number, public Parented<LD2420
void control(float move_threshold) override;
};
} // namespace ld2420
} // namespace esphome
} // namespace esphome::ld2420

View File

@@ -2,8 +2,7 @@
#include "esphome/core/helpers.h"
#include "esphome/core/log.h"
namespace esphome {
namespace ld2420 {
namespace esphome::ld2420 {
static const char *const TAG = "ld2420.select";
@@ -12,5 +11,4 @@ void LD2420Select::control(size_t index) {
this->parent_->set_operating_mode(this->option_at(index));
}
} // namespace ld2420
} // namespace esphome
} // namespace esphome::ld2420

View File

@@ -3,8 +3,7 @@
#include "../ld2420.h"
#include "esphome/components/select/select.h"
namespace esphome {
namespace ld2420 {
namespace esphome::ld2420 {
class LD2420Select : public Component, public select::Select, public Parented<LD2420Component> {
public:
@@ -14,5 +13,4 @@ class LD2420Select : public Component, public select::Select, public Parented<LD
void control(size_t index) override;
};
} // namespace ld2420
} // namespace esphome
} // namespace esphome::ld2420

View File

@@ -2,8 +2,7 @@
#include "esphome/core/helpers.h"
#include "esphome/core/log.h"
namespace esphome {
namespace ld2420 {
namespace esphome::ld2420 {
static const char *const TAG = "ld2420.sensor";
@@ -12,5 +11,4 @@ void LD2420Sensor::dump_config() {
LOG_SENSOR(" ", "Distance", this->distance_sensor_);
}
} // namespace ld2420
} // namespace esphome
} // namespace esphome::ld2420

View File

@@ -3,8 +3,7 @@
#include "../ld2420.h"
#include "esphome/components/sensor/sensor.h"
namespace esphome {
namespace ld2420 {
namespace esphome::ld2420 {
class LD2420Sensor : public LD2420Listener, public Component, sensor::Sensor {
public:
@@ -30,5 +29,4 @@ class LD2420Sensor : public LD2420Listener, public Component, sensor::Sensor {
std::vector<sensor::Sensor *> energy_sensors_ = std::vector<sensor::Sensor *>(TOTAL_GATES);
};
} // namespace ld2420
} // namespace esphome
} // namespace esphome::ld2420

View File

@@ -2,8 +2,7 @@
#include "esphome/core/helpers.h"
#include "esphome/core/log.h"
namespace esphome {
namespace ld2420 {
namespace esphome::ld2420 {
static const char *const TAG = "ld2420.text_sensor";
@@ -12,5 +11,4 @@ void LD2420TextSensor::dump_config() {
LOG_TEXT_SENSOR(" ", "Firmware", this->fw_version_text_sensor_);
}
} // namespace ld2420
} // namespace esphome
} // namespace esphome::ld2420

View File

@@ -3,8 +3,7 @@
#include "../ld2420.h"
#include "esphome/components/text_sensor/text_sensor.h"
namespace esphome {
namespace ld2420 {
namespace esphome::ld2420 {
class LD2420TextSensor : public LD2420Listener, public Component, text_sensor::TextSensor {
public:
@@ -20,5 +19,4 @@ class LD2420TextSensor : public LD2420Listener, public Component, text_sensor::T
text_sensor::TextSensor *fw_version_text_sensor_{nullptr};
};
} // namespace ld2420
} // namespace esphome
} // namespace esphome::ld2420

View File

@@ -1,9 +1,7 @@
#include "factory_reset_button.h"
namespace esphome {
namespace ld2450 {
namespace esphome::ld2450 {
void FactoryResetButton::press_action() { this->parent_->factory_reset(); }
} // namespace ld2450
} // namespace esphome
} // namespace esphome::ld2450

View File

@@ -3,8 +3,7 @@
#include "esphome/components/button/button.h"
#include "../ld2450.h"
namespace esphome {
namespace ld2450 {
namespace esphome::ld2450 {
class FactoryResetButton : public button::Button, public Parented<LD2450Component> {
public:
@@ -14,5 +13,4 @@ class FactoryResetButton : public button::Button, public Parented<LD2450Componen
void press_action() override;
};
} // namespace ld2450
} // namespace esphome
} // namespace esphome::ld2450

View File

@@ -1,9 +1,7 @@
#include "restart_button.h"
namespace esphome {
namespace ld2450 {
namespace esphome::ld2450 {
void RestartButton::press_action() { this->parent_->restart_and_read_all_info(); }
} // namespace ld2450
} // namespace esphome
} // namespace esphome::ld2450

View File

@@ -3,8 +3,7 @@
#include "esphome/components/button/button.h"
#include "../ld2450.h"
namespace esphome {
namespace ld2450 {
namespace esphome::ld2450 {
class RestartButton : public button::Button, public Parented<LD2450Component> {
public:
@@ -14,5 +13,4 @@ class RestartButton : public button::Button, public Parented<LD2450Component> {
void press_action() override;
};
} // namespace ld2450
} // namespace esphome
} // namespace esphome::ld2450

View File

@@ -13,12 +13,9 @@
#include <cmath>
#include <numbers>
namespace esphome {
namespace ld2450 {
namespace esphome::ld2450 {
static const char *const TAG = "ld2450";
static const char *const UNKNOWN_MAC = "unknown";
static const char *const VERSION_FMT = "%u.%02X.%02X%02X%02X%02X";
enum BaudRate : uint8_t {
BAUD_RATE_9600 = 1,
@@ -192,15 +189,15 @@ void LD2450Component::setup() {
}
void LD2450Component::dump_config() {
std::string mac_str =
mac_address_is_valid(this->mac_address_) ? format_mac_address_pretty(this->mac_address_) : UNKNOWN_MAC;
std::string version = str_sprintf(VERSION_FMT, this->version_[1], this->version_[0], this->version_[5],
this->version_[4], this->version_[3], this->version_[2]);
char mac_s[18];
char version_s[20];
const char *mac_str = ld24xx::format_mac_str(this->mac_address_, mac_s);
ld24xx::format_version_str(this->version_, version_s);
ESP_LOGCONFIG(TAG,
"LD2450:\n"
" Firmware version: %s\n"
" MAC address: %s",
version.c_str(), mac_str.c_str());
version_s, mac_str);
#ifdef USE_BINARY_SENSOR
ESP_LOGCONFIG(TAG, "Binary Sensors:");
LOG_BINARY_SENSOR(" ", "MovingTarget", this->moving_target_binary_sensor_);
@@ -642,12 +639,12 @@ bool LD2450Component::handle_ack_data_() {
case CMD_QUERY_VERSION: {
std::memcpy(this->version_, &this->buffer_data_[12], sizeof(this->version_));
std::string version = str_sprintf(VERSION_FMT, this->version_[1], this->version_[0], this->version_[5],
this->version_[4], this->version_[3], this->version_[2]);
ESP_LOGV(TAG, "Firmware version: %s", version.c_str());
char version_s[20];
ld24xx::format_version_str(this->version_, version_s);
ESP_LOGV(TAG, "Firmware version: %s", version_s);
#ifdef USE_TEXT_SENSOR
if (this->version_text_sensor_ != nullptr) {
this->version_text_sensor_->publish_state(version);
this->version_text_sensor_->publish_state(version_s);
}
#endif
break;
@@ -663,9 +660,9 @@ bool LD2450Component::handle_ack_data_() {
std::memcpy(this->mac_address_, &this->buffer_data_[10], sizeof(this->mac_address_));
}
std::string mac_str =
mac_address_is_valid(this->mac_address_) ? format_mac_address_pretty(this->mac_address_) : UNKNOWN_MAC;
ESP_LOGV(TAG, "MAC address: %s", mac_str.c_str());
char mac_s[18];
const char *mac_str = ld24xx::format_mac_str(this->mac_address_, mac_s);
ESP_LOGV(TAG, "MAC address: %s", mac_str);
#ifdef USE_TEXT_SENSOR
if (this->mac_text_sensor_ != nullptr) {
this->mac_text_sensor_->publish_state(mac_str);
@@ -941,5 +938,4 @@ float LD2450Component::restore_from_flash_() {
}
#endif
} // namespace ld2450
} // namespace esphome
} // namespace esphome::ld2450

View File

@@ -31,8 +31,7 @@
#include <array>
namespace esphome {
namespace ld2450 {
namespace esphome::ld2450 {
using namespace ld24xx;
@@ -193,5 +192,4 @@ class LD2450Component : public Component, public uart::UARTDevice {
#endif
};
} // namespace ld2450
} // namespace esphome
} // namespace esphome::ld2450

View File

@@ -1,12 +1,10 @@
#include "presence_timeout_number.h"
namespace esphome {
namespace ld2450 {
namespace esphome::ld2450 {
void PresenceTimeoutNumber::control(float value) {
this->publish_state(value);
this->parent_->set_presence_timeout();
}
} // namespace ld2450
} // namespace esphome
} // namespace esphome::ld2450

View File

@@ -3,8 +3,7 @@
#include "esphome/components/number/number.h"
#include "../ld2450.h"
namespace esphome {
namespace ld2450 {
namespace esphome::ld2450 {
class PresenceTimeoutNumber : public number::Number, public Parented<LD2450Component> {
public:
@@ -14,5 +13,4 @@ class PresenceTimeoutNumber : public number::Number, public Parented<LD2450Compo
void control(float value) override;
};
} // namespace ld2450
} // namespace esphome
} // namespace esphome::ld2450

View File

@@ -1,7 +1,6 @@
#include "zone_coordinate_number.h"
namespace esphome {
namespace ld2450 {
namespace esphome::ld2450 {
ZoneCoordinateNumber::ZoneCoordinateNumber(uint8_t zone) : zone_(zone) {}
@@ -10,5 +9,4 @@ void ZoneCoordinateNumber::control(float value) {
this->parent_->set_zone_coordinate(this->zone_);
}
} // namespace ld2450
} // namespace esphome
} // namespace esphome::ld2450

View File

@@ -3,8 +3,7 @@
#include "esphome/components/number/number.h"
#include "../ld2450.h"
namespace esphome {
namespace ld2450 {
namespace esphome::ld2450 {
class ZoneCoordinateNumber : public number::Number, public Parented<LD2450Component> {
public:
@@ -15,5 +14,4 @@ class ZoneCoordinateNumber : public number::Number, public Parented<LD2450Compon
void control(float value) override;
};
} // namespace ld2450
} // namespace esphome
} // namespace esphome::ld2450

View File

@@ -1,12 +1,10 @@
#include "baud_rate_select.h"
namespace esphome {
namespace ld2450 {
namespace esphome::ld2450 {
void BaudRateSelect::control(size_t index) {
this->publish_state(index);
this->parent_->set_baud_rate(this->option_at(index));
}
} // namespace ld2450
} // namespace esphome
} // namespace esphome::ld2450

View File

@@ -3,8 +3,7 @@
#include "esphome/components/select/select.h"
#include "../ld2450.h"
namespace esphome {
namespace ld2450 {
namespace esphome::ld2450 {
class BaudRateSelect : public select::Select, public Parented<LD2450Component> {
public:
@@ -14,5 +13,4 @@ class BaudRateSelect : public select::Select, public Parented<LD2450Component> {
void control(size_t index) override;
};
} // namespace ld2450
} // namespace esphome
} // namespace esphome::ld2450

View File

@@ -1,12 +1,10 @@
#include "zone_type_select.h"
namespace esphome {
namespace ld2450 {
namespace esphome::ld2450 {
void ZoneTypeSelect::control(size_t index) {
this->publish_state(index);
this->parent_->set_zone_type(this->option_at(index));
}
} // namespace ld2450
} // namespace esphome
} // namespace esphome::ld2450

Some files were not shown because too many files have changed in this diff Show More