[ld6002b] Name the button function after its first button and note the last-type fallback

This commit is contained in:
J. Nick Koston
2026-10-16 11:49:35 -10:00
parent 9dc43f5668
commit 3db32a284c
2 changed files with 6 additions and 4 deletions
@@ -5,6 +5,7 @@ from esphome.components.select import DOMAIN as SELECT_DOMAIN
import esphome.config_validation as cv
from esphome.const import (
CONF_AREA_ID,
CONF_ID,
CONF_WAKEUP_PIN,
ENTITY_CATEGORY_CONFIG,
ENTITY_CATEGORY_DIAGNOSTIC,
@@ -141,7 +142,8 @@ async def to_code(config: ConfigType) -> None:
hub = await cg.get_variable(config[CONF_LD6002B_ID])
params = button.sub_buttons(config).apply_entity.params
# One function for all buttons, picking the type by pointer: one class instead of one per button.
fn = f"esphome__{hub}__button_fn"
# Named after the first button so two button blocks on one hub do not clash.
fn = f"esphome__{confs[0][1][CONF_ID].id}__button_fn"
cg.add_global(
cg.RawStatement(f"static void {fn}({ParameterListExpression(*params)});")
)
+3 -3
View File
@@ -1390,7 +1390,7 @@ void LD6002BComponent::set_number_value(number::Number *entity, float value) {
type = NumberType::AREA_Y_MAX;
else if (entity == this->area_z_min_number_)
type = NumberType::AREA_Z_MIN;
else
else // Only registered entities call this, so the last one needs no compare
type = NumberType::AREA_Z_MAX;
switch (type) {
case NumberType::HOLD_DELAY: {
@@ -1453,7 +1453,7 @@ void LD6002BComponent::set_select_value(select::Select *entity, size_t index) {
type = SelectType::TRIGGER_SPEED;
else if (entity == this->installation_select_)
type = SelectType::INSTALLATION_MODE;
else
else // Only registered entities call this, so the last one needs no compare
type = SelectType::AREA_ID;
switch (type) {
case SelectType::SENSITIVITY:
@@ -1825,7 +1825,7 @@ void LD6002BComponent::set_switch_state(switch_::Switch *entity, bool state) {
type = SwitchType::LOW_POWER;
else if (entity == this->point_cloud_switch_)
type = SwitchType::POINT_CLOUD;
else
else // Only registered entities call this, so the last one needs no compare
type = SwitchType::TARGET_DISPLAY;
switch (type) {
case SwitchType::LOW_POWER: