[iaqcore][scd30][sen21231][beken_spi_led_strip] Fix uninitialized variables and missing error checks (#14568)

Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
Jonathan Swoboda
2026-03-06 16:03:53 -05:00
committed by GitHub
parent 587bf68091
commit 5777908da7
4 changed files with 14 additions and 7 deletions
@@ -78,7 +78,7 @@ static void spi_set_clock(uint32_t max_hz) {
int source_clk = 0;
int spi_clk = 0;
int div = 0;
uint32_t param;
uint32_t param = PWD_SPI_CLK_BIT;
if (max_hz > 4333000) {
if (max_hz > 30000000) {
spi_clk = 30000000;
+6 -4
View File
@@ -10,11 +10,13 @@ static const char *const TAG = "iaqcore";
enum IAQCoreErrorCode : uint8_t { ERROR_OK = 0, ERROR_RUNIN = 0x10, ERROR_BUSY = 0x01, ERROR_ERROR = 0x80 };
static constexpr size_t SENSOR_DATA_LENGTH = 9;
struct SensorData {
uint16_t co2;
IAQCoreErrorCode status;
int32_t resistance;
uint16_t co2;
uint16_t tvoc;
IAQCoreErrorCode status;
SensorData(const uint8_t *buffer) {
this->co2 = encode_uint16(buffer[0], buffer[1]);
@@ -33,9 +35,9 @@ void IAQCore::setup() {
}
void IAQCore::update() {
uint8_t buffer[sizeof(SensorData)];
uint8_t buffer[SENSOR_DATA_LENGTH];
if (this->read_register(0xB5, buffer, sizeof(buffer)) != i2c::ERROR_OK) {
if (this->read_register(0xB5, buffer, SENSOR_DATA_LENGTH) != i2c::ERROR_OK) {
ESP_LOGD(TAG, "Read failed");
this->status_set_warning();
this->publish_nans_();
+1 -1
View File
@@ -222,7 +222,7 @@ bool SCD30Component::force_recalibration_with_reference(uint16_t co2_reference)
}
uint16_t SCD30Component::get_forced_calibration_reference() {
uint16_t forced_calibration_reference;
uint16_t forced_calibration_reference = 0;
// Get current CO2 calibration
if (!this->get_register(SCD30_CMD_FORCED_CALIBRATION, forced_calibration_reference)) {
ESP_LOGE(TAG, "Unable to read forced calibration reference.");
+6 -1
View File
@@ -20,7 +20,12 @@ void Sen21231Sensor::dump_config() {
void Sen21231Sensor::read_data_() {
person_sensor_results_t results;
this->read_bytes(PERSON_SENSOR_I2C_ADDRESS, (uint8_t *) &results, sizeof(results));
if (!this->read_bytes(PERSON_SENSOR_I2C_ADDRESS, (uint8_t *) &results, sizeof(results))) {
ESP_LOGW(TAG, "Failed to read data from SEN21231");
this->status_set_warning();
return;
}
this->status_clear_warning();
ESP_LOGD(TAG, "SEN21231: %d faces detected", results.num_faces);
this->publish_state(results.num_faces);
if (results.num_faces == 1) {