ESPHome 2026.5.0-dev
Loading...
Searching...
No Matches
tmp117.cpp
Go to the documentation of this file.
1// Implementation based on:
2// - DHT 12 Component
3
4#include "tmp117.h"
5#include "esphome/core/log.h"
6
7namespace esphome::tmp117 {
8
9static const char *const TAG = "tmp117";
10
12 int16_t data;
13 if (!this->read_data_(&data)) {
14 this->status_set_warning();
15 return;
16 }
17 if ((uint16_t) data != 0x8000) {
18 float temperature = data * 0.0078125f;
19
20 this->publish_state(temperature);
22 } else {
23 ESP_LOGD(TAG, "Not ready");
24 }
25}
27 if (!this->write_config_(this->config_)) {
28 this->mark_failed();
29 return;
30 }
31
32 int16_t data;
33 if (!this->read_data_(&data)) {
34 this->mark_failed();
35 return;
36 }
37}
39 ESP_LOGCONFIG(TAG, "TMP117:");
40 LOG_I2C_DEVICE(this);
41 if (this->is_failed()) {
42 ESP_LOGE(TAG, ESP_LOG_MSG_COMM_FAIL);
43 }
44 LOG_SENSOR(" ", "Temperature", this);
45}
46
47bool TMP117Component::read_data_(int16_t *data) {
48 if (!this->read_byte_16(0, (uint16_t *) data)) {
49 ESP_LOGW(TAG, "Updating failed");
50 return false;
51 }
52 return true;
53}
54
55bool TMP117Component::read_config_(uint16_t *config) {
56 if (!this->read_byte_16(1, (uint16_t *) config)) {
57 ESP_LOGW(TAG, "Reading config failed");
58 return false;
59 }
60 return true;
61}
62
63bool TMP117Component::write_config_(uint16_t config) {
64 if (!this->write_byte_16(1, config)) {
65 ESP_LOGE(TAG, "Writing config failed");
66 return false;
67 }
68 return true;
69}
70
71} // namespace esphome::tmp117
void mark_failed()
Mark this component as failed.
bool is_failed() const
Definition component.h:284
void status_clear_warning()
Definition component.h:306
bool read_byte_16(uint8_t a_register, uint16_t *data)
Definition i2c.h:249
bool write_byte_16(uint8_t a_register, uint16_t data) const
Definition i2c.h:267
void publish_state(float state)
Publish a new state to the front-end.
Definition sensor.cpp:68
bool write_config_(uint16_t config)
Definition tmp117.cpp:63
bool read_config_(uint16_t *config)
Definition tmp117.cpp:55
bool read_data_(int16_t *data)
Definition tmp117.cpp:47
uint16_t temperature
Definition sun_gtil2.cpp:12