Merge pull request #5590 from esphome/bump-2023.10.2

2023.10.2
This commit is contained in:
Jesse Hills 2023-10-24 10:15:07 +13:00 committed by GitHub
commit 0104bf3fc8
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
17 changed files with 234 additions and 79 deletions

View file

@ -225,7 +225,7 @@ esphome/components/pn532_spi/* @OttoWinter @jesserockz
esphome/components/power_supply/* @esphome/core esphome/components/power_supply/* @esphome/core
esphome/components/preferences/* @esphome/core esphome/components/preferences/* @esphome/core
esphome/components/psram/* @esphome/core esphome/components/psram/* @esphome/core
esphome/components/pulse_meter/* @cstaahl @stevebaxter esphome/components/pulse_meter/* @TrentHouliston @cstaahl @stevebaxter
esphome/components/pvvx_mithermometer/* @pasiz esphome/components/pvvx_mithermometer/* @pasiz
esphome/components/qmp6988/* @andrewpc esphome/components/qmp6988/* @andrewpc
esphome/components/qr_code/* @wjtje esphome/components/qr_code/* @wjtje

View file

@ -17,11 +17,12 @@ CONF_ON_FRAME = "on_frame"
def validate_id(config): def validate_id(config):
can_id = config[CONF_CAN_ID] if CONF_CAN_ID in config:
id_ext = config[CONF_USE_EXTENDED_ID] can_id = config[CONF_CAN_ID]
if not id_ext: id_ext = config[CONF_USE_EXTENDED_ID]
if can_id > 0x7FF: if not id_ext:
raise cv.Invalid("Standard IDs must be 11 Bit (0x000-0x7ff / 0-2047)") if can_id > 0x7FF:
raise cv.Invalid("Standard IDs must be 11 Bit (0x000-0x7ff / 0-2047)")
return config return config
@ -151,22 +152,18 @@ async def canbus_action_to_code(config, action_id, template_arg, args):
if can_id := config.get(CONF_CAN_ID): if can_id := config.get(CONF_CAN_ID):
can_id = await cg.templatable(can_id, args, cg.uint32) can_id = await cg.templatable(can_id, args, cg.uint32)
cg.add(var.set_can_id(can_id)) cg.add(var.set_can_id(can_id))
use_extended_id = await cg.templatable( cg.add(var.set_use_extended_id(config[CONF_USE_EXTENDED_ID]))
config[CONF_USE_EXTENDED_ID], args, cg.uint32
)
cg.add(var.set_use_extended_id(use_extended_id))
remote_transmission_request = await cg.templatable( cg.add(
config[CONF_REMOTE_TRANSMISSION_REQUEST], args, bool var.set_remote_transmission_request(config[CONF_REMOTE_TRANSMISSION_REQUEST])
) )
cg.add(var.set_remote_transmission_request(remote_transmission_request))
data = config[CONF_DATA] data = config[CONF_DATA]
if isinstance(data, bytes):
data = [int(x) for x in data]
if cg.is_template(data): if cg.is_template(data):
templ = await cg.templatable(data, args, cg.std_vector.template(cg.uint8)) templ = await cg.templatable(data, args, cg.std_vector.template(cg.uint8))
cg.add(var.set_data_template(templ)) cg.add(var.set_data_template(templ))
else: else:
if isinstance(data, bytes):
data = [int(x) for x in data]
cg.add(var.set_data_static(data)) cg.add(var.set_data_static(data))
return var return var

View file

@ -213,6 +213,8 @@ ClimateCall &ClimateCall::set_preset(const std::string &preset) {
this->set_preset(CLIMATE_PRESET_SLEEP); this->set_preset(CLIMATE_PRESET_SLEEP);
} else if (str_equals_case_insensitive(preset, "ACTIVITY")) { } else if (str_equals_case_insensitive(preset, "ACTIVITY")) {
this->set_preset(CLIMATE_PRESET_ACTIVITY); this->set_preset(CLIMATE_PRESET_ACTIVITY);
} else if (str_equals_case_insensitive(preset, "NONE")) {
this->set_preset(CLIMATE_PRESET_NONE);
} else { } else {
if (this->parent_->get_traits().supports_custom_preset(preset)) { if (this->parent_->get_traits().supports_custom_preset(preset)) {
this->custom_preset_ = preset; this->custom_preset_ = preset;

View file

@ -1,10 +1,14 @@
from esphome.components.logger import USB_CDC, USB_SERIAL_JTAG from esphome.components import improv_base
from esphome.components.esp32 import get_esp32_variant
from esphome.components.esp32.const import (
VARIANT_ESP32S3,
)
from esphome.components.logger import USB_CDC
from esphome.const import CONF_BAUD_RATE, CONF_HARDWARE_UART, CONF_ID, CONF_LOGGER from esphome.const import CONF_BAUD_RATE, CONF_HARDWARE_UART, CONF_ID, CONF_LOGGER
import esphome.codegen as cg import esphome.codegen as cg
import esphome.config_validation as cv import esphome.config_validation as cv
from esphome.core import CORE from esphome.core import CORE
import esphome.final_validate as fv import esphome.final_validate as fv
from esphome.components import improv_base
AUTO_LOAD = ["improv_base"] AUTO_LOAD = ["improv_base"]
CODEOWNERS = ["@esphome/core"] CODEOWNERS = ["@esphome/core"]
@ -30,7 +34,10 @@ def validate_logger(config):
if logger_conf[CONF_BAUD_RATE] == 0: if logger_conf[CONF_BAUD_RATE] == 0:
raise cv.Invalid("improv_serial requires the logger baud_rate to be not 0") raise cv.Invalid("improv_serial requires the logger baud_rate to be not 0")
if CORE.using_esp_idf: if CORE.using_esp_idf:
if logger_conf[CONF_HARDWARE_UART] in [USB_SERIAL_JTAG, USB_CDC]: if (
logger_conf[CONF_HARDWARE_UART] == USB_CDC
and get_esp32_variant() == VARIANT_ESP32S3
):
raise cv.Invalid( raise cv.Invalid(
"improv_serial does not support the selected logger hardware_uart" "improv_serial does not support the selected logger hardware_uart"
) )

View file

@ -31,26 +31,57 @@ void ImprovSerialComponent::setup() {
void ImprovSerialComponent::dump_config() { ESP_LOGCONFIG(TAG, "Improv Serial:"); } void ImprovSerialComponent::dump_config() { ESP_LOGCONFIG(TAG, "Improv Serial:"); }
int ImprovSerialComponent::available_() { optional<uint8_t> ImprovSerialComponent::read_byte_() {
optional<uint8_t> byte;
uint8_t data = 0;
#ifdef USE_ARDUINO #ifdef USE_ARDUINO
return this->hw_serial_->available(); if (this->hw_serial_->available()) {
this->hw_serial_->readBytes(&data, 1);
byte = data;
}
#endif #endif
#ifdef USE_ESP_IDF #ifdef USE_ESP_IDF
size_t available; switch (logger::global_logger->get_uart()) {
uart_get_buffered_data_len(this->uart_num_, &available); case logger::UART_SELECTION_UART0:
return available; case logger::UART_SELECTION_UART1:
#if !defined(USE_ESP32_VARIANT_ESP32C3) && !defined(USE_ESP32_VARIANT_ESP32C6) && \
!defined(USE_ESP32_VARIANT_ESP32S2) && !defined(USE_ESP32_VARIANT_ESP32S3)
case logger::UART_SELECTION_UART2:
#endif // !USE_ESP32_VARIANT_ESP32C3 && !USE_ESP32_VARIANT_ESP32S2 && !USE_ESP32_VARIANT_ESP32S3
if (this->uart_num_ >= 0) {
size_t available;
uart_get_buffered_data_len(this->uart_num_, &available);
if (available) {
uart_read_bytes(this->uart_num_, &data, 1, 20 / portTICK_PERIOD_MS);
byte = data;
}
}
break;
#if defined(CONFIG_ESP_CONSOLE_USB_CDC) && (defined(USE_ESP32_VARIANT_ESP32S2) || defined(USE_ESP32_VARIANT_ESP32S3))
case logger::UART_SELECTION_USB_CDC:
#if ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(5, 0, 0)
if (esp_usb_console_available_for_read()) {
#else
if (esp_usb_console_read_available()) {
#endif #endif
} esp_usb_console_read_buf((char *) &data, 1);
byte = data;
uint8_t ImprovSerialComponent::read_byte_() { }
uint8_t data; break;
#ifdef USE_ARDUINO #endif // USE_ESP32_VARIANT_ESP32S2 || USE_ESP32_VARIANT_ESP32S3
this->hw_serial_->readBytes(&data, 1); #if defined(USE_ESP32_VARIANT_ESP32C3) || defined(USE_ESP32_VARIANT_ESP32C6) || defined(USE_ESP32_VARIANT_ESP32S3)
case logger::UART_SELECTION_USB_SERIAL_JTAG: {
if (usb_serial_jtag_read_bytes((char *) &data, 1, 20 / portTICK_PERIOD_MS)) {
byte = data;
}
break;
}
#endif // USE_ESP32_VARIANT_ESP32C3 || USE_ESP32_VARIANT_ESP32C6 || USE_ESP32_VARIANT_ESP32S3
default:
break;
}
#endif #endif
#ifdef USE_ESP_IDF return byte;
uart_read_bytes(this->uart_num_, &data, 1, 20 / portTICK_PERIOD_MS);
#endif
return data;
} }
void ImprovSerialComponent::write_data_(std::vector<uint8_t> &data) { void ImprovSerialComponent::write_data_(std::vector<uint8_t> &data) {
@ -59,24 +90,49 @@ void ImprovSerialComponent::write_data_(std::vector<uint8_t> &data) {
this->hw_serial_->write(data.data(), data.size()); this->hw_serial_->write(data.data(), data.size());
#endif #endif
#ifdef USE_ESP_IDF #ifdef USE_ESP_IDF
uart_write_bytes(this->uart_num_, data.data(), data.size()); switch (logger::global_logger->get_uart()) {
case logger::UART_SELECTION_UART0:
case logger::UART_SELECTION_UART1:
#if !defined(USE_ESP32_VARIANT_ESP32C3) && !defined(USE_ESP32_VARIANT_ESP32C6) && \
!defined(USE_ESP32_VARIANT_ESP32S2) && !defined(USE_ESP32_VARIANT_ESP32S3)
case logger::UART_SELECTION_UART2:
#endif // !USE_ESP32_VARIANT_ESP32C3 && !USE_ESP32_VARIANT_ESP32S2 && !USE_ESP32_VARIANT_ESP32S3
uart_write_bytes(this->uart_num_, data.data(), data.size());
break;
#if defined(CONFIG_ESP_CONSOLE_USB_CDC) && (defined(USE_ESP32_VARIANT_ESP32S2) || defined(USE_ESP32_VARIANT_ESP32S3))
case logger::UART_SELECTION_USB_CDC: {
const char *msg = (char *) data.data();
esp_usb_console_write_buf(msg, data.size());
break;
}
#endif // USE_ESP32_VARIANT_ESP32S2 || USE_ESP32_VARIANT_ESP32S3
#if defined(USE_ESP32_VARIANT_ESP32C3) || defined(USE_ESP32_VARIANT_ESP32C6) || defined(USE_ESP32_VARIANT_ESP32S3)
case logger::UART_SELECTION_USB_SERIAL_JTAG:
usb_serial_jtag_write_bytes((char *) data.data(), data.size(), 20 / portTICK_PERIOD_MS);
break;
#endif // USE_ESP32_VARIANT_ESP32C3 || USE_ESP32_VARIANT_ESP32S3
default:
break;
}
#endif #endif
} }
void ImprovSerialComponent::loop() { void ImprovSerialComponent::loop() {
const uint32_t now = millis(); if (this->last_read_byte_ && (millis() - this->last_read_byte_ > IMPROV_SERIAL_TIMEOUT)) {
if (now - this->last_read_byte_ > 50) { this->last_read_byte_ = 0;
this->rx_buffer_.clear(); this->rx_buffer_.clear();
this->last_read_byte_ = now; ESP_LOGV(TAG, "Improv Serial timeout");
} }
while (this->available_()) { auto byte = this->read_byte_();
uint8_t byte = this->read_byte_(); while (byte.has_value()) {
if (this->parse_improv_serial_byte_(byte)) { if (this->parse_improv_serial_byte_(byte.value())) {
this->last_read_byte_ = now; this->last_read_byte_ = millis();
} else { } else {
this->last_read_byte_ = 0;
this->rx_buffer_.clear(); this->rx_buffer_.clear();
} }
byte = this->read_byte_();
} }
if (this->state_ == improv::STATE_PROVISIONING) { if (this->state_ == improv::STATE_PROVISIONING) {

View file

@ -14,6 +14,13 @@
#endif #endif
#ifdef USE_ESP_IDF #ifdef USE_ESP_IDF
#include <driver/uart.h> #include <driver/uart.h>
#if defined(USE_ESP32_VARIANT_ESP32C3) || defined(USE_ESP32_VARIANT_ESP32C6) || defined(USE_ESP32_VARIANT_ESP32S3) || \
defined(USE_ESP32_VARIANT_ESP32H2)
#include <driver/usb_serial_jtag.h>
#endif
#if defined(USE_ESP32_VARIANT_ESP32S2) || defined(USE_ESP32_VARIANT_ESP32S3)
#include <esp_private/usb_console.h>
#endif
#endif #endif
namespace esphome { namespace esphome {
@ -26,6 +33,7 @@ enum ImprovSerialType : uint8_t {
TYPE_RPC_RESPONSE = 0x04 TYPE_RPC_RESPONSE = 0x04
}; };
static const uint16_t IMPROV_SERIAL_TIMEOUT = 100;
static const uint8_t IMPROV_SERIAL_VERSION = 1; static const uint8_t IMPROV_SERIAL_VERSION = 1;
class ImprovSerialComponent : public Component, public improv_base::ImprovBase { class ImprovSerialComponent : public Component, public improv_base::ImprovBase {
@ -48,8 +56,7 @@ class ImprovSerialComponent : public Component, public improv_base::ImprovBase {
std::vector<uint8_t> build_rpc_settings_response_(improv::Command command); std::vector<uint8_t> build_rpc_settings_response_(improv::Command command);
std::vector<uint8_t> build_version_info_(); std::vector<uint8_t> build_version_info_();
int available_(); optional<uint8_t> read_byte_();
uint8_t read_byte_();
void write_data_(std::vector<uint8_t> &data); void write_data_(std::vector<uint8_t> &data);
#ifdef USE_ARDUINO #ifdef USE_ARDUINO

View file

@ -3,8 +3,21 @@
#ifdef USE_ESP_IDF #ifdef USE_ESP_IDF
#include <driver/uart.h> #include <driver/uart.h>
#if defined(USE_ESP32_VARIANT_ESP32C3) || defined(USE_ESP32_VARIANT_ESP32C6) || defined(USE_ESP32_VARIANT_ESP32S3) || \
defined(USE_ESP32_VARIANT_ESP32H2)
#include <driver/usb_serial_jtag.h>
#include <esp_vfs_dev.h>
#include <esp_vfs_usb_serial_jtag.h>
#endif
#include "freertos/FreeRTOS.h" #include "freertos/FreeRTOS.h"
#include "esp_idf_version.h" #include "esp_idf_version.h"
#include <cstdint>
#include <cstdio>
#include <fcntl.h>
#endif // USE_ESP_IDF #endif // USE_ESP_IDF
#if defined(USE_ESP32_FRAMEWORK_ARDUINO) || defined(USE_ESP_IDF) #if defined(USE_ESP32_FRAMEWORK_ARDUINO) || defined(USE_ESP_IDF)
@ -93,6 +106,58 @@ void Logger::log_vprintf_(int level, const char *tag, int line, const __FlashStr
} }
#endif #endif
#ifdef USE_ESP_IDF
void Logger::init_uart_() {
uart_config_t uart_config{};
uart_config.baud_rate = (int) baud_rate_;
uart_config.data_bits = UART_DATA_8_BITS;
uart_config.parity = UART_PARITY_DISABLE;
uart_config.stop_bits = UART_STOP_BITS_1;
uart_config.flow_ctrl = UART_HW_FLOWCTRL_DISABLE;
#if ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(5, 0, 0)
uart_config.source_clk = UART_SCLK_DEFAULT;
#endif
uart_param_config(this->uart_num_, &uart_config);
const int uart_buffer_size = tx_buffer_size_;
// Install UART driver using an event queue here
uart_driver_install(this->uart_num_, uart_buffer_size, uart_buffer_size, 10, nullptr, 0);
}
#if defined(USE_ESP32_VARIANT_ESP32S2) || defined(USE_ESP32_VARIANT_ESP32S3)
void Logger::init_usb_cdc_() {}
#endif
#if defined(USE_ESP32_VARIANT_ESP32C3) || defined(USE_ESP32_VARIANT_ESP32C6) || defined(USE_ESP32_VARIANT_ESP32S3) || \
defined(USE_ESP32_VARIANT_ESP32H2)
void Logger::init_usb_serial_jtag_() {
setvbuf(stdin, NULL, _IONBF, 0); // Disable buffering on stdin
// Minicom, screen, idf_monitor send CR when ENTER key is pressed
esp_vfs_dev_usb_serial_jtag_set_rx_line_endings(ESP_LINE_ENDINGS_CR);
// Move the caret to the beginning of the next line on '\n'
esp_vfs_dev_usb_serial_jtag_set_tx_line_endings(ESP_LINE_ENDINGS_CRLF);
// Enable non-blocking mode on stdin and stdout
fcntl(fileno(stdout), F_SETFL, 0);
fcntl(fileno(stdin), F_SETFL, 0);
usb_serial_jtag_driver_config_t usb_serial_jtag_config{};
usb_serial_jtag_config.rx_buffer_size = 512;
usb_serial_jtag_config.tx_buffer_size = 512;
esp_err_t ret = ESP_OK;
// Install USB-SERIAL-JTAG driver for interrupt-driven reads and writes
ret = usb_serial_jtag_driver_install(&usb_serial_jtag_config);
if (ret != ESP_OK) {
return;
}
// Tell vfs to use usb-serial-jtag driver
esp_vfs_usb_serial_jtag_use_driver();
}
#endif
#endif
int HOT Logger::level_for(const char *tag) { int HOT Logger::level_for(const char *tag) {
// Uses std::vector<> for low memory footprint, though the vector // Uses std::vector<> for low memory footprint, though the vector
// could be sorted to minimize lookup times. This feature isn't used that // could be sorted to minimize lookup times. This feature isn't used that
@ -120,19 +185,19 @@ void HOT Logger::log_message_(int level, const char *tag, int offset) {
#ifdef USE_ESP_IDF #ifdef USE_ESP_IDF
if ( if (
#if defined(USE_ESP32_VARIANT_ESP32S2) #if defined(USE_ESP32_VARIANT_ESP32S2)
uart_ == UART_SELECTION_USB_CDC this->uart_ == UART_SELECTION_USB_CDC
#elif defined(USE_ESP32_VARIANT_ESP32C3) || defined(USE_ESP32_VARIANT_ESP32C6) || defined(USE_ESP32_VARIANT_ESP32H2) #elif defined(USE_ESP32_VARIANT_ESP32C3) || defined(USE_ESP32_VARIANT_ESP32C6) || defined(USE_ESP32_VARIANT_ESP32H2)
uart_ == UART_SELECTION_USB_SERIAL_JTAG this->uart_ == UART_SELECTION_USB_SERIAL_JTAG
#elif defined(USE_ESP32_VARIANT_ESP32S3) #elif defined(USE_ESP32_VARIANT_ESP32S3)
uart_ == UART_SELECTION_USB_CDC || uart_ == UART_SELECTION_USB_SERIAL_JTAG this->uart_ == UART_SELECTION_USB_CDC || this->uart_ == UART_SELECTION_USB_SERIAL_JTAG
#else #else
/* DISABLES CODE */ (false) // NOLINT /* DISABLES CODE */ (false) // NOLINT
#endif #endif
) { ) {
puts(msg); puts(msg);
} else { } else {
uart_write_bytes(uart_num_, msg, strlen(msg)); uart_write_bytes(this->uart_num_, msg, strlen(msg));
uart_write_bytes(uart_num_, "\n", 1); uart_write_bytes(this->uart_num_, "\n", 1);
} }
#endif #endif
} }
@ -209,48 +274,38 @@ void Logger::pre_setup() {
} }
#endif // USE_ARDUINO #endif // USE_ARDUINO
#ifdef USE_ESP_IDF #ifdef USE_ESP_IDF
uart_num_ = UART_NUM_0; this->uart_num_ = UART_NUM_0;
switch (uart_) { switch (this->uart_) {
case UART_SELECTION_UART0: case UART_SELECTION_UART0:
uart_num_ = UART_NUM_0; this->uart_num_ = UART_NUM_0;
break; break;
case UART_SELECTION_UART1: case UART_SELECTION_UART1:
uart_num_ = UART_NUM_1; this->uart_num_ = UART_NUM_1;
break; break;
#if !defined(USE_ESP32_VARIANT_ESP32C3) && !defined(USE_ESP32_VARIANT_ESP32C6) && \ #if !defined(USE_ESP32_VARIANT_ESP32C3) && !defined(USE_ESP32_VARIANT_ESP32C6) && \
!defined(USE_ESP32_VARIANT_ESP32S2) && !defined(USE_ESP32_VARIANT_ESP32S3) && !defined(USE_ESP32_VARIANT_ESP32H2) !defined(USE_ESP32_VARIANT_ESP32S2) && !defined(USE_ESP32_VARIANT_ESP32S3) && !defined(USE_ESP32_VARIANT_ESP32H2)
case UART_SELECTION_UART2: case UART_SELECTION_UART2:
uart_num_ = UART_NUM_2; this->uart_num_ = UART_NUM_2;
break; break;
#endif // !USE_ESP32_VARIANT_ESP32C3 && !USE_ESP32_VARIANT_ESP32S2 && !USE_ESP32_VARIANT_ESP32S3 && #endif // !USE_ESP32_VARIANT_ESP32C3 && !USE_ESP32_VARIANT_ESP32S2 && !USE_ESP32_VARIANT_ESP32S3 &&
// !USE_ESP32_VARIANT_ESP32H2 // !USE_ESP32_VARIANT_ESP32H2
#if defined(USE_ESP32_VARIANT_ESP32S2) || defined(USE_ESP32_VARIANT_ESP32S3) #if defined(USE_ESP32_VARIANT_ESP32S2) || defined(USE_ESP32_VARIANT_ESP32S3)
case UART_SELECTION_USB_CDC: case UART_SELECTION_USB_CDC:
uart_num_ = -1; this->uart_num_ = -1;
this->init_usb_cdc_();
break; break;
#endif // USE_ESP32_VARIANT_ESP32S2 || USE_ESP32_VARIANT_ESP32S3 #endif // USE_ESP32_VARIANT_ESP32S2 || USE_ESP32_VARIANT_ESP32S3
#if defined(USE_ESP32_VARIANT_ESP32C3) || defined(USE_ESP32_VARIANT_ESP32C6) || defined(USE_ESP32_VARIANT_ESP32S3) || \ #if defined(USE_ESP32_VARIANT_ESP32C3) || defined(USE_ESP32_VARIANT_ESP32C6) || defined(USE_ESP32_VARIANT_ESP32S3) || \
defined(USE_ESP32_VARIANT_ESP32H2) defined(USE_ESP32_VARIANT_ESP32H2)
case UART_SELECTION_USB_SERIAL_JTAG: case UART_SELECTION_USB_SERIAL_JTAG:
uart_num_ = -1; this->uart_num_ = -1;
this->init_usb_serial_jtag_();
break; break;
#endif // USE_ESP32_VARIANT_ESP32C3 || USE_ESP32_VARIANT_ESP32C6 || USE_ESP32_VARIANT_ESP32S3 || #endif // USE_ESP32_VARIANT_ESP32C3 || USE_ESP32_VARIANT_ESP32C6 || USE_ESP32_VARIANT_ESP32S3 ||
// USE_ESP32_VARIANT_ESP32H2 // USE_ESP32_VARIANT_ESP32H2
} }
if (uart_num_ >= 0) { if (this->uart_num_ >= 0) {
uart_config_t uart_config{}; this->init_uart_();
uart_config.baud_rate = (int) baud_rate_;
uart_config.data_bits = UART_DATA_8_BITS;
uart_config.parity = UART_PARITY_DISABLE;
uart_config.stop_bits = UART_STOP_BITS_1;
uart_config.flow_ctrl = UART_HW_FLOWCTRL_DISABLE;
#if ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(5, 0, 0)
uart_config.source_clk = UART_SCLK_DEFAULT;
#endif
uart_param_config(uart_num_, &uart_config);
const int uart_buffer_size = tx_buffer_size_;
// Install UART driver using an event queue here
uart_driver_install(uart_num_, uart_buffer_size, uart_buffer_size, 10, nullptr, 0);
} }
#endif // USE_ESP_IDF #endif // USE_ESP_IDF
} }

View file

@ -107,6 +107,16 @@ class Logger : public Component {
#endif #endif
protected: protected:
#ifdef USE_ESP_IDF
void init_uart_();
#if defined(USE_ESP32_VARIANT_ESP32S2) || defined(USE_ESP32_VARIANT_ESP32S3)
void init_usb_cdc_();
#endif
#if defined(USE_ESP32_VARIANT_ESP32C3) || defined(USE_ESP32_VARIANT_ESP32C6) || defined(USE_ESP32_VARIANT_ESP32S3) || \
defined(USE_ESP32_VARIANT_ESP32H2)
void init_usb_serial_jtag_();
#endif
#endif
void write_header_(int level, const char *tag, int line); void write_header_(int level, const char *tag, int line);
void write_footer_(); void write_footer_();
void log_message_(int level, const char *tag, int offset = 0); void log_message_(int level, const char *tag, int offset = 0);

View file

@ -19,9 +19,7 @@ class MQTTBackendLibreTiny final : public MQTTBackend {
void set_will(const char *topic, uint8_t qos, bool retain, const char *payload) final { void set_will(const char *topic, uint8_t qos, bool retain, const char *payload) final {
mqtt_client_.setWill(topic, qos, retain, payload); mqtt_client_.setWill(topic, qos, retain, payload);
} }
void set_server(network::IPAddress ip, uint16_t port) final { void set_server(network::IPAddress ip, uint16_t port) final { mqtt_client_.setServer(IPAddress(ip), port); }
mqtt_client_.setServer(IPAddress(static_cast<uint32_t>(ip)), port);
}
void set_server(const char *host, uint16_t port) final { mqtt_client_.setServer(host, port); } void set_server(const char *host, uint16_t port) final { mqtt_client_.setServer(host, port); }
#if ASYNC_TCP_SSL_ENABLED #if ASYNC_TCP_SSL_ENABLED
void set_secure(bool secure) { mqtt_client.setSecure(secure); } void set_secure(bool secure) { mqtt_client.setSecure(secure); }

View file

@ -34,7 +34,12 @@ struct IPAddress {
} }
IPAddress(const ip_addr_t *other_ip) { ip_addr_copy(ip_addr_, *other_ip); } IPAddress(const ip_addr_t *other_ip) { ip_addr_copy(ip_addr_, *other_ip); }
IPAddress(const std::string &in_address) { ipaddr_aton(in_address.c_str(), &ip_addr_); } IPAddress(const std::string &in_address) { ipaddr_aton(in_address.c_str(), &ip_addr_); }
IPAddress(ip4_addr_t *other_ip) { memcpy((void *) &ip_addr_, (void *) other_ip, sizeof(ip4_addr_t)); } IPAddress(ip4_addr_t *other_ip) {
memcpy((void *) &ip_addr_, (void *) other_ip, sizeof(ip4_addr_t));
#if USE_ESP32
ip_addr_.type = IPADDR_TYPE_V4;
#endif
}
#if USE_ARDUINO #if USE_ARDUINO
IPAddress(const arduino_ns::IPAddress &other_ip) { ip_addr_set_ip4_u32(&ip_addr_, other_ip); } IPAddress(const arduino_ns::IPAddress &other_ip) { ip_addr_set_ip4_u32(&ip_addr_, other_ip); }
#endif #endif

View file

@ -7,6 +7,13 @@ namespace pulse_meter {
static const char *const TAG = "pulse_meter"; static const char *const TAG = "pulse_meter";
void PulseMeterSensor::set_total_pulses(uint32_t pulses) {
this->total_pulses_ = pulses;
if (this->total_sensor_ != nullptr) {
this->total_sensor_->publish_state(this->total_pulses_);
}
}
void PulseMeterSensor::setup() { void PulseMeterSensor::setup() {
this->pin_->setup(); this->pin_->setup();
this->isr_pin_ = pin_->to_isr(); this->isr_pin_ = pin_->to_isr();

View file

@ -20,7 +20,8 @@ class PulseMeterSensor : public sensor::Sensor, public Component {
void set_timeout_us(uint32_t timeout) { this->timeout_us_ = timeout; } void set_timeout_us(uint32_t timeout) { this->timeout_us_ = timeout; }
void set_total_sensor(sensor::Sensor *sensor) { this->total_sensor_ = sensor; } void set_total_sensor(sensor::Sensor *sensor) { this->total_sensor_ = sensor; }
void set_filter_mode(InternalFilterMode mode) { this->filter_mode_ = mode; } void set_filter_mode(InternalFilterMode mode) { this->filter_mode_ = mode; }
void set_total_pulses(uint32_t pulses) { this->total_pulses_ = pulses; }
void set_total_pulses(uint32_t pulses);
void setup() override; void setup() override;
void loop() override; void loop() override;

View file

@ -19,7 +19,7 @@ from esphome.const import (
) )
from esphome.core import CORE from esphome.core import CORE
CODEOWNERS = ["@stevebaxter", "@cstaahl"] CODEOWNERS = ["@stevebaxter", "@cstaahl", "@TrentHouliston"]
pulse_meter_ns = cg.esphome_ns.namespace("pulse_meter") pulse_meter_ns = cg.esphome_ns.namespace("pulse_meter")

View file

@ -1,6 +1,6 @@
"""Constants used by esphome.""" """Constants used by esphome."""
__version__ = "2023.10.1" __version__ = "2023.10.2"
ALLOWED_NAME_CHARS = "abcdefghijklmnopqrstuvwxyz0123456789-_" ALLOWED_NAME_CHARS = "abcdefghijklmnopqrstuvwxyz0123456789-_"
VALID_SUBSTITUTIONS_CHARACTERS = ( VALID_SUBSTITUTIONS_CHARACTERS = (

View file

@ -52,12 +52,12 @@ template<typename... Ts> class XorCondition : public Condition<Ts...> {
public: public:
explicit XorCondition(const std::vector<Condition<Ts...> *> &conditions) : conditions_(conditions) {} explicit XorCondition(const std::vector<Condition<Ts...> *> &conditions) : conditions_(conditions) {}
bool check(Ts... x) override { bool check(Ts... x) override {
bool xor_state = false; size_t result = 0;
for (auto *condition : this->conditions_) { for (auto *condition : this->conditions_) {
xor_state = xor_state ^ condition->check(x...); result += condition->check(x...);
} }
return xor_state; return result == 1;
} }
protected: protected:

View file

@ -3326,6 +3326,10 @@ text_sensor:
canbus_id: mcp2515_can canbus_id: mcp2515_can
can_id: 23 can_id: 23
data: [0x10, 0x20, 0x30] data: [0x10, 0x20, 0x30]
- canbus.send:
canbus_id: mcp2515_can
can_id: 23
data: !lambda return {0x10, 0x20, 0x30};
- canbus.send: - canbus.send:
canbus_id: esp32_internal_can canbus_id: esp32_internal_can
can_id: 23 can_id: 23

View file

@ -26,3 +26,9 @@ sensor:
name: ADC name: ADC
pin: GPIO23 pin: GPIO23
update_interval: 1s update_interval: 1s
mqtt:
broker: test.mosquitto.org
port: 1883
discovery: true
discovery_prefix: homeassistant