mirror of
https://github.com/esphome/esphome.git
synced 2024-11-10 01:07:45 +01:00
Force heater off on setup (#5161)
Co-authored-by: Jesse Hills <3060199+jesserockz@users.noreply.github.com>
This commit is contained in:
parent
bf5352b44e
commit
b8fa737bc9
3 changed files with 12 additions and 1 deletions
|
@ -12,6 +12,8 @@ from esphome.const import (
|
|||
UNIT_PERCENT,
|
||||
)
|
||||
|
||||
CONF_HEATER_ENABLED = "heater_enabled"
|
||||
|
||||
DEPENDENCIES = ["i2c"]
|
||||
AUTO_LOAD = ["sensirion_common"]
|
||||
|
||||
|
@ -36,7 +38,8 @@ CONFIG_SCHEMA = (
|
|||
device_class=DEVICE_CLASS_HUMIDITY,
|
||||
state_class=STATE_CLASS_MEASUREMENT,
|
||||
),
|
||||
}
|
||||
cv.Optional(CONF_HEATER_ENABLED, default=True): cv.boolean,
|
||||
},
|
||||
)
|
||||
.extend(cv.polling_component_schema("60s"))
|
||||
.extend(i2c.i2c_device_schema(0x44))
|
||||
|
@ -48,6 +51,8 @@ async def to_code(config):
|
|||
await cg.register_component(var, config)
|
||||
await i2c.register_i2c_device(var, config)
|
||||
|
||||
cg.add(var.set_heater_enabled(config[CONF_HEATER_ENABLED]))
|
||||
|
||||
if CONF_TEMPERATURE in config:
|
||||
sens = await sensor.new_sensor(config[CONF_TEMPERATURE])
|
||||
cg.add(var.set_temperature_sensor(sens))
|
||||
|
|
|
@ -22,6 +22,10 @@ void SHT3XDComponent::setup() {
|
|||
this->mark_failed();
|
||||
return;
|
||||
}
|
||||
if (!this->write_command(heater_enabled_ ? SHT3XD_COMMAND_HEATER_ENABLE : SHT3XD_COMMAND_HEATER_DISABLE)) {
|
||||
this->mark_failed();
|
||||
return;
|
||||
}
|
||||
uint32_t serial_number = (uint32_t(raw_serial_number[0]) << 16) | uint32_t(raw_serial_number[1]);
|
||||
ESP_LOGV(TAG, " Serial Number: 0x%08X", serial_number);
|
||||
}
|
||||
|
|
|
@ -17,10 +17,12 @@ class SHT3XDComponent : public PollingComponent, public sensirion_common::Sensir
|
|||
void dump_config() override;
|
||||
float get_setup_priority() const override;
|
||||
void update() override;
|
||||
void set_heater_enabled(bool heater_enabled) { heater_enabled_ = heater_enabled; }
|
||||
|
||||
protected:
|
||||
sensor::Sensor *temperature_sensor_{nullptr};
|
||||
sensor::Sensor *humidity_sensor_{nullptr};
|
||||
bool heater_enabled_{true};
|
||||
};
|
||||
|
||||
} // namespace sht3xd
|
||||
|
|
Loading…
Reference in a new issue