1
0
mirror of https://github.com/esphome/esphome.git synced 2025-10-31 15:12:06 +00:00
This commit is contained in:
J. Nick Koston
2025-10-30 13:12:28 -05:00
parent fd8726b479
commit b6d178b8c1
30 changed files with 60 additions and 67 deletions

View File

@@ -17,9 +17,9 @@ void CopySelect::setup() {
void CopySelect::dump_config() { LOG_SELECT("", "Copy Select", this); }
void CopySelect::control(const std::string &value) {
void CopySelect::control(size_t index) {
auto call = source_->make_call();
call.set_option(value);
call.set_index(index);
call.perform();
}

View File

@@ -13,7 +13,7 @@ class CopySelect : public select::Select, public Component {
void dump_config() override;
protected:
void control(const std::string &value) override;
void control(size_t index) override;
select::Select *source_;
};

View File

@@ -626,16 +626,16 @@ void LD2410Component::set_bluetooth(bool enable) {
this->set_timeout(200, [this]() { this->restart_and_read_all_info(); });
}
void LD2410Component::set_distance_resolution(const std::string &state) {
void LD2410Component::set_distance_resolution(const char *state) {
this->set_config_mode_(true);
const uint8_t cmd_value[2] = {find_uint8(DISTANCE_RESOLUTIONS_BY_STR, state.c_str()), 0x00};
const uint8_t cmd_value[2] = {find_uint8(DISTANCE_RESOLUTIONS_BY_STR, state), 0x00};
this->send_command_(CMD_SET_DISTANCE_RESOLUTION, cmd_value, sizeof(cmd_value));
this->set_timeout(200, [this]() { this->restart_and_read_all_info(); });
}
void LD2410Component::set_baud_rate(const std::string &state) {
void LD2410Component::set_baud_rate(const char *state) {
this->set_config_mode_(true);
const uint8_t cmd_value[2] = {find_uint8(BAUD_RATES_BY_STR, state.c_str()), 0x00};
const uint8_t cmd_value[2] = {find_uint8(BAUD_RATES_BY_STR, state), 0x00};
this->send_command_(CMD_SET_BAUD_RATE, cmd_value, sizeof(cmd_value));
this->set_timeout(200, [this]() { this->restart_(); });
}

View File

@@ -98,8 +98,8 @@ class LD2410Component : public Component, public uart::UARTDevice {
void read_all_info();
void restart_and_read_all_info();
void set_bluetooth(bool enable);
void set_distance_resolution(const std::string &state);
void set_baud_rate(const std::string &state);
void set_distance_resolution(const char *state);
void set_baud_rate(const char *state);
void factory_reset();
protected:

View File

@@ -3,9 +3,9 @@
namespace esphome {
namespace ld2410 {
void BaudRateSelect::control(const std::string &value) {
this->publish_state(value);
this->parent_->set_baud_rate(value);
void BaudRateSelect::control(size_t index) {
this->publish_state(index);
this->parent_->set_baud_rate(this->option_at(index));
}
} // namespace ld2410

View File

@@ -11,7 +11,7 @@ class BaudRateSelect : public select::Select, public Parented<LD2410Component> {
BaudRateSelect() = default;
protected:
void control(const std::string &value) override;
void control(size_t index) override;
};
} // namespace ld2410

View File

@@ -3,9 +3,9 @@
namespace esphome {
namespace ld2410 {
void DistanceResolutionSelect::control(const std::string &value) {
this->publish_state(value);
this->parent_->set_distance_resolution(value);
void DistanceResolutionSelect::control(size_t index) {
this->publish_state(index);
this->parent_->set_distance_resolution(this->option_at(index));
}
} // namespace ld2410

View File

@@ -11,7 +11,7 @@ class DistanceResolutionSelect : public select::Select, public Parented<LD2410Co
DistanceResolutionSelect() = default;
protected:
void control(const std::string &value) override;
void control(size_t index) override;
};
} // namespace ld2410

View File

@@ -11,7 +11,7 @@ class LightOutControlSelect : public select::Select, public Parented<LD2410Compo
LightOutControlSelect() = default;
protected:
void control(const std::string &value) override;
void control(size_t index) override;
};
} // namespace ld2410

View File

@@ -699,16 +699,16 @@ void LD2412Component::set_bluetooth(bool enable) {
this->set_timeout(200, [this]() { this->restart_and_read_all_info(); });
}
void LD2412Component::set_distance_resolution(const std::string &state) {
void LD2412Component::set_distance_resolution(const char *state) {
this->set_config_mode_(true);
const uint8_t cmd_value[6] = {find_uint8(DISTANCE_RESOLUTIONS_BY_STR, state.c_str()), 0x00, 0x00, 0x00, 0x00, 0x00};
const uint8_t cmd_value[6] = {find_uint8(DISTANCE_RESOLUTIONS_BY_STR, state), 0x00, 0x00, 0x00, 0x00, 0x00};
this->send_command_(CMD_SET_DISTANCE_RESOLUTION, cmd_value, sizeof(cmd_value));
this->set_timeout(200, [this]() { this->restart_and_read_all_info(); });
}
void LD2412Component::set_baud_rate(const std::string &state) {
void LD2412Component::set_baud_rate(const char *state) {
this->set_config_mode_(true);
const uint8_t cmd_value[2] = {find_uint8(BAUD_RATES_BY_STR, state.c_str()), 0x00};
const uint8_t cmd_value[2] = {find_uint8(BAUD_RATES_BY_STR, state), 0x00};
this->send_command_(CMD_SET_BAUD_RATE, cmd_value, sizeof(cmd_value));
this->set_timeout(200, [this]() { this->restart_(); });
}

View File

@@ -99,8 +99,8 @@ class LD2412Component : public Component, public uart::UARTDevice {
void read_all_info();
void restart_and_read_all_info();
void set_bluetooth(bool enable);
void set_distance_resolution(const std::string &state);
void set_baud_rate(const std::string &state);
void set_distance_resolution(const char *state);
void set_baud_rate(const char *state);
void factory_reset();
void start_dynamic_background_correction();

View File

@@ -3,9 +3,9 @@
namespace esphome {
namespace ld2412 {
void BaudRateSelect::control(const std::string &value) {
this->publish_state(value);
this->parent_->set_baud_rate(value);
void BaudRateSelect::control(size_t index) {
this->publish_state(index);
this->parent_->set_baud_rate(this->option_at(index));
}
} // namespace ld2412

View File

@@ -11,7 +11,7 @@ class BaudRateSelect : public select::Select, public Parented<LD2412Component> {
BaudRateSelect() = default;
protected:
void control(const std::string &value) override;
void control(size_t index) override;
};
} // namespace ld2412

View File

@@ -3,9 +3,9 @@
namespace esphome {
namespace ld2412 {
void DistanceResolutionSelect::control(const std::string &value) {
this->publish_state(value);
this->parent_->set_distance_resolution(value);
void DistanceResolutionSelect::control(size_t index) {
this->publish_state(index);
this->parent_->set_distance_resolution(this->option_at(index));
}
} // namespace ld2412

View File

@@ -11,7 +11,7 @@ class DistanceResolutionSelect : public select::Select, public Parented<LD2412Co
DistanceResolutionSelect() = default;
protected:
void control(const std::string &value) override;
void control(size_t index) override;
};
} // namespace ld2412

View File

@@ -11,7 +11,7 @@ class LightOutControlSelect : public select::Select, public Parented<LD2412Compo
LightOutControlSelect() = default;
protected:
void control(const std::string &value) override;
void control(size_t index) override;
};
} // namespace ld2412

View File

@@ -379,7 +379,7 @@ void LD2420Component::report_gate_data() {
ESP_LOGI(TAG, "Total samples: %d", this->total_sample_number_counter);
}
void LD2420Component::set_operating_mode(const std::string &state) {
void LD2420Component::set_operating_mode(const char *state) {
// If unsupported firmware ignore mode select
if (ld2420::get_firmware_int(firmware_ver_) >= CALIBRATE_VERSION_MIN) {
this->current_operating_mode = find_uint8(OP_MODE_BY_STR, state);

View File

@@ -107,7 +107,7 @@ class LD2420Component : public Component, public uart::UARTDevice {
int send_cmd_from_array(CmdFrameT cmd_frame);
void report_gate_data();
void handle_cmd_error(uint8_t error);
void set_operating_mode(const std::string &state);
void set_operating_mode(const char *state);
void auto_calibrate_sensitivity();
void update_radar_data(uint16_t const *gate_energy, uint8_t sample_number);
uint8_t set_config_mode(bool enable);

View File

@@ -7,9 +7,9 @@ namespace ld2420 {
static const char *const TAG = "ld2420.select";
void LD2420Select::control(const std::string &value) {
this->publish_state(value);
this->parent_->set_operating_mode(value);
void LD2420Select::control(size_t index) {
this->publish_state(index);
this->parent_->set_operating_mode(this->option_at(index));
}
} // namespace ld2420

View File

@@ -11,7 +11,7 @@ class LD2420Select : public Component, public select::Select, public Parented<LD
LD2420Select() = default;
protected:
void control(const std::string &value) override;
void control(size_t index) override;
};
} // namespace ld2420

View File

@@ -790,7 +790,7 @@ void LD2450Component::set_bluetooth(bool enable) {
}
// Set Baud rate
void LD2450Component::set_baud_rate(const std::string &state) {
void LD2450Component::set_baud_rate(const char *state) {
this->set_config_mode_(true);
const uint8_t cmd_value[2] = {find_uint8(BAUD_RATES_BY_STR, state), 0x00};
this->send_command_(CMD_SET_BAUD_RATE, cmd_value, sizeof(cmd_value));
@@ -798,8 +798,8 @@ void LD2450Component::set_baud_rate(const std::string &state) {
}
// Set Zone Type - one of: Disabled, Detection, Filter
void LD2450Component::set_zone_type(const std::string &state) {
ESP_LOGV(TAG, "Set zone type: %s", state.c_str());
void LD2450Component::set_zone_type(const char *state) {
ESP_LOGV(TAG, "Set zone type: %s", state);
uint8_t zone_type = find_uint8(ZONE_TYPE_BY_STR, state);
this->zone_type_ = zone_type;
this->send_set_zone_command_();

View File

@@ -115,8 +115,8 @@ class LD2450Component : public Component, public uart::UARTDevice {
void restart_and_read_all_info();
void set_bluetooth(bool enable);
void set_multi_target(bool enable);
void set_baud_rate(const std::string &state);
void set_zone_type(const std::string &state);
void set_baud_rate(const char *state);
void set_zone_type(const char *state);
void publish_zone_type();
void factory_reset();
#ifdef USE_TEXT_SENSOR

View File

@@ -3,9 +3,9 @@
namespace esphome {
namespace ld2450 {
void BaudRateSelect::control(const std::string &value) {
this->publish_state(value);
this->parent_->set_baud_rate(value);
void BaudRateSelect::control(size_t index) {
this->publish_state(index);
this->parent_->set_baud_rate(this->option_at(index));
}
} // namespace ld2450

View File

@@ -11,7 +11,7 @@ class BaudRateSelect : public select::Select, public Parented<LD2450Component> {
BaudRateSelect() = default;
protected:
void control(const std::string &value) override;
void control(size_t index) override;
};
} // namespace ld2450

View File

@@ -3,9 +3,9 @@
namespace esphome {
namespace ld2450 {
void ZoneTypeSelect::control(const std::string &value) {
this->publish_state(value);
this->parent_->set_zone_type(value);
void ZoneTypeSelect::control(size_t index) {
this->publish_state(index);
this->parent_->set_zone_type(this->option_at(index));
}
} // namespace ld2450

View File

@@ -11,7 +11,7 @@ class ZoneTypeSelect : public select::Select, public Parented<LD2450Component> {
ZoneTypeSelect() = default;
protected:
void control(const std::string &value) override;
void control(size_t index) override;
};
} // namespace ld2450

View File

@@ -14,11 +14,6 @@ void LoggerLevelSelect::setup() {
this->publish_state(this->parent_->get_log_level());
}
void LoggerLevelSelect::control(const std::string &value) {
const auto index = this->index_of(value);
if (!index)
return;
this->parent_->set_log_level(index_to_level(index.value()));
}
void LoggerLevelSelect::control(size_t index) { this->parent_->set_log_level(index_to_level(index)); }
} // namespace esphome::logger

View File

@@ -9,7 +9,7 @@ class LoggerLevelSelect : public Component, public select::Select, public Parent
public:
void publish_state(int level);
void setup() override;
void control(const std::string &value) override;
void control(size_t index) override;
protected:
// Convert log level to option index (skip CONFIG at level 4)

View File

@@ -41,16 +41,14 @@ void TemplateSelect::update() {
}
}
void TemplateSelect::control(const std::string &value) {
this->set_trigger_->trigger(value);
void TemplateSelect::control(size_t index) {
this->set_trigger_->trigger(std::string(this->option_at(index)));
if (this->optimistic_)
this->publish_state(value);
this->publish_state(index);
if (this->restore_value_) {
auto index = this->index_of(value);
this->pref_.save(&index.value());
}
if (this->restore_value_)
this->pref_.save(&index);
}
void TemplateSelect::dump_config() {

View File

@@ -24,7 +24,7 @@ class TemplateSelect : public select::Select, public PollingComponent {
void set_restore_value(bool restore_value) { this->restore_value_ = restore_value; }
protected:
void control(const std::string &value) override;
void control(size_t index) override;
bool optimistic_ = false;
size_t initial_option_index_{0};
bool restore_value_ = false;