11static constexpr uint32_t HEATER_OFF_TIMEOUT_ID = 0;
14static const uint8_t HDC302X_CMD_SOFT_RESET[2] = {0x30, 0xa2};
15static const uint8_t HDC302X_CMD_CLEAR_STATUS_REGISTER[2] = {0x30, 0x41};
17static const uint8_t HDC302X_CMD_TRIGGER_MSB = 0x24;
19static const uint8_t HDC302X_CMD_HEATER_ENABLE[2] = {0x30, 0x6d};
20static const uint8_t HDC302X_CMD_HEATER_DISABLE[2] = {0x30, 0x66};
21static const uint8_t HDC302X_CMD_HEATER_CONFIGURE[2] = {0x30, 0x6e};
43 this->
heater_active_ ? LOG_STR_LITERAL(
"active") : LOG_STR_LITERAL(
"inactive"));
45 LOG_UPDATE_INTERVAL(
this);
52 HDC302X_CMD_TRIGGER_MSB,
66 ESP_LOGD(TAG,
"Heater disable before start failed");
69 ESP_LOGW(TAG,
"Heater start failed");
74 if (duration_ms > 0) {
82 ESP_LOGW(TAG,
"Heater stop failed");
89 ESP_LOGE(TAG,
"Enable heater failed");
96 if (power_level > 0x3fff) {
97 ESP_LOGW(TAG,
"Heater power 0x%04x exceeds max 0x3fff", power_level);
103 static_cast<uint8_t
>((power_level >> 8) & 0xff),
104 static_cast<uint8_t
>(power_level & 0xff)
109 HDC302X_CMD_HEATER_CONFIGURE[0], HDC302X_CMD_HEATER_CONFIGURE[1], config[0], config[1],
110 crc8(config, 2, 0xff, 0x31,
true),
113 ESP_LOGE(TAG,
"Configure heater failed");
122 ESP_LOGE(TAG,
"Disable heater failed");
136 const bool crc_ok =
crc8(buf, 2, 0xff, 0x31,
true) == buf[2] &&
crc8(buf + 3, 2, 0xff, 0x31,
true) == buf[5];
143 float temp = -45 + 175 * (float(raw_t) / 65535.0f);
150 float humidity = 100 * (float(raw_rh) / 65535.0f);
void mark_failed()
Mark this component as failed.
void status_set_warning()
bool status_comm_result(bool ok)
Clears the warning when ok, else sets it with message (default "Communication failed"); returns ok.
bool cancel_timeout(const char *name)
Cancel a timeout function.
void set_timeout(const char *name, uint32_t timeout, std::function< void()> &&f)
Set a timeout function with a const char* name.
sensor::Sensor * humidity_sensor_
void start_heater(uint16_t power, uint32_t duration_ms)
sensor::Sensor * temp_sensor_
void dump_config() override
HDC302XPowerMode power_mode_
uint32_t conversion_delay_ms_()
bool configure_heater_(uint16_t power_level)
ErrorCode write(const uint8_t *data, size_t len) const
writes an array of bytes to a device using an I2CBus
ErrorCode read(uint8_t *data, size_t len) const
reads an array of bytes from the device using an I2CBus
void publish_state(float state)
Publish a new state to the front-end.
ESPHOME_LOG_TAG(TAG, "hdc302x.sensor")
@ ERROR_OK
No error found during execution of method.
uint8_t crc8(const uint8_t *data, uint8_t len, uint8_t crc, uint8_t poly, bool msb_first)
Calculate a CRC-8 checksum of data with size len.
constexpr uint16_t encode_uint16(uint8_t msb, uint8_t lsb)
Encode a 16-bit value given the most and least significant byte.
void HOT delay(uint32_t ms)