Compare commits

...
Author SHA1 Message Date
J. Nick Koston 4ea7546980 [graph] Drop the unused vector include 2026-11-14 10:27:14 -06:00
J. Nick Koston c08e2bedab Merge remote-tracking branch 'origin/dev' into HEAD 2026-11-14 08:37:27 -06:00
J. Nick Koston d314e7435e Drop the wiegand test; its triggers are converted on dev already 2026-11-12 09:48:19 -06:00
J. Nick Koston 2b62b202af Merge remote-tracking branch 'origin/dev' into hub-lists-static-vector
# Conflicts:
#	esphome/components/sprinkler/__init__.py
2026-11-12 09:39:34 -06:00
J. Nick Koston b02bfbba14 Merge remote-tracking branch 'upstream/dev' into hub-lists-static-vector
# Conflicts:
#	esphome/components/nextion/nextion.h
2026-11-09 08:50:18 -08:00
J. Nick Koston f9ad2a0dd1 Merge branch 'dev' into hub-lists-static-vector 2026-11-04 21:20:55 -06:00
J. Nick Koston d25370da30 Merge dev into hub-lists-static-vector 2026-11-04 21:15:16 -06:00
J. Nick Koston d950e8672e Merge dev into hub-lists-static-vector 2026-11-04 21:10:43 -06:00
J. Nick Koston ff98b5404b Merge branch 'slot-list-migrate' into hub-lists-static-vector
# Conflicts:
#	esphome/components/canbus/__init__.py
#	esphome/components/canbus/canbus.h
#	esphome/components/usb_uart/usb_uart.h
2026-11-04 18:38:39 -06:00
J. Nick Koston 83c52100a9 Merge branch 'slot-list-helper' into slot-list-migrate 2026-11-04 18:35:20 -06:00
J. Nick Koston 0891a605c2 Merge remote-tracking branch 'origin/dev' into slot-list-helper
# Conflicts:
#	.agents/skills/component-codegen/SKILL.md
#	.agents/skills/embedded-memory/SKILL.md
#	esphome/cpp_helpers.py
#	tests/unit_tests/test_cpp_helpers.py
2026-11-04 18:35:15 -06:00
J. Nick Koston 6a90377541 Trim the slot list comments 2026-11-01 09:00:21 -10:00
J. Nick Koston a8cce79d4d Write the slot list skill text as instructions 2026-11-01 08:59:01 -10:00
J. Nick Koston 6c42ffe363 Merge branch 'slot-list-migrate' into hub-lists-static-vector 2026-10-31 21:46:59 -10:00
J. Nick Koston f7d81810cf Replace the pn532 and duco count guards with an empty list check 2026-10-31 21:46:55 -10:00
J. Nick Koston 9a10880bea Merge branch 'slot-list-helper' into slot-list-migrate 2026-10-31 21:44:38 -10:00
J. Nick Koston 05a7ac5070 Drop a redundant set from the empty slot list check 2026-10-31 21:44:29 -10:00
J. Nick Koston c946a78af0 Merge remote-tracking branch 'origin/slot-list-migrate' into hub-lists-static-vector 2026-10-31 21:36:46 -10:00
J. Nick Koston 12be180106 Merge remote-tracking branch 'origin/slot-list-helper' into slot-list-migrate 2026-10-31 21:36:30 -10:00
J. Nick Koston 2b8283b769 Trim slot list comments and docstrings 2026-10-31 21:36:21 -10:00
J. Nick Koston 020f7518e4 Merge remote-tracking branch 'origin/slot-list-migrate' into hub-lists-static-vector 2026-10-31 21:28:16 -10:00
J. Nick Koston e768b3ad38 Merge remote-tracking branch 'origin/slot-list-helper' into slot-list-migrate 2026-10-31 21:28:13 -10:00
J. Nick Koston a895299fbc Say where cg.slot_list must be called 2026-10-31 21:28:10 -10:00
J. Nick Koston fd8c321deb Merge remote-tracking branch 'origin/slot-list-migrate' into hub-lists-static-vector 2026-10-31 21:07:07 -10:00
J. Nick Koston 6bc65977c8 Merge remote-tracking branch 'origin/slot-list-helper' into slot-list-migrate 2026-10-31 21:07:04 -10:00
J. Nick Koston e2c3183e72 Wrap the slot_list line in the AI guide 2026-10-31 21:07:00 -10:00
J. Nick Koston 6bd95ae68b Mention cg.slot_list and SLOT_LIST in the AI guide 2026-10-31 21:06:44 -10:00
J. Nick Koston 12a1f94325 Drop doc comments that would now attach to the slot list members 2026-10-31 21:04:54 -10:00
J. Nick Koston a290033ada Merge branch 'slot-list-helper' into slot-list-migrate 2026-10-31 21:04:46 -10:00
J. Nick Koston 186ba0c9fd Merge branch 'slot-list-migrate' into hub-lists-static-vector 2026-10-31 21:04:46 -10:00
J. Nick Koston 25864f8fca Tidy the slot list test comments, skill text and emitter note 2026-10-31 21:04:40 -10:00
J. Nick Koston 2d06ba192a Guard kamstrup's add_custom_sensor; include helpers.h outside USE_TIME in bedjet; drop unused vector includes 2026-10-31 20:55:16 -10:00
J. Nick Koston 76d429e9c5 Merge branch 'slot-list-migrate' into hub-lists-static-vector 2026-10-31 20:54:58 -10:00
J. Nick Koston a38940d114 Guard gps and duco register methods with SLOT_LIST_REQUIRES; leave uart binary_sensor on slot_counter 2026-10-31 20:54:46 -10:00
J. Nick Koston fab2486c0f Merge branch 'slot-list-helper' into slot-list-migrate 2026-10-31 20:54:39 -10:00
J. Nick Koston 2feb806357 Emit empty slot lists for the domains the build copies; add SLOT_LIST_REQUIRES for hand-written register methods 2026-10-31 20:54:31 -10:00
J. Nick Koston b1c400a9ce Pass each hub's DOMAIN to cg.slot_list 2026-10-31 20:45:50 -10:00
J. Nick Koston 216a936f8f Merge branch 'slot-list-migrate' into hub-lists-static-vector 2026-10-31 20:45:35 -10:00
J. Nick Koston 23ed987da5 Pass each hub's DOMAIN to cg.slot_list 2026-10-31 20:44:55 -10:00
J. Nick Koston 2a600801ec Merge branch 'slot-list-helper' into slot-list-migrate 2026-10-31 20:44:45 -10:00
J. Nick Koston aebef214bc Take the hub's DOMAIN in cg.slot_list instead of reading the caller's module 2026-10-31 20:44:34 -10:00
J. Nick Koston 7fbedf5276 canbus triggers in SLOT_LIST without a Component base; usb_uart get_channels returns the list 2026-10-31 20:28:59 -10:00
J. Nick Koston 9e679e620c Merge branch 'slot-list-migrate' into hub-lists-static-vector 2026-10-31 20:28:02 -10:00
J. Nick Koston f5882a19ca Merge branch 'slot-list-helper' into slot-list-migrate 2026-10-31 20:27:54 -10:00
J. Nick Koston 7df1e8ddfc Register ecocomfort2 children with SLOT_LIST and set their parent from codegen; trim repeated comments 2026-10-31 20:27:54 -10:00
J. Nick Koston 7cde55341d Fail to compile a SLOT_LIST registration that code generation did not count; reject a define declared twice 2026-10-31 20:27:29 -10:00
J. Nick Koston dc1bbe089e Merge branch 'slot-list-migrate' into hub-lists-static-vector 2026-10-31 20:21:41 -10:00
J. Nick Koston 8c50dca737 Merge branch 'slot-list-helper' into slot-list-migrate 2026-10-31 20:21:40 -10:00
J. Nick Koston 42fb1b00e5 Leave a slot_list define alone when something already set it 2026-10-31 20:21:40 -10:00
J. Nick Koston 144fe66e36 Merge branch 'slot-list-migrate' into hub-lists-static-vector 2026-10-31 20:20:30 -10:00
J. Nick Koston 7f79868b92 Merge branch 'slot-list-helper' into slot-list-migrate 2026-10-31 20:20:30 -10:00
J. Nick Koston 548d5041ca Include helpers.h directly in every header that declares a slot list 2026-10-31 20:20:30 -10:00
J. Nick Koston 2e342a469e Emit the empty slot_list defines from code generation for every component whose sources are built 2026-10-31 20:20:20 -10:00
J. Nick Koston 77cf5df19c Merge branch 'slot-list-helper' into slot-list-migrate 2026-10-31 20:17:58 -10:00
J. Nick Koston 50acc2095f Merge branch 'slot-list-migrate' into hub-lists-static-vector 2026-10-31 20:17:58 -10:00
J. Nick Koston 7d99802baa A BLE controller without trackers now gets a scan listener count of 0 2026-10-31 20:17:58 -10:00
J. Nick Koston c8d1a5dc24 Find slot_list's calling module through inspect; keep the empty-list test off static members via an instance 2026-10-31 20:17:57 -10:00
J. Nick Koston 15f45ecc9b Prove multi-reader sizing with three Wiegand readers 2026-10-31 20:05:02 -10:00
J. Nick Koston 9d8ab61d20 Merge branch 'slot-list-migrate' into hub-lists-static-vector 2026-10-31 20:04:47 -10:00
J. Nick Koston d4b723813d Make each sweep list one SLOT_LIST or SlotList member, declared in its hub's __init__.py 2026-10-31 20:04:47 -10:00
J. Nick Koston b51c5d752f Leave the ld2450 polygon zones on slot_counter: the define also gates their text and binary_sensor code 2026-10-31 20:04:37 -10:00
J. Nick Koston 32b2601019 Leave the hubs that HubFunction will replace on std::vector 2026-10-31 20:03:09 -10:00
J. Nick Koston 6204a2e4bf Merge branch 'slot-list-migrate' into hub-lists-static-vector 2026-10-31 20:02:53 -10:00
J. Nick Koston 1b01363dee Make each converted slot list one SLOT_LIST or SlotList member without #ifdef 2026-10-31 20:02:45 -10:00
J. Nick Koston 9148aae3cb Leave the hubs that HubFunction will replace, and the lists whose define gates more than the list, on slot_counter 2026-10-31 20:00:25 -10:00
J. Nick Koston 4c321183c4 Merge branch 'slot-list-helper' into slot-list-migrate 2026-10-31 19:57:56 -10:00
J. Nick Koston f8271968c1 Emit slot_list defines as 0 for hubs in the build so SLOT_LIST needs no #ifdef 2026-10-31 19:57:44 -10:00
J. Nick Koston b06d6cecad Merge branch 'slot-list-migrate' into hub-lists-static-vector 2026-10-31 19:47:56 -10:00
J. Nick Koston 9a91bf8d00 Merge branch 'slot-list-helper' into slot-list-migrate 2026-10-31 19:47:53 -10:00
J. Nick Koston 623962dfef Silence bugprone-macro-parentheses on the SLOT_LIST type uses 2026-10-31 19:47:44 -10:00
J. Nick Koston 1a6f2f6dc5 [components] Keep codegen-registered hub child lists in StaticVector 2026-10-31 19:36:01 -10:00
J. Nick Koston 50f50956b9 [components] Use cg.slot_list and SLOT_LIST for existing codegen-sized registration lists 2026-10-31 19:34:42 -10:00
J. Nick Koston 7ca31423ec [core] Add cg.slot_list and SLOT_LIST for codegen-sized registration lists 2026-10-31 19:33:08 -10:00
32 changed files with 182 additions and 99 deletions

No files matched your search

+5 -1
View File
@@ -35,9 +35,13 @@ BEDJET_CLIENT_SCHEMA = cv.Schema(
)
_register_child = cg.slot_list("BEDJET_CHILD_COUNT", "register_child", DOMAIN)
async def register_bedjet_child(var: MockObj, config: ConfigType) -> None:
parent = await cg.get_variable(config[CONF_BEDJET_ID])
cg.add(parent.register_child(var))
await cg.register_parented(var, parent)
cg.add(_register_child(parent, var))
async def to_code(config: ConfigType) -> None:
-5
View File
@@ -547,11 +547,6 @@ void BedJetHub::dispatch_status_() {
}
}
void BedJetHub::register_child(BedJetClient *obj) {
this->children_.push_back(obj);
obj->set_parent(this);
}
} // namespace esphome::bedjet
#endif
+2 -5
View File
@@ -6,11 +6,10 @@
#include "esphome/core/component.h"
#include "esphome/core/defines.h"
#include "esphome/core/hal.h"
#include "esphome/core/helpers.h"
#include "bedjet_child.h"
#include "bedjet_codec.h"
#include <vector>
#ifdef USE_TIME
#include "esphome/components/time/real_time_clock.h"
#include "esphome/core/time.h"
@@ -92,8 +91,7 @@ class BedJetHub final : public esphome::ble_client::BLEClientNode, public Pollin
bool has_status() { return this->codec_->has_status(); }
const BedjetStatusPacket *get_status_packet() const { return this->codec_->get_status_packet(); }
/** Register a `BedJetClient` child component. */
void register_child(BedJetClient *obj);
SLOT_LIST(BedJetClient, children_, register_child, BEDJET_CHILD_COUNT)
/** Set the status timeout.
*
@@ -127,7 +125,6 @@ class BedJetHub final : public esphome::ble_client::BLEClientNode, public Pollin
esp_ble_gattc_cb_param_t *param) override;
protected:
std::vector<BedJetClient *> children_;
void dispatch_status_();
void dispatch_state_(bool is_ready);
@@ -185,6 +185,9 @@ EFFECTIVE_HIGH_VOLTAGE = {
}
register_touch_pad = cg.slot_list("ESP32_TOUCH_PAD_COUNT", "register_touch_pad", DOMAIN)
def validate_touch_pad(value: Any) -> int:
value = gpio.gpio_pin_number_validator(value)
variant = get_esp32_variant()
@@ -4,7 +4,12 @@ import esphome.config_validation as cv
from esphome.const import CONF_ID, CONF_PIN, CONF_THRESHOLD
from esphome.types import ConfigType
from . import ESP32TouchComponent, esp32_touch_ns, validate_touch_pad
from . import (
ESP32TouchComponent,
esp32_touch_ns,
register_touch_pad,
validate_touch_pad,
)
DEPENDENCIES = ["esp32_touch", "esp32"]
@@ -34,4 +39,4 @@ async def to_code(config: ConfigType) -> None:
config[CONF_WAKEUP_THRESHOLD],
)
await binary_sensor.register_binary_sensor(var, config)
cg.add(hub.register_touch_pad(var))
cg.add(register_touch_pad(hub, var))
+2 -4
View File
@@ -3,10 +3,9 @@
#ifdef USE_ESP32
#include "esphome/core/component.h"
#include "esphome/core/helpers.h"
#include "esphome/components/binary_sensor/binary_sensor.h"
#include <vector>
#include <driver/touch_sens.h>
#include <freertos/FreeRTOS.h>
#include <freertos/queue.h>
@@ -28,7 +27,7 @@ class ESP32TouchBinarySensor;
class ESP32TouchComponent final : public Component {
public:
void register_touch_pad(ESP32TouchBinarySensor *pad) { this->children_.push_back(pad); }
SLOT_LIST(ESP32TouchBinarySensor, children_, register_touch_pad, ESP32_TOUCH_PAD_COUNT)
void set_setup_mode(bool setup_mode) { this->setup_mode_ = setup_mode; }
void set_meas_interval_us(float meas_interval_us) { this->meas_interval_us_ = meas_interval_us; }
@@ -118,7 +117,6 @@ class ESP32TouchComponent final : public Component {
static bool on_inactive_cb(touch_sensor_handle_t handle, const touch_inactive_event_data_t *event, void *ctx);
// Common members
std::vector<ESP32TouchBinarySensor *> children_;
bool setup_mode_{false};
uint32_t setup_mode_last_log_print_{0};
+4 -1
View File
@@ -143,6 +143,9 @@ CONFIG_SCHEMA = cv.All(
)
_add_trace = cg.slot_list("GRAPH_TRACE_COUNT", "add_trace", DOMAIN)
async def to_code(config: ConfigType) -> None:
var = cg.new_Pvariable(config[CONF_ID])
cg.add(var.set_duration(config[CONF_DURATION]))
@@ -179,7 +182,7 @@ async def to_code(config: ConfigType) -> None:
await cg.add_variable(tr.set_line_color, trace.get(CONF_COLOR))
if CONF_CONTINUOUS in trace:
cg.add(tr.set_continuous(trace[CONF_CONTINUOUS]))
cg.add(var.add_trace(tr))
cg.add(_add_trace(var, tr))
# Add legend
if CONF_LEGEND in config:
lgd = config[CONF_LEGEND]
+2 -3
View File
@@ -1,9 +1,9 @@
#pragma once
#include <cstdint>
#include <span>
#include <vector>
#include "esphome/components/sensor/sensor.h"
#include "esphome/core/color.h"
#include "esphome/core/helpers.h"
#include "esphome/core/string_ref.h"
#include "esphome/core/component.h"
@@ -157,7 +157,7 @@ class Graph final : public Component {
void set_grid_x(float val) { this->gridspacing_x_ = val; }
void set_grid_y(float val) { this->gridspacing_y_ = val; }
void set_border(bool val) { this->border_ = val; }
void add_trace(GraphTrace *trace) { traces_.push_back(trace); }
SLOT_LIST(GraphTrace, traces_, add_trace, GRAPH_TRACE_COUNT)
void add_legend(GraphLegend *legend) {
this->legend_ = legend;
legend->init(this);
@@ -181,7 +181,6 @@ class Graph final : public Component {
float gridspacing_x_{NAN};
float gridspacing_y_{NAN};
bool border_{true};
std::vector<GraphTrace *> traces_;
GraphLegend *legend_{nullptr};
friend GraphLegend;
@@ -1 +1,7 @@
import esphome.codegen as cg
DOMAIN = "kamstrup_kmp"
add_custom_sensor = cg.slot_list(
"KAMSTRUP_KMP_CUSTOM_SENSOR_COUNT", "add_custom_sensor", DOMAIN
)
@@ -28,9 +28,9 @@ void KamstrupKMPComponent::dump_config() {
LOG_SENSOR(" ", "Flow", this->flow_sensor_);
LOG_SENSOR(" ", "Volume", this->volume_sensor_);
for (size_t i = 0; i < this->custom_sensors_.size(); i++) {
LOG_SENSOR(" ", "Custom Sensor", this->custom_sensors_[i]);
ESP_LOGCONFIG(TAG, " Command: 0x%04X", this->custom_commands_[i]);
for (const auto &custom : this->custom_sensors_) {
LOG_SENSOR(" ", "Custom Sensor", custom.sensor);
ESP_LOGCONFIG(TAG, " Command: 0x%04X", custom.command);
}
}
@@ -63,8 +63,8 @@ void KamstrupKMPComponent::update() {
this->command_queue_.push(CMD_VOLUME);
}
for (uint16_t custom_command : this->custom_commands_) {
this->command_queue_.push(custom_command);
for (const auto &custom : this->custom_sensors_) {
this->command_queue_.push(custom.command);
}
}
@@ -261,9 +261,9 @@ void KamstrupKMPComponent::set_sensor_value_(uint16_t command, float value, uint
}
// Custom sensors
for (size_t i = 0; i < this->custom_commands_.size(); i++) {
if (command == this->custom_commands_[i]) {
this->custom_sensors_[i]->publish_state(value);
for (const auto &custom : this->custom_sensors_) {
if (command == custom.command) {
custom.sensor->publish_state(value);
}
}
@@ -4,6 +4,7 @@
#include "esphome/components/sensor/sensor.h"
#include "esphome/components/uart/uart.h"
#include "esphome/core/component.h"
#include "esphome/core/helpers.h"
namespace esphome::kamstrup_kmp {
@@ -75,15 +76,17 @@ class KamstrupKMPComponent final : public PollingComponent, public uart::UARTDev
void dump_config() override;
void update() override;
void loop() override;
SLOT_LIST_REQUIRES(KAMSTRUP_KMP_CUSTOM_SENSOR_COUNT)
void add_custom_sensor(sensor::Sensor *sensor, uint16_t command) {
this->custom_sensors_.push_back(sensor);
this->custom_commands_.push_back(command);
this->custom_sensors_.push_back({sensor, command});
}
protected:
// Custom sensors and commands
std::vector<sensor::Sensor *> custom_sensors_;
std::vector<uint16_t> custom_commands_;
struct CustomSensor {
sensor::Sensor *sensor;
uint16_t command;
};
[[no_unique_address]] SlotList<CustomSensor, KAMSTRUP_KMP_CUSTOM_SENSOR_COUNT> custom_sensors_;
// Command queue
std::queue<uint16_t> command_queue_;
+3 -1
View File
@@ -24,6 +24,8 @@ from esphome.const import (
)
from esphome.types import ConfigType
from . import add_custom_sensor
CODEOWNERS = ["@cfeenstra1024"]
DEPENDENCIES = ["uart"]
@@ -134,4 +136,4 @@ async def to_code(config: ConfigType) -> None:
if CONF_CUSTOM in config:
for conf in config[CONF_CUSTOM]:
sens = await sensor.new_sensor(conf)
cg.add(var.add_custom_sensor(sens, conf[CONF_COMMAND]))
cg.add(add_custom_sensor(var, sens, conf[CONF_COMMAND]))
+8 -2
View File
@@ -152,6 +152,12 @@ def _final_validate(config: ConfigType) -> None:
FINAL_VALIDATE_SCHEMA = _final_validate
_add_server_register = cg.slot_list(
"MODBUS_SERVER_REGISTER_COUNT", "add_server_register", DOMAIN
)
_add_server_bit = cg.slot_list("MODBUS_SERVER_BIT_COUNT", "add_server_bit", DOMAIN)
async def to_code(config: ConfigType) -> None:
var = cg.new_Pvariable(config[CONF_ID])
if server_courtesy_response := config.get(CONF_COURTESY_RESPONSE):
@@ -200,7 +206,7 @@ async def to_code(config: ConfigType) -> None:
)
if server_register[CONF_ALLOW_PARTIAL_READ]:
cg.add(server_register_var.set_allow_partial_read(True))
cg.add(var.add_server_register(server_register_var))
cg.add(_add_server_register(var, server_register_var))
for server_bit in config.get(CONF_BITS, []):
server_bit_var = cg.new_Pvariable(server_bit[CONF_ID], server_bit[CONF_ADDRESS])
cg.add(
@@ -222,6 +228,6 @@ async def to_code(config: ConfigType) -> None:
)
)
)
cg.add(var.add_server_bit(server_bit_var))
cg.add(_add_server_bit(var, server_bit_var))
await cg.register_component(var, config)
return await modbus.register_modbus_server_device(var, config)
@@ -5,9 +5,9 @@
#include "esphome/components/modbus/modbus.h"
#include "esphome/components/modbus/modbus_helpers.h"
#include "esphome/core/automation.h"
#include "esphome/core/helpers.h"
#include <utility>
#include <vector>
namespace esphome::modbus_server {
@@ -125,10 +125,8 @@ class ModbusServer final : public Component, public modbus::ModbusServerDevice {
public:
void dump_config() override;
/// Registers a server register with the controller. Called by esphomes code generator
void add_server_register(ServerRegister *server_register) { server_registers_.push_back(server_register); }
/// Registers a server bit with the controller. Called by esphomes code generator
void add_server_bit(ServerBit *server_bit) { server_bits_.push_back(server_bit); }
SLOT_LIST(ServerRegister, server_registers_, add_server_register, MODBUS_SERVER_REGISTER_COUNT)
SLOT_LIST(ServerBit, server_bits_, add_server_bit, MODBUS_SERVER_BIT_COUNT)
/// called when a modbus request (function code 0x03 or 0x04) was parsed without errors
modbus::ResponseStatus on_read_registers(uint16_t start_address, uint16_t number_of_registers,
modbus::RegisterValues &registers) final;
@@ -151,10 +149,6 @@ class ModbusServer final : public Component, public modbus::ModbusServerDevice {
ServerRegister *find_containing_register_(uint32_t address) const;
/// Find the registered bit at address, or nullptr if none is.
ServerBit *find_bit_(uint16_t address) const;
/// Collection of all server registers for this component
std::vector<ServerRegister *> server_registers_{};
/// Collection of all server bits (coils/discrete inputs) for this component
std::vector<ServerBit *> server_bits_{};
/// Server courtesy response
ServerCourtesyResponse server_courtesy_response_{
.enabled = false, .register_last_address = 0xFFFF, .register_value = 0};
+16
View File
@@ -23,3 +23,19 @@ FILTER_SOURCE_FILES = filter_source_files_from_platform(
},
}
)
register_sensor_component = cg.slot_list(
"NEXTION_SENSOR_COUNT", "register_sensor_component", DOMAIN
)
register_textsensor_component = cg.slot_list(
"NEXTION_TEXT_SENSOR_COUNT", "register_textsensor_component", DOMAIN
)
register_switch_component = cg.slot_list(
"NEXTION_SWITCH_COUNT", "register_switch_component", DOMAIN
)
register_touch_component = cg.slot_list(
"NEXTION_TOUCH_COUNT", "register_touch_component", DOMAIN
)
register_binarysensor_component = cg.slot_list(
"NEXTION_BINARY_SENSOR_COUNT", "register_binarysensor_component", DOMAIN
)
@@ -4,7 +4,14 @@ from esphome.components import binary_sensor
import esphome.config_validation as cv
from esphome.const import CONF_COMPONENT_ID, CONF_ID, CONF_PAGE_ID, CONF_STATE
from .. import CONF_NEXTION_ID, CONF_PUBLISH_STATE, CONF_SEND_TO_NEXTION, nextion_ns
from .. import (
CONF_NEXTION_ID,
CONF_PUBLISH_STATE,
CONF_SEND_TO_NEXTION,
nextion_ns,
register_binarysensor_component,
register_touch_component,
)
from ..base_component import (
CONF_COMPONENT_NAME,
CONF_VARIABLE_NAME,
@@ -44,13 +51,13 @@ async def to_code(config):
await cg.register_component(var, config)
if config.keys() >= {CONF_PAGE_ID, CONF_COMPONENT_ID}:
cg.add(hub.register_touch_component(var))
cg.add(register_touch_component(hub, var))
cg.add(var.set_component_id(config[CONF_COMPONENT_ID]))
cg.add(var.set_page_id(config[CONF_PAGE_ID]))
if CONF_COMPONENT_NAME in config or CONF_VARIABLE_NAME in config:
await setup_component_core_(var, config, ".val")
cg.add(hub.register_binarysensor_component(var))
cg.add(register_binarysensor_component(hub, var))
automation.register_apply_action(
+6 -15
View File
@@ -2,19 +2,15 @@
#include <list>
#include <utility>
#include <vector>
#include "esphome/components/display/display.h"
#include "esphome/components/display/display_color_utils.h"
#include "esphome/components/uart/uart.h"
#include "esphome/core/defines.h"
#include "esphome/core/helpers.h"
#include "esphome/core/string_ref.h"
#include "esphome/core/time.h"
#ifdef USE_NEXTION_WAVEFORM
#include "esphome/core/helpers.h"
#endif // USE_NEXTION_WAVEFORM
#include "nextion_base.h"
#include "nextion_component.h"
@@ -1050,11 +1046,11 @@ class Nextion final : public NextionBase, public PollingComponent, public uart::
// ========== INTERNAL METHODS ==========
// (In most use cases you won't need these)
void register_touch_component(NextionComponentBase *obj) { this->touch_.push_back(obj); }
void register_switch_component(NextionComponentBase *obj) { this->switchtype_.push_back(obj); }
void register_binarysensor_component(NextionComponentBase *obj) { this->binarysensortype_.push_back(obj); }
void register_sensor_component(NextionComponentBase *obj) { this->sensortype_.push_back(obj); }
void register_textsensor_component(NextionComponentBase *obj) { this->textsensortype_.push_back(obj); }
SLOT_LIST(NextionComponentBase, touch_, register_touch_component, NEXTION_TOUCH_COUNT)
SLOT_LIST(NextionComponentBase, switchtype_, register_switch_component, NEXTION_SWITCH_COUNT)
SLOT_LIST(NextionComponentBase, binarysensortype_, register_binarysensor_component, NEXTION_BINARY_SENSOR_COUNT)
SLOT_LIST(NextionComponentBase, sensortype_, register_sensor_component, NEXTION_SENSOR_COUNT)
SLOT_LIST(NextionComponentBase, textsensortype_, register_textsensor_component, NEXTION_TEXT_SENSOR_COUNT)
void setup() override;
void set_brightness(float brightness) { this->brightness_ = brightness; }
@@ -1631,11 +1627,6 @@ class Nextion final : public NextionBase, public PollingComponent, public uart::
bool check_connect_();
std::vector<NextionComponentBase *> touch_;
std::vector<NextionComponentBase *> switchtype_;
std::vector<NextionComponentBase *> sensortype_;
std::vector<NextionComponentBase *> textsensortype_;
std::vector<NextionComponentBase *> binarysensortype_;
CallbackManager<void()> setup_callback_{};
CallbackManager<void()> sleep_callback_{};
CallbackManager<void()> wake_callback_{};
@@ -4,7 +4,13 @@ from esphome.components import sensor
import esphome.config_validation as cv
from esphome.const import CONF_COMPONENT_ID, CONF_ID, CONF_STATE
from .. import CONF_NEXTION_ID, CONF_PUBLISH_STATE, CONF_SEND_TO_NEXTION, nextion_ns
from .. import (
CONF_NEXTION_ID,
CONF_PUBLISH_STATE,
CONF_SEND_TO_NEXTION,
nextion_ns,
register_sensor_component,
)
from ..base_component import (
CONF_COMPONENT_NAME,
CONF_PRECISION,
@@ -61,7 +67,7 @@ async def to_code(config):
await cg.register_component(var, config)
await sensor.register_sensor(var, config)
cg.add(hub.register_sensor_component(var))
cg.add(register_sensor_component(hub, var))
await setup_component_core_(var, config, ".val")
@@ -4,7 +4,13 @@ from esphome.components import switch
import esphome.config_validation as cv
from esphome.const import CONF_ID, CONF_STATE
from .. import CONF_NEXTION_ID, CONF_PUBLISH_STATE, CONF_SEND_TO_NEXTION, nextion_ns
from .. import (
CONF_NEXTION_ID,
CONF_PUBLISH_STATE,
CONF_SEND_TO_NEXTION,
nextion_ns,
register_switch_component,
)
from ..base_component import (
CONF_COMPONENT_NAME,
CONF_VARIABLE_NAME,
@@ -30,7 +36,7 @@ async def to_code(config):
await cg.register_component(var, config)
await switch.register_switch(var, config)
cg.add(hub.register_switch_component(var))
cg.add(register_switch_component(hub, var))
await setup_component_core_(var, config, ".val")
@@ -4,7 +4,13 @@ from esphome.components import text_sensor
import esphome.config_validation as cv
from esphome.const import CONF_ID, CONF_STATE
from .. import CONF_NEXTION_ID, CONF_PUBLISH_STATE, CONF_SEND_TO_NEXTION, nextion_ns
from .. import (
CONF_NEXTION_ID,
CONF_PUBLISH_STATE,
CONF_SEND_TO_NEXTION,
nextion_ns,
register_textsensor_component,
)
from ..base_component import CONFIG_TEXT_COMPONENT_SCHEMA, setup_component_core_
CODEOWNERS = ["@senexcrenshaw"]
@@ -26,7 +32,7 @@ async def to_code(config):
await text_sensor.register_text_sensor(var, config)
await cg.register_component(var, config)
cg.add(hub.register_textsensor_component(var))
cg.add(register_textsensor_component(hub, var))
await setup_component_core_(var, config, ".txt")
+3
View File
@@ -34,6 +34,9 @@ RC522_SCHEMA = cv.Schema(
).extend(cv.polling_component_schema("1s"))
register_tag = cg.slot_list("RC522_BINARY_SENSOR_COUNT", "register_tag", DOMAIN)
async def setup_rc522(var: MockObj, config: ConfigType) -> None:
await cg.register_component(var, config)
+2 -2
View File
@@ -7,7 +7,7 @@ from esphome.const import CONF_UID
from esphome.core import HexInt
from esphome.types import ConfigType
from . import CONF_RC522_ID, RC522, rc522_ns
from . import CONF_RC522_ID, RC522, rc522_ns, register_tag
DEPENDENCIES = ["rc522"]
@@ -46,6 +46,6 @@ async def to_code(config: ConfigType) -> None:
var = await binary_sensor.new_binary_sensor(config)
hub = await cg.get_variable(config[CONF_RC522_ID])
cg.add(hub.register_tag(var))
cg.add(register_tag(hub, var))
addr = [HexInt(int(x, 16)) for x in config[CONF_UID].split("-")]
cg.add(var.set_uid(addr))
+2 -2
View File
@@ -3,6 +3,7 @@
#include "esphome/core/component.h"
#include "esphome/core/hal.h"
#include "esphome/core/automation.h"
#include "esphome/core/helpers.h"
#include "esphome/components/binary_sensor/binary_sensor.h"
#include <vector>
@@ -20,7 +21,7 @@ class RC522 : public PollingComponent {
void loop() override;
void register_tag(RC522BinarySensor *tag) { this->binary_sensors_.push_back(tag); }
SLOT_LIST(RC522BinarySensor, binary_sensors_, register_tag, RC522_BINARY_SENSOR_COUNT)
#ifdef RC522_ON_TAG_COUNT
void add_on_tag_automation(Automation<std::string> *automation) { this->tag_automations_.add(automation); }
#endif
@@ -245,7 +246,6 @@ class RC522 : public PollingComponent {
GPIOPin *reset_pin_{nullptr};
uint8_t reset_count_{0};
uint32_t reset_timeout_{0};
std::vector<RC522BinarySensor *> binary_sensors_;
#ifdef RC522_ON_TAG_COUNT
AutomationList<RC522_ON_TAG_COUNT, std::string> tag_automations_;
#endif
+7 -1
View File
@@ -473,6 +473,11 @@ for _name, _schema, _apply in (
automation.register_apply_action(_name, _schema, _apply)
_add_controller = cg.slot_list(
"SPRINKLER_OTHER_CONTROLLER_COUNT", "add_controller", DOMAIN
)
async def to_code(config):
for sprinkler_controller in config:
if len(sprinkler_controller[CONF_VALVES]) > 1:
@@ -714,4 +719,5 @@ async def to_code(config):
var = await cg.get_variable(sprinkler_controller[CONF_ID])
for controller_to_add in config:
if sprinkler_controller[CONF_ID] != controller_to_add[CONF_ID]:
await cg.add_variable(var.add_controller, controller_to_add[CONF_ID])
other = await cg.get_variable(controller_to_add[CONF_ID])
cg.add(_add_controller(var, other))
@@ -377,8 +377,6 @@ void Sprinkler::add_valve(SprinklerControllerSwitch *valve_sw, SprinklerControll
}
}
void Sprinkler::add_controller(Sprinkler *other_controller) { this->other_controllers_.push_back(other_controller); }
void Sprinkler::set_controller_main_switch(SprinklerControllerSwitch *controller_switch) {
this->controller_sw_ = controller_switch;
controller_switch->set_state_lambda([this]() -> optional<bool> {
+2 -5
View File
@@ -184,8 +184,8 @@ class Sprinkler final : public Component {
/// add a valve to the controller
void add_valve(SprinklerControllerSwitch *valve_sw, SprinklerControllerSwitch *enable_sw = nullptr);
/// add another controller to the controller so it can check if pumps/main valves are in use
void add_controller(Sprinkler *other_controller);
// Other controllers, to check if pumps/main valves are in use
SLOT_LIST(Sprinkler, other_controllers_, add_controller, SPRINKLER_OTHER_CONTROLLER_COUNT)
/// configure important controller switches
void set_controller_main_switch(SprinklerControllerSwitch *controller_switch);
@@ -568,9 +568,6 @@ class Sprinkler final : public Component {
/// Valve control timers, indexed by SprinklerTimerIndex (also used as the scheduler id)
std::array<SprinklerTimer, 2> timer_;
/// Other Sprinkler instances we should be aware of (used to check if pumps are in use)
std::vector<Sprinkler *> other_controllers_;
/// Switches we'll present to the front end
SprinklerControllerSwitch *auto_adv_sw_{nullptr};
SprinklerControllerSwitch *controller_sw_{nullptr};
+4 -1
View File
@@ -239,6 +239,9 @@ CONFIG_SCHEMA = cv.ensure_list(
)
_add_channel = cg.slot_list("USB_UART_CHANNEL_COUNT", "add_channel", DOMAIN)
async def to_code(config: list[ConfigType]) -> None:
# The output chunk pool/queue are compile-time-sized templates shared by all
# USBUartChannel instances, so use the largest buffer_size across every channel
@@ -271,6 +274,6 @@ async def to_code(config: list[ConfigType]) -> None:
cg.add(chvar.set_debug(channel[CONF_DEBUG]))
if channel[CONF_DEBUG_PREFIX]:
cg.add(chvar.set_debug_prefix(channel[CONF_DEBUG_PREFIX]))
cg.add(var.add_channel(chvar))
cg.add(_add_channel(var, chvar))
if channel[CONF_DEBUG]:
cg.add_define("USE_UART_DEBUGGER")
+2 -4
View File
@@ -243,9 +243,9 @@ class USBUartComponent : public usb_host::USBClient {
void setup() override;
void loop() override;
void dump_config() override;
std::vector<USBUartChannelBase *> get_channels() { return this->channels_; }
const auto &get_channels() const { return this->channels_; }
void add_channel(USBUartChannelBase *channel) { this->channels_.push_back(channel); }
SLOT_LIST(USBUartChannelBase, channels_, add_channel, USB_UART_CHANNEL_COUNT)
virtual void start_input(USBUartChannelBase *channel);
void start_output(USBUartChannelBase *channel);
@@ -306,8 +306,6 @@ class USBUartComponent : public usb_host::USBClient {
void read_interface_descriptions_();
void on_interface_string(uint8_t interface_number, const usb_str_desc_t *desc) override;
std::vector<USBUartChannelBase *> channels_{};
// Config state machine
USBUartChannelBase *cfg_single_{nullptr}; // non-null: single-channel run (RELOAD or MODEM)
uint8_t *cfg_read_dest_{nullptr}; // where the step in flight stores its reply, if not cfg_response_
+4
View File
@@ -74,6 +74,9 @@ WKBASE_SCHEMA = cv.Schema(
).extend(cv.COMPONENT_SCHEMA)
_register_channel = cg.slot_list("WEIKAI_CHANNEL_COUNT", "register_channel", DOMAIN)
async def register_weikai(var: MockObj, config: ConfigType) -> None:
"""Register an weikai device with the given config."""
cg.add(var.set_crystal(config[CONF_CRYSTAL]))
@@ -83,6 +86,7 @@ async def register_weikai(var: MockObj, config: ConfigType) -> None:
chan = cg.new_Pvariable(uart_elem[CONF_ID])
cg.add(chan.set_channel_name(str(uart_elem[CONF_ID])))
cg.add(chan.set_parent(var))
cg.add(_register_channel(var, chan))
cg.add(chan.set_channel(uart_elem[CONF_CHANNEL]))
cg.add(chan.set_baud_rate(uart_elem[CONF_BAUD_RATE]))
cg.add(chan.set_stop_bits(uart_elem[CONF_STOP_BITS]))
+10 -12
View File
@@ -147,6 +147,8 @@ class WeikaiComponent : public Component {
bool page1() { return page1_; }
SLOT_LIST(WeikaiChannel, children_, register_channel, WEIKAI_CHANNEL_COUNT)
/// @brief Factory method to create a Register object
/// @param reg address of the register
/// @param channel channel associated with this register
@@ -182,14 +184,13 @@ class WeikaiComponent : public Component {
/// @}
#endif
uint8_t pin_config_{0x00}; ///< pin config mask: 1 means OUTPUT, 0 means INPUT
uint8_t output_state_{0x00}; ///< output state: 1 means HIGH, 0 means LOW
uint8_t input_state_{0x00}; ///< input pin states: 1 means HIGH, 0 means LOW
uint32_t crystal_; ///< crystal value;
int test_mode_; ///< test mode value (0 -> no tests)
bool page1_{false}; ///< set to true when in "page1 mode"
std::vector<WeikaiChannel *> children_{}; ///< the list of WeikaiChannel UART children
std::string name_; ///< name of entity
uint8_t pin_config_{0x00}; ///< pin config mask: 1 means OUTPUT, 0 means INPUT
uint8_t output_state_{0x00}; ///< output state: 1 means HIGH, 0 means LOW
uint8_t input_state_{0x00}; ///< input pin states: 1 means HIGH, 0 means LOW
uint32_t crystal_; ///< crystal value;
int test_mode_; ///< test mode value (0 -> no tests)
bool page1_{false}; ///< set to true when in "page1 mode"
std::string name_; ///< name of entity
};
///////////////////////////////////////////////////////////////////////////////
@@ -226,10 +227,7 @@ class WeikaiChannel final : public uart::UARTComponent {
public:
/// @brief We belongs to this WeikaiComponent
/// @param parent pointer to the component we belongs to
void set_parent(WeikaiComponent *parent) {
this->parent_ = parent;
this->parent_->children_.push_back(this); // add ourself to the list (vector)
}
void set_parent(WeikaiComponent *parent) { this->parent_ = parent; }
/// @brief Sets the channel number
/// @param channel number
+15
View File
@@ -292,6 +292,21 @@
#define SYSTA_BUS_LISTENER_COUNT 2
#define SERIAL_PROXY_COUNT 2
#define SNTP_SERVER_COUNT 3
#define BEDJET_CHILD_COUNT 1
#define ESP32_TOUCH_PAD_COUNT 1
#define GRAPH_TRACE_COUNT 1
#define KAMSTRUP_KMP_CUSTOM_SENSOR_COUNT 1
#define MODBUS_SERVER_BIT_COUNT 1
#define MODBUS_SERVER_REGISTER_COUNT 1
#define NEXTION_BINARY_SENSOR_COUNT 1
#define NEXTION_SENSOR_COUNT 1
#define NEXTION_SWITCH_COUNT 1
#define NEXTION_TEXT_SENSOR_COUNT 1
#define NEXTION_TOUCH_COUNT 1
#define RC522_BINARY_SENSOR_COUNT 1
#define SPRINKLER_OTHER_CONTROLLER_COUNT 1
#define USB_UART_CHANNEL_COUNT 1
#define WEIKAI_CHANNEL_COUNT 1
#define USE_MEDIA_PLAYER
#define USE_MEDIA_SOURCE
#define NETWORK_ACTIVE_INTERFACE_LISTENER_COUNT 1
@@ -0,0 +1,14 @@
import esphome.codegen as cg
from esphome.types import ConfigType
from tests.testing_helpers import ComponentManifestOverride
def override_manifest(manifest: ComponentManifestOverride) -> None:
async def to_code_testing(config: ConfigType) -> None:
# Register and bit lists are sized by code generation; a gtest server holds at most three of each.
cg.add_define("MODBUS_SERVER_REGISTER_COUNT", 3)
cg.add_define("MODBUS_SERVER_BIT_COUNT", 3)
# A MULTI_CONF component gets no entry in the host build, so its to_code would never run.
manifest.multi_conf = False
manifest.to_code = to_code_testing