7static 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());
42 ESP_LOGW(TAG,
"Invalid value %s", value.c_str());
46 LOG_SELECT(
"",
"Tuya Select",
this);
47 ESP_LOGCONFIG(TAG,
" Select has datapoint ID %u", this->
select_id_);
48 ESP_LOGCONFIG(TAG,
" Data type: %s", this->
is_int_ ?
"int" :
"enum");
49 ESP_LOGCONFIG(TAG,
" Options are:");
51 for (
auto i = 0; i < this->
mappings_.size(); i++) {
optional< size_t > index_of(const std::string &option) const
Find the (optional) index offset of the provided option value.
optional< std::string > at(size_t index) const
Return the (optional) option value at the provided index offset.
void publish_state(const std::string &state)
std::vector< std::string > get_options() const
void set_enum_datapoint_value(uint8_t datapoint_id, uint8_t value)
void register_listener(uint8_t datapoint_id, const std::function< void(TuyaDatapoint)> &func)
void set_integer_datapoint_value(uint8_t datapoint_id, uint32_t value)
void dump_config() override
void control(const std::string &value) override
std::vector< uint8_t > mappings_
Providing packet encoding functions for exchanging data with a remote host.