ESPHome  2024.11.1
ezo.h
Go to the documentation of this file.
1 #pragma once
2 
6 #include <deque>
7 
8 namespace esphome {
9 namespace ezo {
10 
11 static const char *const TAG = "ezo.sensor";
12 
13 enum EzoCommandType : uint8_t {
14  EZO_READ = 0,
23 };
24 
25 enum EzoCalibrationType : uint8_t { EZO_CAL_LOW = 0, EZO_CAL_MID = 1, EZO_CAL_HIGH = 2 };
26 
27 class EzoCommand {
28  public:
29  std::string command;
30  uint16_t delay_ms = 0;
31  bool command_sent = false;
33 };
34 
36 class EZOSensor : public sensor::Sensor, public PollingComponent, public i2c::I2CDevice {
37  public:
38  void loop() override;
39  void dump_config() override;
40  void update() override;
41  float get_setup_priority() const override { return setup_priority::DATA; };
42 
43  // I2C
44  void set_address(uint8_t address);
45 
46  // Device Information
47  void get_device_information();
48  void add_device_infomation_callback(std::function<void(std::string)> &&callback) {
49  this->device_infomation_callback_.add(std::move(callback));
50  }
51 
52  // Sleep
53  void set_sleep();
54 
55  // R
56  void get_state();
57 
58  // Slope
59  void get_slope();
60  void add_slope_callback(std::function<void(std::string)> &&callback) {
61  this->slope_callback_.add(std::move(callback));
62  }
63 
64  // T
65  void get_t();
66  void set_t(float value);
67  void set_tempcomp_value(float temp); // For backwards compatibility
68  void add_t_callback(std::function<void(std::string)> &&callback) { this->t_callback_.add(std::move(callback)); }
69 
70  // Calibration
71  void get_calibration();
72  void set_calibration_point_low(float value);
73  void set_calibration_point_mid(float value);
74  void set_calibration_point_high(float value);
75  void set_calibration_generic(float value);
76  void clear_calibration();
77  void add_calibration_callback(std::function<void(std::string)> &&callback) {
78  this->calibration_callback_.add(std::move(callback));
79  }
80 
81  // LED
82  void get_led_state();
83  void set_led_state(bool on);
84  void add_led_state_callback(std::function<void(bool)> &&callback) { this->led_callback_.add(std::move(callback)); }
85 
86  // Custom
87  void send_custom(const std::string &to_send);
88  void add_custom_callback(std::function<void(std::string)> &&callback) {
89  this->custom_callback_.add(std::move(callback));
90  }
91 
92  protected:
93  std::deque<std::unique_ptr<EzoCommand>> commands_;
95 
96  void add_command_(const std::string &command, EzoCommandType command_type, uint16_t delay_ms = 300);
97 
98  void set_calibration_point_(EzoCalibrationType type, float value);
99 
100  CallbackManager<void(std::string)> device_infomation_callback_{};
101  CallbackManager<void(std::string)> calibration_callback_{};
106 
107  uint32_t start_time_ = 0;
108 };
109 
110 } // namespace ezo
111 } // namespace esphome
void loop()
const float DATA
For components that import data from directly connected sensors like DHT.
Definition: component.cpp:19
EzoCommandType command_type
Definition: ezo.h:32
void add_led_state_callback(std::function< void(bool)> &&callback)
Definition: ezo.h:84
std::string command
Definition: ezo.h:29
This class simplifies creating components that periodically check a state.
Definition: component.h:283
This class implements support for the EZO circuits in i2c mode.
Definition: ezo.h:36
uint16_t delay_ms
Definition: ezo.h:30
void add_calibration_callback(std::function< void(std::string)> &&callback)
Definition: ezo.h:77
float get_setup_priority() const override
Definition: ezo.h:41
void add_slope_callback(std::function< void(std::string)> &&callback)
Definition: ezo.h:60
uint8_t type
Implementation of SPI Controller mode.
Definition: a01nyub.cpp:7
void add_custom_callback(std::function< void(std::string)> &&callback)
Definition: ezo.h:88
EzoCalibrationType
Definition: ezo.h:25
uint8_t address
Definition: bl0906.h:211
void add_t_callback(std::function< void(std::string)> &&callback)
Definition: ezo.h:68
void add_device_infomation_callback(std::function< void(std::string)> &&callback)
Definition: ezo.h:48
Base-class for all sensors.
Definition: sensor.h:57
std::deque< std::unique_ptr< EzoCommand > > commands_
Definition: ezo.h:93
This Class provides the methods to read/write bytes from/to an i2c device.
Definition: i2c.h:133
EzoCommandType
Definition: ezo.h:13