Skip to content

Commit 4a41d38

Browse files
committed
Fix string compares and logging issues
1 parent 6e94f1b commit 4a41d38

File tree

2 files changed

+15
-14
lines changed

2 files changed

+15
-14
lines changed

components/sen5x/sen5x.cpp

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,14 @@
44
#include "esphome/core/log.h"
55
#include <cinttypes>
66

7+
#define ESP_LOG_MSG_CO2_CAL_FAIL = "Perform Forced CO₂ Calibration failed";
8+
#define ESP_LOG_MSG_ACT_SHT_HEATER_FAIL = "Activate SHT Heater failed";
9+
#define ESP_LOG_MSG_FAN_CLEAN_FAIL = "Fan Cleaning failed";
10+
711
namespace esphome {
812
namespace sen5x {
913

1014
static const char *const TAG = "sen5x";
11-
static const char *const ESP_LOG_MSG_CO2_CAL_FAIL = "Perform Forced CO₂ Calibration failed";
12-
static const char *const ESP_LOG_MSG_ACT_SHT_HEATER_FAIL = "Activate SHT Heater failed";
13-
static const char *const ESP_LOG_MSG_FAN_CLEAN_FAIL = "Fan Cleaning failed";
1415

1516
static const uint16_t SEN5X_CMD_READ_MEASUREMENT = 0x03C4;
1617
static const uint16_t SEN60_CMD_READ_MEASUREMENT = 0xEC05;
@@ -79,21 +80,21 @@ static const char *model_to_str(Sen5xType model) {
7980
}
8081
}
8182
static const Sen5xType str_to_model(const char *product_name) {
82-
if (product_name == "SEN50") {
83+
if (strcmp(product_name, "SEN50") == 0) {
8384
return SEN50;
84-
} else if (product_name == "SEN54") {
85+
} else if (strcmp(product_name, "SEN54") == 0) {
8586
return SEN54;
86-
} else if (product_name == "SEN55") {
87+
} else if (strcmp(product_name, "SEN55") == 0) {
8788
return SEN55;
88-
} else if (product_name == "SEN60") {
89+
} else if (strcmp(product_name, "SEN60") == 0) {
8990
return SEN60;
90-
} else if (product_name == "SEN63C") {
91+
} else if (strcmp(product_name, "SEN63C") == 0) {
9192
return SEN63C;
92-
} else if (product_name == "SEN65") {
93+
} else if (strcmp(product_name, "SEN65") == 0) {
9394
return SEN65;
94-
} else if (product_name == "SEN66") {
95+
} else if (strcmp(product_name, "SEN66") == 0) {
9596
return SEN66;
96-
} else if (product_name == "SEN68") {
97+
} else if (strcmp(product_name, "SEN68") == 0) {
9798
return SEN68;
9899
} else {
99100
return UNKNOWN_MODEL;
@@ -688,7 +689,7 @@ void SEN5XComponent::update() {
688689
if (this->model_.value() == SEN66) {
689690
measurement = measurements[8];
690691
}
691-
ESP_LOGVV(TAG, "co2 = 0x%.4x", co2);
692+
ESP_LOGVV(TAG, "co2 = 0x%.4x", measurement);
692693
float co2 = measurement == UINT16_MAX ? NAN : measurement / 1.0f;
693694
if (this->co2_sensor_ != nullptr) {
694695
this->co2_sensor_->publish_state(co2);
@@ -979,4 +980,4 @@ bool SEN5XComponent::perform_forced_co2_calibration(uint16_t co2) {
979980
}
980981
}
981982
} // namespace sen5x
982-
} // namespace esphome
983+
} // namespace esphome

components/sen5x/sen5x.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,4 +159,4 @@ class SEN5XComponent : public PollingComponent, public sensirion_common::Sensiri
159159
};
160160

161161
} // namespace sen5x
162-
} // namespace esphome
162+
} // namespace esphome

0 commit comments

Comments
 (0)