diff --git a/.clang-tidy b/.clang-tidy index f784cd65ec..c9b77b5720 100644 --- a/.clang-tidy +++ b/.clang-tidy @@ -68,7 +68,6 @@ Checks: >- -modernize-use-nodiscard, -mpi-*, -objc-*, - -readability-braces-around-statements, -readability-convert-member-functions-to-static, -readability-else-after-return, -readability-function-cognitive-complexity, @@ -109,6 +108,8 @@ CheckOptions: value: 'make_unique' - key: modernize-make-unique.MakeSmartPtrFunctionHeader value: 'esphome/core/helpers.h' + - key: readability-braces-around-statements.ShortStatementLines + value: 2 - key: readability-identifier-naming.LocalVariableCase value: 'lower_case' - key: readability-identifier-naming.ClassCase diff --git a/esphome/components/ac_dimmer/ac_dimmer.cpp b/esphome/components/ac_dimmer/ac_dimmer.cpp index a7f1e6f3a9..e9af828a9d 100644 --- a/esphome/components/ac_dimmer/ac_dimmer.cpp +++ b/esphome/components/ac_dimmer/ac_dimmer.cpp @@ -52,10 +52,10 @@ uint32_t IRAM_ATTR HOT AcDimmerDataStore::timer_intr(uint32_t now) { this->gate_pin.digital_write(false); } - if (time_since_zc < this->enable_time_us) + if (time_since_zc < this->enable_time_us) { // Next event is enable, return time until that event return this->enable_time_us - time_since_zc; - else if (time_since_zc < disable_time_us) { + } else if (time_since_zc < disable_time_us) { // Next event is disable, return time until that event return this->disable_time_us - time_since_zc; } @@ -74,9 +74,10 @@ uint32_t IRAM_ATTR HOT timer_interrupt() { uint32_t min_dt_us = 1000; uint32_t now = micros(); for (auto *dimmer : all_dimmers) { - if (dimmer == nullptr) + if (dimmer == nullptr) { // no more dimmers break; + } uint32_t res = dimmer->timer_intr(now); if (res != 0 && res < min_dt_us) min_dt_us = res; @@ -212,12 +213,13 @@ void AcDimmer::dump_config() { LOG_PIN(" Zero-Cross Pin: ", this->zero_cross_pin_); ESP_LOGCONFIG(TAG, " Min Power: %.1f%%", this->store_.min_power / 10.0f); ESP_LOGCONFIG(TAG, " Init with half cycle: %s", YESNO(this->init_with_half_cycle_)); - if (method_ == DIM_METHOD_LEADING_PULSE) + if (method_ == DIM_METHOD_LEADING_PULSE) { ESP_LOGCONFIG(TAG, " Method: leading pulse"); - else if (method_ == DIM_METHOD_LEADING) + } else if (method_ == DIM_METHOD_LEADING) { ESP_LOGCONFIG(TAG, " Method: leading"); - else + } else { ESP_LOGCONFIG(TAG, " Method: trailing"); + } LOG_FLOAT_OUTPUT(this); ESP_LOGV(TAG, " Estimated Frequency: %.3fHz", 1e6f / this->store_.cycle_time_us / 2); diff --git a/esphome/components/adc/adc_sensor.cpp b/esphome/components/adc/adc_sensor.cpp index 0a439f8b8d..c3e5221bf7 100644 --- a/esphome/components/adc/adc_sensor.cpp +++ b/esphome/components/adc/adc_sensor.cpp @@ -65,9 +65,9 @@ void ADCSensor::dump_config() { #ifdef USE_ESP32 LOG_PIN(" Pin: ", pin_); - if (autorange_) + if (autorange_) { ESP_LOGCONFIG(TAG, " Attenuation: auto"); - else + } else { switch (this->attenuation_) { case ADC_ATTEN_DB_0: ESP_LOGCONFIG(TAG, " Attenuation: 0db (max 1.1V)"); @@ -84,6 +84,7 @@ void ADCSensor::dump_config() { default: // This is to satisfy the unused ADC_ATTEN_MAX break; } + } #endif // USE_ESP32 LOG_UPDATE_INTERVAL(this); } diff --git a/esphome/components/am2320/am2320.cpp b/esphome/components/am2320/am2320.cpp index c06a2a34d7..8ab48a348e 100644 --- a/esphome/components/am2320/am2320.cpp +++ b/esphome/components/am2320/am2320.cpp @@ -19,12 +19,14 @@ uint16_t crc_16(uint8_t *ptr, uint8_t length) { //------------------------------ while (length--) { crc ^= *ptr++; - for (i = 0; i < 8; i++) + for (i = 0; i < 8; i++) { if ((crc & 0x01) != 0) { crc >>= 1; crc ^= 0xA001; - } else + } else { crc >>= 1; + } + } } return crc; } diff --git a/esphome/components/am43/am43.cpp b/esphome/components/am43/am43.cpp index ced2ff8196..1c4bad64c3 100644 --- a/esphome/components/am43/am43.cpp +++ b/esphome/components/am43/am43.cpp @@ -79,9 +79,10 @@ void Am43::gattc_event_handler(esp_gattc_cb_event_t event, esp_gatt_if_t gattc_i auto status = esp_ble_gattc_write_char(this->parent_->gattc_if, this->parent_->conn_id, this->char_handle_, packet->length, packet->data, ESP_GATT_WRITE_TYPE_NO_RSP, ESP_GATT_AUTH_REQ_NONE); - if (status) + if (status) { ESP_LOGW(TAG, "[%s] esp_ble_gattc_write_char failed, status=%d", this->parent_->address_str().c_str(), status); + } } this->current_sensor_ = 0; } diff --git a/esphome/components/am43/cover/am43_cover.cpp b/esphome/components/am43/cover/am43_cover.cpp index afdbe65630..39089e73c0 100644 --- a/esphome/components/am43/cover/am43_cover.cpp +++ b/esphome/components/am43/cover/am43_cover.cpp @@ -30,10 +30,11 @@ void Am43Component::loop() { esp_ble_gattc_write_char(this->parent_->gattc_if, this->parent_->conn_id, this->char_handle_, packet->length, packet->data, ESP_GATT_WRITE_TYPE_NO_RSP, ESP_GATT_AUTH_REQ_NONE); ESP_LOGI(TAG, "[%s] Logging into AM43", this->get_name().c_str()); - if (status) + if (status) { ESP_LOGW(TAG, "[%s] Error writing set_pin to device, error = %d", this->get_name().c_str(), status); - else + } else { this->logged_in_ = true; + } } } diff --git a/esphome/components/anova/anova.cpp b/esphome/components/anova/anova.cpp index 5dfafbd2c9..39b1187caf 100644 --- a/esphome/components/anova/anova.cpp +++ b/esphome/components/anova/anova.cpp @@ -114,9 +114,10 @@ void Anova::gattc_event_handler(esp_gattc_cb_event_t event, esp_gatt_if_t gattc_ auto status = esp_ble_gattc_write_char(this->parent_->gattc_if, this->parent_->conn_id, this->char_handle_, pkt->length, pkt->data, ESP_GATT_WRITE_TYPE_NO_RSP, ESP_GATT_AUTH_REQ_NONE); - if (status) + if (status) { ESP_LOGW(TAG, "[%s] esp_ble_gattc_write_char failed, status=%d", this->parent_->address_str().c_str(), status); + } } } break; diff --git a/esphome/components/apds9960/apds9960.cpp b/esphome/components/apds9960/apds9960.cpp index 9ee873ac64..5ba3afbacc 100644 --- a/esphome/components/apds9960/apds9960.cpp +++ b/esphome/components/apds9960/apds9960.cpp @@ -225,9 +225,10 @@ void APDS9960::read_gesture_data_() { uint8_t fifo_level; APDS9960_WARNING_CHECK(this->read_byte(0xAE, &fifo_level), "Reading FIFO level failed."); - if (fifo_level == 0) + if (fifo_level == 0) { // no data to process return; + } APDS9960_WARNING_CHECK(fifo_level <= 32, "FIFO level has invalid value.") diff --git a/esphome/components/api/api_connection.cpp b/esphome/components/api/api_connection.cpp index fc10fb103b..8a106dc39c 100644 --- a/esphome/components/api/api_connection.cpp +++ b/esphome/components/api/api_connection.cpp @@ -469,10 +469,11 @@ void APIConnection::switch_command(const SwitchCommandRequest &msg) { if (a_switch == nullptr) return; - if (msg.state) + if (msg.state) { a_switch->turn_on(); - else + } else { a_switch->turn_off(); + } } #endif @@ -810,10 +811,11 @@ DeviceInfoResponse APIConnection::device_info(const DeviceInfoRequest &msg) { return resp; } void APIConnection::on_home_assistant_state_response(const HomeAssistantStateResponse &msg) { - for (auto &it : this->parent_->get_state_subs()) + for (auto &it : this->parent_->get_state_subs()) { if (it.entity_id == msg.entity_id && it.attribute.value() == msg.attribute) { it.callback(msg.state); } + } } void APIConnection::execute_service(const ExecuteServiceRequest &msg) { bool found = false; diff --git a/esphome/components/api/api_server.cpp b/esphome/components/api/api_server.cpp index c857763f95..3614c7d593 100644 --- a/esphome/components/api/api_server.cpp +++ b/esphome/components/api/api_server.cpp @@ -80,9 +80,10 @@ void APIServer::setup() { if (esp32_camera::global_esp32_camera != nullptr && !esp32_camera::global_esp32_camera->is_internal()) { esp32_camera::global_esp32_camera->add_image_callback( [this](const std::shared_ptr &image) { - for (auto &c : this->clients_) + for (auto &c : this->clients_) { if (!c->remove_) c->send_camera_state(image); + } }); } #endif diff --git a/esphome/components/api/proto.h b/esphome/components/api/proto.h index edbc916b01..38fd98b489 100644 --- a/esphome/components/api/proto.h +++ b/esphome/components/api/proto.h @@ -55,17 +55,19 @@ class ProtoVarInt { } int32_t as_sint32() const { // with ZigZag encoding - if (this->value_ & 1) + if (this->value_ & 1) { return static_cast(~(this->value_ >> 1)); - else + } else { return static_cast(this->value_ >> 1); + } } int64_t as_sint64() const { // with ZigZag encoding - if (this->value_ & 1) + if (this->value_ & 1) { return static_cast(~(this->value_ >> 1)); - else + } else { return static_cast(this->value_ >> 1); + } } void encode(std::vector &out) { uint32_t val = this->value_; @@ -220,10 +222,11 @@ class ProtoWriteBuffer { } void encode_sint32(uint32_t field_id, int32_t value, bool force = false) { uint32_t uvalue; - if (value < 0) + if (value < 0) { uvalue = ~(value << 1); - else + } else { uvalue = value << 1; + } this->encode_uint32(field_id, uvalue, force); } template void encode_message(uint32_t field_id, const C &value, bool force = false) { diff --git a/esphome/components/as3935/as3935.cpp b/esphome/components/as3935/as3935.cpp index 1cc400bb7b..b36856218a 100644 --- a/esphome/components/as3935/as3935.cpp +++ b/esphome/components/as3935/as3935.cpp @@ -58,10 +58,11 @@ void AS3935Component::loop() { void AS3935Component::write_indoor(bool indoor) { ESP_LOGV(TAG, "Setting indoor to %d", indoor); - if (indoor) + if (indoor) { this->write_register(AFE_GAIN, GAIN_MASK, INDOOR, 1); - else + } else { this->write_register(AFE_GAIN, GAIN_MASK, OUTDOOR, 1); + } } // REG0x01, bits[3:0], manufacturer default: 0010 (2). // This setting determines the threshold for events that trigger the diff --git a/esphome/components/ballu/ballu.cpp b/esphome/components/ballu/ballu.cpp index 96eefca5fb..b33ad11c1f 100644 --- a/esphome/components/ballu/ballu.cpp +++ b/esphome/components/ballu/ballu.cpp @@ -130,10 +130,10 @@ bool BalluClimate::on_receive(remote_base::RemoteReceiveData data) { for (int i = 0; i < BALLU_STATE_LENGTH; i++) { // Read bit for (int j = 0; j < 8; j++) { - if (data.expect_item(BALLU_BIT_MARK, BALLU_ONE_SPACE)) + if (data.expect_item(BALLU_BIT_MARK, BALLU_ONE_SPACE)) { remote_state[i] |= 1 << j; - else if (!data.expect_item(BALLU_BIT_MARK, BALLU_ZERO_SPACE)) { + } else if (!data.expect_item(BALLU_BIT_MARK, BALLU_ZERO_SPACE)) { ESP_LOGV(TAG, "Byte %d bit %d fail", i, j); return false; } diff --git a/esphome/components/bang_bang/bang_bang_climate.cpp b/esphome/components/bang_bang/bang_bang_climate.cpp index 4a95f8c339..20cb87025a 100644 --- a/esphome/components/bang_bang/bang_bang_climate.cpp +++ b/esphome/components/bang_bang/bang_bang_climate.cpp @@ -21,12 +21,13 @@ void BangBangClimate::setup() { restore->to_call(this).perform(); } else { // restore from defaults, change_away handles those for us - if (supports_cool_ && supports_heat_) + if (supports_cool_ && supports_heat_) { this->mode = climate::CLIMATE_MODE_HEAT_COOL; - else if (supports_cool_) + } else if (supports_cool_) { this->mode = climate::CLIMATE_MODE_COOL; - else if (supports_heat_) + } else if (supports_heat_) { this->mode = climate::CLIMATE_MODE_HEAT; + } this->change_away_(false); } } @@ -56,11 +57,12 @@ climate::ClimateTraits BangBangClimate::traits() { if (supports_cool_ && supports_heat_) traits.add_supported_mode(climate::CLIMATE_MODE_HEAT_COOL); traits.set_supports_two_point_target_temperature(true); - if (supports_away_) + if (supports_away_) { traits.set_supported_presets({ climate::CLIMATE_PRESET_HOME, climate::CLIMATE_PRESET_AWAY, }); + } traits.set_supports_action(true); return traits; } @@ -82,17 +84,19 @@ void BangBangClimate::compute_state_() { if (too_cold) { // too cold -> enable heating if possible and enabled, else idle if (this->supports_heat_ && - (this->mode == climate::CLIMATE_MODE_HEAT_COOL || this->mode == climate::CLIMATE_MODE_HEAT)) + (this->mode == climate::CLIMATE_MODE_HEAT_COOL || this->mode == climate::CLIMATE_MODE_HEAT)) { target_action = climate::CLIMATE_ACTION_HEATING; - else + } else { target_action = climate::CLIMATE_ACTION_IDLE; + } } else if (too_hot) { // too hot -> enable cooling if possible and enabled, else idle if (this->supports_cool_ && - (this->mode == climate::CLIMATE_MODE_HEAT_COOL || this->mode == climate::CLIMATE_MODE_COOL)) + (this->mode == climate::CLIMATE_MODE_HEAT_COOL || this->mode == climate::CLIMATE_MODE_COOL)) { target_action = climate::CLIMATE_ACTION_COOLING; - else + } else { target_action = climate::CLIMATE_ACTION_IDLE; + } } else { // neither too hot nor too cold -> in range if (this->supports_cool_ && this->supports_heat_ && this->mode == climate::CLIMATE_MODE_HEAT_COOL) { @@ -107,9 +111,10 @@ void BangBangClimate::compute_state_() { this->switch_to_action_(target_action); } void BangBangClimate::switch_to_action_(climate::ClimateAction action) { - if (action == this->action) + if (action == this->action) { // already in target mode return; + } if ((action == climate::CLIMATE_ACTION_OFF && this->action == climate::CLIMATE_ACTION_IDLE) || (action == climate::CLIMATE_ACTION_IDLE && this->action == climate::CLIMATE_ACTION_OFF)) { diff --git a/esphome/components/ble_client/ble_client.cpp b/esphome/components/ble_client/ble_client.cpp index d17292b88f..89981e8174 100644 --- a/esphome/components/ble_client/ble_client.cpp +++ b/esphome/components/ble_client/ble_client.cpp @@ -252,9 +252,10 @@ float BLEClient::parse_char_value(uint8_t *value, uint16_t length) { } BLEService *BLEClient::get_service(espbt::ESPBTUUID uuid) { - for (auto *svc : this->services_) + for (auto *svc : this->services_) { if (svc->uuid == uuid) return svc; + } return nullptr; } @@ -272,19 +273,24 @@ BLECharacteristic *BLEClient::get_characteristic(uint16_t service, uint16_t chr) } BLEDescriptor *BLEClient::get_config_descriptor(uint16_t handle) { - for (auto &svc : this->services_) - for (auto &chr : svc->characteristics) - if (chr->handle == handle) - for (auto &desc : chr->descriptors) + for (auto &svc : this->services_) { + for (auto &chr : svc->characteristics) { + if (chr->handle == handle) { + for (auto &desc : chr->descriptors) { if (desc->uuid == espbt::ESPBTUUID::from_uint16(0x2902)) return desc; + } + } + } + } return nullptr; } BLECharacteristic *BLEService::get_characteristic(espbt::ESPBTUUID uuid) { - for (auto &chr : this->characteristics) + for (auto &chr : this->characteristics) { if (chr->uuid == uuid) return chr; + } return nullptr; } @@ -379,9 +385,10 @@ void BLECharacteristic::parse_descriptors() { } BLEDescriptor *BLECharacteristic::get_descriptor(espbt::ESPBTUUID uuid) { - for (auto &desc : this->descriptors) + for (auto &desc : this->descriptors) { if (desc->uuid == uuid) return desc; + } return nullptr; } BLEDescriptor *BLECharacteristic::get_descriptor(uint16_t uuid) { diff --git a/esphome/components/ble_client/ble_client.h b/esphome/components/ble_client/ble_client.h index 5680b69f72..c173f7a995 100644 --- a/esphome/components/ble_client/ble_client.h +++ b/esphome/components/ble_client/ble_client.h @@ -126,9 +126,10 @@ class BLEClient : public espbt::ESPBTClient, public Component { bool all_nodes_established_() { if (this->state() != espbt::ClientState::ESTABLISHED) return false; - for (auto &node : nodes_) + for (auto &node : nodes_) { if (node->node_state != espbt::ClientState::ESTABLISHED) return false; + } return true; } diff --git a/esphome/components/bme280/bme280.cpp b/esphome/components/bme280/bme280.cpp index d3a228328b..fcb293afa0 100644 --- a/esphome/components/bme280/bme280.cpp +++ b/esphome/components/bme280/bme280.cpp @@ -214,9 +214,10 @@ void BME280Component::update() { float BME280Component::read_temperature_(const uint8_t *data, int32_t *t_fine) { int32_t adc = ((data[3] & 0xFF) << 16) | ((data[4] & 0xFF) << 8) | (data[5] & 0xFF); adc >>= 4; - if (adc == 0x80000) + if (adc == 0x80000) { // temperature was disabled return NAN; + } const int32_t t1 = this->calibration_.t1; const int32_t t2 = this->calibration_.t2; @@ -233,9 +234,10 @@ float BME280Component::read_temperature_(const uint8_t *data, int32_t *t_fine) { float BME280Component::read_pressure_(const uint8_t *data, int32_t t_fine) { int32_t adc = ((data[0] & 0xFF) << 16) | ((data[1] & 0xFF) << 8) | (data[2] & 0xFF); adc >>= 4; - if (adc == 0x80000) + if (adc == 0x80000) { // pressure was disabled return NAN; + } const int64_t p1 = this->calibration_.p1; const int64_t p2 = this->calibration_.p2; const int64_t p3 = this->calibration_.p3; diff --git a/esphome/components/bme680/bme680.cpp b/esphome/components/bme680/bme680.cpp index 9856304c81..64770ac0d5 100644 --- a/esphome/components/bme680/bme680.cpp +++ b/esphome/components/bme680/bme680.cpp @@ -420,10 +420,11 @@ float BME680Component::calc_humidity_(uint16_t raw_humidity) { calc_hum = var2 + (var3 + var4 * temp_comp) * var2 * var2; - if (calc_hum > 100.0f) + if (calc_hum > 100.0f) { calc_hum = 100.0f; - else if (calc_hum < 0.0f) + } else if (calc_hum < 0.0f) { calc_hum = 0.0f; + } return calc_hum; } diff --git a/esphome/components/bmp280/bmp280.cpp b/esphome/components/bmp280/bmp280.cpp index b4348e8a74..bda34e6c2b 100644 --- a/esphome/components/bmp280/bmp280.cpp +++ b/esphome/components/bmp280/bmp280.cpp @@ -161,9 +161,10 @@ float BMP280Component::read_temperature_(int32_t *t_fine) { return NAN; int32_t adc = ((data[0] & 0xFF) << 16) | ((data[1] & 0xFF) << 8) | (data[2] & 0xFF); adc >>= 4; - if (adc == 0x80000) + if (adc == 0x80000) { // temperature was disabled return NAN; + } const int32_t t1 = this->calibration_.t1; const int32_t t2 = this->calibration_.t2; @@ -183,9 +184,10 @@ float BMP280Component::read_pressure_(int32_t t_fine) { return NAN; int32_t adc = ((data[0] & 0xFF) << 16) | ((data[1] & 0xFF) << 8) | (data[2] & 0xFF); adc >>= 4; - if (adc == 0x80000) + if (adc == 0x80000) { // pressure was disabled return NAN; + } const int64_t p1 = this->calibration_.p1; const int64_t p2 = this->calibration_.p2; const int64_t p3 = this->calibration_.p3; diff --git a/esphome/components/ccs811/ccs811.cpp b/esphome/components/ccs811/ccs811.cpp index f8cee79c55..5c60989afa 100644 --- a/esphome/components/ccs811/ccs811.cpp +++ b/esphome/components/ccs811/ccs811.cpp @@ -39,14 +39,15 @@ void CCS811Component::setup() { // set MEAS_MODE (page 5) uint8_t meas_mode = 0; uint32_t interval = this->get_update_interval(); - if (interval >= 60 * 1000) + if (interval >= 60 * 1000) { meas_mode = 3 << 4; // sensor takes a reading every 60 seconds - else if (interval >= 10 * 1000) + } else if (interval >= 10 * 1000) { meas_mode = 2 << 4; // sensor takes a reading every 10 seconds - else if (interval >= 1 * 1000) + } else if (interval >= 1 * 1000) { meas_mode = 1 << 4; // sensor takes a reading every second - else + } else { meas_mode = 4 << 4; // sensor takes a reading every 250ms + } CHECKED_IO(this->write_byte(0x01, meas_mode)) diff --git a/esphome/components/climate_ir_lg/climate_ir_lg.cpp b/esphome/components/climate_ir_lg/climate_ir_lg.cpp index 31c7f22be5..a41aad1bd0 100644 --- a/esphome/components/climate_ir_lg/climate_ir_lg.cpp +++ b/esphome/components/climate_ir_lg/climate_ir_lg.cpp @@ -137,11 +137,11 @@ bool LgIrClimate::on_receive(remote_base::RemoteReceiveData data) { this->swing_mode = this->swing_mode == climate::CLIMATE_SWING_OFF ? climate::CLIMATE_SWING_VERTICAL : climate::CLIMATE_SWING_OFF; } else { - if ((remote_state & COMMAND_MASK) == COMMAND_AUTO) + if ((remote_state & COMMAND_MASK) == COMMAND_AUTO) { this->mode = climate::CLIMATE_MODE_HEAT_COOL; - else if ((remote_state & COMMAND_MASK) == COMMAND_DRY_FAN) + } else if ((remote_state & COMMAND_MASK) == COMMAND_DRY_FAN) { this->mode = climate::CLIMATE_MODE_DRY; - else if ((remote_state & COMMAND_MASK) == COMMAND_HEAT) { + } else if ((remote_state & COMMAND_MASK) == COMMAND_HEAT) { this->mode = climate::CLIMATE_MODE_HEAT; } else { this->mode = climate::CLIMATE_MODE_COOL; @@ -156,14 +156,15 @@ bool LgIrClimate::on_receive(remote_base::RemoteReceiveData data) { this->fan_mode = climate::CLIMATE_FAN_AUTO; } else if (this->mode == climate::CLIMATE_MODE_COOL || this->mode == climate::CLIMATE_MODE_HEAT || this->mode == climate::CLIMATE_MODE_DRY) { - if ((remote_state & FAN_MASK) == FAN_AUTO) + if ((remote_state & FAN_MASK) == FAN_AUTO) { this->fan_mode = climate::CLIMATE_FAN_AUTO; - else if ((remote_state & FAN_MASK) == FAN_MIN) + } else if ((remote_state & FAN_MASK) == FAN_MIN) { this->fan_mode = climate::CLIMATE_FAN_LOW; - else if ((remote_state & FAN_MASK) == FAN_MED) + } else if ((remote_state & FAN_MASK) == FAN_MED) { this->fan_mode = climate::CLIMATE_FAN_MEDIUM; - else if ((remote_state & FAN_MASK) == FAN_MAX) + } else if ((remote_state & FAN_MASK) == FAN_MAX) { this->fan_mode = climate::CLIMATE_FAN_HIGH; + } } } this->publish_state(); diff --git a/esphome/components/coolix/coolix.cpp b/esphome/components/coolix/coolix.cpp index c5d8cb07e9..738fd8d00d 100644 --- a/esphome/components/coolix/coolix.cpp +++ b/esphome/components/coolix/coolix.cpp @@ -125,34 +125,37 @@ bool CoolixClimate::on_coolix(climate::Climate *parent, remote_base::RemoteRecei parent->swing_mode = parent->swing_mode == climate::CLIMATE_SWING_OFF ? climate::CLIMATE_SWING_VERTICAL : climate::CLIMATE_SWING_OFF; } else { - if ((remote_state & COOLIX_MODE_MASK) == COOLIX_HEAT) + if ((remote_state & COOLIX_MODE_MASK) == COOLIX_HEAT) { parent->mode = climate::CLIMATE_MODE_HEAT; - else if ((remote_state & COOLIX_MODE_MASK) == COOLIX_AUTO) + } else if ((remote_state & COOLIX_MODE_MASK) == COOLIX_AUTO) { parent->mode = climate::CLIMATE_MODE_HEAT_COOL; - else if ((remote_state & COOLIX_MODE_MASK) == COOLIX_DRY_FAN) { - if ((remote_state & COOLIX_FAN_MASK) == COOLIX_FAN_MODE_AUTO_DRY) + } else if ((remote_state & COOLIX_MODE_MASK) == COOLIX_DRY_FAN) { + if ((remote_state & COOLIX_FAN_MASK) == COOLIX_FAN_MODE_AUTO_DRY) { parent->mode = climate::CLIMATE_MODE_DRY; - else + } else { parent->mode = climate::CLIMATE_MODE_FAN_ONLY; + } } 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 || - parent->mode == climate::CLIMATE_MODE_DRY) + parent->mode == climate::CLIMATE_MODE_DRY) { parent->fan_mode = climate::CLIMATE_FAN_AUTO; - else if ((remote_state & COOLIX_FAN_MIN) == COOLIX_FAN_MIN) + } else if ((remote_state & COOLIX_FAN_MIN) == COOLIX_FAN_MIN) { parent->fan_mode = climate::CLIMATE_FAN_LOW; - else if ((remote_state & COOLIX_FAN_MED) == COOLIX_FAN_MED) + } else if ((remote_state & COOLIX_FAN_MED) == COOLIX_FAN_MED) { parent->fan_mode = climate::CLIMATE_FAN_MEDIUM; - else if ((remote_state & COOLIX_FAN_MAX) == COOLIX_FAN_MAX) + } else if ((remote_state & COOLIX_FAN_MAX) == COOLIX_FAN_MAX) { parent->fan_mode = climate::CLIMATE_FAN_HIGH; + } // Temperature uint8_t temperature_code = remote_state & COOLIX_TEMP_MASK; - for (uint8_t i = 0; i < COOLIX_TEMP_RANGE; i++) + for (uint8_t i = 0; i < COOLIX_TEMP_RANGE; i++) { if (COOLIX_TEMP_MAP[i] == temperature_code) parent->target_temperature = i + COOLIX_TEMP_MIN; + } } parent->publish_state(); diff --git a/esphome/components/daikin/daikin.cpp b/esphome/components/daikin/daikin.cpp index 820cf78b3f..bb8587fbeb 100644 --- a/esphome/components/daikin/daikin.cpp +++ b/esphome/components/daikin/daikin.cpp @@ -175,14 +175,15 @@ bool DaikinClimate::parse_state_frame_(const uint8_t frame[]) { } uint8_t fan_mode = frame[8]; uint8_t swing_mode = frame[9]; - if (fan_mode & 0xF && swing_mode & 0xF) + if (fan_mode & 0xF && swing_mode & 0xF) { this->swing_mode = climate::CLIMATE_SWING_BOTH; - else if (fan_mode & 0xF) + } else if (fan_mode & 0xF) { this->swing_mode = climate::CLIMATE_SWING_VERTICAL; - else if (swing_mode & 0xF) + } else if (swing_mode & 0xF) { this->swing_mode = climate::CLIMATE_SWING_HORIZONTAL; - else + } else { this->swing_mode = climate::CLIMATE_SWING_OFF; + } switch (fan_mode & 0xF0) { case DAIKIN_FAN_1: case DAIKIN_FAN_2: @@ -212,9 +213,9 @@ bool DaikinClimate::on_receive(remote_base::RemoteReceiveData data) { for (uint8_t pos = 0; pos < DAIKIN_STATE_FRAME_SIZE; pos++) { uint8_t byte = 0; for (int8_t bit = 0; bit < 8; bit++) { - if (data.expect_item(DAIKIN_BIT_MARK, DAIKIN_ONE_SPACE)) + if (data.expect_item(DAIKIN_BIT_MARK, DAIKIN_ONE_SPACE)) { byte |= 1 << bit; - else if (!data.expect_item(DAIKIN_BIT_MARK, DAIKIN_ZERO_SPACE)) { + } else if (!data.expect_item(DAIKIN_BIT_MARK, DAIKIN_ZERO_SPACE)) { return false; } } diff --git a/esphome/components/dallas/esp_one_wire.cpp b/esphome/components/dallas/esp_one_wire.cpp index a0ab10f8a4..6dc085a0bf 100644 --- a/esphome/components/dallas/esp_one_wire.cpp +++ b/esphome/components/dallas/esp_one_wire.cpp @@ -145,9 +145,10 @@ uint64_t ESPOneWire::search() { // read its complement bool cmp_id_bit = this->read_bit(); - if (id_bit && cmp_id_bit) + if (id_bit && cmp_id_bit) { // No devices participating in search break; + } bool branch; @@ -170,12 +171,13 @@ uint64_t ESPOneWire::search() { } } - if (branch) + if (branch) { // set bit this->rom_number8_()[rom_byte_number] |= rom_byte_mask; - else + } else { // clear bit this->rom_number8_()[rom_byte_number] &= ~rom_byte_mask; + } // choose/announce branch this->write_bit(branch); @@ -190,9 +192,10 @@ uint64_t ESPOneWire::search() { if (id_bit_number >= 65) { this->last_discrepancy_ = last_zero; - if (this->last_discrepancy_ == 0) + if (this->last_discrepancy_ == 0) { // we're at root and have no choices left, so this was the last one. this->last_device_flag_ = true; + } search_result = true; } diff --git a/esphome/components/dht/dht.cpp b/esphome/components/dht/dht.cpp index 2a4ccf1529..c70b227330 100644 --- a/esphome/components/dht/dht.cpp +++ b/esphome/components/dht/dht.cpp @@ -114,10 +114,11 @@ bool HOT IRAM_ATTR DHT::read_sensor_(float *temperature, float *humidity, bool r // Wait for rising edge while (!this->pin_->digital_read()) { if (micros() - start_time > 90) { - if (i < 0) + if (i < 0) { error_code = 1; - else + } else { error_code = 2; + } break; } } @@ -130,10 +131,11 @@ bool HOT IRAM_ATTR DHT::read_sensor_(float *temperature, float *humidity, bool r // Wait for falling edge while (this->pin_->digital_read()) { if ((end_time = micros()) - start_time > 90) { - if (i < 0) + if (i < 0) { error_code = 3; - else + } else { error_code = 4; + } break; } } diff --git a/esphome/components/display/display_buffer.cpp b/esphome/components/display/display_buffer.cpp index bdf299e8f1..ac878b01e1 100644 --- a/esphome/components/display/display_buffer.cpp +++ b/esphome/components/display/display_buffer.cpp @@ -176,9 +176,10 @@ void DisplayBuffer::print(int x, int y, Font *font, Color color, TextAlign align ESP_LOGW(TAG, "Encountered character without representation in font: '%c'", text[i]); if (!font->get_glyphs().empty()) { uint8_t glyph_width = font->get_glyphs()[0].glyph_data_->width; - for (int glyph_x = 0; glyph_x < glyph_width; glyph_x++) + for (int glyph_x = 0; glyph_x < glyph_width; glyph_x++) { for (int glyph_y = 0; glyph_y < height; glyph_y++) this->draw_pixel_at(glyph_x + x_at, glyph_y + y_start, color); + } x_at += glyph_width; } @@ -425,10 +426,11 @@ int Font::match_next_glyph(const char *str, int *match_length) { int hi = this->glyphs_.size() - 1; while (lo != hi) { int mid = (lo + hi + 1) / 2; - if (this->glyphs_[mid].compare_to(str)) + if (this->glyphs_[mid].compare_to(str)) { lo = mid; - else + } else { hi = mid - 1; + } } *match_length = this->glyphs_[lo].match_length(str); if (*match_length <= 0) @@ -454,10 +456,11 @@ void Font::measure(const char *str, int *width, int *x_offset, int *baseline, in } const Glyph &glyph = this->glyphs_[glyph_n]; - if (!has_char) + if (!has_char) { min_x = glyph.glyph_data_->offset_x; - else + } else { min_x = std::min(min_x, x + glyph.glyph_data_->offset_x); + } x += glyph.glyph_data_->width + glyph.glyph_data_->offset_x; i += match_length; diff --git a/esphome/components/ektf2232/ektf2232.cpp b/esphome/components/ektf2232/ektf2232.cpp index da16dc3cfe..f96928a8de 100644 --- a/esphome/components/ektf2232/ektf2232.cpp +++ b/esphome/components/ektf2232/ektf2232.cpp @@ -68,9 +68,10 @@ void EKTF2232Touchscreen::loop() { uint8_t raw[8]; this->read(raw, 8); - for (int i = 0; i < 8; i++) + for (int i = 0; i < 8; i++) { if (raw[7] & (1 << i)) touch_count++; + } if (touch_count == 0) { for (auto *listener : this->touch_listeners_) diff --git a/esphome/components/esp32_ble_server/ble_characteristic.cpp b/esphome/components/esp32_ble_server/ble_characteristic.cpp index fae8c13934..df822ac0b9 100644 --- a/esphome/components/esp32_ble_server/ble_characteristic.cpp +++ b/esphome/components/esp32_ble_server/ble_characteristic.cpp @@ -147,40 +147,46 @@ bool BLECharacteristic::is_failed() { } void BLECharacteristic::set_broadcast_property(bool value) { - if (value) + if (value) { this->properties_ = (esp_gatt_char_prop_t)(this->properties_ | ESP_GATT_CHAR_PROP_BIT_BROADCAST); - else + } else { this->properties_ = (esp_gatt_char_prop_t)(this->properties_ & ~ESP_GATT_CHAR_PROP_BIT_BROADCAST); + } } void BLECharacteristic::set_indicate_property(bool value) { - if (value) + if (value) { this->properties_ = (esp_gatt_char_prop_t)(this->properties_ | ESP_GATT_CHAR_PROP_BIT_INDICATE); - else + } else { this->properties_ = (esp_gatt_char_prop_t)(this->properties_ & ~ESP_GATT_CHAR_PROP_BIT_INDICATE); + } } void BLECharacteristic::set_notify_property(bool value) { - if (value) + if (value) { this->properties_ = (esp_gatt_char_prop_t)(this->properties_ | ESP_GATT_CHAR_PROP_BIT_NOTIFY); - else + } else { this->properties_ = (esp_gatt_char_prop_t)(this->properties_ & ~ESP_GATT_CHAR_PROP_BIT_NOTIFY); + } } void BLECharacteristic::set_read_property(bool value) { - if (value) + if (value) { this->properties_ = (esp_gatt_char_prop_t)(this->properties_ | ESP_GATT_CHAR_PROP_BIT_READ); - else + } else { this->properties_ = (esp_gatt_char_prop_t)(this->properties_ & ~ESP_GATT_CHAR_PROP_BIT_READ); + } } void BLECharacteristic::set_write_property(bool value) { - if (value) + if (value) { this->properties_ = (esp_gatt_char_prop_t)(this->properties_ | ESP_GATT_CHAR_PROP_BIT_WRITE); - else + } else { this->properties_ = (esp_gatt_char_prop_t)(this->properties_ & ~ESP_GATT_CHAR_PROP_BIT_WRITE); + } } void BLECharacteristic::set_write_no_response_property(bool value) { - if (value) + if (value) { this->properties_ = (esp_gatt_char_prop_t)(this->properties_ | ESP_GATT_CHAR_PROP_BIT_WRITE_NR); - else + } else { this->properties_ = (esp_gatt_char_prop_t)(this->properties_ & ~ESP_GATT_CHAR_PROP_BIT_WRITE_NR); + } } void BLECharacteristic::gatts_event_handler(esp_gatts_cb_event_t event, esp_gatt_if_t gatts_if, diff --git a/esphome/components/esp32_ble_server/ble_service.cpp b/esphome/components/esp32_ble_server/ble_service.cpp index 281164f0f5..4fcd2e3e79 100644 --- a/esphome/components/esp32_ble_server/ble_service.cpp +++ b/esphome/components/esp32_ble_server/ble_service.cpp @@ -18,9 +18,10 @@ BLEService::~BLEService() { } BLECharacteristic *BLEService::get_characteristic(ESPBTUUID uuid) { - for (auto *chr : this->characteristics_) + for (auto *chr : this->characteristics_) { if (chr->get_uuid() == uuid) return chr; + } return nullptr; } diff --git a/esphome/components/esp32_ble_tracker/esp32_ble_tracker.cpp b/esphome/components/esp32_ble_tracker/esp32_ble_tracker.cpp index 084dab4c84..7614e33979 100644 --- a/esphome/components/esp32_ble_tracker/esp32_ble_tracker.cpp +++ b/esphome/components/esp32_ble_tracker/esp32_ble_tracker.cpp @@ -58,11 +58,12 @@ void ESP32BLETracker::setup() { void ESP32BLETracker::loop() { BLEEvent *ble_event = this->ble_events_.pop(); while (ble_event != nullptr) { - if (ble_event->type_) + if (ble_event->type_) { this->real_gattc_event_handler_(ble_event->event_.gattc.gattc_event, ble_event->event_.gattc.gattc_if, &ble_event->event_.gattc.gattc_param); - else + } else { this->real_gap_event_handler_(ble_event->event_.gap.gap_event, &ble_event->event_.gap.gap_param); + } delete ble_event; // NOLINT(cppcoreguidelines-owning-memory) ble_event = this->ble_events_.pop(); } @@ -89,11 +90,12 @@ void ESP32BLETracker::loop() { device.parse_scan_rst(this->scan_result_buffer_[i]); bool found = false; - for (auto *listener : this->listeners_) + for (auto *listener : this->listeners_) { if (listener->parse_device(device)) found = true; + } - for (auto *client : this->clients_) + for (auto *client : this->clients_) { if (client->parse_device(device)) { found = true; if (client->state() == ClientState::DISCOVERED) { @@ -103,6 +105,7 @@ void ESP32BLETracker::loop() { } } } + } if (!found) { this->print_bt_device_info(device); diff --git a/esphome/components/esp32_camera_web_server/camera_web_server.cpp b/esphome/components/esp32_camera_web_server/camera_web_server.cpp index 39b110bc85..3210989ff5 100644 --- a/esphome/components/esp32_camera_web_server/camera_web_server.cpp +++ b/esphome/components/esp32_camera_web_server/camera_web_server.cpp @@ -87,10 +87,11 @@ void CameraWebServer::on_shutdown() { void CameraWebServer::dump_config() { ESP_LOGCONFIG(TAG, "ESP32 Camera Web Server:"); ESP_LOGCONFIG(TAG, " Port: %d", this->port_); - if (this->mode_ == STREAM) + if (this->mode_ == STREAM) { ESP_LOGCONFIG(TAG, " Mode: stream"); - else + } else { ESP_LOGCONFIG(TAG, " Mode: snapshot"); + } if (this->is_failed()) { ESP_LOGE(TAG, " Setup Failed"); diff --git a/esphome/components/esp8266/preferences.cpp b/esphome/components/esp8266/preferences.cpp index a8f8bd0d41..0e42cea576 100644 --- a/esphome/components/esp8266/preferences.cpp +++ b/esphome/components/esp8266/preferences.cpp @@ -98,16 +98,18 @@ static bool load_from_flash(size_t offset, uint32_t *data, size_t len) { } static bool save_to_rtc(size_t offset, const uint32_t *data, size_t len) { - for (uint32_t i = 0; i < len; i++) + for (uint32_t i = 0; i < len; i++) { if (!esp_rtc_user_mem_write(offset + i, data[i])) return false; + } return true; } static bool load_from_rtc(size_t offset, uint32_t *data, size_t len) { - for (uint32_t i = 0; i < len; i++) + for (uint32_t i = 0; i < len; i++) { if (!esp_rtc_user_mem_read(offset + i, &data[i])) return false; + } return true; } diff --git a/esphome/components/ezo/ezo.cpp b/esphome/components/ezo/ezo.cpp index 2ee5782ff6..12f88a0f66 100644 --- a/esphome/components/ezo/ezo.cpp +++ b/esphome/components/ezo/ezo.cpp @@ -75,9 +75,10 @@ void EZOSensor::loop() { return; // some sensors return multiple comma-separated values, terminate string after first one - for (size_t i = 1; i < sizeof(buf) - 1; i++) + for (size_t i = 1; i < sizeof(buf) - 1; i++) { if (buf[i] == ',') buf[i] = '\0'; + } float val = parse_number((char *) &buf[1]).value_or(0); this->publish_state(val); diff --git a/esphome/components/fingerprint_grow/fingerprint_grow.cpp b/esphome/components/fingerprint_grow/fingerprint_grow.cpp index be17e29de3..3b8c52fea2 100644 --- a/esphome/components/fingerprint_grow/fingerprint_grow.cpp +++ b/esphome/components/fingerprint_grow/fingerprint_grow.cpp @@ -278,10 +278,11 @@ void FingerprintGrowComponent::delete_all_fingerprints() { void FingerprintGrowComponent::led_control(bool state) { ESP_LOGD(TAG, "Setting LED"); - if (state) + if (state) { this->data_ = {LED_ON}; - else + } else { this->data_ = {LED_OFF}; + } switch (this->send_command_()) { case OK: ESP_LOGD(TAG, "LED set"); diff --git a/esphome/components/gpio/switch/gpio_switch.cpp b/esphome/components/gpio/switch/gpio_switch.cpp index 56e0087eae..714f2ea6d8 100644 --- a/esphome/components/gpio/switch/gpio_switch.cpp +++ b/esphome/components/gpio/switch/gpio_switch.cpp @@ -33,16 +33,18 @@ void GPIOSwitch::setup() { } // write state before setup - if (initial_state) + if (initial_state) { this->turn_on(); - else + } else { this->turn_off(); + } this->pin_->setup(); // write after setup again for other IOs - if (initial_state) + if (initial_state) { this->turn_on(); - else + } else { this->turn_off(); + } } void GPIOSwitch::dump_config() { LOG_SWITCH("", "GPIO Switch", this); diff --git a/esphome/components/hitachi_ac344/hitachi_ac344.cpp b/esphome/components/hitachi_ac344/hitachi_ac344.cpp index f8c3f1722d..7b93b00503 100644 --- a/esphome/components/hitachi_ac344/hitachi_ac344.cpp +++ b/esphome/components/hitachi_ac344/hitachi_ac344.cpp @@ -19,10 +19,11 @@ void set_bits(uint8_t *const dst, const uint8_t offset, const uint8_t nbits, con void set_bit(uint8_t *const data, const uint8_t position, const bool on) { uint8_t mask = 1 << position; - if (on) + if (on) { *data |= mask; - else + } else { *data &= ~mask; + } } uint8_t *invert_byte_pairs(uint8_t *ptr, const uint16_t length) { @@ -69,10 +70,11 @@ void HitachiClimate::set_temp_(uint8_t celsius, bool set_previous) { temp = std::min(celsius, HITACHI_AC344_TEMP_MAX); temp = std::max(temp, HITACHI_AC344_TEMP_MIN); set_bits(&remote_state_[HITACHI_AC344_TEMP_BYTE], HITACHI_AC344_TEMP_OFFSET, HITACHI_AC344_TEMP_SIZE, temp); - if (previous_temp_ > temp) + if (previous_temp_ > temp) { set_button_(HITACHI_AC344_BUTTON_TEMP_DOWN); - else if (previous_temp_ < temp) + } else if (previous_temp_ < temp) { set_button_(HITACHI_AC344_BUTTON_TEMP_UP); + } if (set_previous) previous_temp_ = temp; } @@ -110,11 +112,12 @@ void HitachiClimate::set_fan_(uint8_t speed) { void HitachiClimate::set_swing_v_toggle_(bool on) { uint8_t button = get_button_(); // Get the current button value. - if (on) - button = HITACHI_AC344_BUTTON_SWINGV; // Set the button to SwingV. - else if (button == HITACHI_AC344_BUTTON_SWINGV) // Asked to unset it + if (on) { + button = HITACHI_AC344_BUTTON_SWINGV; // Set the button to SwingV. + } else if (button == HITACHI_AC344_BUTTON_SWINGV) { // Asked to unset it // It was set previous, so use Power as a default button = HITACHI_AC344_BUTTON_POWER; + } set_button_(button); } @@ -320,9 +323,9 @@ bool HitachiClimate::on_receive(remote_base::RemoteReceiveData data) { for (uint8_t pos = 0; pos < HITACHI_AC344_STATE_LENGTH; pos++) { // Read bit for (int8_t bit = 0; bit < 8; bit++) { - if (data.expect_item(HITACHI_AC344_BIT_MARK, HITACHI_AC344_ONE_SPACE)) + if (data.expect_item(HITACHI_AC344_BIT_MARK, HITACHI_AC344_ONE_SPACE)) { recv_state[pos] |= 1 << bit; - else if (!data.expect_item(HITACHI_AC344_BIT_MARK, HITACHI_AC344_ZERO_SPACE)) { + } else if (!data.expect_item(HITACHI_AC344_BIT_MARK, HITACHI_AC344_ZERO_SPACE)) { ESP_LOGVV(TAG, "Byte %d bit %d fail", pos, bit); return false; } diff --git a/esphome/components/hitachi_ac424/hitachi_ac424.cpp b/esphome/components/hitachi_ac424/hitachi_ac424.cpp index a6f146c6c3..65cfaa4175 100644 --- a/esphome/components/hitachi_ac424/hitachi_ac424.cpp +++ b/esphome/components/hitachi_ac424/hitachi_ac424.cpp @@ -19,10 +19,11 @@ void set_bits(uint8_t *const dst, const uint8_t offset, const uint8_t nbits, con void set_bit(uint8_t *const data, const uint8_t position, const bool on) { uint8_t mask = 1 << position; - if (on) + if (on) { *data |= mask; - else + } else { *data &= ~mask; + } } uint8_t *invert_byte_pairs(uint8_t *ptr, const uint16_t length) { @@ -69,10 +70,11 @@ void HitachiClimate::set_temp_(uint8_t celsius, bool set_previous) { temp = std::min(celsius, HITACHI_AC424_TEMP_MAX); temp = std::max(temp, HITACHI_AC424_TEMP_MIN); set_bits(&remote_state_[HITACHI_AC424_TEMP_BYTE], HITACHI_AC424_TEMP_OFFSET, HITACHI_AC424_TEMP_SIZE, temp); - if (previous_temp_ > temp) + if (previous_temp_ > temp) { set_button_(HITACHI_AC424_BUTTON_TEMP_DOWN); - else if (previous_temp_ < temp) + } else if (previous_temp_ < temp) { set_button_(HITACHI_AC424_BUTTON_TEMP_UP); + } if (set_previous) previous_temp_ = temp; } @@ -110,11 +112,12 @@ void HitachiClimate::set_fan_(uint8_t speed) { void HitachiClimate::set_swing_v_toggle_(bool on) { uint8_t button = get_button_(); // Get the current button value. - if (on) - button = HITACHI_AC424_BUTTON_SWINGV; // Set the button to SwingV. - else if (button == HITACHI_AC424_BUTTON_SWINGV) // Asked to unset it + if (on) { + button = HITACHI_AC424_BUTTON_SWINGV; // Set the button to SwingV. + } else if (button == HITACHI_AC424_BUTTON_SWINGV) { // Asked to unset it // It was set previous, so use Power as a default button = HITACHI_AC424_BUTTON_POWER; + } set_button_(button); } @@ -321,9 +324,9 @@ bool HitachiClimate::on_receive(remote_base::RemoteReceiveData data) { for (uint8_t pos = 0; pos < HITACHI_AC424_STATE_LENGTH; pos++) { // Read bit for (int8_t bit = 0; bit < 8; bit++) { - if (data.expect_item(HITACHI_AC424_BIT_MARK, HITACHI_AC424_ONE_SPACE)) + if (data.expect_item(HITACHI_AC424_BIT_MARK, HITACHI_AC424_ONE_SPACE)) { recv_state[pos] |= 1 << bit; - else if (!data.expect_item(HITACHI_AC424_BIT_MARK, HITACHI_AC424_ZERO_SPACE)) { + } else if (!data.expect_item(HITACHI_AC424_BIT_MARK, HITACHI_AC424_ZERO_SPACE)) { ESP_LOGVV(TAG, "Byte %d bit %d fail", pos, bit); return false; } diff --git a/esphome/components/homeassistant/binary_sensor/homeassistant_binary_sensor.cpp b/esphome/components/homeassistant/binary_sensor/homeassistant_binary_sensor.cpp index cea02f072a..a36fcb204a 100644 --- a/esphome/components/homeassistant/binary_sensor/homeassistant_binary_sensor.cpp +++ b/esphome/components/homeassistant/binary_sensor/homeassistant_binary_sensor.cpp @@ -25,10 +25,11 @@ void HomeassistantBinarySensor::setup() { } else { ESP_LOGD(TAG, "'%s': Got state %s", this->entity_id_.c_str(), ONOFF(new_state)); } - if (this->initial_) + if (this->initial_) { this->publish_initial_state(new_state); - else + } else { this->publish_state(new_state); + } break; } this->initial_ = false; diff --git a/esphome/components/i2c/i2c_bus_arduino.cpp b/esphome/components/i2c/i2c_bus_arduino.cpp index b605928692..693b869bf7 100644 --- a/esphome/components/i2c/i2c_bus_arduino.cpp +++ b/esphome/components/i2c/i2c_bus_arduino.cpp @@ -16,10 +16,11 @@ void ArduinoI2CBus::setup() { #ifdef USE_ESP32 static uint8_t next_bus_num = 0; - if (next_bus_num == 0) + if (next_bus_num == 0) { wire_ = &Wire; - else + } else { wire_ = new TwoWire(next_bus_num); // NOLINT(cppcoreguidelines-owning-memory) + } next_bus_num++; #else wire_ = &Wire; // NOLINT(cppcoreguidelines-prefer-member-initializer) @@ -55,10 +56,11 @@ void ArduinoI2CBus::dump_config() { ESP_LOGI(TAG, "Found no i2c devices!"); } else { for (const auto &s : scan_results_) { - if (s.second) + if (s.second) { ESP_LOGI(TAG, "Found i2c device at address 0x%02X", s.first); - else + } else { ESP_LOGE(TAG, "Unknown error at address 0x%02X", s.first); + } } } } diff --git a/esphome/components/i2c/i2c_bus_esp_idf.cpp b/esphome/components/i2c/i2c_bus_esp_idf.cpp index 109c3f890d..606583fd7c 100644 --- a/esphome/components/i2c/i2c_bus_esp_idf.cpp +++ b/esphome/components/i2c/i2c_bus_esp_idf.cpp @@ -65,10 +65,11 @@ void IDFI2CBus::dump_config() { ESP_LOGI(TAG, "Found no i2c devices!"); } else { for (const auto &s : scan_results_) { - if (s.second) + if (s.second) { ESP_LOGI(TAG, "Found i2c device at address 0x%02X", s.first); - else + } else { ESP_LOGE(TAG, "Unknown error at address 0x%02X", s.first); + } } } } diff --git a/esphome/components/inkplate6/inkplate.cpp b/esphome/components/inkplate6/inkplate.cpp index e62e594a49..8b7890feb7 100644 --- a/esphome/components/inkplate6/inkplate.cpp +++ b/esphome/components/inkplate6/inkplate.cpp @@ -548,14 +548,15 @@ void Inkplate6::clean_fast_(uint8_t c, uint8_t rep) { eink_on_(); uint8_t data = 0; - if (c == 0) // White + if (c == 0) { // White data = 0b10101010; - else if (c == 1) // Black + } else if (c == 1) { // Black data = 0b01010101; - else if (c == 2) // Discharge + } else if (c == 2) { // Discharge data = 0b00000000; - else if (c == 3) // Skip + } else if (c == 3) { // Skip data = 0b11111111; + } uint32_t send = ((data & 0b00000011) << 4) | (((data & 0b00001100) >> 2) << 18) | (((data & 0b00010000) >> 4) << 23) | (((data & 0b11100000) >> 5) << 25); diff --git a/esphome/components/inkplate6/inkplate.h b/esphome/components/inkplate6/inkplate.h index 2dac12a0c4..6cbb24805d 100644 --- a/esphome/components/inkplate6/inkplate.h +++ b/esphome/components/inkplate6/inkplate.h @@ -109,18 +109,20 @@ class Inkplate6 : public PollingComponent, public display::DisplayBuffer, public void pins_as_outputs_(); int get_width_internal() override { - if (this->model_ == INKPLATE_6) + if (this->model_ == INKPLATE_6) { return 800; - else if (this->model_ == INKPLATE_10) + } else if (this->model_ == INKPLATE_10) { return 1200; + } return 0; } int get_height_internal() override { - if (this->model_ == INKPLATE_6) + if (this->model_ == INKPLATE_6) { return 600; - else if (this->model_ == INKPLATE_10) + } else if (this->model_ == INKPLATE_10) { return 825; + } return 0; } diff --git a/esphome/components/light/light_call.cpp b/esphome/components/light/light_call.cpp index 3f1b8aef30..fb4e45b3b6 100644 --- a/esphome/components/light/light_call.cpp +++ b/esphome/components/light/light_call.cpp @@ -98,10 +98,11 @@ void LightCall::perform() { // EFFECT auto effect = this->effect_; const char *effect_s; - if (effect == 0u) + if (effect == 0u) { effect_s = "None"; - else + } else { effect_s = this->parent_->effects_[*this->effect_ - 1]->get_name().c_str(); + } if (this->publish_) { ESP_LOGD(TAG, " Effect: '%s'", effect_s); @@ -445,9 +446,10 @@ std::set LightCall::get_suitable_color_modes_() { }; auto key = KEY(has_white, has_ct, has_cwww, has_rgb); - for (auto &item : lookup_table) + for (auto &item : lookup_table) { if (std::get<0>(item) == key) return std::get<1>(item); + } // This happens if there are conflicting flags given. return {}; diff --git a/esphome/components/light/light_state.cpp b/esphome/components/light/light_state.cpp index 5f16585c36..151bc58a1c 100644 --- a/esphome/components/light/light_state.cpp +++ b/esphome/components/light/light_state.cpp @@ -145,10 +145,11 @@ void LightState::publish_state() { this->remote_values_callback_.call(); } LightOutput *LightState::get_output() const { return this->output_; } std::string LightState::get_effect_name() { - if (this->active_effect_index_ > 0) + if (this->active_effect_index_ > 0) { return this->effects_[this->active_effect_index_ - 1]->get_name(); - else + } else { return "None"; + } } void LightState::add_new_remote_values_callback(std::function &&send_callback) { @@ -219,10 +220,11 @@ void LightState::start_effect_(uint32_t effect_index) { effect->start_internal(); } LightEffect *LightState::get_active_effect_() { - if (this->active_effect_index_ == 0) + if (this->active_effect_index_ == 0) { return nullptr; - else + } else { return this->effects_[this->active_effect_index_ - 1]; + } } void LightState::stop_effect_() { auto *effect = this->get_active_effect_(); diff --git a/esphome/components/max7219/max7219.cpp b/esphome/components/max7219/max7219.cpp index 960ac58071..b50a78eb96 100644 --- a/esphome/components/max7219/max7219.cpp +++ b/esphome/components/max7219/max7219.cpp @@ -143,11 +143,13 @@ void MAX7219Component::dump_config() { void MAX7219Component::display() { for (uint8_t i = 0; i < 8; i++) { this->enable(); - for (uint8_t j = 0; j < this->num_chips_; j++) - if (reverse_) + for (uint8_t j = 0; j < this->num_chips_; j++) { + if (reverse_) { this->send_byte_(8 - i, buffer_[(num_chips_ - j - 1) * 8 + i]); - else + } else { this->send_byte_(8 - i, buffer_[j * 8 + i]); + } + } this->disable(); } } diff --git a/esphome/components/max7219digit/max7219digit.cpp b/esphome/components/max7219digit/max7219digit.cpp index 2368c17448..1b9ae230f7 100644 --- a/esphome/components/max7219digit/max7219digit.cpp +++ b/esphome/components/max7219digit/max7219digit.cpp @@ -253,10 +253,11 @@ void MAX7219Component::send_char(uint8_t chip, uint8_t data) { void MAX7219Component::send64pixels(uint8_t chip, const uint8_t pixels[8]) { for (uint8_t col = 0; col < 8; col++) { // RUN THIS LOOP 8 times until column is 7 this->enable(); // start sending by enabling SPI - for (uint8_t i = 0; i < chip; i++) // send extra NOPs to push the pixels out to extra displays + for (uint8_t i = 0; i < chip; i++) { // send extra NOPs to push the pixels out to extra displays this->send_byte_(MAX7219_REGISTER_NOOP, MAX7219_REGISTER_NOOP); // run this loop unit the matching chip is reached - uint8_t b = 0; // rotate pixels 90 degrees -- set byte to 0 + } + uint8_t b = 0; // rotate pixels 90 degrees -- set byte to 0 if (this->orientation_ == 0) { for (uint8_t i = 0; i < 8; i++) { // run this loop 8 times for all the pixels[8] received diff --git a/esphome/components/mcp23016/mcp23016.cpp b/esphome/components/mcp23016/mcp23016.cpp index a8df4e1745..9787da6faa 100644 --- a/esphome/components/mcp23016/mcp23016.cpp +++ b/esphome/components/mcp23016/mcp23016.cpp @@ -62,10 +62,11 @@ void MCP23016::update_reg_(uint8_t pin, bool pin_value, uint8_t reg_addr) { this->read_reg_(reg_addr, ®_value); } - if (pin_value) + if (pin_value) { reg_value |= 1 << bit; - else + } else { reg_value &= ~(1 << bit); + } this->write_reg_(reg_addr, reg_value); diff --git a/esphome/components/mcp23x08_base/mcp23x08_base.cpp b/esphome/components/mcp23x08_base/mcp23x08_base.cpp index 2137b36921..0c20e902c4 100644 --- a/esphome/components/mcp23x08_base/mcp23x08_base.cpp +++ b/esphome/components/mcp23x08_base/mcp23x08_base.cpp @@ -67,10 +67,11 @@ void MCP23X08Base::update_reg(uint8_t pin, bool pin_value, uint8_t reg_addr) { this->read_reg(reg_addr, ®_value); } - if (pin_value) + if (pin_value) { reg_value |= 1 << bit; - else + } else { reg_value &= ~(1 << bit); + } this->write_reg(reg_addr, reg_value); diff --git a/esphome/components/mcp23x17_base/mcp23x17_base.cpp b/esphome/components/mcp23x17_base/mcp23x17_base.cpp index 744f2fbe9c..99064f8880 100644 --- a/esphome/components/mcp23x17_base/mcp23x17_base.cpp +++ b/esphome/components/mcp23x17_base/mcp23x17_base.cpp @@ -70,10 +70,11 @@ void MCP23X17Base::update_reg(uint8_t pin, bool pin_value, uint8_t reg_addr) { this->read_reg(reg_addr, ®_value); } - if (pin_value) + if (pin_value) { reg_value |= 1 << bit; - else + } else { reg_value &= ~(1 << bit); + } this->write_reg(reg_addr, reg_value); diff --git a/esphome/components/midea/air_conditioner.cpp b/esphome/components/midea/air_conditioner.cpp index dd48f640a2..1ad5ade53d 100644 --- a/esphome/components/midea/air_conditioner.cpp +++ b/esphome/components/midea/air_conditioner.cpp @@ -59,14 +59,16 @@ void AirConditioner::control(const ClimateCall &call) { ctrl.swingMode = Converters::to_midea_swing_mode(call.get_swing_mode().value()); if (call.get_mode().has_value()) ctrl.mode = Converters::to_midea_mode(call.get_mode().value()); - if (call.get_preset().has_value()) + if (call.get_preset().has_value()) { ctrl.preset = Converters::to_midea_preset(call.get_preset().value()); - else if (call.get_custom_preset().has_value()) + } else if (call.get_custom_preset().has_value()) { ctrl.preset = Converters::to_midea_preset(call.get_custom_preset().value()); - if (call.get_fan_mode().has_value()) + } + if (call.get_fan_mode().has_value()) { ctrl.fanMode = Converters::to_midea_fan_mode(call.get_fan_mode().value()); - else if (call.get_custom_fan_mode().has_value()) + } else if (call.get_custom_fan_mode().has_value()) { ctrl.fanMode = Converters::to_midea_fan_mode(call.get_custom_fan_mode().value()); + } this->base_.control(ctrl); } diff --git a/esphome/components/midea_ir/midea_ir.cpp b/esphome/components/midea_ir/midea_ir.cpp index 5e507cbbb0..aa5e2b46f5 100644 --- a/esphome/components/midea_ir/midea_ir.cpp +++ b/esphome/components/midea_ir/midea_ir.cpp @@ -172,10 +172,11 @@ bool MideaIR::on_midea_(const MideaData &data) { this->target_temperature = status.get_temp(); this->mode = status.get_mode(); this->fan_mode = status.get_fan_mode(); - if (status.get_sleep_preset()) + if (status.get_sleep_preset()) { this->preset = climate::CLIMATE_PRESET_SLEEP; - else if (this->preset == climate::CLIMATE_PRESET_SLEEP) + } else if (this->preset == climate::CLIMATE_PRESET_SLEEP) { this->preset = climate::CLIMATE_PRESET_NONE; + } this->publish_state(); return true; } diff --git a/esphome/components/mitsubishi/mitsubishi.cpp b/esphome/components/mitsubishi/mitsubishi.cpp index 4d47b1ac14..99ca6d1cc5 100644 --- a/esphome/components/mitsubishi/mitsubishi.cpp +++ b/esphome/components/mitsubishi/mitsubishi.cpp @@ -63,12 +63,13 @@ void MitsubishiClimate::transmit_state() { data->mark(MITSUBISHI_HEADER_MARK); data->space(MITSUBISHI_HEADER_SPACE); // Data - for (uint8_t i : remote_state) + for (uint8_t i : remote_state) { for (uint8_t j = 0; j < 8; j++) { data->mark(MITSUBISHI_BIT_MARK); bool bit = i & (1 << j); data->space(bit ? MITSUBISHI_ONE_SPACE : MITSUBISHI_ZERO_SPACE); } + } // Footer if (r == 0) { data->mark(MITSUBISHI_BIT_MARK); diff --git a/esphome/components/modbus_controller/binary_sensor/modbus_binarysensor.h b/esphome/components/modbus_controller/binary_sensor/modbus_binarysensor.h index 41f1f1b054..3a8e175c26 100644 --- a/esphome/components/modbus_controller/binary_sensor/modbus_binarysensor.h +++ b/esphome/components/modbus_controller/binary_sensor/modbus_binarysensor.h @@ -19,10 +19,11 @@ class ModbusBinarySensor : public Component, public binary_sensor::BinarySensor, this->skip_updates = skip_updates; this->force_new_range = force_new_range; - if (register_type == ModbusRegisterType::COIL || register_type == ModbusRegisterType::DISCRETE_INPUT) + if (register_type == ModbusRegisterType::COIL || register_type == ModbusRegisterType::DISCRETE_INPUT) { this->register_count = offset + 1; - else + } else { this->register_count = 1; + } } void parse_and_publish(const std::vector &data) override; diff --git a/esphome/components/modbus_controller/modbus_controller.h b/esphome/components/modbus_controller/modbus_controller.h index ada6843ca3..88e2bba9ad 100644 --- a/esphome/components/modbus_controller/modbus_controller.h +++ b/esphome/components/modbus_controller/modbus_controller.h @@ -230,10 +230,11 @@ class SensorItem { void set_custom_data(const std::vector &data) { custom_data = data; } size_t virtual get_register_size() const { - if (register_type == ModbusRegisterType::COIL || register_type == ModbusRegisterType::DISCRETE_INPUT) + if (register_type == ModbusRegisterType::COIL || register_type == ModbusRegisterType::DISCRETE_INPUT) { return 1; - else // if CONF_RESPONSE_BYTES is used override the default + } else { // if CONF_RESPONSE_BYTES is used override the default return response_bytes > 0 ? response_bytes : register_count * 2; + } } // Override register size for modbus devices not using 1 register for one dword void set_register_size(uint8_t register_size) { response_bytes = register_size; } diff --git a/esphome/components/mqtt/mqtt_client.cpp b/esphome/components/mqtt/mqtt_client.cpp index de25c5b2e3..67063d4c72 100644 --- a/esphome/components/mqtt/mqtt_client.cpp +++ b/esphome/components/mqtt/mqtt_client.cpp @@ -373,10 +373,11 @@ void MQTTClientComponent::unsubscribe(const std::string &topic) { auto it = subscriptions_.begin(); while (it != subscriptions_.end()) { - if (it->topic == topic) + if (it->topic == topic) { it = subscriptions_.erase(it); - else + } else { ++it; + } } } @@ -484,9 +485,10 @@ void MQTTClientComponent::on_message(const std::string &topic, const std::string // in an ISR. this->defer([this, topic, payload]() { #endif - for (auto &subscription : this->subscriptions_) + for (auto &subscription : this->subscriptions_) { if (topic_match(topic.c_str(), subscription.topic.c_str())) subscription.callback(topic, payload); + } #ifdef USE_ESP8266 }); #endif diff --git a/esphome/components/mqtt/mqtt_climate.cpp b/esphome/components/mqtt/mqtt_climate.cpp index f6ef3a5e8f..7c3c414b3a 100644 --- a/esphome/components/mqtt/mqtt_climate.cpp +++ b/esphome/components/mqtt/mqtt_climate.cpp @@ -299,7 +299,7 @@ bool MQTTClimateComponent::publish_state_() { if (traits.get_supports_fan_modes()) { std::string payload; - if (this->device_->fan_mode.has_value()) + if (this->device_->fan_mode.has_value()) { switch (this->device_->fan_mode.value()) { case CLIMATE_FAN_ON: payload = "on"; @@ -329,6 +329,7 @@ bool MQTTClimateComponent::publish_state_() { payload = "diffuse"; break; } + } if (this->device_->custom_fan_mode.has_value()) payload = this->device_->custom_fan_mode.value(); if (!this->publish(this->get_fan_mode_state_topic(), payload)) diff --git a/esphome/components/nextion/nextion.cpp b/esphome/components/nextion/nextion.cpp index 709e2bffcd..46c063e5ee 100644 --- a/esphome/components/nextion/nextion.cpp +++ b/esphome/components/nextion/nextion.cpp @@ -737,9 +737,10 @@ void Nextion::process_nextion_commands_() { for (size_t i = 0; i < this->nextion_queue_.size(); i++) { NextionComponentBase *component = this->nextion_queue_[i]->component; if (this->nextion_queue_[i]->queue_time + this->max_q_age_ms_ < ms) { - if (this->nextion_queue_[i]->queue_time == 0) + if (this->nextion_queue_[i]->queue_time == 0) { ESP_LOGD(TAG, "Removing old queue type \"%s\" name \"%s\" queue_time 0", component->get_queue_type_string().c_str(), component->get_variable_name().c_str()); + } if (component->get_variable_name() == "sleep_wake") { this->is_sleeping_ = false; @@ -873,9 +874,9 @@ uint16_t Nextion::recv_ret_string_(std::string &response, uint32_t timeout, bool while ((timeout == 0 && this->available()) || millis() - start <= timeout) { this->read_byte(&c); - if (c == 0xFF) + if (c == 0xFF) { nr_of_ff_bytes++; - else { + } else { nr_of_ff_bytes = 0; ff_flag = false; } diff --git a/esphome/components/ota/ota_component.cpp b/esphome/components/ota/ota_component.cpp index 92256eb1b6..c05f2aa546 100644 --- a/esphome/components/ota/ota_component.cpp +++ b/esphome/components/ota/ota_component.cpp @@ -452,10 +452,11 @@ bool OTAComponent::should_enter_safe_mode(uint8_t num_attempts, uint32_t enable_ bool is_manual_safe_mode = this->safe_mode_rtc_value_ == esphome::ota::OTAComponent::ENTER_SAFE_MODE_MAGIC; - if (is_manual_safe_mode) + if (is_manual_safe_mode) { ESP_LOGI(TAG, "Safe mode has been entered manually"); - else + } else { ESP_LOGCONFIG(TAG, "There have been %u suspected unsuccessful boot attempts.", this->safe_mode_rtc_value_); + } if (this->safe_mode_rtc_value_ >= num_attempts || is_manual_safe_mode) { this->clean_rtc(); diff --git a/esphome/components/output/binary_output.h b/esphome/components/output/binary_output.h index 993ed9e8ac..7a15bc7b51 100644 --- a/esphome/components/output/binary_output.h +++ b/esphome/components/output/binary_output.h @@ -32,10 +32,11 @@ class BinaryOutput { /// Enable or disable this binary output. virtual void set_state(bool state) { - if (state) + if (state) { this->turn_on(); - else + } else { this->turn_off(); + } } /// Enable this binary output. diff --git a/esphome/components/output/switch/output_switch.cpp b/esphome/components/output/switch/output_switch.cpp index 3691896cbe..ec9c8afc01 100644 --- a/esphome/components/output/switch/output_switch.cpp +++ b/esphome/components/output/switch/output_switch.cpp @@ -30,10 +30,11 @@ void OutputSwitch::setup() { break; } - if (initial_state) + if (initial_state) { this->turn_on(); - else + } else { this->turn_off(); + } } void OutputSwitch::write_state(bool state) { if (state) { diff --git a/esphome/components/partition/light_partition.h b/esphome/components/partition/light_partition.h index f74001cf75..5790fd2b39 100644 --- a/esphome/components/partition/light_partition.h +++ b/esphome/components/partition/light_partition.h @@ -78,10 +78,11 @@ class PartitionLightOutput : public light::AddressableLight { int32_t seg_off = index - seg.get_dst_offset(); // offset within the src int32_t src_off; - if (seg.is_reversed()) + if (seg.is_reversed()) { src_off = seg.get_src_offset() + seg.get_size() - seg_off - 1; - else + } else { src_off = seg.get_src_offset() + seg_off; + } auto view = (*seg.get_src())[src_off]; view.raw_set_color_correction(&this->correction_); diff --git a/esphome/components/pid/pid_climate.cpp b/esphome/components/pid/pid_climate.cpp index f5c7792782..3f8377c720 100644 --- a/esphome/components/pid/pid_climate.cpp +++ b/esphome/components/pid/pid_climate.cpp @@ -20,12 +20,13 @@ void PIDClimate::setup() { restore->to_call(this).perform(); } else { // restore from defaults, change_away handles those for us - if (supports_heat_() && supports_cool_()) + if (supports_heat_() && supports_cool_()) { this->mode = climate::CLIMATE_MODE_HEAT_COOL; - else if (supports_cool_()) + } else if (supports_cool_()) { this->mode = climate::CLIMATE_MODE_COOL; - else if (supports_heat_()) + } else if (supports_heat_()) { this->mode = climate::CLIMATE_MODE_HEAT; + } this->target_temperature = this->default_target_temperature_; } } @@ -83,14 +84,15 @@ void PIDClimate::write_output_(float value) { // Update action variable for user feedback what's happening climate::ClimateAction new_action; - if (this->supports_cool_() && value < 0) + if (this->supports_cool_() && value < 0) { new_action = climate::CLIMATE_ACTION_COOLING; - else if (this->supports_heat_() && value > 0) + } else if (this->supports_heat_() && value > 0) { new_action = climate::CLIMATE_ACTION_HEATING; - else if (this->mode == climate::CLIMATE_MODE_OFF) + } else if (this->mode == climate::CLIMATE_MODE_OFF) { new_action = climate::CLIMATE_ACTION_OFF; - else + } else { new_action = climate::CLIMATE_ACTION_IDLE; + } if (new_action != this->action) { this->action = new_action; diff --git a/esphome/components/pipsolar/pipsolar.cpp b/esphome/components/pipsolar/pipsolar.cpp index 13a08bbd16..c1935509f0 100644 --- a/esphome/components/pipsolar/pipsolar.cpp +++ b/esphome/components/pipsolar/pipsolar.cpp @@ -908,10 +908,11 @@ uint16_t Pipsolar::crc_xmodem_update_(uint16_t crc, uint8_t data) { int i; crc = crc ^ ((uint16_t) data << 8); for (i = 0; i < 8; i++) { - if (crc & 0x8000) + if (crc & 0x8000) { crc = (crc << 1) ^ 0x1021; //(polynomial = 0x1021) - else + } else { crc <<= 1; + } } return crc; } diff --git a/esphome/components/rc522/rc522.cpp b/esphome/components/rc522/rc522.cpp index d203b3ce8f..5bfeb40156 100644 --- a/esphome/components/rc522/rc522.cpp +++ b/esphome/components/rc522/rc522.cpp @@ -139,10 +139,11 @@ void RC522::loop() { StatusCode status = STATUS_ERROR; // For lint passing. TODO: refactor this if (awaiting_comm_) { - if (state_ == STATE_SELECT_SERIAL_DONE) + if (state_ == STATE_SELECT_SERIAL_DONE) { status = await_crc_(); - else + } else { status = await_transceive_(); + } if (status == STATUS_WAITING) { return; @@ -210,11 +211,12 @@ void RC522::loop() { } case STATE_READ_SERIAL_DONE: { if (status != STATUS_OK || back_length_ != 3) { - if (status == STATUS_TIMEOUT) + if (status == STATUS_TIMEOUT) { ESP_LOGV(TAG, "STATE_READ_SERIAL_DONE -> TIMEOUT (no tag present) %d", status); - else + } else { ESP_LOGW(TAG, "Unexpected response. Read status is %d. Read bytes: %d (%s)", status, back_length_, format_buffer(buffer_, 9).c_str()); + } state_ = STATE_DONE; uid_idx_ = 0; @@ -476,9 +478,9 @@ RC522::StatusCode RC522::await_crc_() { bool RC522BinarySensor::process(std::vector &data) { bool result = true; - if (data.size() != this->uid_.size()) + if (data.size() != this->uid_.size()) { result = false; - else { + } else { for (size_t i = 0; i < data.size(); i++) { if (data[i] != this->uid_[i]) { result = false; diff --git a/esphome/components/remote_base/coolix_protocol.cpp b/esphome/components/remote_base/coolix_protocol.cpp index 3e6e7e185a..252b6f0e91 100644 --- a/esphome/components/remote_base/coolix_protocol.cpp +++ b/esphome/components/remote_base/coolix_protocol.cpp @@ -51,10 +51,11 @@ static bool decode_data(RemoteReceiveData &src, CoolixData &dst) { for (uint32_t mask = 1 << 7; mask; mask >>= 1) { if (!src.expect_mark(BIT_MARK_US)) return false; - if (src.expect_space(BIT_ONE_SPACE_US)) + if (src.expect_space(BIT_ONE_SPACE_US)) { data |= mask; - else if (!src.expect_space(BIT_ZERO_SPACE_US)) + } else if (!src.expect_space(BIT_ZERO_SPACE_US)) { return false; + } } // Check for inverse byte for (uint32_t mask = 1 << 7; mask; mask >>= 1) { diff --git a/esphome/components/remote_base/dish_protocol.cpp b/esphome/components/remote_base/dish_protocol.cpp index 1257e22a45..47bfdc5c58 100644 --- a/esphome/components/remote_base/dish_protocol.cpp +++ b/esphome/components/remote_base/dish_protocol.cpp @@ -24,18 +24,20 @@ void DishProtocol::encode(RemoteTransmitData *dst, const DishData &data) { for (uint i = 0; i < 4; i++) { // COMMAND (function, in MSB) for (uint8_t mask = 1UL << 5; mask; mask >>= 1) { - if (data.command & mask) + if (data.command & mask) { dst->item(BIT_HIGH_US, BIT_ONE_LOW_US); - else + } else { dst->item(BIT_HIGH_US, BIT_ZERO_LOW_US); + } } // ADDRESS (unit code, in LSB) for (uint8_t mask = 1UL; mask < 1UL << 4; mask <<= 1) { - if ((data.address - 1) & mask) + if ((data.address - 1) & mask) { dst->item(BIT_HIGH_US, BIT_ONE_LOW_US); - else + } else { dst->item(BIT_HIGH_US, BIT_ZERO_LOW_US); + } } // PADDING for (uint j = 0; j < 6; j++) diff --git a/esphome/components/remote_base/jvc_protocol.cpp b/esphome/components/remote_base/jvc_protocol.cpp index f43a28bdc5..169b1d00bf 100644 --- a/esphome/components/remote_base/jvc_protocol.cpp +++ b/esphome/components/remote_base/jvc_protocol.cpp @@ -20,10 +20,11 @@ void JVCProtocol::encode(RemoteTransmitData *dst, const JVCData &data) { dst->item(HEADER_HIGH_US, HEADER_LOW_US); for (uint32_t mask = 1UL << (NBITS - 1); mask != 0; mask >>= 1) { - if (data.data & mask) + if (data.data & mask) { dst->item(BIT_HIGH_US, BIT_ONE_LOW_US); - else + } else { dst->item(BIT_HIGH_US, BIT_ZERO_LOW_US); + } } dst->mark(BIT_HIGH_US); diff --git a/esphome/components/remote_base/lg_protocol.cpp b/esphome/components/remote_base/lg_protocol.cpp index a3e7f9828b..8040b0f3fc 100644 --- a/esphome/components/remote_base/lg_protocol.cpp +++ b/esphome/components/remote_base/lg_protocol.cpp @@ -19,10 +19,11 @@ void LGProtocol::encode(RemoteTransmitData *dst, const LGData &data) { dst->item(HEADER_HIGH_US, HEADER_LOW_US); for (uint32_t mask = 1UL << (data.nbits - 1); mask != 0; mask >>= 1) { - if (data.data & mask) + if (data.data & mask) { dst->item(BIT_HIGH_US, BIT_ONE_LOW_US); - else + } else { dst->item(BIT_HIGH_US, BIT_ZERO_LOW_US); + } } dst->mark(BIT_HIGH_US); diff --git a/esphome/components/remote_base/midea_protocol.cpp b/esphome/components/remote_base/midea_protocol.cpp index bf67429001..f619d201bc 100644 --- a/esphome/components/remote_base/midea_protocol.cpp +++ b/esphome/components/remote_base/midea_protocol.cpp @@ -31,14 +31,16 @@ void MideaProtocol::encode(RemoteTransmitData *dst, const MideaData &src) { dst->set_carrier_frequency(38000); dst->reserve(2 + 48 * 2 + 2 + 2 + 48 * 2 + 1); dst->item(HEADER_MARK_US, HEADER_SPACE_US); - for (unsigned idx = 0; idx < 6; idx++) + for (unsigned idx = 0; idx < 6; idx++) { for (uint8_t mask = 1 << 7; mask; mask >>= 1) dst->item(BIT_MARK_US, (src[idx] & mask) ? BIT_ONE_SPACE_US : BIT_ZERO_SPACE_US); + } dst->item(FOOTER_MARK_US, FOOTER_SPACE_US); dst->item(HEADER_MARK_US, HEADER_SPACE_US); - for (unsigned idx = 0; idx < 6; idx++) + for (unsigned idx = 0; idx < 6; idx++) { for (uint8_t mask = 1 << 7; mask; mask >>= 1) dst->item(BIT_MARK_US, (src[idx] & mask) ? BIT_ZERO_SPACE_US : BIT_ONE_SPACE_US); + } dst->mark(FOOTER_MARK_US); } @@ -48,10 +50,11 @@ static bool decode_data(RemoteReceiveData &src, MideaData &dst) { for (uint8_t mask = 1 << 7; mask; mask >>= 1) { if (!src.expect_mark(BIT_MARK_US)) return false; - if (src.expect_space(BIT_ONE_SPACE_US)) + if (src.expect_space(BIT_ONE_SPACE_US)) { data |= mask; - else if (!src.expect_space(BIT_ZERO_SPACE_US)) + } else if (!src.expect_space(BIT_ZERO_SPACE_US)) { return false; + } } dst[idx] = data; } diff --git a/esphome/components/remote_base/nec_protocol.cpp b/esphome/components/remote_base/nec_protocol.cpp index 47b4d676dd..ee3fec5992 100644 --- a/esphome/components/remote_base/nec_protocol.cpp +++ b/esphome/components/remote_base/nec_protocol.cpp @@ -18,17 +18,19 @@ void NECProtocol::encode(RemoteTransmitData *dst, const NECData &data) { dst->item(HEADER_HIGH_US, HEADER_LOW_US); for (uint16_t mask = 1; mask; mask <<= 1) { - if (data.address & mask) + if (data.address & mask) { dst->item(BIT_HIGH_US, BIT_ONE_LOW_US); - else + } else { dst->item(BIT_HIGH_US, BIT_ZERO_LOW_US); + } } for (uint16_t mask = 1; mask; mask <<= 1) { - if (data.command & mask) + if (data.command & mask) { dst->item(BIT_HIGH_US, BIT_ONE_LOW_US); - else + } else { dst->item(BIT_HIGH_US, BIT_ZERO_LOW_US); + } } dst->mark(BIT_HIGH_US); diff --git a/esphome/components/remote_base/nexa_protocol.cpp b/esphome/components/remote_base/nexa_protocol.cpp index 814b46135a..dbdc835fe3 100644 --- a/esphome/components/remote_base/nexa_protocol.cpp +++ b/esphome/components/remote_base/nexa_protocol.cpp @@ -41,43 +41,48 @@ void NexaProtocol::encode(RemoteTransmitData *dst, const NexaData &data) { // Device (26 bits) for (int16_t i = 26 - 1; i >= 0; i--) { - if (data.device & (1 << i)) + if (data.device & (1 << i)) { this->one(dst); - else + } else { this->zero(dst); + } } // Group (1 bit) - if (data.group != 0) + if (data.group != 0) { this->one(dst); - else + } else { this->zero(dst); + } // State (1 bit) if (data.state == 2) { // Special case for dimmers...send 00 as state dst->item(TX_BIT_HIGH_US, TX_BIT_ZERO_LOW_US); dst->item(TX_BIT_HIGH_US, TX_BIT_ZERO_LOW_US); - } else if (data.state == 1) + } else if (data.state == 1) { this->one(dst); - else + } else { this->zero(dst); + } // Channel (4 bits) for (int16_t i = 4 - 1; i >= 0; i--) { - if (data.channel & (1 << i)) + if (data.channel & (1 << i)) { this->one(dst); - else + } else { this->zero(dst); + } } // Level (4 bits) if (data.state == 2) { for (int16_t i = 4 - 1; i >= 0; i--) { - if (data.level & (1 << i)) + if (data.level & (1 << i)) { this->one(dst); - else + } else { this->zero(dst); + } } } diff --git a/esphome/components/remote_base/panasonic_protocol.cpp b/esphome/components/remote_base/panasonic_protocol.cpp index fd4f7c4bf7..fe1060e935 100644 --- a/esphome/components/remote_base/panasonic_protocol.cpp +++ b/esphome/components/remote_base/panasonic_protocol.cpp @@ -19,17 +19,19 @@ void PanasonicProtocol::encode(RemoteTransmitData *dst, const PanasonicData &dat uint32_t mask; for (mask = 1UL << 15; mask != 0; mask >>= 1) { - if (data.address & mask) + if (data.address & mask) { dst->item(BIT_HIGH_US, BIT_ONE_LOW_US); - else + } else { dst->item(BIT_HIGH_US, BIT_ZERO_LOW_US); + } } for (mask = 1UL << 31; mask != 0; mask >>= 1) { - if (data.command & mask) + if (data.command & mask) { dst->item(BIT_HIGH_US, BIT_ONE_LOW_US); - else + } else { dst->item(BIT_HIGH_US, BIT_ZERO_LOW_US); + } } dst->mark(BIT_HIGH_US); } diff --git a/esphome/components/remote_base/pioneer_protocol.cpp b/esphome/components/remote_base/pioneer_protocol.cpp index 74a3998f11..5c10eab48d 100644 --- a/esphome/components/remote_base/pioneer_protocol.cpp +++ b/esphome/components/remote_base/pioneer_protocol.cpp @@ -42,26 +42,29 @@ void PioneerProtocol::encode(RemoteTransmitData *dst, const PioneerData &data) { command1 = (command1 << 8) | ((~command1) & 0xff); command2 = (command2 << 8) | ((~command2) & 0xff); - if (data.rc_code_2 == 0) + if (data.rc_code_2 == 0) { dst->reserve(68); - else + } else { dst->reserve((68 * 2) + 1); + } dst->set_carrier_frequency(40000); dst->item(HEADER_HIGH_US, HEADER_LOW_US); for (uint32_t mask = 1UL << 15; mask; mask >>= 1) { - if (address1 & mask) + if (address1 & mask) { dst->item(BIT_HIGH_US, BIT_ONE_LOW_US); - else + } else { dst->item(BIT_HIGH_US, BIT_ZERO_LOW_US); + } } for (uint32_t mask = 1UL << 15; mask; mask >>= 1) { - if (command1 & mask) + if (command1 & mask) { dst->item(BIT_HIGH_US, BIT_ONE_LOW_US); - else + } else { dst->item(BIT_HIGH_US, BIT_ZERO_LOW_US); + } } dst->mark(BIT_HIGH_US); @@ -70,17 +73,19 @@ void PioneerProtocol::encode(RemoteTransmitData *dst, const PioneerData &data) { dst->space(TRAILER_SPACE_US); dst->item(HEADER_HIGH_US, HEADER_LOW_US); for (uint32_t mask = 1UL << 15; mask; mask >>= 1) { - if (address2 & mask) + if (address2 & mask) { dst->item(BIT_HIGH_US, BIT_ONE_LOW_US); - else + } else { dst->item(BIT_HIGH_US, BIT_ZERO_LOW_US); + } } for (uint32_t mask = 1UL << 15; mask; mask >>= 1) { - if (command2 & mask) + if (command2 & mask) { dst->item(BIT_HIGH_US, BIT_ONE_LOW_US); - else + } else { dst->item(BIT_HIGH_US, BIT_ZERO_LOW_US); + } } dst->mark(BIT_HIGH_US); @@ -140,10 +145,11 @@ optional PioneerProtocol::decode(RemoteReceiveData src) { return data; } void PioneerProtocol::dump(const PioneerData &data) { - if (data.rc_code_2 == 0) + if (data.rc_code_2 == 0) { ESP_LOGD(TAG, "Received Pioneer: rc_code_X=0x%04X", data.rc_code_1); - else + } else { ESP_LOGD(TAG, "Received Pioneer: rc_code_1=0x%04X, rc_code_2=0x%04X", data.rc_code_1, data.rc_code_2); + } } } // namespace remote_base diff --git a/esphome/components/remote_base/raw_protocol.h b/esphome/components/remote_base/raw_protocol.h index 1d9f1c5acc..054f02ff7c 100644 --- a/esphome/components/remote_base/raw_protocol.h +++ b/esphome/components/remote_base/raw_protocol.h @@ -50,10 +50,11 @@ template class RawAction : public RemoteTransmitterActionBasecode_static_ != nullptr) { for (size_t i = 0; i < this->code_static_len_; i++) { auto val = this->code_static_[i]; - if (val < 0) + if (val < 0) { dst->space(static_cast(-val)); - else + } else { dst->mark(static_cast(val)); + } } } else { dst->set_data(this->code_func_(x...)); diff --git a/esphome/components/remote_base/rc_switch_protocol.cpp b/esphome/components/remote_base/rc_switch_protocol.cpp index 1dc094d552..b353f0254e 100644 --- a/esphome/components/remote_base/rc_switch_protocol.cpp +++ b/esphome/components/remote_base/rc_switch_protocol.cpp @@ -57,10 +57,11 @@ void RCSwitchBase::transmit(RemoteTransmitData *dst, uint64_t code, uint8_t len) dst->set_carrier_frequency(0); this->sync(dst); for (int16_t i = len - 1; i >= 0; i--) { - if (code & ((uint64_t) 1 << i)) + if (code & ((uint64_t) 1 << i)) { this->one(dst); - else + } else { this->zero(dst); + } } } @@ -148,10 +149,11 @@ void RCSwitchBase::simple_code_to_tristate(uint16_t code, uint8_t nbits, uint64_ *out_code = 0; for (int8_t i = nbits - 1; i >= 0; i--) { *out_code <<= 2; - if (code & (1 << i)) + if (code & (1 << i)) { *out_code |= 0b01; - else + } else { *out_code |= 0b00; + } } } void RCSwitchBase::type_a_code(uint8_t switch_group, uint8_t switch_device, bool state, uint64_t *out_code, diff --git a/esphome/components/remote_base/samsung_protocol.cpp b/esphome/components/remote_base/samsung_protocol.cpp index 4571f332b3..20e8285a03 100644 --- a/esphome/components/remote_base/samsung_protocol.cpp +++ b/esphome/components/remote_base/samsung_protocol.cpp @@ -22,10 +22,11 @@ void SamsungProtocol::encode(RemoteTransmitData *dst, const SamsungData &data) { dst->item(HEADER_HIGH_US, HEADER_LOW_US); for (uint8_t bit = data.nbits; bit > 0; bit--) { - if ((data.data >> (bit - 1)) & 1) + if ((data.data >> (bit - 1)) & 1) { dst->item(BIT_HIGH_US, BIT_ONE_LOW_US); - else + } else { dst->item(BIT_HIGH_US, BIT_ZERO_LOW_US); + } } dst->item(FOOTER_HIGH_US, FOOTER_LOW_US); diff --git a/esphome/components/remote_base/sony_protocol.cpp b/esphome/components/remote_base/sony_protocol.cpp index 3bb643266a..8634cf7d61 100644 --- a/esphome/components/remote_base/sony_protocol.cpp +++ b/esphome/components/remote_base/sony_protocol.cpp @@ -19,10 +19,11 @@ void SonyProtocol::encode(RemoteTransmitData *dst, const SonyData &data) { dst->item(HEADER_HIGH_US, HEADER_LOW_US); for (uint32_t mask = 1UL << (data.nbits - 1); mask != 0; mask >>= 1) { - if (data.data & mask) + if (data.data & mask) { dst->item(BIT_ONE_HIGH_US, BIT_LOW_US); - else + } else { dst->item(BIT_ZERO_HIGH_US, BIT_LOW_US); + } } } optional SonyProtocol::decode(RemoteReceiveData src) { diff --git a/esphome/components/remote_base/toshiba_ac_protocol.cpp b/esphome/components/remote_base/toshiba_ac_protocol.cpp index bd1d2a8f5b..1a19f534f8 100644 --- a/esphome/components/remote_base/toshiba_ac_protocol.cpp +++ b/esphome/components/remote_base/toshiba_ac_protocol.cpp @@ -24,10 +24,11 @@ void ToshibaAcProtocol::encode(RemoteTransmitData *dst, const ToshibaAcData &dat dst->item(HEADER_HIGH_US, HEADER_LOW_US); for (uint8_t bit = 48; bit > 0; bit--) { dst->mark(BIT_HIGH_US); - if ((data.rc_code_1 >> (bit - 1)) & 1) + if ((data.rc_code_1 >> (bit - 1)) & 1) { dst->space(BIT_ONE_LOW_US); - else + } else { dst->space(BIT_ZERO_LOW_US); + } } dst->item(FOOTER_HIGH_US, FOOTER_LOW_US); } @@ -36,10 +37,11 @@ void ToshibaAcProtocol::encode(RemoteTransmitData *dst, const ToshibaAcData &dat dst->item(HEADER_HIGH_US, HEADER_LOW_US); for (uint8_t bit = 48; bit > 0; bit--) { dst->mark(BIT_HIGH_US); - if ((data.rc_code_2 >> (bit - 1)) & 1) + if ((data.rc_code_2 >> (bit - 1)) & 1) { dst->space(BIT_ONE_LOW_US); - else + } else { dst->space(BIT_ZERO_LOW_US); + } } dst->item(FOOTER_HIGH_US, FOOTER_LOW_US); } @@ -102,10 +104,11 @@ optional ToshibaAcProtocol::decode(RemoteReceiveData src) { } void ToshibaAcProtocol::dump(const ToshibaAcData &data) { - if (data.rc_code_2 != 0) + if (data.rc_code_2 != 0) { ESP_LOGD(TAG, "Received Toshiba AC: rc_code_1=0x%" PRIX64 ", rc_code_2=0x%" PRIX64, data.rc_code_1, data.rc_code_2); - else + } else { ESP_LOGD(TAG, "Received Toshiba AC: rc_code_1=0x%" PRIX64, data.rc_code_1); + } } } // namespace remote_base diff --git a/esphome/components/remote_receiver/remote_receiver_esp8266.cpp b/esphome/components/remote_receiver/remote_receiver_esp8266.cpp index cf2c15402e..8700fcf0bb 100644 --- a/esphome/components/remote_receiver/remote_receiver_esp8266.cpp +++ b/esphome/components/remote_receiver/remote_receiver_esp8266.cpp @@ -79,9 +79,10 @@ void RemoteReceiverComponent::loop() { if (dist <= 1) return; const uint32_t now = micros(); - if (now - s.buffer[write_at] < this->idle_us_) + if (now - s.buffer[write_at] < this->idle_us_) { // The last change was fewer than the configured idle time ago. return; + } ESP_LOGVV(TAG, "read_at=%u write_at=%u dist=%u now=%u end=%u", s.buffer_read_at, write_at, dist, now, s.buffer[write_at]); diff --git a/esphome/components/remote_transmitter/remote_transmitter_esp8266.cpp b/esphome/components/remote_transmitter/remote_transmitter_esp8266.cpp index 39752cac5b..1c0eb94e61 100644 --- a/esphome/components/remote_transmitter/remote_transmitter_esp8266.cpp +++ b/esphome/components/remote_transmitter/remote_transmitter_esp8266.cpp @@ -35,10 +35,11 @@ void RemoteTransmitterComponent::calculate_on_off_time_(uint32_t carrier_frequen void RemoteTransmitterComponent::await_target_time_() { const uint32_t current_time = micros(); - if (this->target_time_ == 0) + if (this->target_time_ == 0) { this->target_time_ = current_time; - else if (this->target_time_ > current_time) + } else if (this->target_time_ > current_time) { delayMicroseconds(this->target_time_ - current_time); + } } void RemoteTransmitterComponent::mark_(uint32_t on_time, uint32_t off_time, uint32_t usec) { diff --git a/esphome/components/resistance/resistance_sensor.cpp b/esphome/components/resistance/resistance_sensor.cpp index 4d3dfa5928..e13959fd37 100644 --- a/esphome/components/resistance/resistance_sensor.cpp +++ b/esphome/components/resistance/resistance_sensor.cpp @@ -20,16 +20,18 @@ void ResistanceSensor::process_(float value) { float res = 0; switch (this->configuration_) { case UPSTREAM: - if (value == 0.0f) + if (value == 0.0f) { res = NAN; - else + } else { res = (this->reference_voltage_ - value) / value; + } break; case DOWNSTREAM: - if (value == this->reference_voltage_) + if (value == this->reference_voltage_) { res = NAN; - else + } else { res = value / (this->reference_voltage_ - value); + } break; } diff --git a/esphome/components/rtttl/rtttl.cpp b/esphome/components/rtttl/rtttl.cpp index c76d4a89b0..6274e69ba3 100644 --- a/esphome/components/rtttl/rtttl.cpp +++ b/esphome/components/rtttl/rtttl.cpp @@ -104,10 +104,11 @@ void Rtttl::loop() { // first, get note duration, if available uint8_t num = this->get_integer_(); - if (num) + if (num) { note_duration_ = wholenote_ / num; - else + } else { note_duration_ = wholenote_ / default_duration_; // we will need to check if we are a dotted note after + } uint8_t note; diff --git a/esphome/components/scd30/scd30.cpp b/esphome/components/scd30/scd30.cpp index 272ee75e30..8603072bd5 100644 --- a/esphome/components/scd30/scd30.cpp +++ b/esphome/components/scd30/scd30.cpp @@ -229,18 +229,20 @@ uint8_t SCD30Component::sht_crc_(uint8_t data1, uint8_t data2) { crc ^= data1; for (bit = 8; bit > 0; --bit) { - if (crc & 0x80) + if (crc & 0x80) { crc = (crc << 1) ^ 0x131; - else + } else { crc = (crc << 1); + } } crc ^= data2; for (bit = 8; bit > 0; --bit) { - if (crc & 0x80) + if (crc & 0x80) { crc = (crc << 1) ^ 0x131; - else + } else { crc = (crc << 1); + } } return crc; diff --git a/esphome/components/scd4x/scd4x.cpp b/esphome/components/scd4x/scd4x.cpp index eacb39edf1..4bd512394f 100644 --- a/esphome/components/scd4x/scd4x.cpp +++ b/esphome/components/scd4x/scd4x.cpp @@ -233,18 +233,20 @@ uint8_t SCD4XComponent::sht_crc_(uint8_t data1, uint8_t data2) { crc ^= data1; for (bit = 8; bit > 0; --bit) { - if (crc & 0x80) + if (crc & 0x80) { crc = (crc << 1) ^ 0x131; - else + } else { crc = (crc << 1); + } } crc ^= data2; for (bit = 8; bit > 0; --bit) { - if (crc & 0x80) + if (crc & 0x80) { crc = (crc << 1) ^ 0x131; - else + } else { crc = (crc << 1); + } } return crc; diff --git a/esphome/components/sdp3x/sdp3x.cpp b/esphome/components/sdp3x/sdp3x.cpp index 107ed2902f..eb1543f2c2 100644 --- a/esphome/components/sdp3x/sdp3x.cpp +++ b/esphome/components/sdp3x/sdp3x.cpp @@ -138,10 +138,11 @@ bool SDP3XComponent::check_crc_(const uint8_t data[], uint8_t size, uint8_t chec for (int i = 0; i < size; i++) { crc ^= (data[i]); for (uint8_t bit = 8; bit > 0; --bit) { - if (crc & 0x80) + if (crc & 0x80) { crc = (crc << 1) ^ 0x31; - else + } else { crc = (crc << 1); + } } } diff --git a/esphome/components/sensor/filter.cpp b/esphome/components/sensor/filter.cpp index 7e7153196c..49d2c648b0 100644 --- a/esphome/components/sensor/filter.cpp +++ b/esphome/components/sensor/filter.cpp @@ -176,10 +176,11 @@ optional SlidingWindowMovingAverageFilter::new_value(float value) { this->sum_ += value; } float average; - if (this->queue_.empty()) + if (this->queue_.empty()) { average = 0.0f; - else + } else { average = this->sum_ / this->queue_.size(); + } ESP_LOGVV(TAG, "SlidingWindowMovingAverageFilter(%p)::new_value(%f) -> %f", this, value, average); if (++this->send_at_ % this->send_every_ == 0) { @@ -203,10 +204,11 @@ ExponentialMovingAverageFilter::ExponentialMovingAverageFilter(float alpha, size : send_every_(send_every), send_at_(send_every - 1), alpha_(alpha) {} optional ExponentialMovingAverageFilter::new_value(float value) { if (!std::isnan(value)) { - if (this->first_value_) + if (this->first_value_) { this->accumulator_ = value; - else + } else { this->accumulator_ = (this->alpha_ * value) + (1.0f - this->alpha_) * this->accumulator_; + } this->first_value_ = false; } @@ -274,19 +276,21 @@ FilterOutValueFilter::FilterOutValueFilter(float value_to_filter_out) : value_to optional FilterOutValueFilter::new_value(float value) { if (std::isnan(this->value_to_filter_out_)) { - if (std::isnan(value)) + if (std::isnan(value)) { return {}; - else + } else { return value; + } } else { int8_t accuracy = this->parent_->get_accuracy_decimals(); float accuracy_mult = powf(10.0f, accuracy); float rounded_filter_out = roundf(accuracy_mult * this->value_to_filter_out_); float rounded_value = roundf(accuracy_mult * value); - if (rounded_filter_out == rounded_value) + if (rounded_filter_out == rounded_value) { return {}; - else + } else { return value; + } } } diff --git a/esphome/components/servo/servo.cpp b/esphome/components/servo/servo.cpp index 2e1ba587a2..78fc45c679 100644 --- a/esphome/components/servo/servo.cpp +++ b/esphome/components/servo/servo.cpp @@ -65,10 +65,11 @@ void Servo::write(float value) { void Servo::internal_write(float value) { value = clamp(value, -1.0f, 1.0f); float level; - if (value < 0.0) + if (value < 0.0) { level = lerp(-value, this->idle_level_, this->min_level_); - else + } else { level = lerp(value, this->idle_level_, this->max_level_); + } this->output_->set_level(level); if (this->target_value_ == this->current_value_) { this->save_level_(level); diff --git a/esphome/components/sgp30/sgp30.cpp b/esphome/components/sgp30/sgp30.cpp index 4157fd55cf..b55097fcd0 100644 --- a/esphome/components/sgp30/sgp30.cpp +++ b/esphome/components/sgp30/sgp30.cpp @@ -220,9 +220,10 @@ void SGP30Component::write_iaq_baseline_(uint16_t eco2_baseline, uint16_t tvoc_b data[6] = sht_crc_(data[4], data[5]); if (!this->write_bytes(SGP30_CMD_SET_IAQ_BASELINE >> 8, data, 7)) { ESP_LOGE(TAG, "Error applying eCO2 baseline: 0x%04X, TVOC baseline: 0x%04X", eco2_baseline, tvoc_baseline); - } else + } else { ESP_LOGI(TAG, "Initial baselines applied successfully! eCO2 baseline: 0x%04X, TVOC baseline: 0x%04X", eco2_baseline, tvoc_baseline); + } } void SGP30Component::dump_config() { @@ -315,18 +316,20 @@ uint8_t SGP30Component::sht_crc_(uint8_t data1, uint8_t data2) { crc ^= data1; for (bit = 8; bit > 0; --bit) { - if (crc & 0x80) + if (crc & 0x80) { crc = (crc << 1) ^ 0x131; - else + } else { crc = (crc << 1); + } } crc ^= data2; for (bit = 8; bit > 0; --bit) { - if (crc & 0x80) + if (crc & 0x80) { crc = (crc << 1) ^ 0x131; - else + } else { crc = (crc << 1); + } } return crc; diff --git a/esphome/components/sgp40/sgp40.cpp b/esphome/components/sgp40/sgp40.cpp index da6659c90f..829c00a218 100644 --- a/esphome/components/sgp40/sgp40.cpp +++ b/esphome/components/sgp40/sgp40.cpp @@ -229,10 +229,11 @@ uint8_t SGP40Component::generate_crc_(const uint8_t *data, uint8_t datalen) { for (uint8_t i = 0; i < datalen; i++) { crc ^= data[i]; for (uint8_t b = 0; b < 8; b++) { - if (crc & 0x80) + if (crc & 0x80) { crc = (crc << 1) ^ SGP40_CRC8_POLYNOMIAL; - else + } else { crc <<= 1; + } } } return crc; @@ -303,18 +304,20 @@ uint8_t SGP40Component::sht_crc_(uint8_t data1, uint8_t data2) { crc ^= data1; for (bit = 8; bit > 0; --bit) { - if (crc & 0x80) + if (crc & 0x80) { crc = (crc << 1) ^ 0x131; - else + } else { crc = (crc << 1); + } } crc ^= data2; for (bit = 8; bit > 0; --bit) { - if (crc & 0x80) + if (crc & 0x80) { crc = (crc << 1) ^ 0x131; - else + } else { crc = (crc << 1); + } } return crc; diff --git a/esphome/components/sht3xd/sht3xd.cpp b/esphome/components/sht3xd/sht3xd.cpp index 56a43d5161..e7981b64cf 100644 --- a/esphome/components/sht3xd/sht3xd.cpp +++ b/esphome/components/sht3xd/sht3xd.cpp @@ -82,18 +82,20 @@ uint8_t sht_crc(uint8_t data1, uint8_t data2) { crc ^= data1; for (bit = 8; bit > 0; --bit) { - if (crc & 0x80) + if (crc & 0x80) { crc = (crc << 1) ^ 0x131; - else + } else { crc = (crc << 1); + } } crc ^= data2; for (bit = 8; bit > 0; --bit) { - if (crc & 0x80) + if (crc & 0x80) { crc = (crc << 1) ^ 0x131; - else + } else { crc = (crc << 1); + } } return crc; diff --git a/esphome/components/shtcx/shtcx.cpp b/esphome/components/shtcx/shtcx.cpp index f2fb6bd5c3..867c26df1d 100644 --- a/esphome/components/shtcx/shtcx.cpp +++ b/esphome/components/shtcx/shtcx.cpp @@ -112,18 +112,20 @@ uint8_t sht_crc(uint8_t data1, uint8_t data2) { crc ^= data1; for (bit = 8; bit > 0; --bit) { - if (crc & 0x80) + if (crc & 0x80) { crc = (crc << 1) ^ 0x131; - else + } else { crc = (crc << 1); + } } crc ^= data2; for (bit = 8; bit > 0; --bit) { - if (crc & 0x80) + if (crc & 0x80) { crc = (crc << 1) ^ 0x131; - else + } else { crc = (crc << 1); + } } return crc; diff --git a/esphome/components/socket/bsd_sockets_impl.cpp b/esphome/components/socket/bsd_sockets_impl.cpp index 49bda7683c..6636bcb3eb 100644 --- a/esphome/components/socket/bsd_sockets_impl.cpp +++ b/esphome/components/socket/bsd_sockets_impl.cpp @@ -88,9 +88,10 @@ class BSDSocketImpl : public Socket { for (int i = 0; i < iovcnt; i++) { ssize_t err = this->read(reinterpret_cast(iov[i].iov_base), iov[i].iov_len); if (err == -1) { - if (ret != 0) + if (ret != 0) { // if we already read some don't return an error break; + } return err; } ret += err; @@ -115,9 +116,10 @@ class BSDSocketImpl : public Socket { ssize_t err = this->send(reinterpret_cast(iov[i].iov_base), iov[i].iov_len, i == iovcnt - 1 ? 0 : MSG_MORE); if (err == -1) { - if (ret != 0) + if (ret != 0) { // if we already wrote some don't return an error break; + } return err; } ret += err; diff --git a/esphome/components/spi/spi.cpp b/esphome/components/spi/spi.cpp index d427e2c91b..95280f23b9 100644 --- a/esphome/components/spi/spi.cpp +++ b/esphome/components/spi/spi.cpp @@ -129,10 +129,11 @@ uint8_t HOT SPIComponent::transfer_(uint8_t data) { for (uint8_t i = 0; i < 8; i++) { uint8_t shift; - if (BIT_ORDER == BIT_ORDER_MSB_FIRST) + if (BIT_ORDER == BIT_ORDER_MSB_FIRST) { shift = 7 - i; - else + } else { shift = i; + } if (CLOCK_PHASE == CLOCK_PHASE_LEADING) { // sampling on leading edge diff --git a/esphome/components/sps30/sps30.cpp b/esphome/components/sps30/sps30.cpp index 6160120564..2bd7bcb458 100644 --- a/esphome/components/sps30/sps30.cpp +++ b/esphome/components/sps30/sps30.cpp @@ -216,18 +216,20 @@ uint8_t SPS30Component::sht_crc_(uint8_t data1, uint8_t data2) { crc ^= data1; for (bit = 8; bit > 0; --bit) { - if (crc & 0x80) + if (crc & 0x80) { crc = (crc << 1) ^ 0x131; - else + } else { crc = (crc << 1); + } } crc ^= data2; for (bit = 8; bit > 0; --bit) { - if (crc & 0x80) + if (crc & 0x80) { crc = (crc << 1) ^ 0x131; - else + } else { crc = (crc << 1); + } } return crc; diff --git a/esphome/components/ssd1306_base/ssd1306_base.cpp b/esphome/components/ssd1306_base/ssd1306_base.cpp index 5ff220fce9..2ba990637e 100644 --- a/esphome/components/ssd1306_base/ssd1306_base.cpp +++ b/esphome/components/ssd1306_base/ssd1306_base.cpp @@ -66,10 +66,11 @@ void SSD1306::setup() { if (!this->is_ssd1305_()) { // Enable charge pump (0x8D) this->command(SSD1306_COMMAND_CHARGE_PUMP); - if (this->external_vcc_) + if (this->external_vcc_) { this->command(0x10); - else + } else { this->command(0x14); + } } // Set addressing mode to horizontal (0x20) @@ -105,10 +106,11 @@ void SSD1306::setup() { // Pre-charge period (0xD9) this->command(SSD1306_COMMAND_SET_PRE_CHARGE); - if (this->external_vcc_) + if (this->external_vcc_) { this->command(0x22); - else + } else { this->command(0xF1); + } // Set V_COM (0xDB) this->command(SSD1306_COMMAND_SET_VCOM_DETECT); diff --git a/esphome/components/ssd1325_base/ssd1325_base.cpp b/esphome/components/ssd1325_base/ssd1325_base.cpp index 60e46f573f..711f9e5197 100644 --- a/esphome/components/ssd1325_base/ssd1325_base.cpp +++ b/esphome/components/ssd1325_base/ssd1325_base.cpp @@ -51,24 +51,27 @@ void SSD1325::setup() { this->command(SSD1325_SETCLOCK); // set osc division this->command(0xF1); // 145 this->command(SSD1325_SETMULTIPLEX); // multiplex ratio - if (this->model_ == SSD1327_MODEL_128_128) + if (this->model_ == SSD1327_MODEL_128_128) { this->command(0x7f); // duty = height - 1 - else - this->command(0x3f); // duty = 1/64 + } else { + this->command(0x3f); // duty = 1/64 + } this->command(SSD1325_SETOFFSET); // set display offset - if (this->model_ == SSD1327_MODEL_128_128) + if (this->model_ == SSD1327_MODEL_128_128) { this->command(0x00); // 0 - else - this->command(0x4C); // 76 + } else { + this->command(0x4C); // 76 + } this->command(SSD1325_SETSTARTLINE); // set start line this->command(0x00); // ... this->command(SSD1325_MASTERCONFIG); // Set Master Config DC/DC Converter this->command(0x02); this->command(SSD1325_SETREMAP); // set segment remapping - if (this->model_ == SSD1327_MODEL_128_128) + if (this->model_ == SSD1327_MODEL_128_128) { this->command(0x53); // COM bottom-up, split odd/even, enable column and nibble remapping - else - this->command(0x50); // COM bottom-up, split odd/even + } else { + this->command(0x50); // COM bottom-up, split odd/even + } this->command(SSD1325_SETCURRENT + 0x2); // Set Full Current Range this->command(SSD1325_SETGRAYTABLE); // gamma ~2.2 @@ -122,10 +125,11 @@ void SSD1325::display() { this->command(0x3F); // set column end address this->command(SSD1325_SETROWADDR); // set row address this->command(0x00); // set row start address - if (this->model_ == SSD1327_MODEL_128_128) + if (this->model_ == SSD1327_MODEL_128_128) { this->command(127); // set last row - else + } else { this->command(63); // set last row + } this->write_display_data(); } @@ -135,12 +139,13 @@ void SSD1325::update() { } void SSD1325::set_brightness(float brightness) { // validation - if (brightness > 1) + if (brightness > 1) { this->brightness_ = 1.0; - else if (brightness < 0) + } else if (brightness < 0) { this->brightness_ = 0; - else + } else { this->brightness_ = brightness; + } // now write the new brightness level to the display this->command(SSD1325_SETCONTRAST); this->command(int(SSD1325_MAX_CONTRAST * (this->brightness_))); diff --git a/esphome/components/ssd1331_base/ssd1331_base.cpp b/esphome/components/ssd1331_base/ssd1331_base.cpp index 88764c3d90..14f94dee4f 100644 --- a/esphome/components/ssd1331_base/ssd1331_base.cpp +++ b/esphome/components/ssd1331_base/ssd1331_base.cpp @@ -129,12 +129,13 @@ void HOT SSD1331::draw_absolute_pixel_internal(int x, int y, Color color) { } void SSD1331::fill(Color color) { const uint32_t color565 = display::ColorUtil::color_to_565(color); - for (uint32_t i = 0; i < this->get_buffer_length_(); i++) + for (uint32_t i = 0; i < this->get_buffer_length_(); i++) { if (i & 1) { this->buffer_[i] = color565 & 0xff; } else { this->buffer_[i] = (color565 >> 8) & 0xff; } + } } void SSD1331::init_reset_() { if (this->reset_pin_ != nullptr) { diff --git a/esphome/components/ssd1351_base/ssd1351_base.cpp b/esphome/components/ssd1351_base/ssd1351_base.cpp index f26cd7c697..036a6a0e82 100644 --- a/esphome/components/ssd1351_base/ssd1351_base.cpp +++ b/esphome/components/ssd1351_base/ssd1351_base.cpp @@ -105,12 +105,13 @@ void SSD1351::update() { } void SSD1351::set_brightness(float brightness) { // validation - if (brightness > 1) + if (brightness > 1) { this->brightness_ = 1.0; - else if (brightness < 0) + } else if (brightness < 0) { this->brightness_ = 0; - else + } else { this->brightness_ = brightness; + } // now write the new brightness level to the display this->command(SSD1351_CONTRASTMASTER); this->data(int(SSD1351_MAX_CONTRAST * (this->brightness_))); @@ -157,12 +158,13 @@ void HOT SSD1351::draw_absolute_pixel_internal(int x, int y, Color color) { } void SSD1351::fill(Color color) { const uint32_t color565 = display::ColorUtil::color_to_565(color); - for (uint32_t i = 0; i < this->get_buffer_length_(); i++) + for (uint32_t i = 0; i < this->get_buffer_length_(); i++) { if (i & 1) { this->buffer_[i] = color565 & 0xff; } else { this->buffer_[i] = (color565 >> 8) & 0xff; } + } } void SSD1351::init_reset_() { if (this->reset_pin_ != nullptr) { diff --git a/esphome/components/sts3x/sts3x.cpp b/esphome/components/sts3x/sts3x.cpp index b1ecbc98f8..ce166f2055 100644 --- a/esphome/components/sts3x/sts3x.cpp +++ b/esphome/components/sts3x/sts3x.cpp @@ -78,18 +78,20 @@ uint8_t sts3x_crc(uint8_t data1, uint8_t data2) { crc ^= data1; for (bit = 8; bit > 0; --bit) { - if (crc & 0x80) + if (crc & 0x80) { crc = (crc << 1) ^ 0x131; - else + } else { crc = (crc << 1); + } } crc ^= data2; for (bit = 8; bit > 0; --bit) { - if (crc & 0x80) + if (crc & 0x80) { crc = (crc << 1) ^ 0x131; - else + } else { crc = (crc << 1); + } } return crc; diff --git a/esphome/components/sun/sun.h b/esphome/components/sun/sun.h index 0a2e6bcf97..efc6a1ab0a 100644 --- a/esphome/components/sun/sun.h +++ b/esphome/components/sun/sun.h @@ -110,10 +110,11 @@ template class SunCondition : public Condition, public Pa bool check(Ts... x) override { double elevation = this->elevation_.value(x...); double current = this->parent_->elevation(); - if (this->above_) + if (this->above_) { return current > elevation; - else + } else { return current < elevation; + } } protected: diff --git a/esphome/components/sun/text_sensor/sun_text_sensor.h b/esphome/components/sun/text_sensor/sun_text_sensor.h index e4f5beca9c..ad01d64ff1 100644 --- a/esphome/components/sun/text_sensor/sun_text_sensor.h +++ b/esphome/components/sun/text_sensor/sun_text_sensor.h @@ -16,10 +16,11 @@ class SunTextSensor : public text_sensor::TextSensor, public PollingComponent { void update() override { optional res; - if (this->sunrise_) + if (this->sunrise_) { res = this->parent_->sunrise(this->elevation_); - else + } else { res = this->parent_->sunset(this->elevation_); + } if (!res) { this->publish_state(""); return; diff --git a/esphome/components/sx1509/sx1509.cpp b/esphome/components/sx1509/sx1509.cpp index 9095dfeffa..16540d0dbf 100644 --- a/esphome/components/sx1509/sx1509.cpp +++ b/esphome/components/sx1509/sx1509.cpp @@ -64,10 +64,11 @@ void SX1509Component::digital_write(uint8_t pin, bool bit_value) { // If the pin is an output, write high/low uint16_t temp_reg_data = 0; this->read_byte_16(REG_DATA_B, &temp_reg_data); - if (bit_value) + if (bit_value) { temp_reg_data |= (1 << pin); - else + } else { temp_reg_data &= ~(1 << pin); + } this->write_byte_16(REG_DATA_B, temp_reg_data); } else { // Otherwise the pin is an input, pull-up/down @@ -94,10 +95,11 @@ void SX1509Component::digital_write(uint8_t pin, bool bit_value) { void SX1509Component::pin_mode(uint8_t pin, gpio::Flags flags) { this->read_byte_16(REG_DIR_B, &this->ddr_mask_); - if (flags == gpio::FLAG_OUTPUT) + if (flags == gpio::FLAG_OUTPUT) { this->ddr_mask_ &= ~(1 << pin); - else + } else { this->ddr_mask_ |= (1 << pin); + } this->write_byte_16(REG_DIR_B, this->ddr_mask_); if (flags & gpio::FLAG_PULLUP) diff --git a/esphome/components/tcl112/tcl112.cpp b/esphome/components/tcl112/tcl112.cpp index e05a07873e..a88e8e96a7 100644 --- a/esphome/components/tcl112/tcl112.cpp +++ b/esphome/components/tcl112/tcl112.cpp @@ -79,11 +79,12 @@ void Tcl112Climate::transmit_state() { safecelsius = std::min(safecelsius, TCL112_TEMP_MAX); // Convert to integer nr. of half degrees. auto half_degrees = static_cast(safecelsius * 2); - if (half_degrees & 1) // Do we have a half degree celsius? + if (half_degrees & 1) { // Do we have a half degree celsius? remote_state[12] |= TCL112_HALF_DEGREE; // Add 0.5 degrees - else + } else { remote_state[12] &= ~TCL112_HALF_DEGREE; // Clear the half degree. - remote_state[7] &= 0xF0; // Clear temp bits. + } + remote_state[7] &= 0xF0; // Clear temp bits. remote_state[7] |= ((uint8_t) TCL112_TEMP_MAX - half_degrees / 2); // Set fan @@ -128,12 +129,13 @@ void Tcl112Climate::transmit_state() { data->mark(TCL112_HEADER_MARK); data->space(TCL112_HEADER_SPACE); // Data - for (uint8_t i : remote_state) + for (uint8_t i : remote_state) { for (uint8_t j = 0; j < 8; j++) { data->mark(TCL112_BIT_MARK); bool bit = i & (1 << j); data->space(bit ? TCL112_ONE_SPACE : TCL112_ZERO_SPACE); } + } // Footer data->mark(TCL112_BIT_MARK); data->space(TCL112_GAP); @@ -153,9 +155,9 @@ bool Tcl112Climate::on_receive(remote_base::RemoteReceiveData data) { for (int i = 0; i < TCL112_STATE_LENGTH; i++) { // Read bit for (int j = 0; j < 8; j++) { - if (data.expect_item(TCL112_BIT_MARK, TCL112_ONE_SPACE)) + if (data.expect_item(TCL112_BIT_MARK, TCL112_ONE_SPACE)) { remote_state[i] |= 1 << j; - else if (!data.expect_item(TCL112_BIT_MARK, TCL112_ZERO_SPACE)) { + } else if (!data.expect_item(TCL112_BIT_MARK, TCL112_ZERO_SPACE)) { ESP_LOGVV(TAG, "Byte %d bit %d fail", i, j); return false; } diff --git a/esphome/components/template/number/template_number.cpp b/esphome/components/template/number/template_number.cpp index a5b015c44d..aaf5b27a71 100644 --- a/esphome/components/template/number/template_number.cpp +++ b/esphome/components/template/number/template_number.cpp @@ -16,10 +16,11 @@ void TemplateNumber::setup() { } else { this->pref_ = global_preferences->make_preference(this->get_object_id_hash()); if (!this->pref_.load(&value)) { - if (!std::isnan(this->initial_value_)) + if (!std::isnan(this->initial_value_)) { value = this->initial_value_; - else + } else { value = this->traits.get_min_value(); + } } } this->publish_state(value); diff --git a/esphome/components/text_sensor/filter.cpp b/esphome/components/text_sensor/filter.cpp index c6cbcd7c1e..ba77913d1b 100644 --- a/esphome/components/text_sensor/filter.cpp +++ b/esphome/components/text_sensor/filter.cpp @@ -64,9 +64,10 @@ optional PrependFilter::new_value(std::string value) { return this- // Substitute optional SubstituteFilter::new_value(std::string value) { std::size_t pos; - for (size_t i = 0; i < this->from_strings_.size(); i++) + for (size_t i = 0; i < this->from_strings_.size(); i++) { while ((pos = value.find(this->from_strings_[i])) != std::string::npos) value.replace(pos, this->from_strings_[i].size(), this->to_strings_[i]); + } return value; } diff --git a/esphome/components/thermostat/thermostat_climate.cpp b/esphome/components/thermostat/thermostat_climate.cpp index ce15c53bbe..760525e2cd 100644 --- a/esphome/components/thermostat/thermostat_climate.cpp +++ b/esphome/components/thermostat/thermostat_climate.cpp @@ -129,9 +129,10 @@ void ThermostatClimate::validate_target_temperature_low() { this->target_temperature_low = this->get_traits().get_visual_min_temperature(); // target_temperature_low must not be greater than the visual maximum minus set_point_minimum_differential_ if (this->target_temperature_low > - this->get_traits().get_visual_max_temperature() - this->set_point_minimum_differential_) + this->get_traits().get_visual_max_temperature() - this->set_point_minimum_differential_) { this->target_temperature_low = this->get_traits().get_visual_max_temperature() - this->set_point_minimum_differential_; + } // if target_temperature_low is set greater than target_temperature_high, move up target_temperature_high if (this->target_temperature_low > this->target_temperature_high - this->set_point_minimum_differential_) this->target_temperature_high = this->target_temperature_low + this->set_point_minimum_differential_; @@ -147,9 +148,10 @@ void ThermostatClimate::validate_target_temperature_high() { this->target_temperature_high = this->get_traits().get_visual_max_temperature(); // target_temperature_high must not be lower than the visual minimum plus set_point_minimum_differential_ if (this->target_temperature_high < - this->get_traits().get_visual_min_temperature() + this->set_point_minimum_differential_) + this->get_traits().get_visual_min_temperature() + this->set_point_minimum_differential_) { this->target_temperature_high = this->get_traits().get_visual_min_temperature() + this->set_point_minimum_differential_; + } // if target_temperature_high is set less than target_temperature_low, move down target_temperature_low if (this->target_temperature_high < this->target_temperature_low + this->set_point_minimum_differential_) this->target_temperature_low = this->target_temperature_high - this->set_point_minimum_differential_; @@ -348,9 +350,10 @@ climate::ClimateAction ThermostatClimate::compute_supplemental_action_() { void ThermostatClimate::switch_to_action_(climate::ClimateAction action, bool publish_state) { // setup_complete_ helps us ensure an action is called immediately after boot - if ((action == this->action) && this->setup_complete_) + if ((action == this->action) && this->setup_complete_) { // already in target mode return; + } if (((action == climate::CLIMATE_ACTION_OFF && this->action == climate::CLIMATE_ACTION_IDLE) || (action == climate::CLIMATE_ACTION_IDLE && this->action == climate::CLIMATE_ACTION_OFF)) && @@ -373,10 +376,11 @@ void ThermostatClimate::switch_to_action_(climate::ClimateAction action, bool pu if (this->action == climate::CLIMATE_ACTION_COOLING) this->start_timer_(thermostat::TIMER_COOLING_OFF); if (this->action == climate::CLIMATE_ACTION_FAN) { - if (this->supports_fan_only_action_uses_fan_mode_timer_) + if (this->supports_fan_only_action_uses_fan_mode_timer_) { this->start_timer_(thermostat::TIMER_FAN_MODE); - else + } else { this->start_timer_(thermostat::TIMER_FANNING_OFF); + } } if (this->action == climate::CLIMATE_ACTION_HEATING) this->start_timer_(thermostat::TIMER_HEATING_OFF); @@ -415,10 +419,11 @@ void ThermostatClimate::switch_to_action_(climate::ClimateAction action, bool pu break; case climate::CLIMATE_ACTION_FAN: if (this->fanning_action_ready_()) { - if (this->supports_fan_only_action_uses_fan_mode_timer_) + if (this->supports_fan_only_action_uses_fan_mode_timer_) { this->start_timer_(thermostat::TIMER_FAN_MODE); - else + } else { this->start_timer_(thermostat::TIMER_FANNING_ON); + } trig = this->fan_only_action_trigger_; ESP_LOGVV(TAG, "Switching to FAN_ONLY action"); action_ready = true; @@ -461,9 +466,10 @@ void ThermostatClimate::switch_to_action_(climate::ClimateAction action, bool pu void ThermostatClimate::switch_to_supplemental_action_(climate::ClimateAction action) { // setup_complete_ helps us ensure an action is called immediately after boot - if ((action == this->supplemental_action_) && this->setup_complete_) + if ((action == this->supplemental_action_) && this->setup_complete_) { // already in target mode return; + } switch (action) { case climate::CLIMATE_ACTION_OFF: @@ -515,9 +521,10 @@ void ThermostatClimate::trigger_supplemental_action_() { void ThermostatClimate::switch_to_fan_mode_(climate::ClimateFanMode fan_mode, bool publish_state) { // setup_complete_ helps us ensure an action is called immediately after boot - if ((fan_mode == this->prev_fan_mode_) && this->setup_complete_) + if ((fan_mode == this->prev_fan_mode_) && this->setup_complete_) { // already in target mode return; + } this->fan_mode = fan_mode; if (publish_state) @@ -582,9 +589,10 @@ void ThermostatClimate::switch_to_fan_mode_(climate::ClimateFanMode fan_mode, bo void ThermostatClimate::switch_to_mode_(climate::ClimateMode mode, bool publish_state) { // setup_complete_ helps us ensure an action is called immediately after boot - if ((mode == this->prev_mode_) && this->setup_complete_) + if ((mode == this->prev_mode_) && this->setup_complete_) { // already in target mode return; + } if (this->prev_mode_trigger_ != nullptr) { this->prev_mode_trigger_->stop_action(); @@ -627,9 +635,10 @@ void ThermostatClimate::switch_to_mode_(climate::ClimateMode mode, bool publish_ void ThermostatClimate::switch_to_swing_mode_(climate::ClimateSwingMode swing_mode, bool publish_state) { // setup_complete_ helps us ensure an action is called immediately after boot - if ((swing_mode == this->prev_swing_mode_) && this->setup_complete_) + if ((swing_mode == this->prev_swing_mode_) && this->setup_complete_) { // already in target mode return; + } if (this->prev_swing_mode_trigger_ != nullptr) { this->prev_swing_mode_trigger_->stop_action(); @@ -1107,16 +1116,18 @@ Trigger<> *ThermostatClimate::get_temperature_change_trigger() const { return th void ThermostatClimate::dump_config() { LOG_CLIMATE("", "Thermostat", this); if (this->supports_heat_) { - if (this->supports_two_points_) + if (this->supports_two_points_) { ESP_LOGCONFIG(TAG, " Default Target Temperature Low: %.1f°C", this->normal_config_.default_temperature_low); - else + } else { ESP_LOGCONFIG(TAG, " Default Target Temperature Low: %.1f°C", this->normal_config_.default_temperature); + } } if ((this->supports_cool_) || (this->supports_fan_only_ && this->supports_fan_only_cooling_)) { - if (this->supports_two_points_) + if (this->supports_two_points_) { ESP_LOGCONFIG(TAG, " Default Target Temperature High: %.1f°C", this->normal_config_.default_temperature_high); - else + } else { ESP_LOGCONFIG(TAG, " Default Target Temperature High: %.1f°C", this->normal_config_.default_temperature); + } } if (this->supports_two_points_) ESP_LOGCONFIG(TAG, " Minimum Set Point Differential: %.1f°C", this->set_point_minimum_differential_); @@ -1186,18 +1197,20 @@ void ThermostatClimate::dump_config() { ESP_LOGCONFIG(TAG, " Supports AWAY mode: %s", YESNO(this->supports_away_)); if (this->supports_away_) { if (this->supports_heat_) { - if (this->supports_two_points_) + if (this->supports_two_points_) { ESP_LOGCONFIG(TAG, " Away Default Target Temperature Low: %.1f°C", this->away_config_.default_temperature_low); - else + } else { ESP_LOGCONFIG(TAG, " Away Default Target Temperature Low: %.1f°C", this->away_config_.default_temperature); + } } if ((this->supports_cool_) || (this->supports_fan_only_)) { - if (this->supports_two_points_) + if (this->supports_two_points_) { ESP_LOGCONFIG(TAG, " Away Default Target Temperature High: %.1f°C", this->away_config_.default_temperature_high); - else + } else { ESP_LOGCONFIG(TAG, " Away Default Target Temperature High: %.1f°C", this->away_config_.default_temperature); + } } } } diff --git a/esphome/components/tm1637/tm1637.cpp b/esphome/components/tm1637/tm1637.cpp index a21d2d438d..44f0a841b8 100644 --- a/esphome/components/tm1637/tm1637.cpp +++ b/esphome/components/tm1637/tm1637.cpp @@ -202,10 +202,11 @@ bool TM1637Display::send_byte_(uint8_t b) { this->bit_delay_(); // Set data bit - if (data & 0x01) + if (data & 0x01) { this->dio_pin_->pin_mode(gpio::FLAG_INPUT); - else + } else { this->dio_pin_->pin_mode(gpio::FLAG_OUTPUT); + } this->bit_delay_(); diff --git a/esphome/components/toshiba/toshiba.cpp b/esphome/components/toshiba/toshiba.cpp index a6af3b1015..c7a5b72852 100644 --- a/esphome/components/toshiba/toshiba.cpp +++ b/esphome/components/toshiba/toshiba.cpp @@ -542,10 +542,11 @@ bool ToshibaClimate::on_receive(remote_base::RemoteReceiveData data) { // case RAC_PT1411HWRU_MODE_DRY: case RAC_PT1411HWRU_MODE_FAN: - if ((message[4] >> 4) == RAC_PT1411HWRU_TEMPERATURE_FAN_ONLY) + if ((message[4] >> 4) == RAC_PT1411HWRU_TEMPERATURE_FAN_ONLY) { this->mode = climate::CLIMATE_MODE_FAN_ONLY; - else + } else { this->mode = climate::CLIMATE_MODE_DRY; + } break; case RAC_PT1411HWRU_MODE_HEAT: diff --git a/esphome/components/tuya/light/tuya_light.cpp b/esphome/components/tuya/light/tuya_light.cpp index ecd3802839..7facc52946 100644 --- a/esphome/components/tuya/light/tuya_light.cpp +++ b/esphome/components/tuya/light/tuya_light.cpp @@ -71,31 +71,34 @@ void TuyaLight::dump_config() { ESP_LOGCONFIG(TAG, " Dimmer has datapoint ID %u", *this->dimmer_id_); if (this->switch_id_.has_value()) ESP_LOGCONFIG(TAG, " Switch has datapoint ID %u", *this->switch_id_); - if (this->rgb_id_.has_value()) + if (this->rgb_id_.has_value()) { ESP_LOGCONFIG(TAG, " RGB has datapoint ID %u", *this->rgb_id_); - else if (this->hsv_id_.has_value()) + } else if (this->hsv_id_.has_value()) { ESP_LOGCONFIG(TAG, " HSV has datapoint ID %u", *this->hsv_id_); + } } light::LightTraits TuyaLight::get_traits() { auto traits = light::LightTraits(); if (this->color_temperature_id_.has_value() && this->dimmer_id_.has_value()) { if (this->rgb_id_.has_value() || this->hsv_id_.has_value()) { - if (this->color_interlock_) + if (this->color_interlock_) { traits.set_supported_color_modes({light::ColorMode::RGB, light::ColorMode::COLOR_TEMPERATURE}); - else + } else { traits.set_supported_color_modes( {light::ColorMode::RGB_COLOR_TEMPERATURE, light::ColorMode::COLOR_TEMPERATURE}); + } } 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->rgb_id_.has_value() || this->hsv_id_.has_value()) { if (this->dimmer_id_.has_value()) { - if (this->color_interlock_) + if (this->color_interlock_) { traits.set_supported_color_modes({light::ColorMode::RGB, light::ColorMode::WHITE}); - else + } else { traits.set_supported_color_modes({light::ColorMode::RGB_WHITE}); + } } else traits.set_supported_color_modes({light::ColorMode::RGB}); } else if (this->dimmer_id_.has_value()) { diff --git a/esphome/components/tuya/tuya.cpp b/esphome/components/tuya/tuya.cpp index 50565fae0a..f2dceed33f 100644 --- a/esphome/components/tuya/tuya.cpp +++ b/esphome/components/tuya/tuya.cpp @@ -33,20 +33,21 @@ void Tuya::dump_config() { return; } for (auto &info : this->datapoints_) { - if (info.type == TuyaDatapointType::RAW) + if (info.type == TuyaDatapointType::RAW) { ESP_LOGCONFIG(TAG, " Datapoint %u: raw (value: %s)", info.id, format_hex_pretty(info.value_raw).c_str()); - else if (info.type == TuyaDatapointType::BOOLEAN) + } else if (info.type == TuyaDatapointType::BOOLEAN) { ESP_LOGCONFIG(TAG, " Datapoint %u: switch (value: %s)", info.id, ONOFF(info.value_bool)); - else if (info.type == TuyaDatapointType::INTEGER) + } else if (info.type == TuyaDatapointType::INTEGER) { ESP_LOGCONFIG(TAG, " Datapoint %u: int value (value: %d)", info.id, info.value_int); - else if (info.type == TuyaDatapointType::STRING) + } else if (info.type == TuyaDatapointType::STRING) { ESP_LOGCONFIG(TAG, " Datapoint %u: string value (value: %s)", info.id, info.value_string.c_str()); - else if (info.type == TuyaDatapointType::ENUM) + } else if (info.type == TuyaDatapointType::ENUM) { ESP_LOGCONFIG(TAG, " Datapoint %u: enum (value: %d)", info.id, info.value_enum); - else if (info.type == TuyaDatapointType::BITMASK) + } else if (info.type == TuyaDatapointType::BITMASK) { ESP_LOGCONFIG(TAG, " Datapoint %u: bitmask (value: %x)", info.id, info.value_bitmask); - else + } else { ESP_LOGCONFIG(TAG, " Datapoint %u: unknown", info.id); + } } if ((this->gpio_status_ != -1) || (this->gpio_reset_ != -1)) { ESP_LOGCONFIG(TAG, " GPIO Configuration: status: pin %d, reset: pin %d (not supported)", this->gpio_status_, @@ -80,9 +81,10 @@ bool Tuya::validate_message_() { // Byte 4: LENGTH1 // Byte 5: LENGTH2 - if (at <= 5) + if (at <= 5) { // no validation for these fields return true; + } uint16_t length = (uint16_t(data[4]) << 8) | (uint16_t(data[5])); @@ -318,9 +320,10 @@ void Tuya::handle_datapoint_(const uint8_t *buffer, size_t len) { } // Run through listeners - for (auto &listener : this->listeners_) + for (auto &listener : this->listeners_) { if (listener.datapoint_id == datapoint.id) listener.on_datapoint(datapoint); + } } void Tuya::send_raw_command_(TuyaCommand command) { @@ -488,9 +491,10 @@ void Tuya::force_set_bitmask_datapoint_value(uint8_t datapoint_id, uint32_t valu } optional Tuya::get_datapoint_(uint8_t datapoint_id) { - for (auto &datapoint : this->datapoints_) + for (auto &datapoint : this->datapoints_) { if (datapoint.id == datapoint_id) return datapoint; + } return {}; } @@ -578,9 +582,10 @@ void Tuya::register_listener(uint8_t datapoint_id, const std::functionlisteners_.push_back(listener); // Run through existing datapoints - for (auto &datapoint : this->datapoints_) + for (auto &datapoint : this->datapoints_) { if (datapoint.id == datapoint_id) func(datapoint); + } } TuyaInitState Tuya::get_init_state() { return this->init_state_; } diff --git a/esphome/components/uart/uart_component_esp32_arduino.cpp b/esphome/components/uart/uart_component_esp32_arduino.cpp index 95cdde4a43..a67e5354fb 100644 --- a/esphome/components/uart/uart_component_esp32_arduino.cpp +++ b/esphome/components/uart/uart_component_esp32_arduino.cpp @@ -41,10 +41,11 @@ uint32_t ESP32ArduinoUARTComponent::get_config() { * tick_ref_always_on:27 select the clock.1:apb clock:ref_tick */ - if (this->parity_ == UART_CONFIG_PARITY_EVEN) + if (this->parity_ == UART_CONFIG_PARITY_EVEN) { config |= UART_PARITY_EVEN | UART_PARITY_ENABLE; - else if (this->parity_ == UART_CONFIG_PARITY_ODD) + } else if (this->parity_ == UART_CONFIG_PARITY_ODD) { config |= UART_PARITY_ODD | UART_PARITY_ENABLE; + } switch (this->data_bits_) { case 5: @@ -61,10 +62,11 @@ uint32_t ESP32ArduinoUARTComponent::get_config() { break; } - if (this->stop_bits_ == 1) + if (this->stop_bits_ == 1) { config |= UART_NB_STOP_BIT_1; - else + } else { config |= UART_NB_STOP_BIT_2; + } config |= UART_TICK_APB_CLOCK; diff --git a/esphome/components/uart/uart_component_esp8266.cpp b/esphome/components/uart/uart_component_esp8266.cpp index 370adad779..529108f439 100644 --- a/esphome/components/uart/uart_component_esp8266.cpp +++ b/esphome/components/uart/uart_component_esp8266.cpp @@ -18,12 +18,13 @@ bool ESP8266UartComponent::serial0_in_use = false; // NOLINT(cppcoreguidelines- uint32_t ESP8266UartComponent::get_config() { uint32_t config = 0; - if (this->parity_ == UART_CONFIG_PARITY_NONE) + if (this->parity_ == UART_CONFIG_PARITY_NONE) { config |= UART_PARITY_NONE; - else if (this->parity_ == UART_CONFIG_PARITY_EVEN) + } else if (this->parity_ == UART_CONFIG_PARITY_EVEN) { config |= UART_PARITY_EVEN; - else if (this->parity_ == UART_CONFIG_PARITY_ODD) + } else if (this->parity_ == UART_CONFIG_PARITY_ODD) { config |= UART_PARITY_ODD; + } switch (this->data_bits_) { case 5: @@ -40,10 +41,11 @@ uint32_t ESP8266UartComponent::get_config() { break; } - if (this->stop_bits_ == 1) + if (this->stop_bits_ == 1) { config |= UART_NB_STOP_BIT_1; - else + } else { config |= UART_NB_STOP_BIT_2; + } if (this->tx_pin_ != nullptr && this->tx_pin_->is_inverted()) config |= BIT(22); @@ -234,12 +236,13 @@ void IRAM_ATTR HOT ESP8266SoftwareSerial::write_byte(uint8_t data) { } bool parity_bit = false; bool need_parity_bit = true; - if (this->parity_ == UART_CONFIG_PARITY_EVEN) + if (this->parity_ == UART_CONFIG_PARITY_EVEN) { parity_bit = false; - else if (this->parity_ == UART_CONFIG_PARITY_ODD) + } else if (this->parity_ == UART_CONFIG_PARITY_ODD) { parity_bit = true; - else + } else { need_parity_bit = false; + } { InterruptLock lock; diff --git a/esphome/components/uart/uart_component_esp_idf.cpp b/esphome/components/uart/uart_component_esp_idf.cpp index 4d6a6af0fc..80255ccddf 100644 --- a/esphome/components/uart/uart_component_esp_idf.cpp +++ b/esphome/components/uart/uart_component_esp_idf.cpp @@ -16,10 +16,11 @@ static const char *const TAG = "uart.idf"; uart_config_t IDFUARTComponent::get_config_() { uart_parity_t parity = UART_PARITY_DISABLE; - if (this->parity_ == UART_CONFIG_PARITY_EVEN) + if (this->parity_ == UART_CONFIG_PARITY_EVEN) { parity = UART_PARITY_EVEN; - else if (this->parity_ == UART_CONFIG_PARITY_ODD) + } else if (this->parity_ == UART_CONFIG_PARITY_ODD) { parity = UART_PARITY_ODD; + } uart_word_length_t data_bits; switch (this->data_bits_) { @@ -141,9 +142,9 @@ bool IDFUARTComponent::peek_byte(uint8_t *data) { if (!this->check_read_timeout_()) return false; xSemaphoreTake(this->lock_, portMAX_DELAY); - if (this->has_peek_) + if (this->has_peek_) { *data = this->peek_byte_; - else { + } else { int len = uart_read_bytes(this->uart_num_, data, 1, 20 / portTICK_RATE_MS); if (len == 0) { *data = 0; diff --git a/esphome/components/vl53l0x/vl53l0x_sensor.cpp b/esphome/components/vl53l0x/vl53l0x_sensor.cpp index d68d69b79c..171484f6f2 100644 --- a/esphome/components/vl53l0x/vl53l0x_sensor.cpp +++ b/esphome/components/vl53l0x/vl53l0x_sensor.cpp @@ -124,10 +124,11 @@ void VL53L0XSensor::setup() { uint8_t &val = ref_spad_map[i / 8]; uint8_t mask = 1 << (i % 8); - if (i < first_spad_to_enable || spads_enabled == spad_count) + if (i < first_spad_to_enable || spads_enabled == spad_count) { val &= ~mask; - else if (val & mask) + } else if (val & mask) { spads_enabled += 1; + } } this->write_bytes(0xB0, ref_spad_map, 6); diff --git a/esphome/components/vl53l0x/vl53l0x_sensor.h b/esphome/components/vl53l0x/vl53l0x_sensor.h index a2e24e7550..85b5e3b31d 100644 --- a/esphome/components/vl53l0x/vl53l0x_sensor.h +++ b/esphome/components/vl53l0x/vl53l0x_sensor.h @@ -60,10 +60,11 @@ class VL53L0XSensor : public sensor::Sensor, public PollingComponent, public i2c if (enables.tcc) budget_us += (timeouts.msrc_dss_tcc_us + tcc_overhead); - if (enables.dss) + if (enables.dss) { budget_us += 2 * (timeouts.msrc_dss_tcc_us + dss_overhead); - else if (enables.msrc) + } else if (enables.msrc) { budget_us += (timeouts.msrc_dss_tcc_us + msrc_overhead); + } if (enables.pre_range) budget_us += (timeouts.pre_range_us + pre_range_overhead); @@ -191,12 +192,13 @@ class VL53L0XSensor : public sensor::Sensor, public PollingComponent, public i2c uint8_t get_vcsel_pulse_period_(VcselPeriodType type) { uint8_t vcsel; - if (type == VCSEL_PERIOD_PRE_RANGE) + if (type == VCSEL_PERIOD_PRE_RANGE) { vcsel = reg(0x50).get(); - else if (type == VCSEL_PERIOD_FINAL_RANGE) + } else if (type == VCSEL_PERIOD_FINAL_RANGE) { vcsel = reg(0x70).get(); - else + } else { return 255; + } return (vcsel + 1) << 1; } diff --git a/esphome/components/waveshare_epaper/waveshare_epaper.cpp b/esphome/components/waveshare_epaper/waveshare_epaper.cpp index 322c375f0e..b2d2d92bb2 100644 --- a/esphome/components/waveshare_epaper/waveshare_epaper.cpp +++ b/esphome/components/waveshare_epaper/waveshare_epaper.cpp @@ -140,10 +140,11 @@ void HOT WaveshareEPaper::draw_absolute_pixel_internal(int x, int y, Color color const uint32_t pos = (x + y * this->get_width_internal()) / 8u; const uint8_t subpos = x & 0x07; // flip logic - if (!color.is_on()) + if (!color.is_on()) { this->buffer_[pos] |= 0x80 >> subpos; - else + } else { this->buffer_[pos] &= ~(0x80 >> subpos); + } } uint32_t WaveshareEPaper::get_buffer_length_() { return this->get_width_internal() * this->get_height_internal() / 8u; } void WaveshareEPaper::start_command_() { @@ -901,18 +902,20 @@ void HOT WaveshareEPaper5P8In::display() { uint8_t temp1 = this->buffer_[i]; for (uint8_t j = 0; j < 8; j++) { uint8_t temp2; - if (temp1 & 0x80) + if (temp1 & 0x80) { temp2 = 0x03; - else + } else { temp2 = 0x00; + } temp2 <<= 4; temp1 <<= 1; j++; - if (temp1 & 0x80) + if (temp1 & 0x80) { temp2 |= 0x03; - else + } else { temp2 |= 0x00; + } temp1 <<= 1; this->write_byte(temp2); } @@ -984,17 +987,19 @@ void HOT WaveshareEPaper7P5In::display() { uint8_t temp1 = this->buffer_[i]; for (uint8_t j = 0; j < 8; j++) { uint8_t temp2; - if (temp1 & 0x80) + if (temp1 & 0x80) { temp2 = 0x03; - else + } else { temp2 = 0x00; + } temp2 <<= 4; temp1 <<= 1; j++; - if (temp1 & 0x80) + if (temp1 & 0x80) { temp2 |= 0x03; - else + } else { temp2 |= 0x00; + } temp1 <<= 1; this->write_byte(temp2); } @@ -1187,10 +1192,11 @@ void HOT WaveshareEPaper2P13InDKE::display() { bool partial = this->at_update_ != 0; this->at_update_ = (this->at_update_ + 1) % this->full_update_every_; - if (partial) + if (partial) { ESP_LOGI(TAG, "Performing partial e-paper update."); - else + } else { ESP_LOGI(TAG, "Performing full e-paper update."); + } // start and set up data format this->command(0x12); diff --git a/esphome/components/web_server/web_server.cpp b/esphome/components/web_server/web_server.cpp index a7dbcd4b85..83b6ca1e2f 100644 --- a/esphome/components/web_server/web_server.cpp +++ b/esphome/components/web_server/web_server.cpp @@ -91,64 +91,74 @@ void WebServer::setup() { client->send("", "ping", millis(), 30000); #ifdef USE_SENSOR - for (auto *obj : App.get_sensors()) + for (auto *obj : App.get_sensors()) { if (this->include_internal_ || !obj->is_internal()) client->send(this->sensor_json(obj, obj->state).c_str(), "state"); + } #endif #ifdef USE_SWITCH - for (auto *obj : App.get_switches()) + for (auto *obj : App.get_switches()) { if (this->include_internal_ || !obj->is_internal()) client->send(this->switch_json(obj, obj->state).c_str(), "state"); + } #endif #ifdef USE_BINARY_SENSOR - for (auto *obj : App.get_binary_sensors()) + for (auto *obj : App.get_binary_sensors()) { if (this->include_internal_ || !obj->is_internal()) client->send(this->binary_sensor_json(obj, obj->state).c_str(), "state"); + } #endif #ifdef USE_FAN - for (auto *obj : App.get_fans()) + for (auto *obj : App.get_fans()) { if (this->include_internal_ || !obj->is_internal()) client->send(this->fan_json(obj).c_str(), "state"); + } #endif #ifdef USE_LIGHT - for (auto *obj : App.get_lights()) + for (auto *obj : App.get_lights()) { if (this->include_internal_ || !obj->is_internal()) client->send(this->light_json(obj).c_str(), "state"); + } #endif #ifdef USE_TEXT_SENSOR - for (auto *obj : App.get_text_sensors()) + for (auto *obj : App.get_text_sensors()) { if (this->include_internal_ || !obj->is_internal()) client->send(this->text_sensor_json(obj, obj->state).c_str(), "state"); + } #endif #ifdef USE_COVER - for (auto *obj : App.get_covers()) + for (auto *obj : App.get_covers()) { if (this->include_internal_ || !obj->is_internal()) client->send(this->cover_json(obj).c_str(), "state"); + } #endif #ifdef USE_NUMBER - for (auto *obj : App.get_numbers()) + for (auto *obj : App.get_numbers()) { if (this->include_internal_ || !obj->is_internal()) client->send(this->number_json(obj, obj->state).c_str(), "state"); + } #endif #ifdef USE_SELECT - for (auto *obj : App.get_selects()) + for (auto *obj : App.get_selects()) { if (this->include_internal_ || !obj->is_internal()) client->send(this->select_json(obj, obj->state).c_str(), "state"); + } #endif }); #ifdef USE_LOGGER - if (logger::global_logger != nullptr) + if (logger::global_logger != nullptr) { logger::global_logger->add_on_log_callback( [this](int level, const char *tag, const char *message) { this->events_.send(message, "log", millis()); }); + } #endif this->base_->add_handler(&this->events_); this->base_->add_handler(this); @@ -187,15 +197,17 @@ void WebServer::handle_index_request(AsyncWebServerRequest *request) { stream->addHeader("Access-Control-Allow-Origin", "*"); #ifdef USE_SENSOR - for (auto *obj : App.get_sensors()) + for (auto *obj : App.get_sensors()) { if (this->include_internal_ || !obj->is_internal()) write_row(stream, obj, "sensor", ""); + } #endif #ifdef USE_SWITCH - for (auto *obj : App.get_switches()) + for (auto *obj : App.get_switches()) { if (this->include_internal_ || !obj->is_internal()) write_row(stream, obj, "switch", ""); + } #endif #ifdef USE_BUTTON @@ -204,38 +216,43 @@ void WebServer::handle_index_request(AsyncWebServerRequest *request) { #endif #ifdef USE_BINARY_SENSOR - for (auto *obj : App.get_binary_sensors()) + for (auto *obj : App.get_binary_sensors()) { if (this->include_internal_ || !obj->is_internal()) write_row(stream, obj, "binary_sensor", ""); + } #endif #ifdef USE_FAN - for (auto *obj : App.get_fans()) + for (auto *obj : App.get_fans()) { if (this->include_internal_ || !obj->is_internal()) write_row(stream, obj, "fan", ""); + } #endif #ifdef USE_LIGHT - for (auto *obj : App.get_lights()) + for (auto *obj : App.get_lights()) { if (this->include_internal_ || !obj->is_internal()) write_row(stream, obj, "light", ""); + } #endif #ifdef USE_TEXT_SENSOR - for (auto *obj : App.get_text_sensors()) + for (auto *obj : App.get_text_sensors()) { if (this->include_internal_ || !obj->is_internal()) write_row(stream, obj, "text_sensor", ""); + } #endif #ifdef USE_COVER - for (auto *obj : App.get_covers()) + for (auto *obj : App.get_covers()) { if (this->include_internal_ || !obj->is_internal()) write_row(stream, obj, "cover", ""); + } #endif #ifdef USE_NUMBER - for (auto *obj : App.get_numbers()) - if (this->include_internal_ || !obj->is_internal()) + for (auto *obj : App.get_numbers()) { + if (this->include_internal_ || !obj->is_internal()) { write_row(stream, obj, "number", "", [](AsyncResponseStream &stream, EntityBase *obj) { number::Number *number = (number::Number *) obj; stream.print(R"(state); stream.print(R"("/>)"); }); + } + } #endif #ifdef USE_SELECT - for (auto *obj : App.get_selects()) - if (this->include_internal_ || !obj->is_internal()) + for (auto *obj : App.get_selects()) { + if (this->include_internal_ || !obj->is_internal()) { write_row(stream, obj, "select", "", [](AsyncResponseStream &stream, EntityBase *obj) { select::Select *select = (select::Select *) obj; stream.print(""); }); + } + } #endif stream->print(F("

See ESPHome Web API for " diff --git a/esphome/components/whirlpool/whirlpool.cpp b/esphome/components/whirlpool/whirlpool.cpp index 61ffffa192..f354ab070d 100644 --- a/esphome/components/whirlpool/whirlpool.cpp +++ b/esphome/components/whirlpool/whirlpool.cpp @@ -164,10 +164,10 @@ bool WhirlpoolClimate::on_receive(remote_base::RemoteReceiveData data) { return false; } for (int j = 0; j < 8; j++) { - if (data.expect_item(WHIRLPOOL_BIT_MARK, WHIRLPOOL_ONE_SPACE)) + if (data.expect_item(WHIRLPOOL_BIT_MARK, WHIRLPOOL_ONE_SPACE)) { remote_state[i] |= 1 << j; - else if (!data.expect_item(WHIRLPOOL_BIT_MARK, WHIRLPOOL_ZERO_SPACE)) { + } else if (!data.expect_item(WHIRLPOOL_BIT_MARK, WHIRLPOOL_ZERO_SPACE)) { ESP_LOGV(TAG, "Byte %d bit %d fail", i, j); return false; } diff --git a/esphome/components/wifi/wifi_component.cpp b/esphome/components/wifi/wifi_component.cpp index 36944e3633..1348b54b37 100644 --- a/esphome/components/wifi/wifi_component.cpp +++ b/esphome/components/wifi/wifi_component.cpp @@ -78,9 +78,10 @@ void WiFiComponent::setup() { #endif } #ifdef USE_IMPROV - if (esp32_improv::global_improv_component != nullptr) + if (esp32_improv::global_improv_component != nullptr) { if (this->wifi_mode_(true, {})) esp32_improv::global_improv_component->start(); + } #endif this->wifi_apply_hostname_(); } @@ -142,10 +143,12 @@ void WiFiComponent::loop() { } #ifdef USE_IMPROV - if (esp32_improv::global_improv_component != nullptr) - if (!this->is_connected()) + if (esp32_improv::global_improv_component != nullptr) { + if (!this->is_connected()) { if (this->wifi_mode_(true, {})) esp32_improv::global_improv_component->start(); + } + } #endif diff --git a/esphome/components/wifi/wifi_component.h b/esphome/components/wifi/wifi_component.h index d032382dc8..615a6905bc 100644 --- a/esphome/components/wifi/wifi_component.h +++ b/esphome/components/wifi/wifi_component.h @@ -227,23 +227,26 @@ class WiFiComponent : public Component { network::IPAddress wifi_soft_ap_ip(); bool has_sta_priority(const bssid_t &bssid) { - for (auto &it : this->sta_priorities_) + for (auto &it : this->sta_priorities_) { if (it.bssid == bssid) return true; + } return false; } float get_sta_priority(const bssid_t bssid) { - for (auto &it : this->sta_priorities_) + for (auto &it : this->sta_priorities_) { if (it.bssid == bssid) return it.priority; + } return 0.0f; } void set_sta_priority(const bssid_t bssid, float priority) { - for (auto &it : this->sta_priorities_) + for (auto &it : this->sta_priorities_) { if (it.bssid == bssid) { it.priority = priority; return; } + } this->sta_priorities_.push_back(WiFiSTAPriority{ .bssid = bssid, .priority = priority, diff --git a/esphome/components/wifi/wifi_component_esp_idf.cpp b/esphome/components/wifi/wifi_component_esp_idf.cpp index 5a81fd0a39..60a3bf171d 100644 --- a/esphome/components/wifi/wifi_component_esp_idf.cpp +++ b/esphome/components/wifi/wifi_component_esp_idf.cpp @@ -182,14 +182,15 @@ bool WiFiComponent::wifi_mode_(optional sta, optional ap) { bool set_ap = ap.has_value() ? *ap : current_ap; wifi_mode_t set_mode; - if (set_sta && set_ap) + if (set_sta && set_ap) { set_mode = WIFI_MODE_APSTA; - else if (set_sta && !set_ap) + } else if (set_sta && !set_ap) { set_mode = WIFI_MODE_STA; - else if (!set_sta && set_ap) + } else if (!set_sta && set_ap) { set_mode = WIFI_MODE_AP; - else + } else { set_mode = WIFI_MODE_NULL; + } if (current_mode == set_mode) return true; diff --git a/esphome/components/xiaomi_miscale/xiaomi_miscale.cpp b/esphome/components/xiaomi_miscale/xiaomi_miscale.cpp index de77e6146b..6c3bd61cac 100644 --- a/esphome/components/xiaomi_miscale/xiaomi_miscale.cpp +++ b/esphome/components/xiaomi_miscale/xiaomi_miscale.cpp @@ -87,12 +87,13 @@ bool XiaomiMiscale::parse_message_v1_(const std::vector &message, Parse // weight, 2 bytes, 16-bit unsigned integer, 1 kg const int16_t weight = uint16_t(data[1]) | (uint16_t(data[2]) << 8); - if (data[0] == 0x22 || data[0] == 0xa2) + if (data[0] == 0x22 || data[0] == 0xa2) { result.weight = weight * 0.01f / 2.0f; // unit 'kg' - else if (data[0] == 0x12 || data[0] == 0xb2) + } else if (data[0] == 0x12 || data[0] == 0xb2) { result.weight = weight * 0.01f * 0.6f; // unit 'jin' - else if (data[0] == 0x03 || data[0] == 0xb3) + } else if (data[0] == 0x03 || data[0] == 0xb3) { result.weight = weight * 0.01f * 0.453592f; // unit 'lbs' + } return true; } @@ -120,10 +121,11 @@ bool XiaomiMiscale::parse_message_v2_(const std::vector &message, Parse // weight, 2 bytes, 16-bit unsigned integer, 1 kg const int16_t weight = uint16_t(data[11]) | (uint16_t(data[12]) << 8); - if (data[0] == 0x02) + if (data[0] == 0x02) { result.weight = weight * 0.01f / 2.0f; // unit 'kg' - else if (data[0] == 0x03) + } else if (data[0] == 0x03) { result.weight = weight * 0.01f * 0.453592f; // unit 'lbs' + } if (has_impedance) { // impedance, 2 bytes, 16-bit diff --git a/esphome/components/yashima/yashima.cpp b/esphome/components/yashima/yashima.cpp index 9a6e85bca1..493c689b42 100644 --- a/esphome/components/yashima/yashima.cpp +++ b/esphome/components/yashima/yashima.cpp @@ -179,12 +179,13 @@ void YashimaClimate::transmit_state_() { data->mark(YASHIMA_HEADER_MARK); data->space(YASHIMA_HEADER_SPACE); // Data (sent from the MSB to the LSB) - for (uint8_t i : remote_state) + for (uint8_t i : remote_state) { for (int8_t j = 7; j >= 0; j--) { data->mark(YASHIMA_BIT_MARK); bool bit = i & (1 << j); data->space(bit ? YASHIMA_ONE_SPACE : YASHIMA_ZERO_SPACE); } + } // Footer data->mark(YASHIMA_BIT_MARK); data->space(YASHIMA_GAP); diff --git a/esphome/core/helpers.cpp b/esphome/core/helpers.cpp index 5f29abe579..dc85bdb17d 100644 --- a/esphome/core/helpers.cpp +++ b/esphome/core/helpers.cpp @@ -206,19 +206,21 @@ void rgb_to_hsv(float red, float green, float blue, int &hue, float &saturation, float min_color_value = std::min(std::min(red, green), blue); float delta = max_color_value - min_color_value; - if (delta == 0) + if (delta == 0) { hue = 0; - else if (max_color_value == red) + } else if (max_color_value == red) { hue = int(fmod(((60 * ((green - blue) / delta)) + 360), 360)); - else if (max_color_value == green) + } else if (max_color_value == green) { hue = int(fmod(((60 * ((blue - red) / delta)) + 120), 360)); - else if (max_color_value == blue) + } else if (max_color_value == blue) { hue = int(fmod(((60 * ((red - green) / delta)) + 240), 360)); + } - if (max_color_value == 0) + if (max_color_value == 0) { saturation = 0; - else + } else { saturation = delta / max_color_value; + } value = max_color_value; } @@ -339,14 +341,15 @@ size_t parse_hex(const char *str, size_t length, uint8_t *data, size_t count) { uint8_t val; size_t chars = std::min(length, 2 * count); for (size_t i = 2 * count - chars; i < 2 * count; i++, str++) { - if (*str >= '0' && *str <= '9') + if (*str >= '0' && *str <= '9') { val = *str - '0'; - else if (*str >= 'A' && *str <= 'F') + } else if (*str >= 'A' && *str <= 'F') { val = 10 + (*str - 'A'); - else if (*str >= 'a' && *str <= 'f') + } else if (*str >= 'a' && *str <= 'f') { val = 10 + (*str - 'a'); - else + } else { return 0; + } data[i >> 1] = !(i & 1) ? val << 4 : data[i >> 1] | val; } return chars; diff --git a/esphome/core/scheduler.cpp b/esphome/core/scheduler.cpp index 3fe07f94b5..7f0ed0b17c 100644 --- a/esphome/core/scheduler.cpp +++ b/esphome/core/scheduler.cpp @@ -167,9 +167,10 @@ void IRAM_ATTR HOT Scheduler::call() { { // Don't copy-by value yet auto &item = this->items_[0]; - if ((now - item->last_execution) < item->interval) + if ((now - item->last_execution) < item->interval) { // Not reached timeout yet, done for this call break; + } uint8_t major = item->next_execution_major(); if (this->millis_major_ - major > 1) break; @@ -190,10 +191,11 @@ void IRAM_ATTR HOT Scheduler::call() { // - timeouts/intervals get cancelled { WarnIfComponentBlockingGuard guard{item->component}; - if (item->type == SchedulerItem::RETRY) + if (item->type == SchedulerItem::RETRY) { retry_result = item->retry_callback(); - else + } else { item->void_callback(); + } } } @@ -257,17 +259,19 @@ void HOT Scheduler::pop_raw_() { void HOT Scheduler::push_(std::unique_ptr item) { this->to_add_.push_back(std::move(item)); } bool HOT Scheduler::cancel_item_(Component *component, const std::string &name, Scheduler::SchedulerItem::Type type) { bool ret = false; - for (auto &it : this->items_) + for (auto &it : this->items_) { if (it->component == component && it->name == name && it->type == type && !it->remove) { to_remove_++; it->remove = true; ret = true; } - for (auto &it : this->to_add_) + } + for (auto &it : this->to_add_) { if (it->component == component && it->name == name && it->type == type) { it->remove = true; ret = true; } + } return ret; }