mirror of
				https://github.com/esphome/esphome.git
				synced 2025-10-31 07:03:55 +00:00 
			
		
		
		
	Merge branch 'select_options_in_flash' into integration
This commit is contained in:
		| @@ -28,7 +28,7 @@ void ModbusSelect::parse_and_publish(const std::vector<uint8_t> &data) { | ||||
|  | ||||
|     if (map_it != this->mapping_.cend()) { | ||||
|       size_t idx = std::distance(this->mapping_.cbegin(), map_it); | ||||
|       new_state = std::string(this->traits.get_options()[idx]); | ||||
|       new_state = std::string(this->option_at(idx)); | ||||
|       ESP_LOGV(TAG, "Found option %s for value %lld", new_state->c_str(), value); | ||||
|     } else { | ||||
|       ESP_LOGE(TAG, "No option found for mapping %lld", value); | ||||
|   | ||||
| @@ -60,5 +60,7 @@ optional<std::string> Select::at(size_t index) const { | ||||
|   } | ||||
| } | ||||
|  | ||||
| const char *Select::option_at(size_t index) const { return traits.get_options().at(index); } | ||||
|  | ||||
| }  // namespace select | ||||
| }  // namespace esphome | ||||
|   | ||||
| @@ -56,6 +56,9 @@ class Select : public EntityBase { | ||||
|   /// Return the (optional) option value at the provided index offset. | ||||
|   optional<std::string> at(size_t index) const; | ||||
|  | ||||
|   /// Return the option value at the provided index offset (as const char* from flash). | ||||
|   const char *option_at(size_t index) const; | ||||
|  | ||||
|   void add_on_state_callback(std::function<void(std::string, size_t)> &&callback); | ||||
|  | ||||
|  protected: | ||||
|   | ||||
| @@ -16,12 +16,12 @@ void TemplateSelect::setup() { | ||||
|     size_t restored_index; | ||||
|     if (this->pref_.load(&restored_index) && this->has_index(restored_index)) { | ||||
|       index = restored_index; | ||||
|       ESP_LOGD(TAG, "State from restore: %s", this->at(index).value().c_str()); | ||||
|       ESP_LOGD(TAG, "State from restore: %s", this->option_at(index)); | ||||
|     } else { | ||||
|       ESP_LOGD(TAG, "State from initial (could not load or invalid stored index): %s", this->at(index).value().c_str()); | ||||
|       ESP_LOGD(TAG, "State from initial (could not load or invalid stored index): %s", this->option_at(index)); | ||||
|     } | ||||
|   } else { | ||||
|     ESP_LOGD(TAG, "State from initial: %s", this->at(index).value().c_str()); | ||||
|     ESP_LOGD(TAG, "State from initial: %s", this->option_at(index)); | ||||
|   } | ||||
|  | ||||
|   this->publish_state(this->at(index).value()); | ||||
| @@ -64,8 +64,7 @@ void TemplateSelect::dump_config() { | ||||
|                 "  Optimistic: %s\n" | ||||
|                 "  Initial Option: %s\n" | ||||
|                 "  Restore Value: %s", | ||||
|                 YESNO(this->optimistic_), this->at(this->initial_option_index_).value().c_str(), | ||||
|                 YESNO(this->restore_value_)); | ||||
|                 YESNO(this->optimistic_), this->option_at(this->initial_option_index_), YESNO(this->restore_value_)); | ||||
| } | ||||
|  | ||||
| }  // namespace template_ | ||||
|   | ||||
		Reference in New Issue
	
	Block a user