9static const char *
const TAG =
"modbus_controller.output";
12static constexpr size_t MODBUS_OUTPUT_MAX_LOG_BYTES = 64;
23 auto original_value = value;
34 }
else if (!
val.has_value()) {
35 ESP_LOGV(TAG,
"Communication handled by lambda - exiting control");
38 ESP_LOGV(TAG,
"Value overwritten by lambda");
49 ESP_LOGD(TAG,
"Updating register: start address=0x%X register count=%u new value=%.02f (val=%.02f)",
54 ESP_LOGW(TAG,
"No payload was created for updating output");
59 if (
data.size() > this->entity_count()) {
60 ESP_LOGE(TAG,
"Payload has %zu registers but the value type only spans %u; dropping write",
data.size(),
61 this->entity_count());
72 ESP_LOGW(TAG,
"Modbus output write (address 0x%X) was refused by the hub", this->
write_address());
77 ESP_LOGCONFIG(TAG,
"Modbus Float Output:");
78 LOG_FLOAT_OUTPUT(
this);
80 " Device start address: 0x%X\n"
81 " Register count: %d\n"
103#if ESPHOME_LOG_LEVEL >= ESPHOME_LOG_LEVEL_VERBOSE
106 ESP_LOGV(TAG,
"Modbus binary output write raw: %s",
110 ESP_LOGW(TAG,
"Modbus output write (address 0x%X) was refused by the hub", this->
write_address());
114 if (!
val.has_value()) {
115 ESP_LOGV(TAG,
"Communication handled by lambda - exiting control");
118 ESP_LOGV(TAG,
"Value overwritten by lambda");
121 ESP_LOGV(TAG,
"Write new state: value is %s, type is %d address = %X, offset = %x", ONOFF(
state),
126 std::array<bool, 1> states{
state};
132 ESP_LOGW(TAG,
"Modbus output write (address 0x%X) was refused by the hub", this->
write_address());
137 ESP_LOGCONFIG(TAG,
"Modbus Binary Output:");
138 LOG_BINARY_OUTPUT(
this);
140 " Device start address: 0x%X\n"
141 " Register count: %d\n"
Minimal static vector - saves memory by avoiding std::vector overhead.
void write_state(bool state) override
optional< write_transform_func_t > write_transform_func_
void dump_config() override
void write_state(float value) override
Write a value to the device.
optional< write_transform_func_t > write_transform_func_
void dump_config() override
modbus::EntityType register_type
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_coil(uint16_t address, bool value)
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_coils(uint16_t address, std::span< const bool > values)
bool write_multiple_registers(uint16_t address, std::span< const uint16_t > values)
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
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 size_t format_hex_pretty_size(size_t byte_count)
Calculate buffer size needed for format_hex_pretty_to with separator: "XX:XX:...:XX\0".