ESPHome  2022.8.0
modbus_binarysensor.h
Go to the documentation of this file.
1 #pragma once
2 
6 
7 namespace esphome {
8 namespace modbus_controller {
9 
11  public:
13  uint8_t skip_updates, bool force_new_range) {
14  this->register_type = register_type;
15  this->start_address = start_address;
16  this->offset = offset;
17  this->bitmask = bitmask;
19  this->skip_updates = skip_updates;
20  this->force_new_range = force_new_range;
21 
22  if (register_type == ModbusRegisterType::COIL || register_type == ModbusRegisterType::DISCRETE_INPUT) {
23  this->register_count = offset + 1;
24  } else {
25  this->register_count = 1;
26  }
27  }
28 
29  void parse_and_publish(const std::vector<uint8_t> &data) override;
30  void set_state(bool state) { this->state = state; }
31 
32  void dump_config() override;
33 
34  using transform_func_t = std::function<optional<bool>(ModbusBinarySensor *, bool, const std::vector<uint8_t> &)>;
36 
37  protected:
39 };
40 
41 } // namespace modbus_controller
42 } // namespace esphome
ModbusBinarySensor(ModbusRegisterType register_type, uint16_t start_address, uint8_t offset, uint32_t bitmask, uint8_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:50
Definition: a4988.cpp:4
Base class for all binary_sensor-type classes.
Definition: binary_sensor.h:26
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