[shtcx] Code clean-up (#15261)

This commit is contained in:
Keith Burzinski
2026-03-30 13:15:27 -05:00
committed by GitHub
parent ddb188e8f0
commit 45e6d49d36
2 changed files with 16 additions and 18 deletions
+7 -11
View File
@@ -2,16 +2,15 @@
#include "esphome/core/log.h"
#include "esphome/core/hal.h"
namespace esphome {
namespace shtcx {
namespace esphome::shtcx {
static const char *const TAG = "shtcx";
static const uint16_t SHTCX_COMMAND_SLEEP = 0xB098;
static const uint16_t SHTCX_COMMAND_WAKEUP = 0x3517;
static const uint16_t SHTCX_COMMAND_READ_ID_REGISTER = 0xEFC8;
static const uint16_t SHTCX_COMMAND_SOFT_RESET = 0x805D;
static const uint16_t SHTCX_COMMAND_POLLING_H = 0x7866;
static constexpr uint16_t SHTCX_COMMAND_SLEEP = 0xB098;
static constexpr uint16_t SHTCX_COMMAND_WAKEUP = 0x3517;
static constexpr uint16_t SHTCX_COMMAND_READ_ID_REGISTER = 0xEFC8;
static constexpr uint16_t SHTCX_COMMAND_SOFT_RESET = 0x805D;
static constexpr uint16_t SHTCX_COMMAND_POLLING_H = 0x7866;
static const LogString *shtcx_type_to_string(SHTCXType type) {
switch (type) {
@@ -91,8 +90,6 @@ void SHTCXComponent::update() {
} else {
temperature = 175.0f * float(raw_data[0]) / 65536.0f - 45.0f;
humidity = 100.0f * float(raw_data[1]) / 65536.0f;
ESP_LOGD(TAG, "Temperature=%.2f°C Humidity=%.2f%%", temperature, humidity);
}
if (this->temperature_sensor_ != nullptr)
this->temperature_sensor_->publish_state(temperature);
@@ -117,5 +114,4 @@ void SHTCXComponent::wake_up() {
delayMicroseconds(200);
}
} // namespace shtcx
} // namespace esphome
} // namespace esphome::shtcx
+9 -7
View File
@@ -4,10 +4,13 @@
#include "esphome/components/sensor/sensor.h"
#include "esphome/components/sensirion_common/i2c_sensirion.h"
namespace esphome {
namespace shtcx {
namespace esphome::shtcx {
enum SHTCXType { SHTCX_TYPE_SHTC3 = 0, SHTCX_TYPE_SHTC1, SHTCX_TYPE_UNKNOWN };
enum SHTCXType : uint8_t {
SHTCX_TYPE_SHTC3 = 0,
SHTCX_TYPE_SHTC1,
SHTCX_TYPE_UNKNOWN,
};
/// This class implements support for the SHT3x-DIS family of temperature+humidity i2c sensors.
class SHTCXComponent : public PollingComponent, public sensirion_common::SensirionI2CDevice {
@@ -23,11 +26,10 @@ class SHTCXComponent : public PollingComponent, public sensirion_common::Sensiri
void wake_up();
protected:
SHTCXType type_;
uint16_t sensor_id_;
sensor::Sensor *temperature_sensor_{nullptr};
sensor::Sensor *humidity_sensor_{nullptr};
uint16_t sensor_id_;
SHTCXType type_;
};
} // namespace shtcx
} // namespace esphome
} // namespace esphome::shtcx