13static constexpr size_t MODBUS_SWITCH_MAX_LOG_BYTES = 64;
39 if (
val.has_value()) {
40 ESP_LOGV(TAG,
"Value overwritten by lambda");
45 ESP_LOGV(TAG,
"Publish '%s': new value = %s type = %d address = %X offset = %zx", LOG_STR_ARG(this->
get_log_name()),
56 bool write_value =
state;
67 ESP_LOGV_HEX(TAG,
data.data(),
data.size(), MODBUS_SWITCH_MAX_LOG_BYTES,
"Modbus Switch write raw: %s");
70 ESP_LOGW(TAG,
"Modbus write for '%s' was refused by the hub; state not published",
77 if (!
val.has_value()) {
78 ESP_LOGV(TAG,
"Communication handled by lambda - exiting control");
83 ESP_LOGV(TAG,
"Value overwritten by lambda");
84 write_value =
val.value();
86 ESP_LOGV(TAG,
"write_state '%s': new value = %s (wire = %s) type = %d address = %X offset = %x",
93 std::array<bool, 1> states{write_value};
100 std::array<uint16_t, 1> states{
static_cast<uint16_t
>(write_value ? (0xFFFF & this->
bitmask) : 0)};
107 ESP_LOGW(TAG,
"Modbus write for '%s' was refused by the hub; state not published",
const LogString * get_log_name() const
Get the name for a "%s" log argument (LOG_STR_ARG).
Minimal static vector - saves memory by avoiding std::vector overhead.
void parse_and_publish(std::span< const uint8_t > data) override
optional< write_transform_func_t > write_transform_func_
bool assumed_state() override
void write_state(bool state) override
void dump_config() override
optional< transform_func_t > publish_transform_func_
modbus::EntityType register_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)
bool state
The current reported state of the binary sensor.
void restore()
Drive the switch to the state its restore mode yields, through control(), so inversion and write_stat...
void publish_state(bool state)
Publish a state to the front-end from the back-end.
T get_data(const uint8_t *data, size_t buffer_offset)
Extract data from modbus response buffer.
bool bit_from_packed(int bit, std::span< const uint8_t > data)
Extract coil data from modbus response buffer Responses for coil are packed into bytes .
const std::vector< uint8_t > & data
ESPHOME_LOG_TAG(TAG, "modbus_controller.binary_sensor")