Skip to content

Commit

Permalink
Fixed test after rebase
Browse files Browse the repository at this point in the history
  • Loading branch information
paveldn committed Oct 8, 2023
1 parent 56db08f commit fa6950f
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 25 deletions.
2 changes: 0 additions & 2 deletions components/haier/haier_base.h
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,6 @@ class HaierClimateBase : public esphome::Component,
WAITING_POWER_ON_ANSWER = 19,
SENDING_POWER_OFF_COMMAND = 20,
WAITING_POWER_OFF_ANSWER = 21,
SENDING_TEST_COMMAND = 22,
WAITING_TEST_COMMAND_ANSWER = 23,
NUM_PROTOCOL_PHASES
};
#if (HAIER_LOG_LEVEL > 4)
Expand Down
39 changes: 19 additions & 20 deletions components/haier/hon_climate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,6 @@ HonClimate::HonClimate()
outdoor_sensor_(nullptr) {
this->fan_mode_speed_ = (uint8_t) hon_protocol::FanMode::FAN_MID;
this->other_modes_fan_speed_ = (uint8_t) hon_protocol::FanMode::FAN_AUTO;
this->command_to_send_ = std::pair<uint8_t, uint16_t>(0, 0);
}

HonClimate::~HonClimate() {}
Expand Down Expand Up @@ -197,8 +196,7 @@ haier_protocol::HandlerError HonClimate::status_handler_(uint8_t request_type, u
this->set_phase(ProtocolPhases::SENDING_ALARM_STATUS_REQUEST);
} else if ((this->protocol_phase_ == ProtocolPhases::WAITING_STATUS_ANSWER) ||
(this->protocol_phase_ == ProtocolPhases::WAITING_POWER_ON_ANSWER) ||
(this->protocol_phase_ == ProtocolPhases::WAITING_POWER_OFF_ANSWER) ||
(this->protocol_phase_ == ProtocolPhases::WAITING_TEST_COMMAND_ANSWER)) {
(this->protocol_phase_ == ProtocolPhases::WAITING_POWER_OFF_ANSWER)) {
this->set_phase(ProtocolPhases::IDLE);
} else if (this->protocol_phase_ == ProtocolPhases::WAITING_CONTROL_ANSWER) {
if (!this->control_messages_queue_.empty())
Expand Down Expand Up @@ -322,7 +320,7 @@ void HonClimate::process_phase(std::chrono::steady_clock::time_point now) {
case ProtocolPhases::SENDING_INIT_1:
if (this->can_send_message() && this->is_protocol_initialisation_interval_exceeded_(now)) {
this->hvac_hardware_info_available_ = false;
// Indiate device capabilities:
// Indicate device capabilities:
// bit 0 - if 1 module support interactive mode
// bit 1 - if 1 module support controller-device mode
// bit 2 - if 1 module support crc
Expand Down Expand Up @@ -439,19 +437,7 @@ void HonClimate::process_phase(std::chrono::steady_clock::time_point now) {
: ProtocolPhases::WAITING_POWER_OFF_ANSWER);
}
break;
case ProtocolPhases::SENDING_TEST_COMMAND:
if (this->can_send_message() && this->is_message_interval_exceeded_(now)) {
uint8_t test_cmd_buf[2];
test_cmd_buf[0] = this->command_to_send_.second >> 8;
test_cmd_buf[1] = this->command_to_send_.second & 0xFF;
haier_protocol::HaierMessage test_cmd((uint8_t) hon_protocol::FrameType::CONTROL,
((uint16_t) hon_protocol::SubcommandsControl::SET_SINGLE_PARAMETER) + this->command_to_send_.first,
test_cmd_buf, sizeof(test_cmd_buf));
this->send_message_(test_cmd, this->use_crc_);
this->command_to_send_ = std::pair<uint8_t, uint16_t>(0, 0);
this->set_phase(ProtocolPhases::WAITING_TEST_COMMAND_ANSWER);
}
break;

case ProtocolPhases::WAITING_INIT_1_ANSWER:
case ProtocolPhases::WAITING_INIT_2_ANSWER:
case ProtocolPhases::WAITING_FIRST_STATUS_ANSWER:
Expand All @@ -460,7 +446,6 @@ void HonClimate::process_phase(std::chrono::steady_clock::time_point now) {
case ProtocolPhases::WAITING_CONTROL_ANSWER:
case ProtocolPhases::WAITING_POWER_ON_ANSWER:
case ProtocolPhases::WAITING_POWER_OFF_ANSWER:
case ProtocolPhases::WAITING_TEST_COMMAND_ANSWER:
break;
case ProtocolPhases::IDLE: {
if (this->forced_request_status_ || this->is_status_request_interval_exceeded_(now)) {
Expand All @@ -473,8 +458,6 @@ void HonClimate::process_phase(std::chrono::steady_clock::time_point now) {
SIGNAL_LEVEL_UPDATE_INTERVAL_MS))
this->set_phase(ProtocolPhases::SENDING_UPDATE_SIGNAL_REQUEST);
#endif
else if (this->command_to_send_.first != 0)
this->set_phase(ProtocolPhases::SENDING_TEST_COMMAND);
} break;
default:
// Shouldn't get here
Expand Down Expand Up @@ -1075,5 +1058,21 @@ void HonClimate::process_pending_action() {
}
}

void HonClimate::send_single_parameter_command(uint8_t command, uint16_t value) {
if (this->control_method_ != HonControlMethod::SET_SINGLE_PARAMETER) {
ESP_LOGW(TAG, "Can't send single parameter command when control method is set to %d", this->control_method_);
return;
}
uint8_t buffer[2];
buffer[0] = value >> 8;
buffer[1] = value & 0xFF;
this->control_messages_queue_.push(haier_protocol::HaierMessage(
(uint8_t) hon_protocol::FrameType::CONTROL,
(uint16_t) hon_protocol::SubcommandsControl::SET_SINGLE_PARAMETER + command,
buffer, 2
));
this->set_phase(ProtocolPhases::SENDING_CONTROL);
}

} // namespace haier
} // namespace esphome
3 changes: 1 addition & 2 deletions components/haier/hon_climate.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ class HonClimate : public HaierClimateBase {
void start_steri_cleaning();
void set_extra_control_packet_bytes_size(size_t size) { this->extra_control_packet_bytes_ = size; };
void set_control_method(HonControlMethod method) { this->control_method_ = method; };
void send_command(uint8_t command, uint16_t value) {this->command_to_send_ = std::pair<uint8_t, uint16_t>(command, value); };
void send_single_parameter_command(uint8_t command, uint16_t value);

protected:
void set_handlers() override;
Expand Down Expand Up @@ -101,7 +101,6 @@ class HonClimate : public HaierClimateBase {
HonControlMethod control_method_;
esphome::sensor::Sensor *outdoor_sensor_;
std::queue<haier_protocol::HaierMessage> control_messages_queue_;
std::pair<uint8_t, uint16_t> command_to_send_;
};

} // namespace haier
Expand Down
2 changes: 1 addition & 1 deletion configs/button/send_test_command.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@ button:
on_press:
then:
lambda: |-
id(${device_id}).send_command(id(${device_id}_test_command_code).state, id(${device_id}_test_command_arg).state);
id(${device_id}).send_single_parameter_command(id(${device_id}_test_command_code).state, id(${device_id}_test_command_arg).state);

0 comments on commit fa6950f

Please sign in to comment.