ESPHome 2025.5.0
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 ESP_LOGCONFIG(TAG, "Setting up TMP117...");
30
31 if (!this->write_config_(this->config_)) {
32 this->mark_failed();
33 return;
34 }
35
36 int16_t data;
37 if (!this->read_data_(&data)) {
38 this->mark_failed();
39 return;
40 }
41}
43 ESP_LOGD(TAG, "TMP117:");
44 LOG_I2C_DEVICE(this);
45 if (this->is_failed()) {
46 ESP_LOGE(TAG, "Communication with TMP117 failed!");
47 }
48 LOG_SENSOR(" ", "Temperature", this);
49}
51bool TMP117Component::read_data_(int16_t *data) {
52 if (!this->read_byte_16(0, (uint16_t *) data)) {
53 ESP_LOGW(TAG, "Updating TMP117 failed!");
54 return false;
55 }
56 return true;
57}
58
59bool TMP117Component::read_config_(uint16_t *config) {
60 if (!this->read_byte_16(1, (uint16_t *) config)) {
61 ESP_LOGW(TAG, "Reading TMP117 config failed!");
62 return false;
63 }
64 return true;
65}
66
67bool TMP117Component::write_config_(uint16_t config) {
68 if (!this->write_byte_16(1, config)) {
69 ESP_LOGE(TAG, "Writing TMP117 config failed!");
70 return false;
71 }
72 return true;
73}
74
75} // namespace tmp117
76} // namespace esphome
virtual void mark_failed()
Mark this component as failed.
bool is_failed() const
void status_set_warning(const char *message="unspecified")
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:39
bool write_config_(uint16_t config)
Definition tmp117.cpp:67
float get_setup_priority() const override
Definition tmp117.cpp:50
bool read_config_(uint16_t *config)
Definition tmp117.cpp:59
bool read_data_(int16_t *data)
Definition tmp117.cpp:51
const float DATA
For components that import data from directly connected sensors like DHT.
Definition component.cpp:19
Providing packet encoding functions for exchanging data with a remote host.
Definition a01nyub.cpp:7
uint16_t temperature
Definition sun_gtil2.cpp:12