Skip to content

Commit e36d922

Browse files
authored
Merge pull request #2 from mikelawrence/dev
Configuration variable optimization and fix
2 parents b76b0ed + 2da726d commit e36d922

File tree

3 files changed

+14
-13
lines changed

3 files changed

+14
-13
lines changed

components/sen5x/automation.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
namespace esphome {
88
namespace sen5x {
99

10-
1110
template<typename... Ts> class SetAmbientPressurehPa : public Action<Ts...>, public Parented<SEN5XComponent> {
1211
public:
1312
void play(Ts... x) override {
@@ -20,7 +19,8 @@ template<typename... Ts> class SetAmbientPressurehPa : public Action<Ts...>, pub
2019
TEMPLATABLE_VALUE(uint16_t, value)
2120
};
2221

23-
template<typename... Ts> class PerformForcedCo2CalibrationAction : public Action<Ts...>, public Parented<SEN5XComponent> {
22+
template<typename... Ts>
23+
class PerformForcedCo2CalibrationAction : public Action<Ts...>, public Parented<SEN5XComponent> {
2424
public:
2525
void play(Ts... x) override {
2626
if (this->value_.has_value()) {
@@ -53,4 +53,4 @@ template<typename... Ts> class ActivateHeaterAction : public Action<Ts...> {
5353
};
5454

5555
} // namespace sen5x
56-
} // namespace esphome
56+
} // namespace esphome

components/sen5x/sen5x.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -332,8 +332,8 @@ void SEN5XComponent::internal_setup_(uint8_t state) {
332332
this->mark_failed();
333333
return;
334334
}
335-
if (!this->write_command(SEN6X_CMD_CO2_SENSOR_AUTO_SELF_CAL, this->co2_auto_calibrate_.value() ? 0x01 : 0x00)) {
336-
ESP_LOGE(TAG, "Failed to set CO₂ Sensor Automatic Self Calibration");
335+
if (!this->write_command(SEN6X_CMD_SENSOR_ALTITUDE, this->co2_altitude_compensation_.value())) {
336+
ESP_LOGE(TAG, "Failed to set CO₂ Sensor Altitude Compensation");
337337
this->error_code_ = COMMUNICATION_FAILED;
338338
this->mark_failed();
339339
return;
@@ -477,7 +477,7 @@ void SEN5XComponent::dump_config() {
477477
LOG_SENSOR(" ", "NOx", this->nox_sensor_);
478478
LOG_SENSOR(" ", "CO₂", this->co2_sensor_);
479479
if (this->co2_sensor_ != nullptr) {
480-
ESP_LOGCONFIG(TAG, " Automatic self calibration: %s", co2_auto_calibrate_ ? "On" : "Off");
480+
ESP_LOGCONFIG(TAG, " Automatic self calibration: %s", this->co2_auto_calibrate_.value() ? "On" : "Off");
481481
if (this->co2_ambient_pressure_source_ != nullptr) {
482482
ESP_LOGCONFIG(TAG, " Dynamic ambient pressure compensation using sensor '%s'",
483483
this->co2_ambient_pressure_source_->get_name().c_str());

components/sen5x/sensor.py

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,12 @@
44
from esphome.components import i2c, sensirion_common, sensor
55
import esphome.config_validation as cv
66
from esphome.const import (
7+
# CONF_ALTITUDE_COMPENSATION,
8+
CONF_AMBIENT_PRESSURE_COMPENSATION,
9+
CONF_AMBIENT_PRESSURE_COMPENSATION_SOURCE,
10+
CONF_AUTOMATIC_SELF_CALIBRATION,
711
CONF_CO2,
12+
CONF_GAIN_FACTOR,
813
CONF_HUMIDITY,
914
CONF_ID,
1015
CONF_MODEL,
@@ -50,13 +55,9 @@
5055

5156

5257
CONF_ACCELERATION_MODE = "acceleration_mode"
53-
CONF_ALTITUDE_COMPENSATION = "altitude_compensation"
54-
CONF_AMBIENT_PRESSURE_COMPENSATION = "ambient_pressure_compensation"
55-
CONF_AMBIENT_PRESSURE_COMPENSATION_SOURCE = "ambient_pressure_compensation_source"
5658
CONF_ALGORITHM_TUNING = "algorithm_tuning"
59+
CONF_ALTITUDE_COMPENSATION = "altitude_compensation"
5760
CONF_AUTO_CLEANING_INTERVAL = "auto_cleaning_interval"
58-
CONF_AUTO_SELF_CALIBRATION = "auto_self_calibration"
59-
CONF_GAIN_FACTOR = "gain_factor"
6061
CONF_GATING_MAX_DURATION_MINUTES = "gating_max_duration_minutes"
6162
CONF_HCHO = "hcho"
6263
CONF_INDEX_OFFSET = "index_offset"
@@ -118,7 +119,7 @@
118119

119120
CO2_SENSOR = cv.Schema(
120121
{
121-
cv.Optional(CONF_AUTO_SELF_CALIBRATION, default=True): cv.boolean,
122+
cv.Optional(CONF_AUTOMATIC_SELF_CALIBRATION, default=True): cv.boolean,
122123
cv.Optional(CONF_ALTITUDE_COMPENSATION, default="0m"): cv.All(
123124
cv.float_with_unit("altitude", "(m|m a.s.l.|MAMSL|MASL)"),
124125
cv.int_range(min=0, max=0xFFFF, max_included=False),
@@ -247,7 +248,7 @@ def float_previously_pct(value):
247248
}
248249

249250
CO2_SETTING_MAP = {
250-
CONF_AUTO_SELF_CALIBRATION: "set_co2_auto_calibrate",
251+
CONF_AUTOMATIC_SELF_CALIBRATION: "set_co2_auto_calibrate",
251252
CONF_ALTITUDE_COMPENSATION: "set_co2_altitude_compensation",
252253
CONF_AMBIENT_PRESSURE_COMPENSATION: "set_co2_ambient_pressure_compensation",
253254
}

0 commit comments

Comments
 (0)