Compare commits

...
Author SHA1 Message Date
J. Nick Koston 3c378581bc [hdc1080] Declare child sensors with SUB_SENSOR 2026-10-28 08:59:53 -10:00
3 changed files with 11 additions and 15 deletions

No files matched your search

+6 -6
View File
@@ -25,8 +25,8 @@ void HDC1080Component::dump_config() {
ESP_LOGCONFIG(TAG, "HDC1080:");
LOG_I2C_DEVICE(this);
LOG_UPDATE_INTERVAL(this);
LOG_SENSOR(" ", "Temperature", this->temperature_);
LOG_SENSOR(" ", "Humidity", this->humidity_);
LOG_SENSOR(" ", "Temperature", this->temperature_sensor_);
LOG_SENSOR(" ", "Humidity", this->humidity_sensor_);
}
void HDC1080Component::update() {
@@ -47,10 +47,10 @@ void HDC1080Component::update() {
return;
}
if (this->temperature_ != nullptr) {
if (this->temperature_sensor_ != nullptr) {
raw_temperature = i2c::i2ctohs(raw_temperature);
float temperature = raw_temperature * 0.0025177f - 40.0f; // raw * 2^-16 * 165 - 40
this->temperature_->publish_state(temperature);
this->temperature_sensor_->publish_state(temperature);
}
if (this->write(&HDC1080_CMD_HUMIDITY, 1) != i2c::ERROR_OK) {
@@ -65,10 +65,10 @@ void HDC1080Component::update() {
return;
}
if (this->humidity_ != nullptr) {
if (this->humidity_sensor_ != nullptr) {
raw_humidity = i2c::i2ctohs(raw_humidity);
float humidity = raw_humidity * 0.001525879f; // raw * 2^-16 * 100
this->humidity_->publish_state(humidity);
this->humidity_sensor_->publish_state(humidity);
}
});
});
+3 -7
View File
@@ -7,17 +7,13 @@
namespace esphome::hdc1080 {
class HDC1080Component final : public PollingComponent, public i2c::I2CDevice {
public:
void set_temperature(sensor::Sensor *temperature) { temperature_ = temperature; }
void set_humidity(sensor::Sensor *humidity) { humidity_ = humidity; }
SUB_SENSOR(temperature)
SUB_SENSOR(humidity)
public:
void setup() override;
void dump_config() override;
void update() override;
protected:
sensor::Sensor *temperature_{nullptr};
sensor::Sensor *humidity_{nullptr};
};
} // namespace esphome::hdc1080
+2 -2
View File
@@ -46,5 +46,5 @@ async def to_code(config: ConfigType) -> None:
var = await i2c.new_i2c_component(config)
sensors = sensor.sub_sensors(config)
await sensors(CONF_TEMPERATURE, var.set_temperature)
await sensors(CONF_HUMIDITY, var.set_humidity)
await sensors(CONF_TEMPERATURE, var.set_temperature_sensor)
await sensors(CONF_HUMIDITY, var.set_humidity_sensor)