ESPHome 2026.10.0-dev
Loading...
Searching...
No Matches
modbus_binarysensor.h
Go to the documentation of this file.
1#pragma once
2
6
7#include <span>
8
10
12 public:
15 this->register_type = register_type;
16 this->set_address(start_address);
18 this->bitmask = bitmask;
20 this->reuse_previous_range = reuse_previous_range;
21 }
22
25 uint16_t entity_count() const override {
27 return this->offset_from_start_address + 1;
28 }
29 return 1;
30 }
31
32 void parse_and_publish(std::span<const uint8_t> data) override;
33 void set_state(bool state) { this->state = state; }
34
35 void dump_config() override;
36
37 using transform_func_t = optional<bool> (*)(ModbusBinarySensor *, bool, std::span<const uint8_t>);
39
40 protected:
41 optional<transform_func_t> transform_func_{nullopt};
42};
43
44} // namespace esphome::modbus_controller
Base class for all binary_sensor-type classes.
bool state
The current state of this binary sensor. Also used as the backing storage for StatefulEntityBase.
uint16_t entity_count() const override
On the bit-addressed tables the bit sits at start_address + offset, so the read must span offset + 1 ...
optional< bool >(*)(ModbusBinarySensor *, bool, std::span< const uint8_t >) transform_func_t
ModbusBinarySensor(modbus::EntityType register_type, uint16_t start_address, uint8_t offset, uint32_t bitmask, RangeReuse reuse_previous_range)
void parse_and_publish(std::span< const uint8_t > data) override
void set_address(uint16_t address)
Sets the configured address, and points the range base at it.
void set_offset_from_start_address(uint8_t offset)
Records the offset as configured, and seeds the resolved position with it.
uint8_t offset
Position of this sensor's data within its range's response - a byte offset for registers,...
uint8_t offset_from_start_address
The offset exactly as configured: measured from this sensor's own start_address, where offset is meas...
bool is_entity_type_binary(EntityType type)
Coils and discrete inputs are the bit-addressed entity tables; the other types are 16-bit registers.
const std::vector< uint8_t > & data
RangeReuse
How an item relates to the register range built just before it (same register type,...
static void uint32_t