mirror of
https://github.com/esphome/esphome.git
synced 2025-01-13 10:07:09 +01:00
Force braces around multi-line statements (#3094)
Co-authored-by: Jesse Hills <3060199+jesserockz@users.noreply.github.com>
This commit is contained in:
parent
6b27f2d2cf
commit
80d03a631e
@ -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
|
||||
|
@ -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);
|
||||
|
@ -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);
|
||||
}
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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;
|
||||
|
@ -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.")
|
||||
|
||||
|
@ -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;
|
||||
|
@ -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
|
||||
|
@ -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) {
|
||||
|
@ -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
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -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)) {
|
||||
|
@ -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) {
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
|
@ -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;
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -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;
|
||||
|
@ -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))
|
||||
|
||||
|
@ -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();
|
||||
|
@ -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();
|
||||
|
||||
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
@ -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;
|
||||
|
@ -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_)
|
||||
|
@ -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,
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
|
@ -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);
|
||||
|
@ -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");
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
|
@ -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);
|
||||
|
@ -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");
|
||||
|
@ -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);
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -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;
|
||||