From 8c4eadbf2c6fc4c3ca08dae8f52e1fa80e064ff8 Mon Sep 17 00:00:00 2001 From: ElVit Date: Sat, 19 Jul 2025 19:25:05 +0200 Subject: [PATCH] Added support for extra query (fixes #11) --- .../panasonic_heatpump/panasonic_heatpump.cpp | 22 +++++++++---------- 1 file changed, 10 insertions(+), 12 deletions(-) diff --git a/components/panasonic_heatpump/panasonic_heatpump.cpp b/components/panasonic_heatpump/panasonic_heatpump.cpp index 4f922d1..4a35bd1 100644 --- a/components/panasonic_heatpump/panasonic_heatpump.cpp +++ b/components/panasonic_heatpump/panasonic_heatpump.cpp @@ -149,12 +149,11 @@ namespace esphome this->payload_length_ = byte_; } // Discard message if format is wrong - if ((this->response_message_.size() == 3 || - this->response_message_.size() == 4) && - byte_ != 0x01 && byte_ != 0x10 && byte_ != 0x21) + if ((this->response_message_.size() == 3 && byte_ != 0x01 && byte_ != 0x10) || + (this->response_message_.size() == 4 && byte_ != 0x10 && byte_ != 0x21)) { this->response_receiving_ = false; - ESP_LOGW(TAG, "Invalid response message: %d. byte is 0x%02X but expexted is 0x01 or 0x10", + ESP_LOGW(TAG, "Invalid response message: %d. byte is 0x%02X but expexted is 0x01, 0x10 or 0x21", response_message_.size(), byte_); delay(10); // NOLINT continue; @@ -227,12 +226,11 @@ namespace esphome this->payload_length_ = byte_; } // Discard message if format is wrong - if ((this->request_message_.size() == 3 || - this->request_message_.size() == 4) && - byte_ != 0x01 && byte_ != 0x10 && byte_ != 0x21) + if ((this->request_message_.size() == 3 && byte_ != 0x01 && byte_ != 0x10) || + (this->request_message_.size() == 4 && byte_ != 0x10 && byte_ != 0x21)) { this->request_receiving_ = false; - ESP_LOGW(TAG, "Invalid request message: %d. byte is 0x%02X but expexted is 0x01 or 0x10", + ESP_LOGW(TAG, "Invalid request message: %d. byte is 0x%02X but expexted is 0x01, 0x10 or 0x21", request_message_.size(), byte_); delay(10); // NOLINT continue; @@ -291,26 +289,26 @@ namespace esphome return ResponseType::UNKNOWN; } + this->send_extra_request_ = data[3] == 0x10 && data[199] > 0x02 && + this->send_extra_request_ == false ? true : false; + // Get response type and save the response auto responseType = ResponseType::UNKNOWN; if (data[3] == 0x10) { responseType = ResponseType::DEFAULT; this->heatpump_default_message_ = data; - this->send_extra_request_ = data[199] > 0x02 ? true : false; } else if (data[3] == 0x21) { responseType = ResponseType::EXTRA; this->heatpump_extra_message_ = data; - this->send_extra_request_ = false; } if (responseType == ResponseType::UNKNOWN) { ESP_LOGW(TAG, "Unknown response type (4. byte): 0x%02X. Expected 0x10 or 0x21.", data[3]); delay(10); // NOLINT - this->send_extra_request_ = false; - return ResponseType::UNKNOWN; + return responseType; } // Check if the current response is a new response