ESPHome 2026.11.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
9ESPHOME_LOG_TAG(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(LOG_STR(ESP_LOG_MSG_COMM_FAIL));
29 return;
30 }
31
32 int16_t data;
33 if (!this->read_data_(&data)) {
34 this->mark_failed(LOG_STR(ESP_LOG_MSG_COMM_FAIL));
35 return;
36 }
37}
39 ESP_LOGCONFIG(TAG, "TMP117:");
40 LOG_I2C_DEVICE(this);
41 LOG_SENSOR(" ", "Temperature", this);
42}
43
44bool TMP117Component::read_data_(int16_t *data) {
45 if (!this->read_byte_16(0, (uint16_t *) data)) {
46 ESP_LOGW(TAG, "Updating failed");
47 return false;
48 }
49 return true;
50}
51
52bool TMP117Component::read_config_(uint16_t *config) {
53 if (!this->read_byte_16(1, (uint16_t *) config)) {
54 ESP_LOGW(TAG, "Reading config failed");
55 return false;
56 }
57 return true;
58}
59
60bool TMP117Component::write_config_(uint16_t config) {
61 if (!this->write_byte_16(1, config)) {
62 ESP_LOGE(TAG, "Writing config failed");
63 return false;
64 }
65 return true;
66}
67
68} // namespace esphome::tmp117
void mark_failed()
Mark this component as failed.
void status_clear_warning()
Definition component.h:296
bool read_byte_16(uint8_t a_register, uint16_t *data)
Definition i2c.h:281
bool write_byte_16(uint8_t a_register, uint16_t data) const
Definition i2c.cpp:101
void publish_state(float state)
Publish a new state to the front-end.
Definition sensor.cpp:65
bool write_config_(uint16_t config)
Definition tmp117.cpp:60
bool read_config_(uint16_t *config)
Definition tmp117.cpp:52
bool read_data_(int16_t *data)
Definition tmp117.cpp:44
ESPHOME_LOG_TAG(TAG, "tmp117")
uint16_t temperature
Definition sun_gtil2.cpp:12