Force braces around multi-line statements (#3094)

Co-authored-by: Jesse Hills <3060199+jesserockz@users.noreply.github.com>
This commit is contained in:
Oxan van Leeuwen 2022-01-24 20:56:36 +01:00 committed by GitHub
parent 6b27f2d2cf
commit 80d03a631e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
125 changed files with 770 additions and 504 deletions

View File

@ -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

View File

@ -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);

View File

@ -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);
}

View File

@ -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;
}

View File

@ -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;
}

View File

@ -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;
}
}
}

View File

@ -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;

View File

@ -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.")

View File

@ -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;

View File

@ -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<esp32_camera::CameraImage> &image) {
for (auto &c : this->clients_)
for (auto &c : this->clients_) {
if (!c->remove_)
c->send_camera_state(image);
}
});
}
#endif

View File

@ -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<int32_t>(~(this->value_ >> 1));
else
} else {
return static_cast<int32_t>(this->value_ >> 1);
}
}
int64_t as_sint64() const {
// with ZigZag encoding
if (this->value_ & 1)
if (this->value_ & 1) {
return static_cast<int64_t>(~(this->value_ >> 1));
else
} else {
return static_cast<int64_t>(this->value_ >> 1);
}
}
void encode(std::vector<uint8_t> &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<class C> void encode_message(uint32_t field_id, const C &value, bool force = false) {

View File

@ -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

View File

@ -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;
}

View File

@ -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)) {

View File

@ -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) {

View File

@ -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;
}

View File

@ -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;

View File

@ -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;
}

View File

@ -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;

View File

@ -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))

View File

@ -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();

View File

@ -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();

View File

@ -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;
}
}

View File

@ -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;
}

View File

@ -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;
}
}

View File

@ -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;

View File

@ -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_)

View File

@ -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,

View File

@ -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;
}

View File

@ -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);

View File

@ -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");

View File

@ -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;
}

View File

@ -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<float>((char *) &buf[1]).value_or(0);
this->publish_state(val);

View File

@ -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");

View File

@ -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);

View File

@ -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;
}

View File

@ -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;
}

View File

@ -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;

View File

@ -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);
}
}
}
}

View File

@ -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);
}
}
}
}

View File

@ -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);

View File

@ -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;
}

View File

@ -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<ColorMode> 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 {};

View File

@ -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<void()> &&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_();

View File

@ -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();
}
}

View File

@ -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

View File

@ -62,10 +62,11 @@ void MCP23016::update_reg_(uint8_t pin, bool pin_value, uint8_t reg_addr) {
this->read_reg_(reg_addr, &reg_value);
}
if (pin_value)
if (pin_value) {
reg_value |= 1 << bit;
else
} else {
reg_value &= ~(1 << bit);
}
this->write_reg_(reg_addr, reg_value);

View File

@ -67,10 +67,11 @@ void MCP23X08Base::update_reg(uint8_t pin, bool pin_value, uint8_t reg_addr) {
this->read_reg(reg_addr, &reg_value);
}
if (pin_value)
if (pin_value) {
reg_value |= 1 << bit;
else
} else {
reg_value &= ~(1 << bit);
}
this->write_reg(reg_addr, reg_value);

View File

@ -70,10 +70,11 @@ void MCP23X17Base::update_reg(uint8_t pin, bool pin_value, uint8_t reg_addr) {
this->read_reg(reg_addr, &reg_value);
}
if (pin_value)
if (pin_value) {
reg_value |= 1 << bit;
else
} else {
reg_value &= ~(1 << bit);
}
this->write_reg(reg_addr, reg_value);

View File

@ -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);
}

View File

@ -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;
}

View File

@ -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);

View File

@ -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<uint8_t> &data) override;

View File

@ -230,10 +230,11 @@ class SensorItem {
void set_custom_data(const std::vector<uint8_t> &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; }

View File

@ -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

View File

@ -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))

View File

@ -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;
}

View File

@ -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();

View File

@ -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.

View File

@ -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) {

View File

@ -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_);

View File

@ -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;

View File

@ -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;
}

View File

@ -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<uint8_t> &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;

View File

@ -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) {

View File

@ -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++)

View File

@ -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);

View File

@ -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);

View File

@ -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;
}

View File

@ -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);

View File

@ -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);
}
}
}

View File

@ -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);
}

View File

@ -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<PioneerData> 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

View File

@ -50,10 +50,11 @@ template<typename... Ts> class RawAction : public RemoteTransmitterActionBase<Ts
if (this->code_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<uint32_t>(-val));
else
} else {
dst->mark(static_cast<uint32_t>(val));
}
}
} else {
dst->set_data(this->code_func_(x...));

View File

@ -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,

View File

@ -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);

View File

@ -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<SonyData> SonyProtocol::decode(RemoteReceiveData src) {

View File

@ -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<ToshibaAcData> 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

View File

@ -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]);

View File

@ -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) {

View File

@ -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;
}

View File

@ -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;

View File

@ -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;

View File

@ -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;

View File

@ -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);
}
}
}

View File

@ -176,10 +176,11 @@ optional<float> 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<float> 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<float> 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;
}
}
}

View File

@ -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);

View File

@ -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;

View File

@ -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;

View File

@ -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;

View File

@ -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;

View File

@ -88,9 +88,10 @@ class BSDSocketImpl : public Socket {
for (int i = 0; i < iovcnt; i++) {
ssize_t err = this->read(reinterpret_cast<uint8_t *>(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<uint8_t *>(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;

View File

@ -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

View File

@ -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;

View File

@ -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);

View File

@ -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_)));

View File

@ -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) {

View File

@ -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) {

View File

@ -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;

View File

@ -110,10 +110,11 @@ template<typename... Ts> class SunCondition : public Condition<Ts...>, 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:

View File

@ -16,10 +16,11 @@ class SunTextSensor : public text_sensor::TextSensor, public PollingComponent {
void update() override {
optional<time::ESPTime> 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;

View File

@ -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)

View File

@ -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<uint8_t>(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;
}

View File

@ -16,10 +16,11 @@ void TemplateNumber::setup() {
} else {
this->pref_ = global_preferences->make_preference<float>(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);

View File

@ -64,9 +64,10 @@ optional<std::string> PrependFilter::new_value(std::string value) { return this-
// Substitute
optional<std::string> 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;
}

View File

@ -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);
}
}
}
}

View File

@ -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_();

View File

@ -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:

View File

@ -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()) {

View File

@ -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<TuyaDatapoint> 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::function<void(Tuya
this->listeners_.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_; }

View File

@ -41,10 +41,11 @@ uint32_t ESP32ArduinoUARTComponent::get_config() {
* tick_ref_always_on:27 select the clock.1apb clockref_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;

View File

@ -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;

View File

@ -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;

View File

@ -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);

View File

@ -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;
}

View File

@ -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);

View File

@ -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", "<button>Toggle</button>");
}
#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", "<button>Toggle</button>");
}
#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", "<button>Toggle</button>");
}
#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", "<button>Open</button><button>Close</button>");
}
#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"(<input type="number" min=")");
@ -248,11 +265,13 @@ void WebServer::handle_index_request(AsyncWebServerRequest *request) {
stream.print(number->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("<select>");
@ -264,6 +283,8 @@ void WebServer::handle_index_request(AsyncWebServerRequest *request) {
}
stream.print("</select>");
});
}
}
#endif
stream->print(F("</tbody></table><p>See <a href=\"https://esphome.io/web-api/index.html\">ESPHome Web API</a> for "

View File

@ -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;
}

View File

@ -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

View File

@ -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,

View File

@ -182,14 +182,15 @@ bool WiFiComponent::wifi_mode_(optional<bool> sta, optional<bool> 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;

View File

@ -87,12 +87,13 @@ bool XiaomiMiscale::parse_message_v1_(const std::vector<uint8_t> &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<uint8_t> &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

View File

@ -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);

View File

@ -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;

View File

@ -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<Scheduler::SchedulerItem> 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;
}