[ld2420] only use select if available

This commit is contained in:
Samuel Sieb 2025-04-11 20:41:54 -07:00 committed by GitHub
parent 7edf458898
commit 865157afba
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -67,8 +67,8 @@ float LD2420Component::get_setup_priority() const { return setup_priority::BUS;
void LD2420Component::dump_config() {
ESP_LOGCONFIG(TAG, "LD2420:");
ESP_LOGCONFIG(TAG, " Firmware Version : %7s", this->ld2420_firmware_ver_);
ESP_LOGCONFIG(TAG, "LD2420 Number:");
#ifdef USE_NUMBER
ESP_LOGCONFIG(TAG, "LD2420 Number:");
LOG_NUMBER(TAG, " Gate Timeout:", this->gate_timeout_number_);
LOG_NUMBER(TAG, " Gate Max Distance:", this->max_gate_distance_number_);
LOG_NUMBER(TAG, " Gate Min Distance:", this->min_gate_distance_number_);
@ -84,8 +84,10 @@ void LD2420Component::dump_config() {
LOG_BUTTON(TAG, " Factory Reset:", this->factory_reset_button_);
LOG_BUTTON(TAG, " Restart Module:", this->restart_module_button_);
#endif
#ifdef USE_SELECT
ESP_LOGCONFIG(TAG, "LD2420 Select:");
LOG_SELECT(TAG, " Operating Mode", this->operating_selector_);
#endif
if (this->get_firmware_int_(ld2420_firmware_ver_) < CALIBRATE_VERSION_MIN) {
ESP_LOGW(TAG, "LD2420 Firmware Version %s and older are only supported in Simple Mode", ld2420_firmware_ver_);
}
@ -137,12 +139,16 @@ void LD2420Component::setup() {
memcpy(&this->new_config, &this->current_config, sizeof(this->current_config));
if (get_firmware_int_(ld2420_firmware_ver_) < CALIBRATE_VERSION_MIN) {
this->set_operating_mode(OP_SIMPLE_MODE_STRING);
#ifdef USE_SELECT
this->operating_selector_->publish_state(OP_SIMPLE_MODE_STRING);
#endif
this->set_mode_(CMD_SYSTEM_MODE_SIMPLE);
ESP_LOGW(TAG, "LD2420 Frimware Version %s and older are only supported in Simple Mode", ld2420_firmware_ver_);
} else {
this->set_mode_(CMD_SYSTEM_MODE_ENERGY);
#ifdef USE_SELECT
this->operating_selector_->publish_state(OP_NORMAL_MODE_STRING);
#endif
}
#ifdef USE_NUMBER
this->init_gate_config_numbers();
@ -293,7 +299,9 @@ void LD2420Component::set_operating_mode(const std::string &state) {
if (get_firmware_int_(ld2420_firmware_ver_) >= CALIBRATE_VERSION_MIN) {
this->current_operating_mode = OP_MODE_TO_UINT.at(state);
// Entering Auto Calibrate we need to clear the privoiuos data collection
#ifdef USE_SELECT
this->operating_selector_->publish_state(state);
#endif
if (current_operating_mode == OP_CALIBRATE_MODE) {
this->set_calibration_(true);
for (uint8_t gate = 0; gate < LD2420_TOTAL_GATES; gate++) {
@ -312,7 +320,9 @@ void LD2420Component::set_operating_mode(const std::string &state) {
}
} else {
this->current_operating_mode = OP_SIMPLE_MODE;
#ifdef USE_SELECT
this->operating_selector_->publish_state(OP_SIMPLE_MODE_STRING);
#endif
}
}