diff --git a/esphome/components/ld6002b/button/__init__.py b/esphome/components/ld6002b/button/__init__.py index 22e88062c1b..961527cef18 100644 --- a/esphome/components/ld6002b/button/__init__.py +++ b/esphome/components/ld6002b/button/__init__.py @@ -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)});") ) diff --git a/esphome/components/ld6002b/ld6002b.cpp b/esphome/components/ld6002b/ld6002b.cpp index f152488fa95..29979a594b1 100644 --- a/esphome/components/ld6002b/ld6002b.cpp +++ b/esphome/components/ld6002b/ld6002b.cpp @@ -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: