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-24 06:43:03 -07:00
parent 3ae82f6b98
commit 4135e0b5db
2 changed files with 9 additions and 7 deletions

View File

@@ -41,10 +41,12 @@ void ModbusSelect::parse_and_publish(const std::vector<uint8_t> &data) {
}
void ModbusSelect::control(const std::string &value) {
auto options = this->traits.get_options();
auto opt_it = std::find(options.cbegin(), options.cend(), value);
size_t idx = std::distance(options.cbegin(), opt_it);
optional<int64_t> mapval = this->mapping_[idx];
auto idx = this->index_of(value);
if (!idx.has_value()) {
ESP_LOGW(TAG, "Invalid option '%s'", value.c_str());
return;
}
optional<int64_t> mapval = this->mapping_[idx.value()];
ESP_LOGD(TAG, "Found value %lld for option '%s'", *mapval, value.c_str());
std::vector<uint16_t> data;

View File

@@ -10,7 +10,7 @@ void TuyaSelect::setup() {
this->parent_->register_listener(this->select_id_, [this](const TuyaDatapoint &datapoint) {
uint8_t enum_value = datapoint.value_enum;
ESP_LOGV(TAG, "MCU reported select %u value %u", this->select_id_, enum_value);
auto options = this->traits.get_options();
const auto &options = this->traits.get_options();
auto mappings = this->mappings_;
auto it = std::find(mappings.cbegin(), mappings.cend(), enum_value);
if (it == mappings.end()) {
@@ -49,9 +49,9 @@ void TuyaSelect::dump_config() {
" Data type: %s\n"
" Options are:",
this->select_id_, this->is_int_ ? "int" : "enum");
auto options = this->traits.get_options();
const auto &options = this->traits.get_options();
for (size_t i = 0; i < this->mappings_.size(); i++) {
ESP_LOGCONFIG(TAG, " %i: %s", this->mappings_.at(i), options.at(i).c_str());
ESP_LOGCONFIG(TAG, " %i: %s", this->mappings_.at(i), options[i]);
}
}