From 3753b3d47580d1feb47c1bf89d1e360cf7a0453e Mon Sep 17 00:00:00 2001 From: ElVit Date: Wed, 16 Jul 2025 16:08:09 +0200 Subject: [PATCH 1/9] Added support for extra query (fixes #11) --- components/panasonic_heatpump/commands.cpp | 10 ++ components/panasonic_heatpump/commands.h | 1 + .../panasonic_heatpump/panasonic_heatpump.cpp | 99 +++++++++++-------- .../panasonic_heatpump/panasonic_heatpump.h | 23 ++++- .../panasonic_heatpump/sensor/__init__.py | 66 +++++++++++++ .../sensor/panasonic_heatpump_sensor.cpp | 37 +++++++ .../sensor/panasonic_heatpump_sensor.h | 7 ++ 7 files changed, 199 insertions(+), 44 deletions(-) diff --git a/components/panasonic_heatpump/commands.cpp b/components/panasonic_heatpump/commands.cpp index b4daff3..7d636ee 100644 --- a/components/panasonic_heatpump/commands.cpp +++ b/components/panasonic_heatpump/commands.cpp @@ -24,6 +24,16 @@ namespace esphome 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x12 }; + const uint8_t PanasonicCommand::PollingExtraMessage[DATA_MESSAGE_SIZE] = { + 0x71, 0x6C, 0x01, 0x21, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x01 + }; const uint8_t PanasonicCommand::CommandMessage[DATA_MESSAGE_SIZE] = { 0xF1, 0x6C, 0x01, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, diff --git a/components/panasonic_heatpump/commands.h b/components/panasonic_heatpump/commands.h index 85de7a8..7a0d634 100644 --- a/components/panasonic_heatpump/commands.h +++ b/components/panasonic_heatpump/commands.h @@ -42,6 +42,7 @@ namespace esphome static const uint8_t InitialRequest[INIT_REQUEST_SIZE]; static const uint8_t InitialResponse[INIT_RESPONSE_SIZE]; static const uint8_t PollingMessage[DATA_MESSAGE_SIZE]; + static const uint8_t PollingExtraMessage[DATA_MESSAGE_SIZE]; static const uint8_t CommandMessage[DATA_MESSAGE_SIZE]; }; } // namespace panasonic_heatpump diff --git a/components/panasonic_heatpump/panasonic_heatpump.cpp b/components/panasonic_heatpump/panasonic_heatpump.cpp index 7910111..0b98c2d 100644 --- a/components/panasonic_heatpump/panasonic_heatpump.cpp +++ b/components/panasonic_heatpump/panasonic_heatpump.cpp @@ -25,8 +25,8 @@ namespace esphome void PanasonicHeatpumpComponent::update() { - if (this->uart_client_ == nullptr) - this->next_request_ = RequestType::POLLING; + if (this->uart_client_ != nullptr) return; + this->next_request_ = this->send_extra_request_ ? RequestType::POLLING_EXTRA : RequestType::POLLING; } void PanasonicHeatpumpComponent::loop() @@ -34,98 +34,91 @@ namespace esphome switch (this->loop_state_) { case LoopState::READ_RESPONSE: - { this->read_response(); this->loop_state_ = LoopState::CHECK_RESPONSE; break; - } case LoopState::CHECK_RESPONSE: - { - bool result = this->check_response(this->heatpump_message_); - this->loop_state_ = result ? - LoopState::PUBLISH_SENSOR : LoopState::SEND_REQUEST; + this->current_response_ = this->check_response(this->heatpump_message_); + switch (this->current_response_) + { + case ResponseType::UNKNOWN: + this->loop_state_ = LoopState::SEND_REQUEST; + break; + case ResponseType::DEFAULT: + this->loop_state_ = LoopState::PUBLISH_SENSOR; + break; + case ResponseType::EXTRA: + this->loop_state_ = LoopState::PUBLISH_EXTRA_SENSOR; + break; + }; break; - } case LoopState::PUBLISH_SENSOR: - { for (auto *entity : this->sensors_) { entity->publish_new_state(this->heatpump_message_); } this->loop_state_ = LoopState::PUBLISH_BINARY_SENSOR; break; - } case LoopState::PUBLISH_BINARY_SENSOR: - { for (auto *entity : this->binary_sensors_) { entity->publish_new_state(this->heatpump_message_); } this->loop_state_ = LoopState::PUBLISH_TEXT_SENSOR; break; - } case LoopState::PUBLISH_TEXT_SENSOR: - { for (auto *entity : this->text_sensors_) { entity->publish_new_state(this->heatpump_message_); } this->loop_state_ = LoopState::PUBLISH_NUMBER; break; - } case LoopState::PUBLISH_NUMBER: - { for (auto *entity : this->numbers_) { entity->publish_new_state(this->heatpump_message_); } this->loop_state_ = LoopState::PUBLISH_SELECT; break; - } case LoopState::PUBLISH_SELECT: - { for (auto *entity : this->selects_) { entity->publish_new_state(this->heatpump_message_); } this->loop_state_ = LoopState::PUBLISH_SWITCH; break; - } case LoopState::PUBLISH_SWITCH: - { for (auto *entity : this->switches_) { entity->publish_new_state(this->heatpump_message_); } this->loop_state_ = LoopState::PUBLISH_CLIMATE; break; - } case LoopState::PUBLISH_CLIMATE: - { for (auto *entity : this->climates_) { entity->publish_new_state(this->heatpump_message_); } this->loop_state_ = LoopState::SEND_REQUEST; break; - } + case LoopState::PUBLISH_EXTRA_SENSOR: + for (auto *entity : this->extra_sensors_) + { + entity->publish_new_state(this->heatpump_message_); + } + this->loop_state_ = LoopState::SEND_REQUEST; + break; case LoopState::SEND_REQUEST: - { this->send_request(this->next_request_); this->loop_state_ = LoopState::READ_REQUEST; break; - } case LoopState::READ_REQUEST: - { this->read_request(); this->loop_state_ = LoopState::RESTART_LOOP; break; - } default: - { this->loop_state_ = LoopState::READ_RESPONSE; break; - } }; } @@ -205,6 +198,13 @@ namespace esphome this->flush(); break; } + case RequestType::POLLING_EXTRA: + { + if (this->log_uart_msg_) PanasonicHelpers::log_uart_hex(UART_LOG_TX, PanasonicCommand::PollingExtraMessage, DATA_MESSAGE_SIZE, ','); + this->write_array(PanasonicCommand::PollingMessage, DATA_MESSAGE_SIZE); + this->flush(); + break; + } }; this->next_request_ = RequestType::NONE; @@ -264,41 +264,62 @@ namespace esphome return -1; } - bool PanasonicHeatpumpComponent::check_response(const std::vector& data) + ResponseType PanasonicHeatpumpComponent::check_response(const std::vector& data) { // Read response message: - // format: 0x71 [payload_length] 0x01 0x10 [[TOP0 - TOP114] ...] 0x00 [checksum] + // format: 0x71 [payload_length] 0x01 [0x10 || 0x21] [[TOP0 - TOP114] ...] 0x00 [checksum] // payload_length: payload_length + 3 = packet_length // checksum: if (sum(all bytes) & 0xFF == 0) ==> valid packet - if (data.empty()) return false; - if (data[0] != 0x71) return false; - if (data[3] != 0x10) return false; + if (data.empty()) return ResponseType::UNKNOWN; + if (data[0] != 0x71) return ResponseType::UNKNOWN; if (data.size() != RESPONSE_MSG_SIZE) { ESP_LOGW(TAG, "Invalid response message length: recieved %d - expected %d", data.size(), RESPONSE_MSG_SIZE); delay(10); // NOLINT - return false; + return ResponseType::UNKNOWN; } + // Verify checksum uint8_t checksum = 0; for (int i = 0; i < data.size(); i++) { checksum += data[i]; } - // checksum = checksum & 0xFF; + // all bytes (including checksum byte) shall be 0x00 if (checksum != 0) { ESP_LOGW(TAG, "Invalid response message: checksum = 0x%02X, last_byte = 0x%02X", checksum, data[202]); delay(10); // NOLINT - return false; + return ResponseType::UNKNOWN; + } + + // Get response type + auto responseType = ResponseType::UNKNOWN; + if (data[3] == 0x10) responseType = ResponseType::DEFAULT; + if (data[3] == 0x21) responseType = ResponseType::EXTRA; + if (responseType == ResponseType::UNKNOWN) + { + ESP_LOGW(TAG, "Unknown response type (4. byte): 0x%02X. Expected 0x10 or 0x21.", data[3]); + delay(10); // NOLINT + return ResponseType::UNKNOWN; + } + + // Check if extra request shall be send + if (responseType == ResponseType::DEFAULT) + { + this->send_extra_request_ = data[199] > 0x02 ? true : false; + } + else + { + this->send_extra_request_ = false; } // Check if the current response is a new response - if (this->last_response_count_ == this->current_response_count_) return false; + if (this->last_response_count_ == this->current_response_count_) return ResponseType::UNKNOWN; this->last_response_count_ = this->current_response_count_; - return true; + return responseType; } void PanasonicHeatpumpComponent::set_command_high_nibble(const uint8_t value, const uint8_t index) diff --git a/components/panasonic_heatpump/panasonic_heatpump.h b/components/panasonic_heatpump/panasonic_heatpump.h index 9a08bd6..18457f2 100644 --- a/components/panasonic_heatpump/panasonic_heatpump.h +++ b/components/panasonic_heatpump/panasonic_heatpump.h @@ -27,17 +27,26 @@ namespace esphome PUBLISH_SELECT, PUBLISH_SWITCH, PUBLISH_CLIMATE, + PUBLISH_EXTRA_SENSOR, SEND_REQUEST, READ_REQUEST, - RESTART_LOOP + RESTART_LOOP, }; enum RequestType : uint8_t { + NONE, + COMMAND, INITIAL, POLLING, - COMMAND, - NONE + POLLING_EXTRA, + }; + + enum ResponseType : uint8_t + { + UNKNOWN, + DEFAULT, + EXTRA, }; class PanasonicHeatpumpEntity @@ -79,6 +88,7 @@ namespace esphome void add_sensor(PanasonicHeatpumpEntity *sensor) { sensors_.push_back(sensor); } void add_switch(PanasonicHeatpumpEntity *switch_) { switches_.push_back(switch_); } void add_text_sensor(PanasonicHeatpumpEntity *text_sensor) { text_sensors_.push_back(text_sensor); } + void add_extra_sensor(PanasonicHeatpumpEntity *sensor) { extra_sensors_.push_back(sensor); } protected: // options variables @@ -95,8 +105,10 @@ namespace esphome uint8_t last_response_count_ { 0 }; bool response_receiving_ { false }; bool request_receiving_ { false }; - RequestType next_request_ { RequestType::INITIAL }; + bool send_extra_request_ { false }; LoopState loop_state_ { LoopState::RESTART_LOOP }; + RequestType next_request_ { RequestType::INITIAL }; + ResponseType current_response_ { ResponseType::UNKNOWN }; // entity vectors std::vector binary_sensors_; std::vector climates_; @@ -105,12 +117,13 @@ namespace esphome std::vector sensors_; std::vector switches_; std::vector text_sensors_; + std::vector extra_sensors_; // uart message functions void read_response(); void send_request(RequestType requestType); void read_request(); - bool check_response(const std::vector& data); + ResponseType check_response(const std::vector& data); }; } // namespace panasonic_heatpump } // namespace esphome diff --git a/components/panasonic_heatpump/sensor/__init__.py b/components/panasonic_heatpump/sensor/__init__.py index 72c4bfa..904ec57 100644 --- a/components/panasonic_heatpump/sensor/__init__.py +++ b/components/panasonic_heatpump/sensor/__init__.py @@ -128,6 +128,13 @@ CONF_TOP136 = "top136" # Bivalent Advanced Start Delay CONF_TOP137 = "top137" # Bivalent Advanced Stop Delay CONF_TOP138 = "top138" # Bivalent Advanced DHW Delay +CONF_XTOP0 = "xtop0" # Heat Power Consumption Extra +CONF_XTOP1 = "xtop1" # Cool Power Consumption Extra +CONF_XTOP2 = "xtop2" # DHW Power Consumption Extra +CONF_XTOP3 = "xtop3" # Heat Power Production Extra +CONF_XTOP4 = "xtop4" # Cool Power Production Extra +CONF_XTOP5 = "xtop5" # DHW Power Production Extra + TYPES = [ CONF_TOP1, CONF_TOP5, @@ -226,6 +233,15 @@ TYPES = [ CONF_TOP138, ] +EXTRA_TYPES = [ + CONF_XTOP0, + CONF_XTOP1, + CONF_XTOP2, + CONF_XTOP3, + CONF_XTOP4, + CONF_XTOP5, +] + PanasonicHeatpumpSensor = panasonic_heatpump_ns.class_("PanasonicHeatpumpSensor", sensor.Sensor, cg.Component) CONFIG_SCHEMA = cv.Schema( @@ -894,6 +910,49 @@ CONFIG_SCHEMA = cv.Schema( state_class=STATE_CLASS_MEASUREMENT, unit_of_measurement = UNIT_MINUTE, ), + + cv.Optional(CONF_XTOP0): sensor.sensor_schema( + PanasonicHeatpumpSensor, + accuracy_decimals=0, + device_class=DEVICE_CLASS_POWER, + state_class=STATE_CLASS_MEASUREMENT, + unit_of_measurement = UNIT_WATT, + ), + cv.Optional(CONF_XTOP1): sensor.sensor_schema( + PanasonicHeatpumpSensor, + accuracy_decimals=0, + device_class=DEVICE_CLASS_POWER, + state_class=STATE_CLASS_MEASUREMENT, + unit_of_measurement = UNIT_WATT, + ), + cv.Optional(CONF_XTOP2): sensor.sensor_schema( + PanasonicHeatpumpSensor, + accuracy_decimals=0, + device_class=DEVICE_CLASS_POWER, + state_class=STATE_CLASS_MEASUREMENT, + unit_of_measurement = UNIT_WATT, + ), + cv.Optional(CONF_XTOP3): sensor.sensor_schema( + PanasonicHeatpumpSensor, + accuracy_decimals=0, + device_class=DEVICE_CLASS_POWER, + state_class=STATE_CLASS_MEASUREMENT, + unit_of_measurement = UNIT_WATT, + ), + cv.Optional(CONF_XTOP4): sensor.sensor_schema( + PanasonicHeatpumpSensor, + accuracy_decimals=0, + device_class=DEVICE_CLASS_POWER, + state_class=STATE_CLASS_MEASUREMENT, + unit_of_measurement = UNIT_WATT, + ), + cv.Optional(CONF_XTOP5): sensor.sensor_schema( + PanasonicHeatpumpSensor, + accuracy_decimals=0, + device_class=DEVICE_CLASS_POWER, + state_class=STATE_CLASS_MEASUREMENT, + unit_of_measurement = UNIT_WATT, + ), } ).extend(cv.COMPONENT_SCHEMA) @@ -906,3 +965,10 @@ async def to_code(config): cg.add(var.set_parent(parent)) cg.add(var.set_id(index)) cg.add(parent.add_sensor(var)) + for index, key in enumerate(EXTRA_TYPES): + if child_config := config.get(key): + var = await sensor.new_sensor(child_config) + await cg.register_component(var, child_config) + cg.add(var.set_parent(parent)) + cg.add(var.set_id(index)) + cg.add(parent.add_extra_sensor(var)) diff --git a/components/panasonic_heatpump/sensor/panasonic_heatpump_sensor.cpp b/components/panasonic_heatpump/sensor/panasonic_heatpump_sensor.cpp index b133a8e..20586eb 100644 --- a/components/panasonic_heatpump/sensor/panasonic_heatpump_sensor.cpp +++ b/components/panasonic_heatpump/sensor/panasonic_heatpump_sensor.cpp @@ -590,6 +590,43 @@ namespace esphome if (this->has_state() && this->get_state() == new_state) return; break; } + + case SensorIds::CONF_XTOP0: + { + new_state = PanasonicDecode::getWordMinus1(data, 14); + if (this->has_state() && this->get_state() == new_state) return; + break; + } + case SensorIds::CONF_XTOP1: + { + new_state = PanasonicDecode::getWordMinus1(data, 16); + if (this->has_state() && this->get_state() == new_state) return; + break; + } + case SensorIds::CONF_XTOP2: + { + new_state = PanasonicDecode::getWordMinus1(data, 18); + if (this->has_state() && this->get_state() == new_state) return; + break; + } + case SensorIds::CONF_XTOP3: + { + new_state = PanasonicDecode::getWordMinus1(data, 20); + if (this->has_state() && this->get_state() == new_state) return; + break; + } + case SensorIds::CONF_XTOP4: + { + new_state = PanasonicDecode::getWordMinus1(data, 22); + if (this->has_state() && this->get_state() == new_state) return; + break; + } + case SensorIds::CONF_XTOP5: + { + new_state = PanasonicDecode::getWordMinus1(data, 24); + if (this->has_state() && this->get_state() == new_state) return; + break; + } default: return; }; diff --git a/components/panasonic_heatpump/sensor/panasonic_heatpump_sensor.h b/components/panasonic_heatpump/sensor/panasonic_heatpump_sensor.h index 637bcfe..c3cea96 100644 --- a/components/panasonic_heatpump/sensor/panasonic_heatpump_sensor.h +++ b/components/panasonic_heatpump/sensor/panasonic_heatpump_sensor.h @@ -106,6 +106,13 @@ namespace esphome CONF_TOP136, CONF_TOP137, CONF_TOP138, + + CONF_XTOP0, + CONF_XTOP1, + CONF_XTOP2, + CONF_XTOP3, + CONF_XTOP4, + CONF_XTOP5, }; class PanasonicHeatpumpSensor : public sensor::Sensor, public Component, From 043eefdf4bc6656e3f548f70886a28f8ebc4a42c Mon Sep 17 00:00:00 2001 From: ElVit Date: Wed, 16 Jul 2025 16:17:43 +0200 Subject: [PATCH 2/9] Added support for extra query (fixes #11) --- components/panasonic_heatpump/helpers.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/components/panasonic_heatpump/helpers.cpp b/components/panasonic_heatpump/helpers.cpp index 6e44b85..81c00fb 100644 --- a/components/panasonic_heatpump/helpers.cpp +++ b/components/panasonic_heatpump/helpers.cpp @@ -24,6 +24,7 @@ namespace esphome break; case 0x71: msgType = "polling_" + msgType; + if (data[3] == 0x21) msgType = "extra_" + msgType; break; case 0xF1: msgType = "command_" + msgType; From fbe604523aa62433b4514a6ebaef7cdfb7e91bcb Mon Sep 17 00:00:00 2001 From: ElVit Date: Thu, 17 Jul 2025 20:23:33 +0200 Subject: [PATCH 3/9] Added support for extra query (fixes #11) --- .../panasonic_heatpump/panasonic_heatpump.cpp | 92 ++++++++++--------- .../panasonic_heatpump/panasonic_heatpump.h | 4 +- 2 files changed, 52 insertions(+), 44 deletions(-) diff --git a/components/panasonic_heatpump/panasonic_heatpump.cpp b/components/panasonic_heatpump/panasonic_heatpump.cpp index 0b98c2d..abeeff9 100644 --- a/components/panasonic_heatpump/panasonic_heatpump.cpp +++ b/components/panasonic_heatpump/panasonic_heatpump.cpp @@ -38,7 +38,7 @@ namespace esphome this->loop_state_ = LoopState::CHECK_RESPONSE; break; case LoopState::CHECK_RESPONSE: - this->current_response_ = this->check_response(this->heatpump_message_); + this->current_response_ = this->check_response(this->response_message_); switch (this->current_response_) { case ResponseType::UNKNOWN: @@ -55,56 +55,56 @@ namespace esphome case LoopState::PUBLISH_SENSOR: for (auto *entity : this->sensors_) { - entity->publish_new_state(this->heatpump_message_); + entity->publish_new_state(this->heatpump_default_message_); } this->loop_state_ = LoopState::PUBLISH_BINARY_SENSOR; break; case LoopState::PUBLISH_BINARY_SENSOR: for (auto *entity : this->binary_sensors_) { - entity->publish_new_state(this->heatpump_message_); + entity->publish_new_state(this->heatpump_default_message_); } this->loop_state_ = LoopState::PUBLISH_TEXT_SENSOR; break; case LoopState::PUBLISH_TEXT_SENSOR: for (auto *entity : this->text_sensors_) { - entity->publish_new_state(this->heatpump_message_); + entity->publish_new_state(this->heatpump_default_message_); } this->loop_state_ = LoopState::PUBLISH_NUMBER; break; case LoopState::PUBLISH_NUMBER: for (auto *entity : this->numbers_) { - entity->publish_new_state(this->heatpump_message_); + entity->publish_new_state(this->heatpump_default_message_); } this->loop_state_ = LoopState::PUBLISH_SELECT; break; case LoopState::PUBLISH_SELECT: for (auto *entity : this->selects_) { - entity->publish_new_state(this->heatpump_message_); + entity->publish_new_state(this->heatpump_default_message_); } this->loop_state_ = LoopState::PUBLISH_SWITCH; break; case LoopState::PUBLISH_SWITCH: for (auto *entity : this->switches_) { - entity->publish_new_state(this->heatpump_message_); + entity->publish_new_state(this->heatpump_default_message_); } this->loop_state_ = LoopState::PUBLISH_CLIMATE; break; case LoopState::PUBLISH_CLIMATE: for (auto *entity : this->climates_) { - entity->publish_new_state(this->heatpump_message_); + entity->publish_new_state(this->heatpump_default_message_); } this->loop_state_ = LoopState::SEND_REQUEST; break; case LoopState::PUBLISH_EXTRA_SENSOR: for (auto *entity : this->extra_sensors_) { - entity->publish_new_state(this->heatpump_message_); + entity->publish_new_state(this->heatpump_extra_message_); } this->loop_state_ = LoopState::SEND_REQUEST; break; @@ -164,7 +164,6 @@ namespace esphome if (this->response_message_.size() > 2 && this->response_message_.size() == this->payload_length_ + 3) { - this->heatpump_message_ = this->response_message_; this->response_receiving_ = false; this->current_response_count_++; if (this->log_uart_msg_) PanasonicHelpers::log_uart_hex(UART_LOG_RX, this->response_message_, ','); @@ -259,8 +258,13 @@ namespace esphome int PanasonicHeatpumpComponent::getResponseByte(const int index) { - if (this->heatpump_message_.size() > index) return this->heatpump_message_[index]; - if (this->response_message_.size() > index) return this->response_message_[index]; + if (this->heatpump_default_message_.size() > index) return this->heatpump_default_message_[index]; + return -1; + } + + int PanasonicHeatpumpComponent::getExtraResponseByte(const int index) + { + if (this->heatpump_extra_message_.size() > index) return this->heatpump_extra_message_[index]; return -1; } @@ -273,6 +277,7 @@ namespace esphome if (data.empty()) return ResponseType::UNKNOWN; if (data[0] != 0x71) return ResponseType::UNKNOWN; + if (this->response_receiving_) return ResponseType::UNKNOWN; if (data.size() != RESPONSE_MSG_SIZE) { ESP_LOGW(TAG, "Invalid response message length: recieved %d - expected %d", data.size(), RESPONSE_MSG_SIZE); @@ -294,25 +299,26 @@ namespace esphome return ResponseType::UNKNOWN; } - // Get response type + // Get response type and save the response auto responseType = ResponseType::UNKNOWN; - if (data[3] == 0x10) responseType = ResponseType::DEFAULT; - if (data[3] == 0x21) responseType = ResponseType::EXTRA; + 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 - return ResponseType::UNKNOWN; - } - - // Check if extra request shall be send - if (responseType == ResponseType::DEFAULT) - { - this->send_extra_request_ = data[199] > 0x02 ? true : false; - } - else - { this->send_extra_request_ = false; + return ResponseType::UNKNOWN; } // Check if the current response is a new response @@ -330,7 +336,7 @@ namespace esphome this->command_message_.assign(std::begin(PanasonicCommand::CommandMessage), std::end(PanasonicCommand::CommandMessage)); } - uint8_t lowNibble = this->heatpump_message_[index] & 0b1111; + uint8_t lowNibble = this->heatpump_default_message_[index] & 0b1111; uint8_t highNibble = value << 4; // set command byte this->command_message_[index] = highNibble + lowNibble; @@ -349,7 +355,7 @@ namespace esphome this->command_message_.assign(std::begin(PanasonicCommand::CommandMessage), std::end(PanasonicCommand::CommandMessage)); } - uint8_t highNibble = this->heatpump_message_[index] & 0b11110000; + uint8_t highNibble = this->heatpump_default_message_[index] & 0b11110000; uint8_t lowNibble = value & 0b1111; // set command byte this->command_message_[index] = highNibble + lowNibble; @@ -390,27 +396,27 @@ namespace esphome if (index == 75 || index == 76 || index == 77 || index == 78 || index == 86 || index == 87 || index == 88 || index == 89) { - this->command_message_[75] = this->heatpump_message_[75]; - this->command_message_[76] = this->heatpump_message_[76]; - this->command_message_[77] = this->heatpump_message_[77]; - this->command_message_[78] = this->heatpump_message_[78]; - this->command_message_[86] = this->heatpump_message_[86]; - this->command_message_[87] = this->heatpump_message_[87]; - this->command_message_[88] = this->heatpump_message_[88]; - this->command_message_[89] = this->heatpump_message_[89]; + this->command_message_[75] = this->heatpump_default_message_[75]; + this->command_message_[76] = this->heatpump_default_message_[76]; + this->command_message_[77] = this->heatpump_default_message_[77]; + this->command_message_[78] = this->heatpump_default_message_[78]; + this->command_message_[86] = this->heatpump_default_message_[86]; + this->command_message_[87] = this->heatpump_default_message_[87]; + this->command_message_[88] = this->heatpump_default_message_[88]; + this->command_message_[89] = this->heatpump_default_message_[89]; } // Set zone 2 curve bytes if (index == 79 || index == 80 || index == 81 || index == 82 || index == 90 || index == 91 || index == 92 || index == 93) { - this->command_message_[79] = this->heatpump_message_[79]; - this->command_message_[80] = this->heatpump_message_[80]; - this->command_message_[81] = this->heatpump_message_[81]; - this->command_message_[82] = this->heatpump_message_[82]; - this->command_message_[90] = this->heatpump_message_[90]; - this->command_message_[91] = this->heatpump_message_[91]; - this->command_message_[92] = this->heatpump_message_[92]; - this->command_message_[93] = this->heatpump_message_[93]; + this->command_message_[79] = this->heatpump_default_message_[79]; + this->command_message_[80] = this->heatpump_default_message_[80]; + this->command_message_[81] = this->heatpump_default_message_[81]; + this->command_message_[82] = this->heatpump_default_message_[82]; + this->command_message_[90] = this->heatpump_default_message_[90]; + this->command_message_[91] = this->heatpump_default_message_[91]; + this->command_message_[92] = this->heatpump_default_message_[92]; + this->command_message_[93] = this->heatpump_default_message_[93]; } // set command byte diff --git a/components/panasonic_heatpump/panasonic_heatpump.h b/components/panasonic_heatpump/panasonic_heatpump.h index 18457f2..faf9f69 100644 --- a/components/panasonic_heatpump/panasonic_heatpump.h +++ b/components/panasonic_heatpump/panasonic_heatpump.h @@ -75,6 +75,7 @@ namespace esphome void set_log_uart_msg(bool active) { this->log_uart_msg_ = active; } // uart message variables to use in lambda functions int getResponseByte(const int index); + int getExtraResponseByte(const int index); // command functions void set_command_high_nibble(const uint8_t value, const uint8_t index); void set_command_low_nibble(const uint8_t value, const uint8_t index); @@ -95,7 +96,8 @@ namespace esphome uart::UARTComponent* uart_client_ { nullptr }; bool log_uart_msg_ { false }; // uart message variables - std::vector heatpump_message_; + std::vector heatpump_default_message_; + std::vector heatpump_extra_message_; std::vector response_message_; std::vector request_message_; std::vector command_message_; From 6cbbebc6f94a62de311b359b5fb8d082420e860a Mon Sep 17 00:00:00 2001 From: ElVit Date: Fri, 18 Jul 2025 15:36:21 +0200 Subject: [PATCH 4/9] Reduce some code lines --- .../panasonic_heatpump_binary_sensor.cpp | 46 ---- .../climate/panasonic_heatpump_climate.cpp | 2 +- .../number/panasonic_heatpump_number.cpp | 133 +----------- .../panasonic_heatpump/panasonic_heatpump.cpp | 8 - .../select/panasonic_heatpump_select.cpp | 29 +-- .../sensor/panasonic_heatpump_sensor.cpp | 202 ------------------ .../switch/panasonic_heatpump_switch.cpp | 51 +---- .../panasonic_heatpump_text_sensor.cpp | 42 ---- 8 files changed, 4 insertions(+), 509 deletions(-) diff --git a/components/panasonic_heatpump/binary_sensor/panasonic_heatpump_binary_sensor.cpp b/components/panasonic_heatpump/binary_sensor/panasonic_heatpump_binary_sensor.cpp index 433bfdd..b8f370e 100644 --- a/components/panasonic_heatpump/binary_sensor/panasonic_heatpump_binary_sensor.cpp +++ b/components/panasonic_heatpump/binary_sensor/panasonic_heatpump_binary_sensor.cpp @@ -21,143 +21,97 @@ namespace esphome switch (this->id_) { case BinarySensorIds::CONF_TOP0: - { new_state = PanasonicDecode::getBinaryState(PanasonicDecode::getBit7and8(data[4])); if (this->has_state() && this->state == new_state) return; break; - } case BinarySensorIds::CONF_TOP2: - { new_state = PanasonicDecode::getBinaryState(PanasonicDecode::getBit1and2(data[4])); if (this->has_state() && this->state == new_state) return; break; - } case BinarySensorIds::CONF_TOP3: - { new_state = PanasonicDecode::getBinaryState(PanasonicDecode::getBit1and2(data[7])); if (this->has_state() && this->state == new_state) return; break; - } case BinarySensorIds::CONF_TOP13: - { new_state = PanasonicDecode::getBinaryState(PanasonicDecode::getBit1and2(data[5])); if (this->has_state() && this->state == new_state) return; break; - } case BinarySensorIds::CONF_TOP26: - { new_state = PanasonicDecode::getBinaryState(PanasonicDecode::getBit5and6(data[111])); if (this->has_state() && this->state == new_state) return; break; - } case BinarySensorIds::CONF_TOP60: - { new_state = PanasonicDecode::getBinaryState(PanasonicDecode::getBit7and8(data[112])); if (this->has_state() && this->state == new_state) return; break; - } case BinarySensorIds::CONF_TOP61: - { new_state = PanasonicDecode::getBinaryState(PanasonicDecode::getBit5and6(data[112])); if (this->has_state() && this->state == new_state) return; break; - } case BinarySensorIds::CONF_TOP68: - { new_state = PanasonicDecode::getBinaryState(PanasonicDecode::getBit5and6(data[5])); if (this->has_state() && this->state == new_state) return; break; - } case BinarySensorIds::CONF_TOP69: - { new_state = PanasonicDecode::getBinaryState(PanasonicDecode::getBit5and6(data[117])); if (this->has_state() && this->state == new_state) return; break; - } case BinarySensorIds::CONF_TOP99: - { new_state = PanasonicDecode::getBinaryState(PanasonicDecode::getBit5and6(data[24])); if (this->has_state() && this->state == new_state) return; break; - } case BinarySensorIds::CONF_TOP100: - { new_state = PanasonicDecode::getBinaryState(PanasonicDecode::getBit7and8(data[24])); if (this->has_state() && this->state == new_state) return; break; - } case BinarySensorIds::CONF_TOP108: - { new_state = PanasonicDecode::getBinaryState(PanasonicDecode::getBit3and4(data[20])); if (this->has_state() && this->state == new_state) return; break; - } case BinarySensorIds::CONF_TOP109: - { new_state = PanasonicDecode::getBinaryState(PanasonicDecode::getBit5and6(data[20])); if (this->has_state() && this->state == new_state) return; break; - } case BinarySensorIds::CONF_TOP110: - { new_state = PanasonicDecode::getBinaryState(PanasonicDecode::getBit7and8(data[20])); if (this->has_state() && this->state == new_state) return; break; - } case BinarySensorIds::CONF_TOP119: - { new_state = PanasonicDecode::getBinaryState(PanasonicDecode::getBit7and8(data[23])); if (this->has_state() && this->state == new_state) return; break; - } case BinarySensorIds::CONF_TOP120: - { new_state = PanasonicDecode::getBinaryState(PanasonicDecode::getBit5and6(data[23])); if (this->has_state() && this->state == new_state) return; break; - } case BinarySensorIds::CONF_TOP121: - { new_state = PanasonicDecode::getBinaryState(PanasonicDecode::getBit3and4(data[23])); if (this->has_state() && this->state == new_state) return; break; - } case BinarySensorIds::CONF_TOP122: - { new_state = PanasonicDecode::getBinaryState(PanasonicDecode::getBit1and2(data[23])); if (this->has_state() && this->state == new_state) return; break; - } case BinarySensorIds::CONF_TOP123: - { new_state = PanasonicDecode::getBinaryState(PanasonicDecode::getBit1and2(data[116])); if (this->has_state() && this->state == new_state) return; break; - } case BinarySensorIds::CONF_TOP124: - { new_state = PanasonicDecode::getBinaryState(PanasonicDecode::getBit3and4(data[116])); if (this->has_state() && this->state == new_state) return; break; - } case BinarySensorIds::CONF_TOP129: - { new_state = PanasonicDecode::getBinaryState(PanasonicDecode::getBit7and8(data[26])); if (this->has_state() && this->state == new_state) return; break; - } case BinarySensorIds::CONF_TOP132: - { new_state = PanasonicDecode::getBinaryState(PanasonicDecode::getBit3and4(data[26])); if (this->has_state() && this->state == new_state) return; break; - } case BinarySensorIds::CONF_TOP133: - { new_state = PanasonicDecode::getBinaryState(PanasonicDecode::getBit1and2(data[26])); if (this->has_state() && this->state == new_state) return; break; - } default: return; }; diff --git a/components/panasonic_heatpump/climate/panasonic_heatpump_climate.cpp b/components/panasonic_heatpump/climate/panasonic_heatpump_climate.cpp index a5dca9b..0a04bfb 100644 --- a/components/panasonic_heatpump/climate/panasonic_heatpump_climate.cpp +++ b/components/panasonic_heatpump/climate/panasonic_heatpump_climate.cpp @@ -20,7 +20,7 @@ namespace esphome //traits.set_supports_action(true); traits.set_supports_current_temperature(true); if (this->cool_mode_ && - (this->id_ == ClimateIds::CONF_CLIMATE_ZONE1 || + (this->id_ == ClimateIds::CONF_CLIMATE_ZONE1 || this->id_ == ClimateIds::CONF_CLIMATE_ZONE2)) { traits.set_supports_two_point_target_temperature(true); diff --git a/components/panasonic_heatpump/number/panasonic_heatpump_number.cpp b/components/panasonic_heatpump/number/panasonic_heatpump_number.cpp index b98f496..0866d48 100644 --- a/components/panasonic_heatpump/number/panasonic_heatpump_number.cpp +++ b/components/panasonic_heatpump/number/panasonic_heatpump_number.cpp @@ -18,172 +18,107 @@ namespace esphome switch (this->id_) { case NumberIds::CONF_SET5: - { this->parent_->set_command_byte(PanasonicCommand::setPlus128(value), 38); break; - } case NumberIds::CONF_SET6: - { this->parent_->set_command_byte(PanasonicCommand::setPlus128(value), 39); break; - } case NumberIds::CONF_SET7: - { this->parent_->set_command_byte(PanasonicCommand::setPlus128(value), 40); break; - } case NumberIds::CONF_SET8: - { this->parent_->set_command_byte(PanasonicCommand::setPlus128(value), 41); break; - } case NumberIds::CONF_SET11: - { this->parent_->set_command_byte(PanasonicCommand::setPlus128(value), 42); break; - } case NumberIds::CONF_SET15: - { this->parent_->set_command_byte(PanasonicCommand::setPlus1(value), 45); break; - } case NumberIds::CONF_SET16_01: - { this->parent_->set_command_curve(PanasonicCommand::setPlus128(value), 75); break; - } case NumberIds::CONF_SET16_02: - { this->parent_->set_command_curve(PanasonicCommand::setPlus128(value), 76); break; - } case NumberIds::CONF_SET16_03: - { this->parent_->set_command_curve(PanasonicCommand::setPlus128(value), 77); break; - } case NumberIds::CONF_SET16_04: - { this->parent_->set_command_curve(PanasonicCommand::setPlus128(value), 78); break; - } case NumberIds::CONF_SET16_05: - { this->parent_->set_command_curve(PanasonicCommand::setPlus128(value), 79); break; - } case NumberIds::CONF_SET16_06: - { this->parent_->set_command_curve(PanasonicCommand::setPlus128(value), 80); break; - } case NumberIds::CONF_SET16_07: - { this->parent_->set_command_curve(PanasonicCommand::setPlus128(value), 81); break; - } case NumberIds::CONF_SET16_08: - { this->parent_->set_command_curve(PanasonicCommand::setPlus128(value), 82); break; - } case NumberIds::CONF_SET16_09: - { this->parent_->set_command_curve(PanasonicCommand::setPlus128(value), 86); break; - } case NumberIds::CONF_SET16_10: - { this->parent_->set_command_curve(PanasonicCommand::setPlus128(value), 87); break; - } case NumberIds::CONF_SET16_11: - { this->parent_->set_command_curve(PanasonicCommand::setPlus128(value), 88); break; - } case NumberIds::CONF_SET16_12: - { this->parent_->set_command_curve(PanasonicCommand::setPlus128(value), 89); break; - } case NumberIds::CONF_SET16_13: - { this->parent_->set_command_curve(PanasonicCommand::setPlus128(value), 90); break; - } case NumberIds::CONF_SET16_14: - { this->parent_->set_command_curve(PanasonicCommand::setPlus128(value), 91); break; - } case NumberIds::CONF_SET16_15: - { this->parent_->set_command_curve(PanasonicCommand::setPlus128(value), 92); break; - } case NumberIds::CONF_SET16_16: - { this->parent_->set_command_curve(PanasonicCommand::setPlus128(value), 93); break; - } case NumberIds::CONF_SET18: - { this->parent_->set_command_byte(PanasonicCommand::setPlus128(value), 84); break; - } case NumberIds::CONF_SET19: - { this->parent_->set_command_byte(PanasonicCommand::setPlus128(value), 94); break; - } case NumberIds::CONF_SET20: - { this->parent_->set_command_byte(PanasonicCommand::setPlus128(value), 99); break; - } case NumberIds::CONF_SET21: - { this->parent_->set_command_byte(PanasonicCommand::setPlus1(value), 104); break; - } case NumberIds::CONF_SET22: - { this->parent_->set_command_byte(PanasonicCommand::setPlus128(value), 105); break; - } case NumberIds::CONF_SET23: - { this->parent_->set_command_byte(PanasonicCommand::setPlus128(value), 106); break; - } case NumberIds::CONF_SET27: - { this->parent_->set_command_byte(PanasonicCommand::setPlus128(value), 59); break; - } case NumberIds::CONF_SET29: - { this->parent_->set_command_byte(PanasonicCommand::setPlus128(value), 83); break; - } case NumberIds::CONF_SET36: - { this->parent_->set_command_byte(PanasonicCommand::setPlus128(value), 65); break; - } case NumberIds::CONF_SET37: - { this->parent_->set_command_byte(PanasonicCommand::setPlus128(value), 66); break; - } case NumberIds::CONF_SET38: - { this->parent_->set_command_byte(PanasonicCommand::setPlus128(value), 68); break; - } default: return; }; + this->publish_state(state); this->keep_state_ = 2; } @@ -201,203 +136,137 @@ namespace esphome switch (this->id_) { case NumberIds::CONF_SET11: - { new_state = PanasonicDecode::getByteMinus128(data[42]); if (this->has_state() && this->state == new_state) return; break; - } case NumberIds::CONF_SET20: - { new_state = PanasonicDecode::getByteMinus128(data[99]); if (this->has_state() && this->state == new_state) return; break; - } case NumberIds::CONF_SET18: - { new_state = PanasonicDecode::getByteMinus128(data[84]); if (this->has_state() && this->state == new_state) return; break; - } case NumberIds::CONF_SET19: - { new_state = PanasonicDecode::getByteMinus128(data[94]); if (this->has_state() && this->state == new_state) return; break; - } case NumberIds::CONF_SET5: - { new_state = PanasonicDecode::getByteMinus128(data[38]); if (this->has_state() && this->state == new_state) return; break; - } case NumberIds::CONF_SET6: - { new_state = PanasonicDecode::getByteMinus128(data[39]); if (this->has_state() && this->state == new_state) return; break; - } case NumberIds::CONF_SET16_01: - { new_state = PanasonicDecode::getByteMinus128(data[75]); if (this->has_state() && this->state == new_state) return; break; - } case NumberIds::CONF_SET16_02: - { new_state = PanasonicDecode::getByteMinus128(data[76]); if (this->has_state() && this->state == new_state) return; break; - } case NumberIds::CONF_SET16_04: - { new_state = PanasonicDecode::getByteMinus128(data[78]); if (this->has_state() && this->state == new_state) return; break; - } case NumberIds::CONF_SET16_03: - { new_state = PanasonicDecode::getByteMinus128(data[77]); if (this->has_state() && this->state == new_state) return; break; - } case NumberIds::CONF_SET7: - { new_state = PanasonicDecode::getByteMinus128(data[40]); if (this->has_state() && this->state == new_state) return; break; - } case NumberIds::CONF_SET8: - { new_state = PanasonicDecode::getByteMinus128(data[41]); if (this->has_state() && this->state == new_state) return; break; - } case NumberIds::CONF_SET16_09: - { new_state = PanasonicDecode::getByteMinus128(data[86]); if (this->has_state() && this->state == new_state) return; break; - } case NumberIds::CONF_SET16_10: - { new_state = PanasonicDecode::getByteMinus128(data[87]); if (this->has_state() && this->state == new_state) return; break; - } case NumberIds::CONF_SET16_12: - { new_state = PanasonicDecode::getByteMinus128(data[89]); if (this->has_state() && this->state == new_state) return; break; - } case NumberIds::CONF_SET16_11: - { new_state = PanasonicDecode::getByteMinus128(data[88]); if (this->has_state() && this->state == new_state) return; break; - } case NumberIds::CONF_SET29: - { new_state = PanasonicDecode::getByteMinus128(data[83]); if (this->has_state() && this->state == new_state) return; break; - } case NumberIds::CONF_SET16_05: - { new_state = PanasonicDecode::getByteMinus128(data[79]); if (this->has_state() && this->state == new_state) return; break; - } case NumberIds::CONF_SET16_06: - { new_state = PanasonicDecode::getByteMinus128(data[80]); if (this->has_state() && this->state == new_state) return; break; - } case NumberIds::CONF_SET16_08: - { new_state = PanasonicDecode::getByteMinus128(data[82]); if (this->has_state() && this->state == new_state) return; break; - } case NumberIds::CONF_SET16_07: - { new_state = PanasonicDecode::getByteMinus128(data[81]); if (this->has_state() && this->state == new_state) return; break; - } case NumberIds::CONF_SET16_13: - { new_state = PanasonicDecode::getByteMinus128(data[90]); if (this->has_state() && this->state == new_state) return; break; - } case NumberIds::CONF_SET16_14: - { new_state = PanasonicDecode::getByteMinus128(data[91]); if (this->has_state() && this->state == new_state) return; break; - } case NumberIds::CONF_SET16_16: - { new_state = PanasonicDecode::getByteMinus128(data[93]); if (this->has_state() && this->state == new_state) return; break; - } case NumberIds::CONF_SET16_15: - { new_state = PanasonicDecode::getByteMinus128(data[92]); if (this->has_state() && this->state == new_state) return; break; - } case NumberIds::CONF_SET15: - { new_state = PanasonicDecode::getByteMinus1(data[45]); if (this->has_state() && this->state == new_state) return; break; - } case NumberIds::CONF_SET21: - { new_state = PanasonicDecode::getByteMinus1(data[104]); if (this->has_state() && this->state == new_state) return; break; - } case NumberIds::CONF_SET22: - { new_state = PanasonicDecode::getByteMinus128(data[105]); if (this->has_state() && this->state == new_state) return; break; - } case NumberIds::CONF_SET23: - { new_state = PanasonicDecode::getByteMinus128(data[106]); if (this->has_state() && this->state == new_state) return; break; - } case NumberIds::CONF_SET27: - { new_state = PanasonicDecode::getByteMinus128(data[59]); if (this->has_state() && this->state == new_state) return; break; - } case NumberIds::CONF_SET36: - { new_state = PanasonicDecode::getByteMinus128(data[65]); if (this->has_state() && this->state == new_state) return; break; - } case NumberIds::CONF_SET37: - { new_state = PanasonicDecode::getByteMinus128(data[66]); if (this->has_state() && this->state == new_state) return; break; - } case NumberIds::CONF_SET38: - { new_state = PanasonicDecode::getByteMinus128(data[68]); if (this->has_state() && this->state == new_state) return; break; - } default: return; }; diff --git a/components/panasonic_heatpump/panasonic_heatpump.cpp b/components/panasonic_heatpump/panasonic_heatpump.cpp index abeeff9..b1c86d4 100644 --- a/components/panasonic_heatpump/panasonic_heatpump.cpp +++ b/components/panasonic_heatpump/panasonic_heatpump.cpp @@ -176,34 +176,26 @@ namespace esphome switch (requestType) { case RequestType::COMMAND: - { if (this->log_uart_msg_) PanasonicHelpers::log_uart_hex(UART_LOG_TX, this->command_message_, ','); this->write_array(this->command_message_); this->flush(); break; - } case RequestType::INITIAL: - { // Probably not necessary but CZ-TAW1 sends this query on boot if (this->log_uart_msg_) PanasonicHelpers::log_uart_hex(UART_LOG_TX, PanasonicCommand::InitialRequest, INIT_REQUEST_SIZE, ','); this->write_array(PanasonicCommand::InitialRequest, INIT_REQUEST_SIZE); this->flush(); break; - } case RequestType::POLLING: - { if (this->log_uart_msg_) PanasonicHelpers::log_uart_hex(UART_LOG_TX, PanasonicCommand::PollingMessage, DATA_MESSAGE_SIZE, ','); this->write_array(PanasonicCommand::PollingMessage, DATA_MESSAGE_SIZE); this->flush(); break; - } case RequestType::POLLING_EXTRA: - { if (this->log_uart_msg_) PanasonicHelpers::log_uart_hex(UART_LOG_TX, PanasonicCommand::PollingExtraMessage, DATA_MESSAGE_SIZE, ','); this->write_array(PanasonicCommand::PollingMessage, DATA_MESSAGE_SIZE); this->flush(); break; - } }; this->next_request_ = RequestType::NONE; diff --git a/components/panasonic_heatpump/select/panasonic_heatpump_select.cpp b/components/panasonic_heatpump/select/panasonic_heatpump_select.cpp index 7dacc18..fa8a0c1 100644 --- a/components/panasonic_heatpump/select/panasonic_heatpump_select.cpp +++ b/components/panasonic_heatpump/select/panasonic_heatpump_select.cpp @@ -22,42 +22,29 @@ namespace esphome switch (this->id_) { case SelectIds::CONF_SET2: - { this->parent_->set_command_byte(PanasonicCommand::setPlus1Multiply16(index), 5); break; - } case SelectIds::CONF_SET3: - { this->parent_->set_command_byte(PanasonicCommand::setPlus1Multiply8(index), 7); break; - } case SelectIds::CONF_SET4: - { this->parent_->set_command_byte(PanasonicCommand::setPlus1(index), 7); break; - } case SelectIds::CONF_SET9: - { this->parent_->set_command_byte(PanasonicCommand::setOperationMode(index), 6); break; - } case SelectIds::CONF_SET17: - { this->parent_->set_command_byte(PanasonicCommand::setPlus1Multiply64(index), 6); break; - } case SelectIds::CONF_SET26: - { this->parent_->set_command_byte(PanasonicCommand::setPlus1Multiply16(index), 25); break; - } case SelectIds::CONF_SET35: - { this->parent_->set_command_byte(PanasonicCommand::setPlus1Multiply4(index), 26); break; - } default: return; }; + this->publish_state(value); this->keep_state_ = 2; } @@ -75,47 +62,33 @@ namespace esphome switch (this->id_) { case SelectIds::CONF_SET9: - { new_state = PanasonicDecode::getTextState(PanasonicDecode::OperationMode, PanasonicDecode::getOperationMode(data[6])); if (this->has_state() && this->state == new_state) return; break; - } case SelectIds::CONF_SET4: - { new_state = PanasonicDecode::getTextState(PanasonicDecode::PowerfulMode, PanasonicDecode::getBit6and7and8(data[7])); if (this->has_state() && this->state == new_state) return; break; - } case SelectIds::CONF_SET3: - { new_state = PanasonicDecode::getTextState(PanasonicDecode::QuietMode, PanasonicDecode::getBit3and4and5(data[7])); if (this->has_state() && this->state == new_state) return; break; - } case SelectIds::CONF_SET2: - { new_state = PanasonicDecode::getTextState(PanasonicDecode::HolidayState, PanasonicDecode::getBit3and4(data[5])); if (this->has_state() && this->state == new_state) return; break; - } case SelectIds::CONF_SET17: - { new_state = PanasonicDecode::getTextState(PanasonicDecode::ZoneState, PanasonicDecode::getBit1and2(data[6])); if (this->has_state() && this->state == new_state) return; break; - } case SelectIds::CONF_SET26: - { new_state = PanasonicDecode::getTextState(PanasonicDecode::ExtPadHeaterType, PanasonicDecode::getBit3and4(data[25])); if (this->has_state() && this->state == new_state) return; break; - } case SelectIds::CONF_SET35: - { new_state = PanasonicDecode::getTextState(PanasonicDecode::BivalentMode, PanasonicDecode::getBit5and6(data[26])); if (this->has_state() && this->state == new_state) return; break; - } default: return; }; diff --git a/components/panasonic_heatpump/sensor/panasonic_heatpump_sensor.cpp b/components/panasonic_heatpump/sensor/panasonic_heatpump_sensor.cpp index 20586eb..110481b 100644 --- a/components/panasonic_heatpump/sensor/panasonic_heatpump_sensor.cpp +++ b/components/panasonic_heatpump/sensor/panasonic_heatpump_sensor.cpp @@ -21,612 +21,410 @@ namespace esphome switch (this->id_) { case SensorIds::CONF_TOP1: - { new_state = PanasonicDecode::getPumpFlow(data, 169); if (this->has_state() && this->get_state() == new_state) return; break; - } case SensorIds::CONF_TOP5: - { new_state = PanasonicDecode::getByteMinus128(data[143]) + PanasonicDecode::getFractional(data[118], 0); if (this->has_state() && this->get_state() == new_state) return; break; - } case SensorIds::CONF_TOP6: - { new_state = PanasonicDecode::getByteMinus128(data[144]) + PanasonicDecode::getFractional(data[118], 3); if (this->has_state() && this->get_state() == new_state) return; break; - } case SensorIds::CONF_TOP7: - { new_state = PanasonicDecode::getByteMinus128(data[153]); if (this->has_state() && this->get_state() == new_state) return; break; - } case SensorIds::CONF_TOP8: - { new_state = PanasonicDecode::getByteMinus1(data[166]); if (this->has_state() && this->get_state() == new_state) return; break; - } case SensorIds::CONF_TOP9: - { new_state = PanasonicDecode::getByteMinus128(data[42]); if (this->has_state() && this->get_state() == new_state) return; break; - } case SensorIds::CONF_TOP10: - { new_state = PanasonicDecode::getByteMinus128(data[141]); if (this->has_state() && this->get_state() == new_state) return; break; - } case SensorIds::CONF_TOP11: - { new_state = PanasonicDecode::getWordMinus1(data, 182); if (this->has_state() && this->get_state() == new_state) return; break; - } case SensorIds::CONF_TOP12: - { new_state = PanasonicDecode::getWordMinus1(data, 179); if (this->has_state() && this->get_state() == new_state) return; break; - } case SensorIds::CONF_TOP14: - { new_state = PanasonicDecode::getByteMinus128(data[142]); if (this->has_state() && this->get_state() == new_state) return; break; - } case SensorIds::CONF_TOP15: - { new_state = PanasonicDecode::getByteMinus1Times200(data[194]); if (this->has_state() && this->get_state() == new_state) return; break; - } case SensorIds::CONF_TOP16: - { new_state = PanasonicDecode::getByteMinus1Times200(data[193]); if (this->has_state() && this->get_state() == new_state) return; break; - } case SensorIds::CONF_TOP21: - { new_state = PanasonicDecode::getByteMinus128(data[158]); if (this->has_state() && this->get_state() == new_state) return; break; - } case SensorIds::CONF_TOP22: - { new_state = PanasonicDecode::getByteMinus128(data[99]); if (this->has_state() && this->get_state() == new_state) return; break; - } case SensorIds::CONF_TOP23: - { new_state = PanasonicDecode::getByteMinus128(data[84]); if (this->has_state() && this->get_state() == new_state) return; break; - } case SensorIds::CONF_TOP24: - { new_state = PanasonicDecode::getByteMinus128(data[94]); if (this->has_state() && this->get_state() == new_state) return; break; - } case SensorIds::CONF_TOP25: - { new_state = PanasonicDecode::getByteMinus128(data[44]); if (this->has_state() && this->get_state() == new_state) return; break; - } case SensorIds::CONF_TOP27: - { new_state = PanasonicDecode::getByteMinus128(data[38]); if (this->has_state() && this->get_state() == new_state) return; break; - } case SensorIds::CONF_TOP28: - { new_state = PanasonicDecode::getByteMinus128(data[39]); if (this->has_state() && this->get_state() == new_state) return; break; - } case SensorIds::CONF_TOP29: - { new_state = PanasonicDecode::getByteMinus128(data[75]); if (this->has_state() && this->get_state() == new_state) return; break; - } case SensorIds::CONF_TOP30: - { new_state = PanasonicDecode::getByteMinus128(data[76]); if (this->has_state() && this->get_state() == new_state) return; break; - } case SensorIds::CONF_TOP31: - { new_state = PanasonicDecode::getByteMinus128(data[78]); if (this->has_state() && this->get_state() == new_state) return; break; - } case SensorIds::CONF_TOP32: - { new_state = PanasonicDecode::getByteMinus128(data[77]); if (this->has_state() && this->get_state() == new_state) return; break; - } case SensorIds::CONF_TOP33: - { new_state = PanasonicDecode::getByteMinus128(data[156]); if (this->has_state() && this->get_state() == new_state) return; break; - } case SensorIds::CONF_TOP34: - { new_state = PanasonicDecode::getByteMinus128(data[40]); if (this->has_state() && this->get_state() == new_state) return; break; - } case SensorIds::CONF_TOP35: - { new_state = PanasonicDecode::getByteMinus128(data[41]); if (this->has_state() && this->get_state() == new_state) return; break; - } case SensorIds::CONF_TOP36: - { new_state = PanasonicDecode::getByteMinus128(data[145]); if (this->has_state() && this->get_state() == new_state) return; break; - } case SensorIds::CONF_TOP37: - { new_state = PanasonicDecode::getByteMinus128(data[146]); if (this->has_state() && this->get_state() == new_state) return; break; - } case SensorIds::CONF_TOP38: - { new_state = PanasonicDecode::getByteMinus1Times200(data[196]); if (this->has_state() && this->get_state() == new_state) return; break; - } case SensorIds::CONF_TOP39: - { new_state = PanasonicDecode::getByteMinus1Times200(data[195]); if (this->has_state() && this->get_state() == new_state) return; break; - } case SensorIds::CONF_TOP40: - { new_state = PanasonicDecode::getByteMinus1Times200(data[198]); if (this->has_state() && this->get_state() == new_state) return; break; - } case SensorIds::CONF_TOP41: - { new_state = PanasonicDecode::getByteMinus1Times200(data[197]); if (this->has_state() && this->get_state() == new_state) return; break; - } case SensorIds::CONF_TOP42: - { new_state = PanasonicDecode::getByteMinus128(data[147]); if (this->has_state() && this->get_state() == new_state) return; break; - } case SensorIds::CONF_TOP43: - { new_state = PanasonicDecode::getByteMinus128(data[148]); if (this->has_state() && this->get_state() == new_state) return; break; - } case SensorIds::CONF_TOP45: - { new_state = PanasonicDecode::getByteMinus128(data[43]); if (this->has_state() && this->get_state() == new_state) return; break; - } case SensorIds::CONF_TOP46: - { new_state = PanasonicDecode::getByteMinus128(data[149]); if (this->has_state() && this->get_state() == new_state) return; break; - } case SensorIds::CONF_TOP47: - { new_state = PanasonicDecode::getByteMinus128(data[150]); if (this->has_state() && this->get_state() == new_state) return; break; - } case SensorIds::CONF_TOP48: - { new_state = PanasonicDecode::getByteMinus128(data[151]); if (this->has_state() && this->get_state() == new_state) return; break; - } case SensorIds::CONF_TOP49: - { new_state = PanasonicDecode::getByteMinus128(data[154]); if (this->has_state() && this->get_state() == new_state) return; break; - } case SensorIds::CONF_TOP50: - { new_state = PanasonicDecode::getByteMinus128(data[155]); if (this->has_state() && this->get_state() == new_state) return; break; - } case SensorIds::CONF_TOP51: - { new_state = PanasonicDecode::getByteMinus128(data[157]); if (this->has_state() && this->get_state() == new_state) return; break; - } case SensorIds::CONF_TOP52: - { new_state = PanasonicDecode::getByteMinus128(data[159]); if (this->has_state() && this->get_state() == new_state) return; break; - } case SensorIds::CONF_TOP53: - { new_state = PanasonicDecode::getByteMinus128(data[160]); if (this->has_state() && this->get_state() == new_state) return; break; - } case SensorIds::CONF_TOP54: - { new_state = PanasonicDecode::getByteMinus128(data[161]); if (this->has_state() && this->get_state() == new_state) return; break; - } case SensorIds::CONF_TOP55: - { new_state = PanasonicDecode::getByteMinus128(data[162]); if (this->has_state() && this->get_state() == new_state) return; break; - } case SensorIds::CONF_TOP56: - { new_state = PanasonicDecode::getByteMinus128(data[139]); if (this->has_state() && this->get_state() == new_state) return; break; - } case SensorIds::CONF_TOP57: - { new_state = PanasonicDecode::getByteMinus128(data[140]); if (this->has_state() && this->get_state() == new_state) return; break; - } case SensorIds::CONF_TOP62: - { new_state = PanasonicDecode::getByteMinus1Times10(data[173]); if (this->has_state() && this->get_state() == new_state) return; break; - } case SensorIds::CONF_TOP63: - { new_state = PanasonicDecode::getByteMinus1Times10(data[174]); if (this->has_state() && this->get_state() == new_state) return; break; - } case SensorIds::CONF_TOP64: - { new_state = PanasonicDecode::getByteMinus1Div5(data[163]); if (this->has_state() && this->get_state() == new_state) return; break; - } case SensorIds::CONF_TOP65: - { new_state = PanasonicDecode::getByteMinus1Times50(data[171]); if (this->has_state() && this->get_state() == new_state) return; break; - } case SensorIds::CONF_TOP66: - { new_state = PanasonicDecode::getByteMinus1Times50(data[164]); if (this->has_state() && this->get_state() == new_state) return; break; - } case SensorIds::CONF_TOP67: - { new_state = PanasonicDecode::getByteMinus1Div5(data[165]); if (this->has_state() && this->get_state() == new_state) return; break; - } case SensorIds::CONF_TOP70: - { new_state = PanasonicDecode::getByteMinus128(data[100]); if (this->has_state() && this->get_state() == new_state) return; break; - } case SensorIds::CONF_TOP71: - { new_state = PanasonicDecode::getByteMinus1(data[101]); if (this->has_state() && this->get_state() == new_state) return; break; - } case SensorIds::CONF_TOP72: - { new_state = PanasonicDecode::getByteMinus128(data[86]); if (this->has_state() && this->get_state() == new_state) return; break; - } case SensorIds::CONF_TOP73: - { new_state = PanasonicDecode::getByteMinus128(data[87]); if (this->has_state() && this->get_state() == new_state) return; break; - } case SensorIds::CONF_TOP74: - { new_state = PanasonicDecode::getByteMinus128(data[89]); if (this->has_state() && this->get_state() == new_state) return; break; - } case SensorIds::CONF_TOP75: - { new_state = PanasonicDecode::getByteMinus128(data[88]); if (this->has_state() && this->get_state() == new_state) return; break; - } case SensorIds::CONF_TOP77: - { new_state = PanasonicDecode::getByteMinus128(data[83]); if (this->has_state() && this->get_state() == new_state) return; break; - } case SensorIds::CONF_TOP78: - { new_state = PanasonicDecode::getByteMinus128(data[85]); if (this->has_state() && this->get_state() == new_state) return; break; - } case SensorIds::CONF_TOP79: - { new_state = PanasonicDecode::getByteMinus128(data[95]); if (this->has_state() && this->get_state() == new_state) return; break; - } case SensorIds::CONF_TOP80: - { new_state = PanasonicDecode::getByteMinus128(data[96]); if (this->has_state() && this->get_state() == new_state) return; break; - } case SensorIds::CONF_TOP82: - { new_state = PanasonicDecode::getByteMinus128(data[79]); if (this->has_state() && this->get_state() == new_state) return; break; - } case SensorIds::CONF_TOP83: - { new_state = PanasonicDecode::getByteMinus128(data[80]); if (this->has_state() && this->get_state() == new_state) return; break; - } case SensorIds::CONF_TOP84: - { new_state = PanasonicDecode::getByteMinus128(data[82]); if (this->has_state() && this->get_state() == new_state) return; break; - } case SensorIds::CONF_TOP85: - { new_state = PanasonicDecode::getByteMinus128(data[81]); if (this->has_state() && this->get_state() == new_state) return; break; - } case SensorIds::CONF_TOP86: - { new_state = PanasonicDecode::getByteMinus128(data[90]); if (this->has_state() && this->get_state() == new_state) return; break; - } case SensorIds::CONF_TOP87: - { new_state = PanasonicDecode::getByteMinus128(data[91]); if (this->has_state() && this->get_state() == new_state) return; break; - } case SensorIds::CONF_TOP88: - { new_state = PanasonicDecode::getByteMinus128(data[93]); if (this->has_state() && this->get_state() == new_state) return; break; - } case SensorIds::CONF_TOP89: - { new_state = PanasonicDecode::getByteMinus128(data[92]); if (this->has_state() && this->get_state() == new_state) return; break; - } case SensorIds::CONF_TOP90: - { new_state = PanasonicDecode::getWordMinus1(data, 185); if (this->has_state() && this->get_state() == new_state) return; break; - } case SensorIds::CONF_TOP91: - { new_state = PanasonicDecode::getWordMinus1(data, 188); if (this->has_state() && this->get_state() == new_state) return; break; - } case SensorIds::CONF_TOP93: - { new_state = PanasonicDecode::getByteMinus1(data[172]); if (this->has_state() && this->get_state() == new_state) return; break; - } case SensorIds::CONF_TOP95: - { new_state = PanasonicDecode::getByteMinus1(data[45]); if (this->has_state() && this->get_state() == new_state) return; break; - } case SensorIds::CONF_TOP96: - { new_state = PanasonicDecode::getByteMinus1(data[104]); if (this->has_state() && this->get_state() == new_state) return; break; - } case SensorIds::CONF_TOP97: - { new_state = PanasonicDecode::getByteMinus128(data[105]); if (this->has_state() && this->get_state() == new_state) return; break; - } case SensorIds::CONF_TOP98: - { new_state = PanasonicDecode::getByteMinus128(data[106]); if (this->has_state() && this->get_state() == new_state) return; break; - } case SensorIds::CONF_TOP102: - { new_state = PanasonicDecode::getByteMinus128(data[61]); if (this->has_state() && this->get_state() == new_state) return; break; - } case SensorIds::CONF_TOP103: - { new_state = PanasonicDecode::getByteMinus128(data[62]); if (this->has_state() && this->get_state() == new_state) return; break; - } case SensorIds::CONF_TOP104: - { new_state = PanasonicDecode::getByteMinus128(data[63]); if (this->has_state() && this->get_state() == new_state) return; break; - } case SensorIds::CONF_TOP105: - { new_state = PanasonicDecode::getByteMinus128(data[64]); if (this->has_state() && this->get_state() == new_state) return; break; - } case SensorIds::CONF_TOP113: - { new_state = PanasonicDecode::getByteMinus128(data[59]); if (this->has_state() && this->get_state() == new_state) return; break; - } case SensorIds::CONF_TOP115: - { new_state = PanasonicDecode::getByteMinus1Div50(data[125]); if (this->has_state() && this->get_state() == new_state) return; break; - } case SensorIds::CONF_TOP116: - { new_state = PanasonicDecode::getByteMinus128(data[126]); if (this->has_state() && this->get_state() == new_state) return; break; - } case SensorIds::CONF_TOP117: - { new_state = PanasonicDecode::getByteMinus128(data[127]); if (this->has_state() && this->get_state() == new_state) return; break; - } case SensorIds::CONF_TOP118: - { new_state = PanasonicDecode::getByteMinus128(data[128]); if (this->has_state() && this->get_state() == new_state) return; break; - } case SensorIds::CONF_TOP127: - { new_state = PanasonicDecode::getByteMinus1Div2(data[177]); if (this->has_state() && this->get_state() == new_state) return; break; - } case SensorIds::CONF_TOP128: - { new_state = PanasonicDecode::getByteMinus1Div2(data[178]); if (this->has_state() && this->get_state() == new_state) return; break; - } case SensorIds::CONF_TOP131: - { new_state = PanasonicDecode::getByteMinus128(data[65]); if (this->has_state() && this->get_state() == new_state) return; break; - } case SensorIds::CONF_TOP134: - { new_state = PanasonicDecode::getByteMinus128(data[66]); if (this->has_state() && this->get_state() == new_state) return; break; - } case SensorIds::CONF_TOP135: - { new_state = PanasonicDecode::getByteMinus128(data[68]); if (this->has_state() && this->get_state() == new_state) return; break; - } case SensorIds::CONF_TOP136: - { new_state = PanasonicDecode::getByteMinus1(data[67]); if (this->has_state() && this->get_state() == new_state) return; break; - } case SensorIds::CONF_TOP137: - { new_state = PanasonicDecode::getByteMinus1(data[69]); if (this->has_state() && this->get_state() == new_state) return; break; - } case SensorIds::CONF_TOP138: - { new_state = PanasonicDecode::getByteMinus1(data[70]); if (this->has_state() && this->get_state() == new_state) return; break; - } case SensorIds::CONF_XTOP0: - { new_state = PanasonicDecode::getWordMinus1(data, 14); if (this->has_state() && this->get_state() == new_state) return; break; - } case SensorIds::CONF_XTOP1: - { new_state = PanasonicDecode::getWordMinus1(data, 16); if (this->has_state() && this->get_state() == new_state) return; break; - } case SensorIds::CONF_XTOP2: - { new_state = PanasonicDecode::getWordMinus1(data, 18); if (this->has_state() && this->get_state() == new_state) return; break; - } case SensorIds::CONF_XTOP3: - { new_state = PanasonicDecode::getWordMinus1(data, 20); if (this->has_state() && this->get_state() == new_state) return; break; - } case SensorIds::CONF_XTOP4: - { new_state = PanasonicDecode::getWordMinus1(data, 22); if (this->has_state() && this->get_state() == new_state) return; break; - } case SensorIds::CONF_XTOP5: - { new_state = PanasonicDecode::getWordMinus1(data, 24); if (this->has_state() && this->get_state() == new_state) return; break; - } default: return; }; diff --git a/components/panasonic_heatpump/switch/panasonic_heatpump_switch.cpp b/components/panasonic_heatpump/switch/panasonic_heatpump_switch.cpp index 6b2ef19..c852856 100644 --- a/components/panasonic_heatpump/switch/panasonic_heatpump_switch.cpp +++ b/components/panasonic_heatpump/switch/panasonic_heatpump_switch.cpp @@ -20,72 +20,47 @@ namespace esphome switch (this->id_) { case SwitchIds::CONF_SET1: - { this->parent_->set_command_byte(PanasonicCommand::setPlus1(value), 4); break; - } case SwitchIds::CONF_SET10: - { this->parent_->set_command_byte(PanasonicCommand::setPlus1Multiply64(value), 4); break; - } case SwitchIds::CONF_SET12: - { this->parent_->set_command_byte(PanasonicCommand::setMultiply2(value), 8); break; - } case SwitchIds::CONF_SET13: - { this->parent_->set_command_byte(PanasonicCommand::setMultiply4(value), 8); break; - } case SwitchIds::CONF_SET14: - { this->parent_->set_command_byte(PanasonicCommand::setPlus1Multiply16(value), 4); break; - } case SwitchIds::CONF_SET24: - { this->parent_->set_command_byte(PanasonicCommand::setPlus1Multiply64(value), 5); break; - } case SwitchIds::CONF_SET25: - { this->parent_->set_command_byte(PanasonicCommand::setPlus1Multiply16(value), 20); break; - } case SwitchIds::CONF_SET28: - { this->parent_->set_command_byte(PanasonicCommand::setPlus1Multiply4(value), 24); break; - } case SwitchIds::CONF_SET30: - { this->parent_->set_command_byte(PanasonicCommand::setPlus1(value), 23); break; - } case SwitchIds::CONF_SET31: - { this->parent_->set_command_byte(PanasonicCommand::setPlus1Multiply16(value), 23); break; - } case SwitchIds::CONF_SET32: - { this->parent_->set_command_byte(PanasonicCommand::setPlus1Multiply64(value), 23); break; - } case SwitchIds::CONF_SET33: - { this->parent_->set_command_byte(PanasonicCommand::setPlus1Multiply4(value), 23); break; - } case SwitchIds::CONF_SET34: - { this->parent_->set_command_byte(PanasonicCommand::setPlus1(value), 26); break; - } default: return; }; + this->publish_state(state); this->keep_state_ = 2; } @@ -103,77 +78,53 @@ namespace esphome switch (this->id_) { case SwitchIds::CONF_SET1: - { new_state = PanasonicDecode::getBinaryState(PanasonicDecode::getBit7and8(data[4])); if (this->state == new_state) return; break; - } case SwitchIds::CONF_SET10: - { new_state = PanasonicDecode::getBinaryState(PanasonicDecode::getBit1and2(data[4])); if (this->state == new_state) return; break; - } case SwitchIds::CONF_SET24: - { new_state = PanasonicDecode::getBinaryState(PanasonicDecode::getBit1and2(data[5])); if (this->state == new_state) return; break; - } case SwitchIds::CONF_SET12: - { new_state = PanasonicDecode::getBinaryState(PanasonicDecode::getBit5and6(data[111])); if (this->state == new_state) return; break; - } case SwitchIds::CONF_SET13: - { new_state = PanasonicDecode::getBinaryState(PanasonicDecode::getBit5and6(data[117])); if (this->state == new_state) return; break; - } case SwitchIds::CONF_SET28: - { new_state = PanasonicDecode::getBinaryState(PanasonicDecode::getBit5and6(data[24])); if (this->state == new_state) return; break; - } case SwitchIds::CONF_SET25: - { new_state = PanasonicDecode::getBinaryState(PanasonicDecode::getBit3and4(data[20])); if (this->state == new_state) return; break; - } case SwitchIds::CONF_SET30: - { new_state = PanasonicDecode::getBinaryState(PanasonicDecode::getBit7and8(data[23])); if (this->state == new_state) return; break; - } case SwitchIds::CONF_SET33: - { new_state = PanasonicDecode::getBinaryState(PanasonicDecode::getBit5and6(data[23])); if (this->state == new_state) return; break; - } case SwitchIds::CONF_SET31: - { new_state = PanasonicDecode::getBinaryState(PanasonicDecode::getBit3and4(data[23])); if (this->state == new_state) return; break; - } case SwitchIds::CONF_SET32: - { new_state = PanasonicDecode::getBinaryState(PanasonicDecode::getBit1and2(data[23])); if (this->state == new_state) return; break; - } case SwitchIds::CONF_SET34: - { new_state = PanasonicDecode::getBinaryState(PanasonicDecode::getBit7and8(data[26])); if (this->state == new_state) return; break; - } default: return; }; diff --git a/components/panasonic_heatpump/text_sensor/panasonic_heatpump_text_sensor.cpp b/components/panasonic_heatpump/text_sensor/panasonic_heatpump_text_sensor.cpp index 18dcd0d..93572b7 100644 --- a/components/panasonic_heatpump/text_sensor/panasonic_heatpump_text_sensor.cpp +++ b/components/panasonic_heatpump/text_sensor/panasonic_heatpump_text_sensor.cpp @@ -21,131 +21,89 @@ namespace esphome switch (this->id_) { case TextSensorIds::CONF_TOP4: - { new_state = PanasonicDecode::getTextState(PanasonicDecode::OperationMode, PanasonicDecode::getOperationMode(data[6])); if (this->has_state() && this->get_state() == new_state) return; break; - } case TextSensorIds::CONF_TOP17: - { new_state = PanasonicDecode::getTextState(PanasonicDecode::PowerfulMode, PanasonicDecode::getBit6and7and8(data[7])); if (this->has_state() && this->get_state() == new_state) return; break; - } case TextSensorIds::CONF_TOP18: - { new_state = PanasonicDecode::getTextState(PanasonicDecode::QuietMode, PanasonicDecode::getBit3and4and5(data[7])); if (this->has_state() && this->get_state() == new_state) return; break; - } case TextSensorIds::CONF_TOP19: - { new_state = PanasonicDecode::getTextState(PanasonicDecode::HolidayState, PanasonicDecode::getBit3and4(data[5])); if (this->has_state() && this->get_state() == new_state) return; break; - } case TextSensorIds::CONF_TOP20: - { new_state = PanasonicDecode::getTextState(PanasonicDecode::ThreeWayValve, PanasonicDecode::getBit7and8(data[111])); if (this->has_state() && this->get_state() == new_state) return; break; - } case TextSensorIds::CONF_TOP44: - { new_state = PanasonicDecode::getErrorInfo(data[113], data[114]); if (this->has_state() && this->get_state() == new_state) return; break; - } case TextSensorIds::CONF_TOP58: - { new_state = PanasonicDecode::getTextState(PanasonicDecode::BlockedFree, PanasonicDecode::getBit5and6(data[9])); if (this->has_state() && this->get_state() == new_state) return; break; - } case TextSensorIds::CONF_TOP59: - { new_state = PanasonicDecode::getTextState(PanasonicDecode::BlockedFree, PanasonicDecode::getBit7and8(data[9])); if (this->has_state() && this->get_state() == new_state) return; break; - } case TextSensorIds::CONF_TOP76: - { new_state = PanasonicDecode::getTextState(PanasonicDecode::WaterTempControl, PanasonicDecode::getBit7and8(data[28])); if (this->has_state() && this->get_state() == new_state) return; break; - } case TextSensorIds::CONF_TOP81: - { new_state = PanasonicDecode::getTextState(PanasonicDecode::WaterTempControl, PanasonicDecode::getBit5and6(data[28])); if (this->has_state() && this->get_state() == new_state) return; break; - } case TextSensorIds::CONF_TOP92: - { new_state = PanasonicDecode::getTextState(PanasonicDecode::ModelNames, PanasonicDecode::getModel(data, 129)); if (this->has_state() && this->get_state() == new_state) return; break; - } case TextSensorIds::CONF_TOP94: - { new_state = PanasonicDecode::getTextState(PanasonicDecode::ZoneState, PanasonicDecode::getBit1and2(data[6])); if (this->has_state() && this->get_state() == new_state) return; break; - } case TextSensorIds::CONF_TOP101: - { new_state = PanasonicDecode::getTextState(PanasonicDecode::SolarMode, PanasonicDecode::getBit3and4(data[24])); if (this->has_state() && this->get_state() == new_state) return; break; - } case TextSensorIds::CONF_TOP106: - { new_state = PanasonicDecode::getTextState(PanasonicDecode::PumpFlowRateMode, PanasonicDecode::getBit3and4(data[29])); if (this->has_state() && this->get_state() == new_state) return; break; - } case TextSensorIds::CONF_TOP107: - { new_state = PanasonicDecode::getTextState(PanasonicDecode::LiquidType, PanasonicDecode::getBit1(data[20])); if (this->has_state() && this->get_state() == new_state) return; break; - } case TextSensorIds::CONF_TOP111: - { new_state = PanasonicDecode::getTextState(PanasonicDecode::ZoneSensorType, PanasonicDecode::getLowNibbleMinus1(data[22])); if (this->has_state() && this->get_state() == new_state) return; break; - } case TextSensorIds::CONF_TOP112: - { new_state = PanasonicDecode::getTextState(PanasonicDecode::ZoneSensorType, PanasonicDecode::getHighNibbleMinus1(data[22])); if (this->has_state() && this->get_state() == new_state) return; break; - } case TextSensorIds::CONF_TOP114: - { new_state = PanasonicDecode::getTextState(PanasonicDecode::ExtPadHeaterType, PanasonicDecode::getBit3and4(data[25])); if (this->has_state() && this->get_state() == new_state) return; break; - } case TextSensorIds::CONF_TOP125: - { new_state = PanasonicDecode::getTextState(PanasonicDecode::TwoWayValve, PanasonicDecode::getBit5and6(data[116])); if (this->has_state() && this->get_state() == new_state) return; break; - } case TextSensorIds::CONF_TOP126: - { new_state = PanasonicDecode::getTextState(PanasonicDecode::ThreeWayValve, PanasonicDecode::getBit7and8(data[116])); if (this->has_state() && this->get_state() == new_state) return; break; - } case TextSensorIds::CONF_TOP130: - { new_state = PanasonicDecode::getTextState(PanasonicDecode::BivalentMode, PanasonicDecode::getBit5and6(data[26])); if (this->has_state() && this->get_state() == new_state) return; break; - } default: return; }; From 9d2bd07ecbf2ce7bece1c0485f2fbd9d80572291 Mon Sep 17 00:00:00 2001 From: ElVit <54866762+ElVit@users.noreply.github.com> Date: Sat, 19 Jul 2025 08:45:54 +0200 Subject: [PATCH 5/9] panasonic_heatpump.cpp aktualisieren Fixed issue in function 'send_request()' (fixes #11) --- components/panasonic_heatpump/panasonic_heatpump.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/components/panasonic_heatpump/panasonic_heatpump.cpp b/components/panasonic_heatpump/panasonic_heatpump.cpp index b1c86d4..4f922d1 100644 --- a/components/panasonic_heatpump/panasonic_heatpump.cpp +++ b/components/panasonic_heatpump/panasonic_heatpump.cpp @@ -193,7 +193,7 @@ namespace esphome break; case RequestType::POLLING_EXTRA: if (this->log_uart_msg_) PanasonicHelpers::log_uart_hex(UART_LOG_TX, PanasonicCommand::PollingExtraMessage, DATA_MESSAGE_SIZE, ','); - this->write_array(PanasonicCommand::PollingMessage, DATA_MESSAGE_SIZE); + this->write_array(PanasonicCommand::PollingExtraMessage, DATA_MESSAGE_SIZE); this->flush(); break; }; From 8c4eadbf2c6fc4c3ca08dae8f52e1fa80e064ff8 Mon Sep 17 00:00:00 2001 From: ElVit Date: Sat, 19 Jul 2025 19:25:05 +0200 Subject: [PATCH 6/9] 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 From 0693ea8413e45f26b367d9df4dbcb2867346740f Mon Sep 17 00:00:00 2001 From: ElVit <54866762+ElVit@users.noreply.github.com> Date: Sat, 19 Jul 2025 19:52:14 +0200 Subject: [PATCH 7/9] Added version to dump_config() --- components/panasonic_heatpump/panasonic_heatpump.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/components/panasonic_heatpump/panasonic_heatpump.cpp b/components/panasonic_heatpump/panasonic_heatpump.cpp index 4a35bd1..d1d72a3 100644 --- a/components/panasonic_heatpump/panasonic_heatpump.cpp +++ b/components/panasonic_heatpump/panasonic_heatpump.cpp @@ -10,7 +10,7 @@ namespace esphome void PanasonicHeatpumpComponent::dump_config() { - ESP_LOGCONFIG(TAG, "Panasonic Heatpump"); + ESP_LOGCONFIG(TAG, "*** Panasonic Heatpump *** v0.0.4-dev1 ***"); delay(10); // NOLINT } From 51c405b543486f8f3f39824775a3cccad188eb29 Mon Sep 17 00:00:00 2001 From: ElVit Date: Sun, 20 Jul 2025 20:13:05 +0200 Subject: [PATCH 8/9] Added support for extra query (fixes #11) --- .../panasonic_heatpump/panasonic_heatpump.cpp | 3 ++- components/panasonic_heatpump/sensor/__init__.py | 14 ++++---------- 2 files changed, 6 insertions(+), 11 deletions(-) diff --git a/components/panasonic_heatpump/panasonic_heatpump.cpp b/components/panasonic_heatpump/panasonic_heatpump.cpp index d1d72a3..14cf300 100644 --- a/components/panasonic_heatpump/panasonic_heatpump.cpp +++ b/components/panasonic_heatpump/panasonic_heatpump.cpp @@ -10,7 +10,8 @@ namespace esphome void PanasonicHeatpumpComponent::dump_config() { - ESP_LOGCONFIG(TAG, "*** Panasonic Heatpump *** v0.0.4-dev1 ***"); + ESP_LOGCONFIG(TAG, "Panasonic Heatpump Component"); + ESP_LOGW(TAG, "*** v0.0.4-dev2 ***"); delay(10); // NOLINT } diff --git a/components/panasonic_heatpump/sensor/__init__.py b/components/panasonic_heatpump/sensor/__init__.py index 904ec57..5298138 100644 --- a/components/panasonic_heatpump/sensor/__init__.py +++ b/components/panasonic_heatpump/sensor/__init__.py @@ -231,9 +231,7 @@ TYPES = [ CONF_TOP136, CONF_TOP137, CONF_TOP138, -] -EXTRA_TYPES = [ CONF_XTOP0, CONF_XTOP1, CONF_XTOP2, @@ -964,11 +962,7 @@ async def to_code(config): await cg.register_component(var, child_config) cg.add(var.set_parent(parent)) cg.add(var.set_id(index)) - cg.add(parent.add_sensor(var)) - for index, key in enumerate(EXTRA_TYPES): - if child_config := config.get(key): - var = await sensor.new_sensor(child_config) - await cg.register_component(var, child_config) - cg.add(var.set_parent(parent)) - cg.add(var.set_id(index)) - cg.add(parent.add_extra_sensor(var)) + if key.startswith("xtop"): + cg.add(parent.add_extra_sensor(var)) + else: + cg.add(parent.add_sensor(var)) From 99c17d53964856a62477e4bd1e4a0631a12e9eef Mon Sep 17 00:00:00 2001 From: ElVit Date: Tue, 22 Jul 2025 19:33:43 +0200 Subject: [PATCH 9/9] Set version to 0.0.4 --- components/panasonic_heatpump/panasonic_heatpump.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/components/panasonic_heatpump/panasonic_heatpump.cpp b/components/panasonic_heatpump/panasonic_heatpump.cpp index 14cf300..4561ce5 100644 --- a/components/panasonic_heatpump/panasonic_heatpump.cpp +++ b/components/panasonic_heatpump/panasonic_heatpump.cpp @@ -10,8 +10,7 @@ namespace esphome void PanasonicHeatpumpComponent::dump_config() { - ESP_LOGCONFIG(TAG, "Panasonic Heatpump Component"); - ESP_LOGW(TAG, "*** v0.0.4-dev2 ***"); + ESP_LOGW(TAG, "*** Panasonic Heatpump Component v0.0.4 ***"); delay(10); // NOLINT }