ESPHome 2025.9.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 {
8namespace tmp117 {
9
10static const char *const TAG = "tmp117";
11
13 int16_t data;
14 if (!this->read_data_(&data)) {
15 this->status_set_warning();
16 return;
17 }
18 if ((uint16_t) data != 0x8000) {
19 float temperature = data * 0.0078125f;
20
21 ESP_LOGD(TAG, "Got temperature=%.2f°C", temperature);
22 this->publish_state(temperature);
24 } else {
25 ESP_LOGD(TAG, "TMP117 not ready");
26 }
27}
29 if (!this->write_config_(this->config_)) {
30 this->mark_failed();
31 return;
32 }
33
34 int16_t data;
35 if (!this->read_data_(&data)) {
36 this->mark_failed();
37 return;
38 }
39}
41 ESP_LOGD(TAG, "TMP117:");
42 LOG_I2C_DEVICE(this);
43 if (this->is_failed()) {
44 ESP_LOGE(TAG, ESP_LOG_MSG_COMM_FAIL);
45 }
46 LOG_SENSOR(" ", "Temperature", this);
47}
49bool TMP117Component::read_data_(int16_t *data) {
50 if (!this->read_byte_16(0, (uint16_t *) data)) {
51 ESP_LOGW(TAG, "Updating TMP117 failed!");
52 return false;
53 }
54 return true;
55}
56
57bool TMP117Component::read_config_(uint16_t *config) {
58 if (!this->read_byte_16(1, (uint16_t *) config)) {
59 ESP_LOGW(TAG, "Reading TMP117 config failed!");
60 return false;
61 }
62 return true;
63}
64
65bool TMP117Component::write_config_(uint16_t config) {
66 if (!this->write_byte_16(1, config)) {
67 ESP_LOGE(TAG, "Writing TMP117 config failed!");
68 return false;
69 }
70 return true;
71}
72
73} // namespace tmp117
74} // namespace esphome
virtual void mark_failed()
Mark this component as failed.
bool is_failed() const
void status_set_warning(const char *message=nullptr)
void status_clear_warning()
bool read_byte_16(uint8_t a_register, uint16_t *data)
Definition i2c.h:250
bool write_byte_16(uint8_t a_register, uint16_t data)
Definition i2c.h:270
void publish_state(float state)
Publish a new state to the front-end.
Definition sensor.cpp:45
bool write_config_(uint16_t config)
Definition tmp117.cpp:65
float get_setup_priority() const override
Definition tmp117.cpp:48
bool read_config_(uint16_t *config)
Definition tmp117.cpp:57
bool read_data_(int16_t *data)
Definition tmp117.cpp:49
const float DATA
For components that import data from directly connected sensors like DHT.
Definition component.cpp:50
Providing packet encoding functions for exchanging data with a remote host.
Definition a01nyub.cpp:7
uint16_t temperature
Definition sun_gtil2.cpp:12