ESPHome  2024.10.2
htu21d.h
Go to the documentation of this file.
1 #pragma once
2 
7 
8 namespace esphome {
9 namespace htu21d {
10 
12 
14  public:
16  void set_humidity(sensor::Sensor *humidity) { humidity_ = humidity; }
17  void set_heater(sensor::Sensor *heater) { heater_ = heater; }
18 
20  void setup() override;
21  void dump_config() override;
22  void set_sensor_model(HTU21DSensorModels sensor_model) { sensor_model_ = sensor_model; }
24  void update() override;
25 
26  bool is_heater_enabled();
27  void set_heater(bool status);
28  void set_heater_level(uint8_t level);
29  int8_t get_heater_level();
30 
31  float get_setup_priority() const override;
32 
33  protected:
38 };
39 
40 template<typename... Ts> class SetHeaterLevelAction : public Action<Ts...>, public Parented<HTU21DComponent> {
41  public:
42  TEMPLATABLE_VALUE(uint8_t, level)
43 
44  void play(Ts... x) override {
45  auto level = this->level_.value(x...);
46 
47  this->parent_->set_heater_level(level);
48  }
49 };
50 
51 template<typename... Ts> class SetHeaterAction : public Action<Ts...>, public Parented<HTU21DComponent> {
52  public:
54 
55  void play(Ts... x) override {
56  auto status = this->status_.value(x...);
57 
58  this->parent_->set_heater(status);
59  }
60 };
61 
62 } // namespace htu21d
63 } // namespace esphome
TEMPLATABLE_VALUE(bool, status) void play(Ts... x) override
Definition: htu21d.h:53
sensor::Sensor * humidity_
Definition: htu21d.h:35
uint16_t x
Definition: tt21100.cpp:17
sensor::Sensor * heater_
Definition: htu21d.h:36
This class simplifies creating components that periodically check a state.
Definition: component.h:283
void setup() override
Setup (reset) the sensor and check connection.
Definition: htu21d.cpp:20
void update() override
Update the sensor values (temperature+humidity).
Definition: htu21d.cpp:41
float get_setup_priority() const override
Definition: htu21d.cpp:153
void set_sensor_model(HTU21DSensorModels sensor_model)
Definition: htu21d.h:22
sensor::Sensor * temperature_
Definition: htu21d.h:34
void dump_config() override
Definition: htu21d.cpp:31
uint16_t temperature
Definition: sun_gtil2.cpp:26
void set_heater(sensor::Sensor *heater)
Definition: htu21d.h:17
uint8_t status
Definition: bl0942.h:74
void set_heater_level(uint8_t level)
Definition: htu21d.cpp:136
Implementation of SPI Controller mode.
Definition: a01nyub.cpp:7
void set_temperature(sensor::Sensor *temperature)
Definition: htu21d.h:15
Base-class for all sensors.
Definition: sensor.h:57
void set_humidity(sensor::Sensor *humidity)
Definition: htu21d.h:16
This Class provides the methods to read/write bytes from/to an i2c device.
Definition: i2c.h:133
HTU21DSensorModels sensor_model_
Definition: htu21d.h:37
TEMPLATABLE_VALUE(uint8_t, level) void play(Ts... x) override
Definition: htu21d.h:42
Helper class to easily give an object a parent of type T.
Definition: helpers.h:521