6static const char *
const TAG =
"modbus_controller.select";
14 ESP_LOGD(TAG,
"New select value %lld from payload", value);
16 optional<std::string> new_state;
20 if (
val.has_value()) {
22 ESP_LOGV(TAG,
"lambda returned option %s", new_state->c_str());
26 if (!new_state.has_value()) {
27 auto map_it = std::find(this->
mapping_.cbegin(), this->mapping_.cend(), value);
29 if (map_it != this->
mapping_.cend()) {
30 size_t idx = std::distance(this->
mapping_.cbegin(), map_it);
31 ESP_LOGV(TAG,
"Found option %s for value %lld", this->
option_at(idx), value);
35 ESP_LOGE(TAG,
"No option found for mapping %lld", value);
39 if (new_state.has_value()) {
45 optional<int64_t> mapval = this->
mapping_[index];
46 const char *option = this->
option_at(index);
47 ESP_LOGD(TAG,
"Found value %lld for option '%s'", *mapval, option);
68 }
else if (!
val.has_value()) {
69 ESP_LOGD(TAG,
"Communication handled by write_lambda - exiting control");
73 ESP_LOGV(TAG,
"write_lambda returned mapping value %lld", *mapval);
81 ESP_LOGW(TAG,
"No payload was created for updating select");
88 if (
data.size() > this->entity_count()) {
89 ESP_LOGE(TAG,
"Payload has %zu registers but the value type only spans %u; dropping write",
data.size(),
90 this->entity_count());
103 ESP_LOGW(TAG,
"Modbus write for '%s' was refused by the hub; state not published", this->
get_name().c_str());
const StringRef & get_name() const
Minimal static vector - saves memory by avoiding std::vector overhead.
optional< write_transform_func_t > write_transform_func_
void control(size_t index) override
std::vector< int64_t > mapping_
void dump_config() override
void parse_and_publish(std::span< const uint8_t > data) override
optional< transform_func_t > transform_func_
virtual uint16_t entity_count() const
Entities this item spans: one bit for bit-addressed types, ceil(bytes / 2) registers for RAW with a r...
SensorValueType sensor_value_type
uint8_t offset
Position of this sensor's data within its range's response - a byte offset for registers,...
uint16_t write_address() const
Address a write entity (switch/number/select) targets, derived from its resolved position within the ...
void warn_write_buffer_deprecated_(const LogString *platform, uint16_t address)
bool dispatched() const
Whether the lambda called a request helper since the last clear_dispatched_().
bool write_single_register(uint16_t address, uint16_t value)
void clear_tx_queue_for_device()
bool write_multiple_registers(uint16_t address, std::span< const uint16_t > values)
const char * option_at(size_t index) const
Return the option value at the provided index offset (as const char* from flash).
void publish_state(const std::string &state)
void number_to_payload(Container &data, int64_t value, SensorValueType value_type)
Append the Modbus register words for value to data.
std::optional< int64_t > payload_to_number(const uint8_t *data, size_t size, SensorValueType sensor_value_type, uint8_t offset, uint32_t bitmask)
Convert a raw response payload to a number.
const std::vector< uint8_t > & data