9 namespace honeywell_hih_i2c {
11 static const char *
const TAG =
"honeywell_hih.i2c";
13 static const uint8_t REQUEST_CMD[1] = {0x00};
14 static const uint16_t MAX_COUNT = 0x3FFE;
16 void HoneywellHIComponent::read_sensor_data_() {
20 ESP_LOGE(TAG,
"Communication with Honeywell HIH failed!");
25 const uint16_t raw_humidity = (
static_cast<uint16_t
>(data[0] & 0x3F) << 8) | data[1];
26 float humidity = (
static_cast<float>(raw_humidity) / MAX_COUNT) * 100;
28 const uint16_t raw_temperature = (
static_cast<uint16_t
>(data[2]) << 6) | (data[3] >> 2);
29 float temperature = (
static_cast<float>(raw_temperature) / MAX_COUNT) * 165 - 40;
31 ESP_LOGD(TAG,
"Got temperature=%.2f°C humidity=%.2f%%", temperature, humidity);
38 void HoneywellHIComponent::start_measurement_() {
40 ESP_LOGE(TAG,
"Communication with Honeywell HIH failed!");
48 bool HoneywellHIComponent::is_measurement_ready_() {
52 ESP_LOGE(TAG,
"Communication with Honeywell HIH failed!");
58 return ((data[0] & 0xC0) == 0x00);
61 void HoneywellHIComponent::measurement_timeout_() {
62 ESP_LOGE(TAG,
"Honeywell HIH Timeout!");
68 ESP_LOGV(TAG,
"Update Honeywell HIH Sensor");
70 this->start_measurement_();
72 this->
set_timeout(
"meas_timeout", 100, [
this] { this->measurement_timeout_(); });
79 this->read_sensor_data_();
84 ESP_LOGD(TAG,
"Honeywell HIH:");
87 ESP_LOGE(TAG,
"Communication with Honeywell HIH failed!");
91 LOG_UPDATE_INTERVAL(
this);
const float DATA
For components that import data from directly connected sensors like DHT.
float get_setup_priority() const override
bool cancel_timeout(const std::string &name)
Cancel a timeout function.
void dump_config() override
ErrorCode read(uint8_t *data, size_t len)
reads an array of bytes from the device using an I2CBus
void set_timeout(const std::string &name, uint32_t timeout, std::function< void()> &&f)
Set a timeout function with a unique name.
ErrorCode write(const uint8_t *data, size_t len, bool stop=true)
writes an array of bytes to a device using an I2CBus
No error found during execution of method.
void publish_state(float state)
Publish a new state to the front-end.
bool measurement_running_
sensor::Sensor * temperature_sensor_
virtual void mark_failed()
Mark this component as failed.
Implementation of SPI Controller mode.
sensor::Sensor * humidity_sensor_