mirror of
https://github.com/esphome/esphome.git
synced 2025-11-01 07:31:51 +00:00
fixes
This commit is contained in:
@@ -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;
|
||||
|
||||
@@ -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]);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user