Skip to content

Commit

Permalink
Format code to align with ESPHome requirements
Browse files Browse the repository at this point in the history
  • Loading branch information
paveldn committed Oct 18, 2023
1 parent c6b8700 commit 599e043
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 16 deletions.
19 changes: 12 additions & 7 deletions components/haier/haier_base.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,9 @@ const char *HaierClimateBase::phase_to_string_(ProtocolPhases phase) {
"SENDING_POWER_OFF_COMMAND",
"UNKNOWN" // Should be the last!
};
static_assert((sizeof(phase_names) / sizeof(char*)) == (((int)ProtocolPhases::NUM_PROTOCOL_PHASES) + 1), "Wrong phase_names array size. Please, make sure that this array is aligned with the enum ProtocolPhases");
static_assert(
(sizeof(phase_names) / sizeof(char *)) == (((int) ProtocolPhases::NUM_PROTOCOL_PHASES) + 1),
"Wrong phase_names array size. Please, make sure that this array is aligned with the enum ProtocolPhases");
int phase_index = (int) phase;
if ((phase_index > (int) ProtocolPhases::NUM_PROTOCOL_PHASES) || (phase_index < 0))
phase_index = (int) ProtocolPhases::NUM_PROTOCOL_PHASES;
Expand Down Expand Up @@ -121,7 +123,8 @@ haier_protocol::HaierMessage HaierClimateBase::get_wifi_signal_message_() {
wifi_status_data[1] = 1;
wifi_status_data[3] = 0;
}
return haier_protocol::HaierMessage(haier_protocol::FrameType::REPORT_NETWORK_STATUS, wifi_status_data, sizeof(wifi_status_data));
return haier_protocol::HaierMessage(haier_protocol::FrameType::REPORT_NETWORK_STATUS, wifi_status_data,
sizeof(wifi_status_data));
}
#endif

Expand Down Expand Up @@ -182,7 +185,8 @@ haier_protocol::HandlerError HaierClimateBase::answer_preprocess_(
if ((expected_answer_message_type != haier_protocol::FrameType::UNKNOWN_FRAME_TYPE) &&
(answer_message_type != expected_answer_message_type))
result = haier_protocol::HandlerError::UNSUPPORTED_MESSAGE;
if (!this->haier_protocol_.is_waiting_for_answer() || ((expected_phase != ProtocolPhases::UNKNOWN) && (expected_phase != this->protocol_phase_)))
if (!this->haier_protocol_.is_waiting_for_answer() ||
((expected_phase != ProtocolPhases::UNKNOWN) && (expected_phase != this->protocol_phase_)))
result = haier_protocol::HandlerError::UNEXPECTED_MESSAGE;
if (answer_message_type == haier_protocol::FrameType::INVALID)
result = haier_protocol::HandlerError::INVALID_ANSWER;
Expand Down Expand Up @@ -244,10 +248,11 @@ void HaierClimateBase::loop() {
return;
}
};
if ((this->protocol_phase_ == ProtocolPhases::IDLE) || (!this->haier_protocol_.is_waiting_for_answer() &&
((this->protocol_phase_ == ProtocolPhases::SENDING_STATUS_REQUEST) ||
(this->protocol_phase_ == ProtocolPhases::SENDING_UPDATE_SIGNAL_REQUEST) ||
(this->protocol_phase_ == ProtocolPhases::SENDING_SIGNAL_LEVEL)))) {
if ((this->protocol_phase_ == ProtocolPhases::IDLE) ||
(!this->haier_protocol_.is_waiting_for_answer() &&
((this->protocol_phase_ == ProtocolPhases::SENDING_STATUS_REQUEST) ||
(this->protocol_phase_ == ProtocolPhases::SENDING_UPDATE_SIGNAL_REQUEST) ||
(this->protocol_phase_ == ProtocolPhases::SENDING_SIGNAL_LEVEL)))) {
// If control message or action is pending we should send it ASAP unless we are in initialisation
// procedure or waiting for an answer
if (this->action_request_ != ActionRequest::NO_ACTION) {
Expand Down
17 changes: 9 additions & 8 deletions components/haier/hon_climate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -120,9 +120,9 @@ haier_protocol::HandlerError HonClimate::get_device_version_answer_handler_(haie
this->set_phase(ProtocolPhases::SENDING_INIT_1);
return haier_protocol::HandlerError::INVALID_ANSWER;
}
haier_protocol::HandlerError result = this->answer_preprocess_(
request_type, haier_protocol::FrameType::GET_DEVICE_VERSION, message_type,
haier_protocol::FrameType::GET_DEVICE_VERSION_RESPONSE, ProtocolPhases::SENDING_INIT_1);
haier_protocol::HandlerError result =
this->answer_preprocess_(request_type, haier_protocol::FrameType::GET_DEVICE_VERSION, message_type,
haier_protocol::FrameType::GET_DEVICE_VERSION_RESPONSE, ProtocolPhases::SENDING_INIT_1);
if (result == haier_protocol::HandlerError::HANDLER_OK) {
if (data_size < sizeof(hon_protocol::DeviceVersionAnswer)) {
// Wrong structure
Expand Down Expand Up @@ -159,9 +159,9 @@ haier_protocol::HandlerError HonClimate::get_device_version_answer_handler_(haie
haier_protocol::HandlerError HonClimate::get_device_id_answer_handler_(haier_protocol::FrameType request_type,
haier_protocol::FrameType message_type,
const uint8_t *data, size_t data_size) {
haier_protocol::HandlerError result = this->answer_preprocess_(
request_type, haier_protocol::FrameType::GET_DEVICE_ID, message_type,
haier_protocol::FrameType::GET_DEVICE_ID_RESPONSE, ProtocolPhases::SENDING_INIT_2);
haier_protocol::HandlerError result =
this->answer_preprocess_(request_type, haier_protocol::FrameType::GET_DEVICE_ID, message_type,
haier_protocol::FrameType::GET_DEVICE_ID_RESPONSE, ProtocolPhases::SENDING_INIT_2);
if (result == haier_protocol::HandlerError::HANDLER_OK) {
this->set_phase(ProtocolPhases::SENDING_FIRST_STATUS_REQUEST);
return result;
Expand Down Expand Up @@ -612,7 +612,8 @@ haier_protocol::HandlerError HonClimate::process_status_message_(const uint8_t *
if (packet.sensors.error_status != 0) {
ESP_LOGW(TAG, "HVAC error, code=0x%02X", packet.sensors.error_status);
}
if ((this->outdoor_sensor_ != nullptr) && (this->got_valid_outdoor_temp_ || (packet.sensors.outdoor_temperature > 0))) {
if ((this->outdoor_sensor_ != nullptr) &&
(this->got_valid_outdoor_temp_ || (packet.sensors.outdoor_temperature > 0))) {
this->got_valid_outdoor_temp_ = true;
float otemp = (float) (packet.sensors.outdoor_temperature + PROTOCOL_OUTDOOR_TEMPERATURE_OFFSET);
if ((!this->outdoor_sensor_->has_state()) || (this->outdoor_sensor_->get_raw_state() != otemp))
Expand Down Expand Up @@ -985,7 +986,7 @@ void HonClimate::process_protocol_reset() {
HaierClimateBase::process_protocol_reset();
if (this->outdoor_sensor_ != nullptr) {
this->outdoor_sensor_->publish_state(NAN);
}
}
this->got_valid_outdoor_temp_ = false;
this->hvac_hardware_info_.reset();
}
Expand Down
3 changes: 2 additions & 1 deletion components/haier/smartair2_climate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,8 @@ haier_protocol::HandlerError Smartair2Climate::messages_timeout_handler_with_cyc
haier_protocol::FrameType message_type) {
if (this->protocol_phase_ >= ProtocolPhases::IDLE)
return HaierClimateBase::timeout_default_handler_(message_type);
ESP_LOGI(TAG, "Answer timeout for command %02X, phase %s", (uint8_t) message_type, phase_to_string_(this->protocol_phase_));
ESP_LOGI(TAG, "Answer timeout for command %02X, phase %s", (uint8_t) message_type,
phase_to_string_(this->protocol_phase_));
ProtocolPhases new_phase = (ProtocolPhases) ((int) this->protocol_phase_ + 1);
if (new_phase >= ProtocolPhases::SENDING_ALARM_STATUS_REQUEST)
new_phase = ProtocolPhases::SENDING_INIT_1;
Expand Down

0 comments on commit 599e043

Please sign in to comment.