ESPHome 2026.11.0-dev
Loading...
Searching...
No Matches
tmp102.h
Go to the documentation of this file.
1#pragma once
2
5#ifdef USE_TMP102_BINARY_SENSOR
7#endif
9#ifdef USE_TMP102_NUMBER
13#endif
15#ifdef USE_TMP102_TEXT_SENSOR
17#endif
18
19#include <cstdint>
20
21namespace esphome::tmp102 {
22
23#ifdef USE_HOST
24namespace testing {
25class TMP102Test;
26}
27#endif
28
29#ifdef USE_TMP102_NUMBER
34
35class TMP102LimitNumber;
36#endif
37
38class TMP102Component final : public PollingComponent, public i2c::I2CDevice, public sensor::Sensor {
39 public:
40#ifdef USE_TMP102_BINARY_SENSOR
42#endif
43#ifdef USE_TMP102_TEXT_SENSOR
44 SUB_TEXT_SENSOR(threshold_status)
45#endif
46#if defined(USE_TMP102_CONFIGURE) || defined(USE_TMP102_TEXT_SENSOR)
47 void setup() override;
48#endif
49#ifdef USE_TMP102_CONFIGURE
50 void set_configuration(uint16_t config, uint16_t high_limit, uint16_t low_limit) {
51 this->config_ = config;
52 this->high_limit_ = high_limit;
53 this->low_limit_ = low_limit;
54 this->configure_ = true;
55 }
56#ifdef USE_TMP102_NUMBER
58#endif
59#endif
60 void dump_config() override;
61 void update() override;
62
63 protected:
64#ifdef USE_TMP102_TEXT_SENSOR
65 void publish_threshold_status_(uint8_t status);
66 void publish_threshold_rejection_(bool high, float value, float other);
67#else
69 void publish_threshold_rejection_(bool, float, float) {}
70#endif
72 this->status_set_warning();
73#ifdef USE_TMP102_BINARY_SENSOR
74 this->invalidate_alert_();
75#endif
76 }
77#ifdef USE_TMP102_BINARY_SENSOR
78 bool read_alert_state_();
79 void invalidate_alert_();
80#endif
81#ifdef USE_TMP102_CONFIGURE
82 void setup_configured_();
83 bool write_register_(uint8_t reg, uint16_t value);
86 void read_temperature_();
87 void update_configured_();
88#ifdef USE_TMP102_NUMBER
89 friend class TMP102LimitNumber;
91 float get_limit_temperature_(TMP102LimitType limit) const;
92 bool prepare_number_limits_(float *restored, bool *restore_corrected);
93
95#endif
96 uint16_t config_{0};
97 uint16_t high_limit_{0};
98 uint16_t low_limit_{0};
99 bool configure_{false};
100#endif
101};
102
103#ifdef USE_TMP102_NUMBER
104class TMP102LimitNumber final : public number::Number, public Parented<TMP102Component> {
105 public:
106 explicit TMP102LimitNumber(TMP102LimitType limit_type) : limit_type_(limit_type) {}
107 void set_restore_value(bool restore_value) { this->restore_value_ = restore_value; }
108
109 protected:
110 friend class TMP102Component;
111#ifdef USE_HOST
112 friend class testing::TMP102Test;
113#endif
114 float load_value_(float fallback, bool &corrected);
115 bool save_value_(float value);
116 void control(float value) override;
117
120 bool restore_value_{true};
121};
122#endif
123
124} // namespace esphome::tmp102
virtual void setup()
Where the component's initialization should happen.
Definition component.cpp:84
Helper class to easily give an object a parent of type T.
Definition helpers.h:2073
This class simplifies creating components that periodically check a state.
Definition component.h:519
This Class provides the methods to read/write bytes from/to an i2c device.
Definition i2c.h:144
I2CRegister reg(uint8_t a_register)
calls the I2CRegister constructor
Definition i2c.h:164
Base-class for all numbers.
Definition number.h:29
Base-class for all sensors.
Definition sensor.h:47
void publish_threshold_status_(uint8_t status)
Definition tmp102.cpp:334
bool write_register_(uint8_t reg, uint16_t value)
Definition tmp102.cpp:215
void set_configuration(uint16_t config, uint16_t high_limit, uint16_t low_limit)
Definition tmp102.h:50
void publish_threshold_rejection_(bool high, float value, float other)
Definition tmp102.cpp:346
TMP102LimitNumber * limit_controls_[2]
Definition tmp102.h:94
SUB_BINARY_SENSOR(alert) SUB_TEXT_SENSOR(threshold_status) void setup() override
float get_limit_temperature_(TMP102LimitType limit) const
Definition tmp102.cpp:303
void publish_threshold_rejection_(bool, float, float)
Definition tmp102.h:69
bool set_limit_temperature_(TMP102LimitType limit, float temperature)
Definition tmp102.cpp:308
void publish_threshold_status_(uint8_t)
Definition tmp102.h:68
void set_limit_control(TMP102LimitNumber *number)
Definition tmp102.cpp:278
bool prepare_number_limits_(float *restored, bool *restore_corrected)
Definition tmp102.cpp:282
void set_restore_value(bool restore_value)
Definition tmp102.h:107
float load_value_(float fallback, bool &corrected)
Definition tmp102.cpp:380
ESPPreferenceObject pref_
Definition tmp102.h:118
TMP102LimitNumber(TMP102LimitType limit_type)
Definition tmp102.h:106
void control(float value) override
Definition tmp102.cpp:396
@ TMP102_LIMIT_HIGH
Definition tmp102.h:32
uint16_t temperature
Definition sun_gtil2.cpp:12