7 static const char *
const TAG =
"tuya.select";
12 ESP_LOGV(TAG,
"MCU reported select %u value %u", this->
select_id_, enum_value);
15 auto it = std::find(mappings.cbegin(), mappings.cend(), enum_value);
16 if (it == mappings.end()) {
17 ESP_LOGW(TAG,
"Invalid value %u", enum_value);
20 size_t mapping_idx = std::distance(mappings.cbegin(), it);
21 auto value = this->
at(mapping_idx);
31 if (idx.has_value()) {
32 uint8_t mapping = this->
mappings_.at(idx.value());
33 ESP_LOGV(TAG,
"Setting %u datapoint value to %u:%s", this->
select_id_, mapping, value.c_str());
38 ESP_LOGW(TAG,
"Invalid value %s", value.c_str());
42 LOG_SELECT(
"",
"Tuya Select",
this);
43 ESP_LOGCONFIG(TAG,
" Select has datapoint ID %u", this->
select_id_);
44 ESP_LOGCONFIG(TAG,
" Options are:");
46 for (
auto i = 0; i < this->
mappings_.size(); i++) {
void dump_config() override
void set_enum_datapoint_value(uint8_t datapoint_id, uint8_t value)
optional< std::string > at(size_t index) const
Return the (optional) option value at the provided index offset.
void register_listener(uint8_t datapoint_id, const std::function< void(TuyaDatapoint)> &func)
void control(const std::string &value) override
std::vector< uint8_t > mappings_
std::vector< std::string > get_options() const
void publish_state(const std::string &state)
Implementation of SPI Controller mode.
optional< size_t > index_of(const std::string &option) const
Find the (optional) index offset of the provided option value.