From 666267fd83b2976c0bce0b8041770ab9cc0604bf Mon Sep 17 00:00:00 2001 From: Peter Zich Date: Thu, 21 Nov 2024 14:35:36 -0800 Subject: [PATCH] Fix braceless else statements --- esphome/components/climate_ir/climate_ir.cpp | 3 +- esphome/components/coolix/coolix.cpp | 3 +- .../dfrobot_sen0395/dfrobot_sen0395.cpp | 3 +- esphome/components/dht/dht.cpp | 3 +- esphome/components/display/display.cpp | 3 +- esphome/components/display/rect.cpp | 3 +- .../esp32_improv/esp32_improv_component.cpp | 2 +- esphome/components/gcja5/gcja5.cpp | 3 +- esphome/components/haier/haier_base.cpp | 3 +- esphome/components/haier/hon_climate.cpp | 3 +- esphome/components/heatpumpir/heatpumpir.cpp | 3 +- .../microphone/i2s_audio_microphone.cpp | 12 ++++---- .../micronova/switch/micronova_switch.cpp | 6 ++-- esphome/components/toshiba/toshiba.cpp | 3 +- esphome/components/tuya/light/tuya_light.cpp | 6 ++-- esphome/components/yashima/yashima.cpp | 3 +- esphome/core/helpers.cpp | 28 ++++++++++--------- 17 files changed, 55 insertions(+), 35 deletions(-) diff --git a/esphome/components/climate_ir/climate_ir.cpp b/esphome/components/climate_ir/climate_ir.cpp index 76adfb42bb..8175383627 100644 --- a/esphome/components/climate_ir/climate_ir.cpp +++ b/esphome/components/climate_ir/climate_ir.cpp @@ -37,8 +37,9 @@ void ClimateIR::setup() { this->publish_state(); }); this->current_temperature = this->sensor_->state; - } else + } else { this->current_temperature = NAN; + } // restore set points auto restore = this->restore_state_(); if (restore.has_value()) { diff --git a/esphome/components/coolix/coolix.cpp b/esphome/components/coolix/coolix.cpp index 22b3431c3e..5c6bfd7740 100644 --- a/esphome/components/coolix/coolix.cpp +++ b/esphome/components/coolix/coolix.cpp @@ -131,8 +131,9 @@ bool CoolixClimate::on_coolix(climate::Climate *parent, remote_base::RemoteRecei } else { parent->mode = climate::CLIMATE_MODE_FAN_ONLY; } - } else + } else { parent->mode = climate::CLIMATE_MODE_COOL; + } // Fan Speed if ((remote_state & COOLIX_FAN_AUTO) == COOLIX_FAN_AUTO || parent->mode == climate::CLIMATE_MODE_HEAT_COOL || diff --git a/esphome/components/dfrobot_sen0395/dfrobot_sen0395.cpp b/esphome/components/dfrobot_sen0395/dfrobot_sen0395.cpp index f8ef6c7138..f47025698b 100644 --- a/esphome/components/dfrobot_sen0395/dfrobot_sen0395.cpp +++ b/esphome/components/dfrobot_sen0395/dfrobot_sen0395.cpp @@ -118,8 +118,9 @@ std::unique_ptr CircularCommandQueue::dequeue() { if (front_ == rear_) { front_ = -1; rear_ = -1; - } else + } else { front_ = (front_ + 1) % COMMAND_QUEUE_SIZE; + } return dequeued_cmd; } diff --git a/esphome/components/dht/dht.cpp b/esphome/components/dht/dht.cpp index db1c851d5f..6f3f8a3937 100644 --- a/esphome/components/dht/dht.cpp +++ b/esphome/components/dht/dht.cpp @@ -156,8 +156,9 @@ bool HOT IRAM_ATTR DHT::read_sensor_(float *temperature, float *humidity, bool r if (bit == 0) { bit = 7; byte++; - } else + } else { bit--; + } } } if (!report_errors && error_code != 0) diff --git a/esphome/components/display/display.cpp b/esphome/components/display/display.cpp index 145a4f5278..0e7cba46c6 100644 --- a/esphome/components/display/display.cpp +++ b/esphome/components/display/display.cpp @@ -266,8 +266,9 @@ void Display::filled_gauge(int center_x, int center_y, int radius1, int radius2, if (dymax < float(-dxmax) * tan_a) { upd_dxmax = ceil(float(dymax) / tan_a); hline_width = -dxmax - upd_dxmax + 1; - } else + } else { hline_width = 0; + } } if (hline_width > 0) this->horizontal_line(center_x + dxmax, center_y - dymax, hline_width, color); diff --git a/esphome/components/display/rect.cpp b/esphome/components/display/rect.cpp index 34b611191f..49bb7d025f 100644 --- a/esphome/components/display/rect.cpp +++ b/esphome/components/display/rect.cpp @@ -90,8 +90,9 @@ void Rect::info(const std::string &prefix) { if (this->is_set()) { ESP_LOGI(TAG, "%s [%3d,%3d,%3d,%3d] (%3d,%3d)", prefix.c_str(), this->x, this->y, this->w, this->h, this->x2(), this->y2()); - } else + } else { ESP_LOGI(TAG, "%s ** IS NOT SET **", prefix.c_str()); + } } } // namespace display diff --git a/esphome/components/esp32_improv/esp32_improv_component.cpp b/esphome/components/esp32_improv/esp32_improv_component.cpp index d36b50feb0..c67431077c 100644 --- a/esphome/components/esp32_improv/esp32_improv_component.cpp +++ b/esphome/components/esp32_improv/esp32_improv_component.cpp @@ -112,7 +112,7 @@ void ESP32ImprovComponent::loop() { this->set_state_(improv::STATE_AUTHORIZED); } else #else - this->set_state_(improv::STATE_AUTHORIZED); + { this->set_state_(improv::STATE_AUTHORIZED); } #endif { if (!this->check_identify_()) diff --git a/esphome/components/gcja5/gcja5.cpp b/esphome/components/gcja5/gcja5.cpp index 7f980ca0ad..b1db58654b 100644 --- a/esphome/components/gcja5/gcja5.cpp +++ b/esphome/components/gcja5/gcja5.cpp @@ -97,8 +97,9 @@ void GCJA5Component::parse_data_() { if (this->rx_message_[0] != 0x02 || this->rx_message_[31] != 0x03 || !this->calculate_checksum_()) { ESP_LOGVV(TAG, "Discarding bad packet - failed checks."); return; - } else + } else { ESP_LOGVV(TAG, "Good packet found."); + } this->have_good_data_ = true; uint8_t status = this->rx_message_[29]; diff --git a/esphome/components/haier/haier_base.cpp b/esphome/components/haier/haier_base.cpp index ba80c1ca1b..f8c0a7587e 100644 --- a/esphome/components/haier/haier_base.cpp +++ b/esphome/components/haier/haier_base.cpp @@ -342,8 +342,9 @@ bool HaierClimateBase::prepare_pending_action() { this->action_request_.reset(); return false; } - } else + } else { return false; + } } ClimateTraits HaierClimateBase::traits() { return traits_; } diff --git a/esphome/components/haier/hon_climate.cpp b/esphome/components/haier/hon_climate.cpp index e7be1fa418..d4c748ff8a 100644 --- a/esphome/components/haier/hon_climate.cpp +++ b/esphome/components/haier/hon_climate.cpp @@ -701,8 +701,9 @@ void HonClimate::process_alarm_message_(const uint8_t *packet, uint8_t size, boo alarm_code++; } active_alarms_[i] = packet[2 + i]; - } else + } else { alarm_code += 8; + } } } else { float alarm_count = 0.0f; diff --git a/esphome/components/heatpumpir/heatpumpir.cpp b/esphome/components/heatpumpir/heatpumpir.cpp index 144dcc9bfa..55f0599cba 100644 --- a/esphome/components/heatpumpir/heatpumpir.cpp +++ b/esphome/components/heatpumpir/heatpumpir.cpp @@ -87,8 +87,9 @@ void HeatpumpIRClimate::setup() { this->publish_state(); }); this->current_temperature = this->sensor_->state; - } else + } else { this->current_temperature = NAN; + } } void HeatpumpIRClimate::transmit_state() { diff --git a/esphome/components/i2s_audio/microphone/i2s_audio_microphone.cpp b/esphome/components/i2s_audio/microphone/i2s_audio_microphone.cpp index 23689afb91..4dbc9dcdac 100644 --- a/esphome/components/i2s_audio/microphone/i2s_audio_microphone.cpp +++ b/esphome/components/i2s_audio/microphone/i2s_audio_microphone.cpp @@ -25,11 +25,13 @@ void I2SAudioMicrophone::setup() { } } else #endif - if (this->pdm_) { - if (this->parent_->get_port() != I2S_NUM_0) { - ESP_LOGE(TAG, "PDM only works on I2S0!"); - this->mark_failed(); - return; + { + if (this->pdm_) { + if (this->parent_->get_port() != I2S_NUM_0) { + ESP_LOGE(TAG, "PDM only works on I2S0!"); + this->mark_failed(); + return; + } } } } diff --git a/esphome/components/micronova/switch/micronova_switch.cpp b/esphome/components/micronova/switch/micronova_switch.cpp index dcc96102db..28674acd96 100644 --- a/esphome/components/micronova/switch/micronova_switch.cpp +++ b/esphome/components/micronova/switch/micronova_switch.cpp @@ -11,15 +11,17 @@ void MicroNovaSwitch::write_state(bool state) { if (this->micronova_->get_current_stove_state() == 0) { this->micronova_->write_address(this->memory_location_, this->memory_address_, this->memory_data_on_); this->publish_state(true); - } else + } else { ESP_LOGW(TAG, "Unable to turn stove on, invalid state: %d", micronova_->get_current_stove_state()); + } } else { // don't send power-off when status is Off or Final cleaning if (this->micronova_->get_current_stove_state() != 0 && micronova_->get_current_stove_state() != 6) { this->micronova_->write_address(this->memory_location_, this->memory_address_, this->memory_data_off_); this->publish_state(false); - } else + } else { ESP_LOGW(TAG, "Unable to turn stove off, invalid state: %d", micronova_->get_current_stove_state()); + } } this->micronova_->update(); break; diff --git a/esphome/components/toshiba/toshiba.cpp b/esphome/components/toshiba/toshiba.cpp index 33d36d6a69..ff4241a81f 100644 --- a/esphome/components/toshiba/toshiba.cpp +++ b/esphome/components/toshiba/toshiba.cpp @@ -106,8 +106,9 @@ void ToshibaClimate::setup() { this->publish_state(); }); this->current_temperature = this->sensor_->state; - } else + } else { this->current_temperature = NAN; + } // restore set points auto restore = this->restore_state_(); if (restore.has_value()) { diff --git a/esphome/components/tuya/light/tuya_light.cpp b/esphome/components/tuya/light/tuya_light.cpp index 66931767b2..815a089d9f 100644 --- a/esphome/components/tuya/light/tuya_light.cpp +++ b/esphome/components/tuya/light/tuya_light.cpp @@ -120,8 +120,9 @@ light::LightTraits TuyaLight::get_traits() { traits.set_supported_color_modes( {light::ColorMode::RGB_COLOR_TEMPERATURE, light::ColorMode::COLOR_TEMPERATURE}); } - } else + } else { traits.set_supported_color_modes({light::ColorMode::COLOR_TEMPERATURE}); + } traits.set_min_mireds(this->cold_white_temperature_); traits.set_max_mireds(this->warm_white_temperature_); } else if (this->color_id_.has_value()) { @@ -131,8 +132,9 @@ light::LightTraits TuyaLight::get_traits() { } else { traits.set_supported_color_modes({light::ColorMode::RGB_WHITE}); } - } else + } else { traits.set_supported_color_modes({light::ColorMode::RGB}); + } } else if (this->dimmer_id_.has_value()) { traits.set_supported_color_modes({light::ColorMode::BRIGHTNESS}); } else { diff --git a/esphome/components/yashima/yashima.cpp b/esphome/components/yashima/yashima.cpp index 493c689b42..a3cf53ff66 100644 --- a/esphome/components/yashima/yashima.cpp +++ b/esphome/components/yashima/yashima.cpp @@ -104,8 +104,9 @@ void YashimaClimate::setup() { this->publish_state(); }); this->current_temperature = this->sensor_->state; - } else + } else { this->current_temperature = NAN; + } // restore set points auto restore = this->restore_state_(); if (restore.has_value()) { diff --git a/esphome/core/helpers.cpp b/esphome/core/helpers.cpp index dae60a4e1d..a1447c43be 100644 --- a/esphome/core/helpers.cpp +++ b/esphome/core/helpers.cpp @@ -126,19 +126,21 @@ uint16_t crc16(const uint8_t *data, uint16_t len, uint16_t crc, uint16_t reverse } } else #endif - if (reverse_poly == 0xa001) { - while (len--) { - uint8_t combo = crc ^ (uint8_t) *data++; - crc = (crc >> 8) ^ CRC16_A001_LE_LUT_L[combo & 0x0F] ^ CRC16_A001_LE_LUT_H[combo >> 4]; - } - } else { - while (len--) { - crc ^= *data++; - for (uint8_t i = 0; i < 8; i++) { - if (crc & 0x0001) { - crc = (crc >> 1) ^ reverse_poly; - } else { - crc >>= 1; + { + if (reverse_poly == 0xa001) { + while (len--) { + uint8_t combo = crc ^ (uint8_t) *data++; + crc = (crc >> 8) ^ CRC16_A001_LE_LUT_L[combo & 0x0F] ^ CRC16_A001_LE_LUT_H[combo >> 4]; + } + } else { + while (len--) { + crc ^= *data++; + for (uint8_t i = 0; i < 8; i++) { + if (crc & 0x0001) { + crc = (crc >> 1) ^ reverse_poly; + } else { + crc >>= 1; + } } } }