7static const char *
const TAG =
"modbus.number";
10static constexpr size_t MODBUS_NUMBER_MAX_LOG_REGISTERS = 32;
20 if (
val.has_value()) {
21 ESP_LOGV(TAG,
"Value overwritten by lambda");
25 ESP_LOGD(TAG,
"Number new state : %.02f", result);
36 float write_value = value;
48#if ESPHOME_LOG_LEVEL >= ESPHOME_LOG_LEVEL_VERBOSE
51 ESP_LOGV(TAG,
"Modbus Number write raw: %s",
55 for (uint16_t word :
data) {
57 bytes.push_back(word_bytes[0]);
58 bytes.push_back(word_bytes[1]);
61 ESP_LOGW(TAG,
"Modbus write for '%s' was refused by the hub; state not published", this->
get_name().c_str());
67 if (!
val.has_value()) {
68 ESP_LOGV(TAG,
"Communication handled by lambda - exiting control");
71 ESP_LOGV(TAG,
"Value overwritten by lambda");
72 write_value =
val.value();
80 ESP_LOGW(TAG,
"No payload was created for updating number");
85 "Updating register: connected Sensor=%s start address=0x%X register count=%d new value=%.02f (val=%.02f)",
95 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.
void control(float value) override
optional< write_transform_func_t > write_transform_func_
void parse_and_publish(std::span< const uint8_t > data) override
optional< transform_func_t > transform_func_
void dump_config() override
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)
bool send_raw_frame_deprecated_(std::span< const uint8_t > frame)
void clear_tx_queue_for_device()
bool write_multiple_registers(uint16_t address, std::span< const uint16_t > values)
void publish_state(float state)
void float_to_payload(Container &data, float value, SensorValueType value_type)
Append a float converted to register words to any push_back container (heap-free with StaticVector).
const std::vector< uint8_t > & data
float payload_to_float(std::span< const uint8_t > data, const SensorItem &item, uint8_t offset)
Convert vector<uint8_t> response payload to float.
char * format_hex_pretty_to(char *buffer, size_t buffer_size, const uint8_t *data, size_t length, char separator)
Format byte array as uppercase hex to buffer (base implementation).
constexpr std::array< uint8_t, sizeof(T)> decode_value(T val)
Decode a value into its constituent bytes (from most to least significant).
constexpr size_t format_hex_pretty_uint16_size(size_t count)
Calculate buffer size needed for format_hex_pretty_to with uint16_t data: "XXXX:XXXX:....