ESPHome  2024.11.1
modbus_binarysensor.h
Go to the documentation of this file.
1 #pragma once
2 
6 
7 #include <vector>
8 
9 namespace esphome {
10 namespace modbus_controller {
11 
13  public:
15  uint16_t skip_updates, bool force_new_range) {
16  this->register_type = register_type;
17  this->start_address = start_address;
18  this->offset = offset;
19  this->bitmask = bitmask;
21  this->skip_updates = skip_updates;
22  this->force_new_range = force_new_range;
23 
24  if (register_type == ModbusRegisterType::COIL || register_type == ModbusRegisterType::DISCRETE_INPUT) {
25  this->register_count = offset + 1;
26  } else {
27  this->register_count = 1;
28  }
29  }
30 
31  void parse_and_publish(const std::vector<uint8_t> &data) override;
32  void set_state(bool state) { this->state = state; }
33 
34  void dump_config() override;
35 
36  using transform_func_t = std::function<optional<bool>(ModbusBinarySensor *, bool, const std::vector<uint8_t> &)>;
38 
39  protected:
41 };
42 
43 } // namespace modbus_controller
44 } // namespace esphome
ModbusBinarySensor(ModbusRegisterType register_type, uint16_t start_address, uint8_t offset, uint32_t bitmask, uint16_t skip_updates, bool force_new_range)
const nullopt_t nullopt((nullopt_t::init()))
bool state
The current reported state of the binary sensor.
Definition: binary_sensor.h:61
Implementation of SPI Controller mode.
Definition: a01nyub.cpp:7
Base class for all binary_sensor-type classes.
Definition: binary_sensor.h:37
std::function< optional< bool >(ModbusBinarySensor *, bool, const std::vector< uint8_t > &)> transform_func_t
void parse_and_publish(const std::vector< uint8_t > &data) override