diff --git a/components/panasonic_heatpump/decode.cpp b/components/panasonic_heatpump/decode.cpp index 0e93d3f..9213c78 100644 --- a/components/panasonic_heatpump/decode.cpp +++ b/components/panasonic_heatpump/decode.cpp @@ -26,61 +26,60 @@ namespace esphome constexpr const char* const PanasonicDecode::Bivalent[]; constexpr const char* const PanasonicDecode::ModelNames[]; - // stores the bytes #129 to #138 of known models in the same order as the ModelNames - static const uint8_t KnownModels[NUMBER_OF_MODELS][10] = + constexpr const uint8_t KnownModels[NUMBER_OF_MODELS][10] = { - 0xE2, 0xCF, 0x0B, 0x13, 0x33, 0x32, 0xD1, 0x0C, 0x16, 0x33, // 0 - 0xE2, 0xCF, 0x0B, 0x14, 0x33, 0x42, 0xD1, 0x0B, 0x17, 0x33, // 1 - 0xE2, 0xCF, 0x0D, 0x77, 0x09, 0x12, 0xD0, 0x0B, 0x05, 0x11, // 2 - 0xE2, 0xCF, 0x0C, 0x88, 0x05, 0x12, 0xD0, 0x0B, 0x97, 0x05, // 3 - 0xE2, 0xCF, 0x0D, 0x85, 0x05, 0x12, 0xD0, 0x0C, 0x94, 0x05, // 4 - 0xE2, 0xCF, 0x0D, 0x86, 0x05, 0x12, 0xD0, 0x0C, 0x95, 0x05, // 5 - 0xE2, 0xCF, 0x0D, 0x87, 0x05, 0x12, 0xD0, 0x0C, 0x96, 0x05, // 6 - 0xE2, 0xCE, 0x0D, 0x71, 0x81, 0x72, 0xCE, 0x0C, 0x92, 0x81, // 7 - 0x62, 0xD2, 0x0B, 0x43, 0x54, 0x42, 0xD2, 0x0B, 0x72, 0x66, // 8 - 0xC2, 0xD3, 0x0B, 0x33, 0x65, 0xB2, 0xD3, 0x0B, 0x94, 0x65, // 9 - 0xE2, 0xCF, 0x0B, 0x15, 0x33, 0x42, 0xD1, 0x0B, 0x18, 0x33, // 10 - 0xE2, 0xCF, 0x0B, 0x41, 0x34, 0x82, 0xD1, 0x0B, 0x31, 0x35, // 11 - 0x62, 0xD2, 0x0B, 0x45, 0x54, 0x42, 0xD2, 0x0B, 0x47, 0x55, // 12 - 0xE2, 0xCF, 0x0C, 0x74, 0x09, 0x12, 0xD0, 0x0D, 0x95, 0x05, // 13 - 0xE2, 0xCF, 0x0B, 0x82, 0x05, 0x12, 0xD0, 0x0C, 0x91, 0x05, // 14 - 0xE2, 0xCF, 0x0C, 0x55, 0x14, 0x12, 0xD0, 0x0B, 0x15, 0x08, // 15 - 0xE2, 0xCF, 0x0C, 0x43, 0x00, 0x12, 0xD0, 0x0B, 0x15, 0x08, // 16 - 0x62, 0xD2, 0x0B, 0x45, 0x54, 0x32, 0xD2, 0x0C, 0x45, 0x55, // 17 - 0x62, 0xD2, 0x0B, 0x43, 0x54, 0x42, 0xD2, 0x0C, 0x46, 0x55, // 18 - 0xE2, 0xCF, 0x0C, 0x54, 0x14, 0x12, 0xD0, 0x0B, 0x14, 0x08, // 19 - 0xC2, 0xD3, 0x0B, 0x34, 0x65, 0xB2, 0xD3, 0x0B, 0x95, 0x65, // 20 - 0xC2, 0xD3, 0x0B, 0x35, 0x65, 0xB2, 0xD3, 0x0B, 0x96, 0x65, // 21 - 0x62, 0xD2, 0x0B, 0x41, 0x54, 0x32, 0xD2, 0x0C, 0x45, 0x55, // 22 - 0x32, 0xD4, 0x0B, 0x87, 0x84, 0x73, 0x90, 0x0C, 0x84, 0x84, // 23 - 0x32, 0xD4, 0x0B, 0x88, 0x84, 0x73, 0x90, 0x0C, 0x85, 0x84, // 24 - 0xE2, 0xCF, 0x0B, 0x75, 0x09, 0x12, 0xD0, 0x0C, 0x06, 0x11, // 25 - 0x42, 0xD4, 0x0B, 0x83, 0x71, 0x42, 0xD2, 0x0C, 0x46, 0x55, // 26 - 0xC2, 0xD3, 0x0C, 0x34, 0x65, 0xB2, 0xD3, 0x0B, 0x95, 0x65, // 27 - 0xC2, 0xD3, 0x0C, 0x33, 0x65, 0xB2, 0xD3, 0x0B, 0x94, 0x65, // 28 - 0xE2, 0xCF, 0x0B, 0x83, 0x05, 0x12, 0xD0, 0x0D, 0x92, 0x05, // 29 - 0xE2, 0xCF, 0x0C, 0x78, 0x09, 0x12, 0xD0, 0x0B, 0x06, 0x11, // 30 - 0xC2, 0xD3, 0x0C, 0x35, 0x65, 0xB2, 0xD3, 0x0B, 0x96, 0x65, // 31 - 0x32, 0xD4, 0x0B, 0x99, 0x77, 0x62, 0x90, 0x0B, 0x01, 0x78, // 32 - 0x42, 0xD4, 0x0B, 0x15, 0x76, 0x12, 0xD0, 0x0B, 0x10, 0x11, // 33 - 0xE2, 0xD5, 0x0C, 0x29, 0x99, 0x83, 0x92, 0x0C, 0x28, 0x98, // 34 - 0xE2, 0xCF, 0x0D, 0x85, 0x05, 0x12, 0xD0, 0x0E, 0x94, 0x05, // 35 - 0xE2, 0xD5, 0x0D, 0x36, 0x99, 0x02, 0xD6, 0x0F, 0x67, 0x95, // 36 - 0xE2, 0xD5, 0x0B, 0x08, 0x95, 0x02, 0xD6, 0x0E, 0x66, 0x95, // 37 - 0xE2, 0xD5, 0x0B, 0x34, 0x99, 0x83, 0x92, 0x0C, 0x29, 0x98, // 38 - 0xE2, 0xCF, 0x0C, 0x89, 0x05, 0x12, 0xD0, 0x0C, 0x98, 0x05, // 39 - 0xE2, 0xD5, 0x0B, 0x08, 0x95, 0x02, 0xD6, 0x0E, 0x67, 0x95, // 40 - 0xE2, 0xCF, 0x0C, 0x74, 0x09, 0x12, 0xD0, 0x0C, 0x96, 0x05, // 41 - 0xE2, 0xCF, 0x0C, 0x74, 0x09, 0x12, 0xD0, 0x0E, 0x95, 0x05, // 42 - 0x32, 0xD4, 0x0B, 0x89, 0x84, 0x73, 0x90, 0x0C, 0x86, 0x84, // 43 - 0x32, 0xD4, 0x0B, 0x00, 0x78, 0x62, 0x90, 0x0B, 0x02, 0x78, // 44 - 0xE2, 0xCF, 0x0B, 0x82, 0x05, 0x12, 0xD0, 0x0D, 0x91, 0x05, // 45 - 0xE2, 0xD5, 0x0D, 0x99, 0x94, 0x02, 0xD6, 0x0D, 0x68, 0x95, // 46 - 0xE2, 0xCF, 0x0C, 0x74, 0x09, 0x12, 0xD0, 0x0C, 0x95, 0x05, // 47 - 0xE2, 0xD5, 0x0B, 0x34, 0x99, 0x83, 0x92, 0x0C, 0x28, 0x98, // 48 - 0xE2, 0xCF, 0x0D, 0x77, 0x09, 0x12, 0xD0, 0x0C, 0x05, 0x11, // 49 - 0xE2, 0xD5, 0x0C, 0x67, 0x00, 0x83, 0x92, 0x0C, 0x27, 0x98, // 51 - 0xE2, 0xD5, 0x0B, 0x34, 0x99, 0x83, 0x92, 0x0C, 0x27, 0x98, // 52 + { 0xE2, 0xCF, 0x0B, 0x13, 0x33, 0x32, 0xD1, 0x0C, 0x16, 0x33 }, // 0 + { 0xE2, 0xCF, 0x0B, 0x14, 0x33, 0x42, 0xD1, 0x0B, 0x17, 0x33 }, // 1 + { 0xE2, 0xCF, 0x0D, 0x77, 0x09, 0x12, 0xD0, 0x0B, 0x05, 0x11 }, // 2 + { 0xE2, 0xCF, 0x0C, 0x88, 0x05, 0x12, 0xD0, 0x0B, 0x97, 0x05 }, // 3 + { 0xE2, 0xCF, 0x0D, 0x85, 0x05, 0x12, 0xD0, 0x0C, 0x94, 0x05 }, // 4 + { 0xE2, 0xCF, 0x0D, 0x86, 0x05, 0x12, 0xD0, 0x0C, 0x95, 0x05 }, // 5 + { 0xE2, 0xCF, 0x0D, 0x87, 0x05, 0x12, 0xD0, 0x0C, 0x96, 0x05 }, // 6 + { 0xE2, 0xCE, 0x0D, 0x71, 0x81, 0x72, 0xCE, 0x0C, 0x92, 0x81 }, // 7 + { 0x62, 0xD2, 0x0B, 0x43, 0x54, 0x42, 0xD2, 0x0B, 0x72, 0x66 }, // 8 + { 0xC2, 0xD3, 0x0B, 0x33, 0x65, 0xB2, 0xD3, 0x0B, 0x94, 0x65 }, // 9 + { 0xE2, 0xCF, 0x0B, 0x15, 0x33, 0x42, 0xD1, 0x0B, 0x18, 0x33 }, // 10 + { 0xE2, 0xCF, 0x0B, 0x41, 0x34, 0x82, 0xD1, 0x0B, 0x31, 0x35 }, // 11 + { 0x62, 0xD2, 0x0B, 0x45, 0x54, 0x42, 0xD2, 0x0B, 0x47, 0x55 }, // 12 + { 0xE2, 0xCF, 0x0C, 0x74, 0x09, 0x12, 0xD0, 0x0D, 0x95, 0x05 }, // 13 + { 0xE2, 0xCF, 0x0B, 0x82, 0x05, 0x12, 0xD0, 0x0C, 0x91, 0x05 }, // 14 + { 0xE2, 0xCF, 0x0C, 0x55, 0x14, 0x12, 0xD0, 0x0B, 0x15, 0x08 }, // 15 + { 0xE2, 0xCF, 0x0C, 0x43, 0x00, 0x12, 0xD0, 0x0B, 0x15, 0x08 }, // 16 + { 0x62, 0xD2, 0x0B, 0x45, 0x54, 0x32, 0xD2, 0x0C, 0x45, 0x55 }, // 17 + { 0x62, 0xD2, 0x0B, 0x43, 0x54, 0x42, 0xD2, 0x0C, 0x46, 0x55 }, // 18 + { 0xE2, 0xCF, 0x0C, 0x54, 0x14, 0x12, 0xD0, 0x0B, 0x14, 0x08 }, // 19 + { 0xC2, 0xD3, 0x0B, 0x34, 0x65, 0xB2, 0xD3, 0x0B, 0x95, 0x65 }, // 20 + { 0xC2, 0xD3, 0x0B, 0x35, 0x65, 0xB2, 0xD3, 0x0B, 0x96, 0x65 }, // 21 + { 0x62, 0xD2, 0x0B, 0x41, 0x54, 0x32, 0xD2, 0x0C, 0x45, 0x55 }, // 22 + { 0x32, 0xD4, 0x0B, 0x87, 0x84, 0x73, 0x90, 0x0C, 0x84, 0x84 }, // 23 + { 0x32, 0xD4, 0x0B, 0x88, 0x84, 0x73, 0x90, 0x0C, 0x85, 0x84 }, // 24 + { 0xE2, 0xCF, 0x0B, 0x75, 0x09, 0x12, 0xD0, 0x0C, 0x06, 0x11 }, // 25 + { 0x42, 0xD4, 0x0B, 0x83, 0x71, 0x42, 0xD2, 0x0C, 0x46, 0x55 }, // 26 + { 0xC2, 0xD3, 0x0C, 0x34, 0x65, 0xB2, 0xD3, 0x0B, 0x95, 0x65 }, // 27 + { 0xC2, 0xD3, 0x0C, 0x33, 0x65, 0xB2, 0xD3, 0x0B, 0x94, 0x65 }, // 28 + { 0xE2, 0xCF, 0x0B, 0x83, 0x05, 0x12, 0xD0, 0x0D, 0x92, 0x05 }, // 29 + { 0xE2, 0xCF, 0x0C, 0x78, 0x09, 0x12, 0xD0, 0x0B, 0x06, 0x11 }, // 30 + { 0xC2, 0xD3, 0x0C, 0x35, 0x65, 0xB2, 0xD3, 0x0B, 0x96, 0x65 }, // 31 + { 0x32, 0xD4, 0x0B, 0x99, 0x77, 0x62, 0x90, 0x0B, 0x01, 0x78 }, // 32 + { 0x42, 0xD4, 0x0B, 0x15, 0x76, 0x12, 0xD0, 0x0B, 0x10, 0x11 }, // 33 + { 0xE2, 0xD5, 0x0C, 0x29, 0x99, 0x83, 0x92, 0x0C, 0x28, 0x98 }, // 34 + { 0xE2, 0xCF, 0x0D, 0x85, 0x05, 0x12, 0xD0, 0x0E, 0x94, 0x05 }, // 35 + { 0xE2, 0xD5, 0x0D, 0x36, 0x99, 0x02, 0xD6, 0x0F, 0x67, 0x95 }, // 36 + { 0xE2, 0xD5, 0x0B, 0x08, 0x95, 0x02, 0xD6, 0x0E, 0x66, 0x95 }, // 37 + { 0xE2, 0xD5, 0x0B, 0x34, 0x99, 0x83, 0x92, 0x0C, 0x29, 0x98 }, // 38 + { 0xE2, 0xCF, 0x0C, 0x89, 0x05, 0x12, 0xD0, 0x0C, 0x98, 0x05 }, // 39 + { 0xE2, 0xD5, 0x0B, 0x08, 0x95, 0x02, 0xD6, 0x0E, 0x67, 0x95 }, // 40 + { 0xE2, 0xCF, 0x0C, 0x74, 0x09, 0x12, 0xD0, 0x0C, 0x96, 0x05 }, // 41 + { 0xE2, 0xCF, 0x0C, 0x74, 0x09, 0x12, 0xD0, 0x0E, 0x95, 0x05 }, // 42 + { 0x32, 0xD4, 0x0B, 0x89, 0x84, 0x73, 0x90, 0x0C, 0x86, 0x84 }, // 43 + { 0x32, 0xD4, 0x0B, 0x00, 0x78, 0x62, 0x90, 0x0B, 0x02, 0x78 }, // 44 + { 0xE2, 0xCF, 0x0B, 0x82, 0x05, 0x12, 0xD0, 0x0D, 0x91, 0x05 }, // 45 + { 0xE2, 0xD5, 0x0D, 0x99, 0x94, 0x02, 0xD6, 0x0D, 0x68, 0x95 }, // 46 + { 0xE2, 0xCF, 0x0C, 0x74, 0x09, 0x12, 0xD0, 0x0C, 0x95, 0x05 }, // 47 + { 0xE2, 0xD5, 0x0B, 0x34, 0x99, 0x83, 0x92, 0x0C, 0x28, 0x98 }, // 48 + { 0xE2, 0xCF, 0x0D, 0x77, 0x09, 0x12, 0xD0, 0x0C, 0x05, 0x11 }, // 49 + { 0xE2, 0xD5, 0x0C, 0x67, 0x00, 0x83, 0x92, 0x0C, 0x27, 0x98 }, // 51 + { 0xE2, 0xD5, 0x0B, 0x34, 0x99, 0x83, 0x92, 0x0C, 0x27, 0x98 }, // 52 }; int PanasonicDecode::getBit1(uint8_t input) @@ -199,25 +198,22 @@ namespace esphome } // TOP92 // - int PanasonicDecode::getModel(std::vector& data, uint8_t index) + int PanasonicDecode::getModel(const std::vector& data, uint8_t index) { - int result = -1; - uint8_t model[10] = + // Ensure there are at least 10 bytes in data message after the start index + if (index + 10 > data.size()) return -1; + // Get model bytes from data message + auto model = std::vector(data.begin() + index, data.begin() + index + 10); + // Search model bytes in the list of known models and return the index + for (size_t i = 0; i < NUMBER_OF_MODELS; i++) { - data[index], data[index+1], data[index+2], data[index+3], data[index+4], - data[index+5], data[index+6], data[index+7], data[index+8], data[index+9] - }; - - for (size_t i = 0 ; i < NUMBER_OF_MODELS; i++) - { - if (memcmp(model, KnownModels[i], 10) == 0) + if (std::equal(KnownModels[i], KnownModels[i] + 10, model.begin())) { - result = i; - break; + return static_cast(i); } } - return result; + return -1; } // TOP1 // diff --git a/components/panasonic_heatpump/decode.h b/components/panasonic_heatpump/decode.h index df64bb0..c207b60 100644 --- a/components/panasonic_heatpump/decode.h +++ b/components/panasonic_heatpump/decode.h @@ -37,7 +37,7 @@ namespace esphome static int getUintt16(uint8_t input1, uint8_t input2); static int getOpMode(uint8_t input); - static int getModel(std::vector& data, uint8_t index); + static int getModel(const std::vector& data, uint8_t index); static float getPumpFlow(uint8_t input1, uint8_t input2); static float getFractional(uint8_t input, uint8_t shift); static std::string getErrorInfo(uint8_t errorType, uint8_t errorNumber); @@ -121,5 +121,7 @@ namespace esphome "IDU:WH-SDC0509L3E5, ODU:WH-WDG05LE5", // 52 }; }; + + extern const uint8_t KnownModels[NUMBER_OF_MODELS][10]; } // namespace panasonic_heatpump } // namespace esphome diff --git a/components/panasonic_heatpump/panasonic_heatpump.cpp b/components/panasonic_heatpump/panasonic_heatpump.cpp index 9a9d213..4784c34 100644 --- a/components/panasonic_heatpump/panasonic_heatpump.cpp +++ b/components/panasonic_heatpump/panasonic_heatpump.cpp @@ -61,7 +61,7 @@ namespace esphome // Add current byte to message buffer this->response_message_.push_back(byte); - // 2. bytes contains the payload size + // 2. byte contains the payload size if (this->response_message_.size() == 2) { this->response_payload_length_ = byte; @@ -138,7 +138,7 @@ namespace esphome // Add current byte to message buffer this->request_message_.push_back(byte); - // 2. bytes contains the payload size + // 2. byte contains the payload size if (this->request_message_.size() == 2) { this->request_payload_length_ = byte; @@ -165,30 +165,29 @@ namespace esphome } } - void PanasonicHeatpumpComponent::log_uart_hex(UartLogDirection direction, const uint8_t *data, size_t length, uint8_t separator) + void PanasonicHeatpumpComponent::log_uart_hex(UartLogDirection direction, const std::vector& data, uint8_t separator) + { + this->log_uart_hex(direction, &data[0], data.size(), separator); + } + void PanasonicHeatpumpComponent::log_uart_hex(UartLogDirection direction, const uint8_t* data, size_t length, uint8_t separator) { if (this->log_uart_msg_ == false) return; std::string logStr; std::string msgDir = direction == UART_LOG_TX ? ">>>" : "<<<"; - std::string msgType = "response"; - if (direction == UART_LOG_TX) + std::string msgType = direction == UART_LOG_TX ? "request" : "response"; + switch(data[0]) { - switch(data[0]) - { - case 0x31: - msgType = "initial_request"; - break; - case 0x71: - msgType = "polling_request"; - break; - case 0xF1: - msgType = "command_request"; - break; - default: - msgType = "request"; - }; - } + case 0x31: + msgType = "initial_" + msgType; + break; + case 0x71: + msgType = "polling_" + msgType; + break; + case 0xF1: + msgType = "command_" + msgType; + break; + }; logStr = "[" + std::to_string(length) + "]"; ESP_LOGI(TAG, "%s %s%s", msgDir.c_str(), msgType.c_str(), logStr.c_str()); @@ -203,7 +202,7 @@ namespace esphome logStr += buffer; } - size_t chunkSize = 90; + size_t chunkSize = 150; for (size_t i = 0; i < logStr.length(); i += chunkSize) { ESP_LOGI(TAG, "%s %s", msgDir.c_str(), logStr.substr(i, chunkSize).c_str()); @@ -211,41 +210,42 @@ namespace esphome } } - void PanasonicHeatpumpComponent::decode_response(std::vector bytes) + void PanasonicHeatpumpComponent::decode_response(const std::vector& data) { // Read response message: // format: 0x71 [payload_length] 0x01 0x10 [[TOP0 - TOP114] ...] 0x00 [checksum] // payload_length: payload_length + 3 = packet_length // checksum: if (sum(all bytes) & 0xFF == 0) ==> valid packet - if (bytes.size() != RESPONSE_MSG_SIZE) + if (data[0] != 0x71) return; + if (data.size() != RESPONSE_MSG_SIZE) { - ESP_LOGW(TAG, "Invalid response message length: recieved %d - expected %d", bytes.size(), RESPONSE_MSG_SIZE); + ESP_LOGW(TAG, "Invalid response message length: recieved %d - expected %d", data.size(), RESPONSE_MSG_SIZE); delay(10); return; } uint8_t checksum = 0; - for (int i = 0; i < bytes.size(); i++) + for (int i = 0; i < data.size(); i++) { - checksum += bytes[i]; + checksum += data[i]; } // checksum = checksum & 0xFF; if (checksum != 0) { - ESP_LOGW(TAG, "Invalid response message: checksum = 0x%02X, last_byte = 0x%02X", checksum, bytes[202]); + ESP_LOGW(TAG, "Invalid response message: checksum = 0x%02X, last_byte = 0x%02X", checksum, data[202]); delay(10); return; } - this->publish_sensor(bytes); - this->publish_binary_sensor(bytes); - this->publish_text_sensor(bytes); - this->publish_number(bytes); - this->publish_select(bytes); - this->publish_switch(bytes); + this->publish_sensor(data); + this->publish_binary_sensor(data); + this->publish_text_sensor(data); + this->publish_number(data); + this->publish_select(data); + this->publish_switch(data); } - + void PanasonicHeatpumpComponent::set_command_byte(uint8_t value, uint8_t index) { if (this->next_request_ == 1) @@ -265,229 +265,253 @@ namespace esphome this->trigger_request_ = true; } - void PanasonicHeatpumpComponent::publish_sensor(std::vector bytes) + void PanasonicHeatpumpComponent::set_command_bytes(const std::vector>& data) + { + if (this->next_request_ == 1) + { + // initialize the command + command_message_.clear(); + command_message_.insert(this->command_message_.end(), PanasonicCommand::CommandMessage, + PanasonicCommand::CommandMessage + DATA_MESSAGE_SIZE); + } + // set command bytes + for (size_t i = 0; i < data.size(); ++i) + { + uint8_t value = std::get<0>(data[i]); + uint8_t index = std::get<1>(data[i]); + command_message_[index] = value; + } + // calculate and set set checksum (last element) + command_message_.back() = PanasonicCommand::calcChecksum(command_message_, command_message_.size() - 1); + + // command will be send on next loop + this->next_request_ = 2; + this->trigger_request_ = true; + } + + void PanasonicHeatpumpComponent::publish_sensor(const std::vector& data) { #ifdef USE_SENSOR - if (this->top1_sensor_) this->top1_sensor_->publish_state(PanasonicDecode::getPumpFlow(bytes[169], bytes[170])); - if (this->top5_sensor_) this->top5_sensor_->publish_state(PanasonicDecode::getByteMinus128(bytes[143]) + PanasonicDecode::getFractional(bytes[118], 0)); - if (this->top6_sensor_) this->top6_sensor_->publish_state(PanasonicDecode::getByteMinus128(bytes[144]) + PanasonicDecode::getFractional(bytes[118], 3)); - if (this->top7_sensor_) this->top7_sensor_->publish_state(PanasonicDecode::getByteMinus128(bytes[153])); - if (this->top8_sensor_) this->top8_sensor_->publish_state(PanasonicDecode::getByteMinus1(bytes[166])); - if (this->top9_sensor_) this->top9_sensor_->publish_state(PanasonicDecode::getByteMinus128(bytes[42])); - if (this->top10_sensor_) this->top10_sensor_->publish_state(PanasonicDecode::getByteMinus128(bytes[141])); - if (this->top11_sensor_) this->top11_sensor_->publish_state(PanasonicDecode::getWordMinus1(bytes[182], bytes[183])); - if (this->top12_sensor_) this->top12_sensor_->publish_state(PanasonicDecode::getWordMinus1(bytes[179], bytes[180])); - if (this->top14_sensor_) this->top14_sensor_->publish_state(PanasonicDecode::getByteMinus128(bytes[142])); - if (this->top15_sensor_) this->top15_sensor_->publish_state(PanasonicDecode::getByteMinus1Times200(bytes[194])); - if (this->top16_sensor_) this->top16_sensor_->publish_state(PanasonicDecode::getByteMinus1Times200(bytes[193])); - if (this->top21_sensor_) this->top21_sensor_->publish_state(PanasonicDecode::getByteMinus128(bytes[158])); - if (this->top22_sensor_) this->top22_sensor_->publish_state(PanasonicDecode::getByteMinus128(bytes[99])); - if (this->top23_sensor_) this->top23_sensor_->publish_state(PanasonicDecode::getByteMinus128(bytes[84])); - if (this->top24_sensor_) this->top24_sensor_->publish_state(PanasonicDecode::getByteMinus128(bytes[94])); - if (this->top25_sensor_) this->top25_sensor_->publish_state(PanasonicDecode::getByteMinus128(bytes[44])); - if (this->top27_sensor_) this->top27_sensor_->publish_state(PanasonicDecode::getByteMinus128(bytes[38])); - if (this->top28_sensor_) this->top28_sensor_->publish_state(PanasonicDecode::getByteMinus128(bytes[39])); - if (this->top29_sensor_) this->top29_sensor_->publish_state(PanasonicDecode::getByteMinus128(bytes[75])); - if (this->top30_sensor_) this->top30_sensor_->publish_state(PanasonicDecode::getByteMinus128(bytes[76])); - if (this->top31_sensor_) this->top31_sensor_->publish_state(PanasonicDecode::getByteMinus128(bytes[78])); - if (this->top32_sensor_) this->top32_sensor_->publish_state(PanasonicDecode::getByteMinus128(bytes[77])); - if (this->top33_sensor_) this->top33_sensor_->publish_state(PanasonicDecode::getByteMinus128(bytes[156])); - if (this->top34_sensor_) this->top34_sensor_->publish_state(PanasonicDecode::getByteMinus128(bytes[40])); - if (this->top35_sensor_) this->top35_sensor_->publish_state(PanasonicDecode::getByteMinus128(bytes[41])); - if (this->top36_sensor_) this->top36_sensor_->publish_state(PanasonicDecode::getByteMinus128(bytes[145])); - if (this->top37_sensor_) this->top37_sensor_->publish_state(PanasonicDecode::getByteMinus128(bytes[146])); - if (this->top38_sensor_) this->top38_sensor_->publish_state(PanasonicDecode::getByteMinus1Times200(bytes[196])); - if (this->top39_sensor_) this->top39_sensor_->publish_state(PanasonicDecode::getByteMinus1Times200(bytes[195])); - if (this->top40_sensor_) this->top40_sensor_->publish_state(PanasonicDecode::getByteMinus1Times200(bytes[198])); - if (this->top41_sensor_) this->top41_sensor_->publish_state(PanasonicDecode::getByteMinus1Times200(bytes[197])); - if (this->top42_sensor_) this->top42_sensor_->publish_state(PanasonicDecode::getByteMinus128(bytes[147])); - if (this->top43_sensor_) this->top43_sensor_->publish_state(PanasonicDecode::getByteMinus128(bytes[148])); - if (this->top45_sensor_) this->top45_sensor_->publish_state(PanasonicDecode::getByteMinus128(bytes[43])); - if (this->top46_sensor_) this->top46_sensor_->publish_state(PanasonicDecode::getByteMinus128(bytes[149])); - if (this->top47_sensor_) this->top47_sensor_->publish_state(PanasonicDecode::getByteMinus128(bytes[150])); - if (this->top48_sensor_) this->top48_sensor_->publish_state(PanasonicDecode::getByteMinus128(bytes[151])); - if (this->top49_sensor_) this->top49_sensor_->publish_state(PanasonicDecode::getByteMinus128(bytes[154])); - if (this->top50_sensor_) this->top50_sensor_->publish_state(PanasonicDecode::getByteMinus128(bytes[155])); - if (this->top51_sensor_) this->top51_sensor_->publish_state(PanasonicDecode::getByteMinus128(bytes[157])); - if (this->top52_sensor_) this->top52_sensor_->publish_state(PanasonicDecode::getByteMinus128(bytes[159])); - if (this->top53_sensor_) this->top53_sensor_->publish_state(PanasonicDecode::getByteMinus128(bytes[160])); - if (this->top54_sensor_) this->top54_sensor_->publish_state(PanasonicDecode::getByteMinus128(bytes[161])); - if (this->top55_sensor_) this->top55_sensor_->publish_state(PanasonicDecode::getByteMinus128(bytes[162])); - if (this->top56_sensor_) this->top56_sensor_->publish_state(PanasonicDecode::getByteMinus128(bytes[139])); - if (this->top57_sensor_) this->top57_sensor_->publish_state(PanasonicDecode::getByteMinus128(bytes[140])); - if (this->top62_sensor_) this->top62_sensor_->publish_state(PanasonicDecode::getByteMinus1Times10(bytes[173])); - if (this->top63_sensor_) this->top63_sensor_->publish_state(PanasonicDecode::getByteMinus1Times10(bytes[174])); - if (this->top64_sensor_) this->top64_sensor_->publish_state(PanasonicDecode::getByteMinus1Div5(bytes[163])); - if (this->top65_sensor_) this->top65_sensor_->publish_state(PanasonicDecode::getByteMinus1Times50(bytes[171])); - if (this->top66_sensor_) this->top66_sensor_->publish_state(PanasonicDecode::getByteMinus1Times50(bytes[164])); - if (this->top67_sensor_) this->top67_sensor_->publish_state(PanasonicDecode::getByteMinus1Div5(bytes[165])); - if (this->top70_sensor_) this->top70_sensor_->publish_state(PanasonicDecode::getByteMinus128(bytes[100])); - if (this->top71_sensor_) this->top71_sensor_->publish_state(PanasonicDecode::getByteMinus1(bytes[101])); - if (this->top72_sensor_) this->top72_sensor_->publish_state(PanasonicDecode::getByteMinus128(bytes[86])); - if (this->top73_sensor_) this->top73_sensor_->publish_state(PanasonicDecode::getByteMinus128(bytes[87])); - if (this->top74_sensor_) this->top74_sensor_->publish_state(PanasonicDecode::getByteMinus128(bytes[89])); - if (this->top75_sensor_) this->top75_sensor_->publish_state(PanasonicDecode::getByteMinus128(bytes[88])); - if (this->top77_sensor_) this->top77_sensor_->publish_state(PanasonicDecode::getByteMinus128(bytes[83])); - if (this->top78_sensor_) this->top78_sensor_->publish_state(PanasonicDecode::getByteMinus128(bytes[85])); - if (this->top79_sensor_) this->top79_sensor_->publish_state(PanasonicDecode::getByteMinus128(bytes[95])); - if (this->top80_sensor_) this->top80_sensor_->publish_state(PanasonicDecode::getByteMinus128(bytes[96])); - if (this->top82_sensor_) this->top82_sensor_->publish_state(PanasonicDecode::getByteMinus128(bytes[79])); - if (this->top83_sensor_) this->top83_sensor_->publish_state(PanasonicDecode::getByteMinus128(bytes[80])); - if (this->top84_sensor_) this->top84_sensor_->publish_state(PanasonicDecode::getByteMinus128(bytes[82])); - if (this->top85_sensor_) this->top85_sensor_->publish_state(PanasonicDecode::getByteMinus128(bytes[81])); - if (this->top86_sensor_) this->top86_sensor_->publish_state(PanasonicDecode::getByteMinus128(bytes[90])); - if (this->top87_sensor_) this->top87_sensor_->publish_state(PanasonicDecode::getByteMinus128(bytes[91])); - if (this->top88_sensor_) this->top88_sensor_->publish_state(PanasonicDecode::getByteMinus128(bytes[93])); - if (this->top89_sensor_) this->top89_sensor_->publish_state(PanasonicDecode::getByteMinus128(bytes[92])); - if (this->top90_sensor_) this->top90_sensor_->publish_state(PanasonicDecode::getWordMinus1(bytes[185], bytes[186])); - if (this->top91_sensor_) this->top91_sensor_->publish_state(PanasonicDecode::getWordMinus1(bytes[188], bytes[189])); - if (this->top93_sensor_) this->top93_sensor_->publish_state(PanasonicDecode::getByteMinus1(bytes[172])); - if (this->top95_sensor_) this->top95_sensor_->publish_state(PanasonicDecode::getByteMinus1(bytes[45])); - if (this->top96_sensor_) this->top96_sensor_->publish_state(PanasonicDecode::getByteMinus1(bytes[104])); - if (this->top97_sensor_) this->top97_sensor_->publish_state(PanasonicDecode::getByteMinus128(bytes[105])); - if (this->top98_sensor_) this->top98_sensor_->publish_state(PanasonicDecode::getByteMinus128(bytes[106])); - if (this->top102_sensor_) this->top102_sensor_->publish_state(PanasonicDecode::getByteMinus128(bytes[61])); - if (this->top103_sensor_) this->top103_sensor_->publish_state(PanasonicDecode::getByteMinus128(bytes[62])); - if (this->top104_sensor_) this->top104_sensor_->publish_state(PanasonicDecode::getByteMinus128(bytes[63])); - if (this->top105_sensor_) this->top105_sensor_->publish_state(PanasonicDecode::getByteMinus128(bytes[64])); - if (this->top113_sensor_) this->top113_sensor_->publish_state(PanasonicDecode::getByteMinus128(bytes[59])); - if (this->top115_sensor_) this->top115_sensor_->publish_state(PanasonicDecode::getByteMinus1Div50(bytes[125])); - if (this->top116_sensor_) this->top116_sensor_->publish_state(PanasonicDecode::getByteMinus128(bytes[126])); - if (this->top117_sensor_) this->top117_sensor_->publish_state(PanasonicDecode::getByteMinus128(bytes[127])); - if (this->top118_sensor_) this->top118_sensor_->publish_state(PanasonicDecode::getByteMinus128(bytes[128])); - if (this->top127_sensor_) this->top127_sensor_->publish_state(PanasonicDecode::getByteMinus1Div2(bytes[177])); - if (this->top128_sensor_) this->top128_sensor_->publish_state(PanasonicDecode::getByteMinus1Div2(bytes[178])); - if (this->top131_sensor_) this->top131_sensor_->publish_state(PanasonicDecode::getByteMinus128(bytes[65])); - if (this->top134_sensor_) this->top134_sensor_->publish_state(PanasonicDecode::getByteMinus128(bytes[66])); - if (this->top135_sensor_) this->top135_sensor_->publish_state(PanasonicDecode::getByteMinus128(bytes[68])); - if (this->top136_sensor_) this->top136_sensor_->publish_state(PanasonicDecode::getByteMinus1(bytes[67])); - if (this->top137_sensor_) this->top137_sensor_->publish_state(PanasonicDecode::getByteMinus1(bytes[69])); - if (this->top138_sensor_) this->top138_sensor_->publish_state(PanasonicDecode::getByteMinus1(bytes[70])); + if (this->top1_sensor_) this->top1_sensor_->publish_state(PanasonicDecode::getPumpFlow(data[169], data[170])); + if (this->top5_sensor_) this->top5_sensor_->publish_state(PanasonicDecode::getByteMinus128(data[143]) + PanasonicDecode::getFractional(data[118], 0)); + if (this->top6_sensor_) this->top6_sensor_->publish_state(PanasonicDecode::getByteMinus128(data[144]) + PanasonicDecode::getFractional(data[118], 3)); + if (this->top7_sensor_) this->top7_sensor_->publish_state(PanasonicDecode::getByteMinus128(data[153])); + if (this->top8_sensor_) this->top8_sensor_->publish_state(PanasonicDecode::getByteMinus1(data[166])); + if (this->top9_sensor_) this->top9_sensor_->publish_state(PanasonicDecode::getByteMinus128(data[42])); + if (this->top10_sensor_) this->top10_sensor_->publish_state(PanasonicDecode::getByteMinus128(data[141])); + if (this->top11_sensor_) this->top11_sensor_->publish_state(PanasonicDecode::getWordMinus1(data[182], data[183])); + if (this->top12_sensor_) this->top12_sensor_->publish_state(PanasonicDecode::getWordMinus1(data[179], data[180])); + if (this->top14_sensor_) this->top14_sensor_->publish_state(PanasonicDecode::getByteMinus128(data[142])); + if (this->top15_sensor_) this->top15_sensor_->publish_state(PanasonicDecode::getByteMinus1Times200(data[194])); + if (this->top16_sensor_) this->top16_sensor_->publish_state(PanasonicDecode::getByteMinus1Times200(data[193])); + if (this->top21_sensor_) this->top21_sensor_->publish_state(PanasonicDecode::getByteMinus128(data[158])); + if (this->top22_sensor_) this->top22_sensor_->publish_state(PanasonicDecode::getByteMinus128(data[99])); + if (this->top23_sensor_) this->top23_sensor_->publish_state(PanasonicDecode::getByteMinus128(data[84])); + if (this->top24_sensor_) this->top24_sensor_->publish_state(PanasonicDecode::getByteMinus128(data[94])); + if (this->top25_sensor_) this->top25_sensor_->publish_state(PanasonicDecode::getByteMinus128(data[44])); + if (this->top27_sensor_) this->top27_sensor_->publish_state(PanasonicDecode::getByteMinus128(data[38])); + if (this->top28_sensor_) this->top28_sensor_->publish_state(PanasonicDecode::getByteMinus128(data[39])); + if (this->top29_sensor_) this->top29_sensor_->publish_state(PanasonicDecode::getByteMinus128(data[75])); + if (this->top30_sensor_) this->top30_sensor_->publish_state(PanasonicDecode::getByteMinus128(data[76])); + if (this->top31_sensor_) this->top31_sensor_->publish_state(PanasonicDecode::getByteMinus128(data[78])); + if (this->top32_sensor_) this->top32_sensor_->publish_state(PanasonicDecode::getByteMinus128(data[77])); + if (this->top33_sensor_) this->top33_sensor_->publish_state(PanasonicDecode::getByteMinus128(data[156])); + if (this->top34_sensor_) this->top34_sensor_->publish_state(PanasonicDecode::getByteMinus128(data[40])); + if (this->top35_sensor_) this->top35_sensor_->publish_state(PanasonicDecode::getByteMinus128(data[41])); + if (this->top36_sensor_) this->top36_sensor_->publish_state(PanasonicDecode::getByteMinus128(data[145])); + if (this->top37_sensor_) this->top37_sensor_->publish_state(PanasonicDecode::getByteMinus128(data[146])); + if (this->top38_sensor_) this->top38_sensor_->publish_state(PanasonicDecode::getByteMinus1Times200(data[196])); + if (this->top39_sensor_) this->top39_sensor_->publish_state(PanasonicDecode::getByteMinus1Times200(data[195])); + if (this->top40_sensor_) this->top40_sensor_->publish_state(PanasonicDecode::getByteMinus1Times200(data[198])); + if (this->top41_sensor_) this->top41_sensor_->publish_state(PanasonicDecode::getByteMinus1Times200(data[197])); + if (this->top42_sensor_) this->top42_sensor_->publish_state(PanasonicDecode::getByteMinus128(data[147])); + if (this->top43_sensor_) this->top43_sensor_->publish_state(PanasonicDecode::getByteMinus128(data[148])); + if (this->top45_sensor_) this->top45_sensor_->publish_state(PanasonicDecode::getByteMinus128(data[43])); + if (this->top46_sensor_) this->top46_sensor_->publish_state(PanasonicDecode::getByteMinus128(data[149])); + if (this->top47_sensor_) this->top47_sensor_->publish_state(PanasonicDecode::getByteMinus128(data[150])); + if (this->top48_sensor_) this->top48_sensor_->publish_state(PanasonicDecode::getByteMinus128(data[151])); + if (this->top49_sensor_) this->top49_sensor_->publish_state(PanasonicDecode::getByteMinus128(data[154])); + if (this->top50_sensor_) this->top50_sensor_->publish_state(PanasonicDecode::getByteMinus128(data[155])); + if (this->top51_sensor_) this->top51_sensor_->publish_state(PanasonicDecode::getByteMinus128(data[157])); + if (this->top52_sensor_) this->top52_sensor_->publish_state(PanasonicDecode::getByteMinus128(data[159])); + if (this->top53_sensor_) this->top53_sensor_->publish_state(PanasonicDecode::getByteMinus128(data[160])); + if (this->top54_sensor_) this->top54_sensor_->publish_state(PanasonicDecode::getByteMinus128(data[161])); + if (this->top55_sensor_) this->top55_sensor_->publish_state(PanasonicDecode::getByteMinus128(data[162])); + if (this->top56_sensor_) this->top56_sensor_->publish_state(PanasonicDecode::getByteMinus128(data[139])); + if (this->top57_sensor_) this->top57_sensor_->publish_state(PanasonicDecode::getByteMinus128(data[140])); + if (this->top62_sensor_) this->top62_sensor_->publish_state(PanasonicDecode::getByteMinus1Times10(data[173])); + if (this->top63_sensor_) this->top63_sensor_->publish_state(PanasonicDecode::getByteMinus1Times10(data[174])); + if (this->top64_sensor_) this->top64_sensor_->publish_state(PanasonicDecode::getByteMinus1Div5(data[163])); + if (this->top65_sensor_) this->top65_sensor_->publish_state(PanasonicDecode::getByteMinus1Times50(data[171])); + if (this->top66_sensor_) this->top66_sensor_->publish_state(PanasonicDecode::getByteMinus1Times50(data[164])); + if (this->top67_sensor_) this->top67_sensor_->publish_state(PanasonicDecode::getByteMinus1Div5(data[165])); + if (this->top70_sensor_) this->top70_sensor_->publish_state(PanasonicDecode::getByteMinus128(data[100])); + if (this->top71_sensor_) this->top71_sensor_->publish_state(PanasonicDecode::getByteMinus1(data[101])); + if (this->top72_sensor_) this->top72_sensor_->publish_state(PanasonicDecode::getByteMinus128(data[86])); + if (this->top73_sensor_) this->top73_sensor_->publish_state(PanasonicDecode::getByteMinus128(data[87])); + if (this->top74_sensor_) this->top74_sensor_->publish_state(PanasonicDecode::getByteMinus128(data[89])); + if (this->top75_sensor_) this->top75_sensor_->publish_state(PanasonicDecode::getByteMinus128(data[88])); + if (this->top77_sensor_) this->top77_sensor_->publish_state(PanasonicDecode::getByteMinus128(data[83])); + if (this->top78_sensor_) this->top78_sensor_->publish_state(PanasonicDecode::getByteMinus128(data[85])); + if (this->top79_sensor_) this->top79_sensor_->publish_state(PanasonicDecode::getByteMinus128(data[95])); + if (this->top80_sensor_) this->top80_sensor_->publish_state(PanasonicDecode::getByteMinus128(data[96])); + if (this->top82_sensor_) this->top82_sensor_->publish_state(PanasonicDecode::getByteMinus128(data[79])); + if (this->top83_sensor_) this->top83_sensor_->publish_state(PanasonicDecode::getByteMinus128(data[80])); + if (this->top84_sensor_) this->top84_sensor_->publish_state(PanasonicDecode::getByteMinus128(data[82])); + if (this->top85_sensor_) this->top85_sensor_->publish_state(PanasonicDecode::getByteMinus128(data[81])); + if (this->top86_sensor_) this->top86_sensor_->publish_state(PanasonicDecode::getByteMinus128(data[90])); + if (this->top87_sensor_) this->top87_sensor_->publish_state(PanasonicDecode::getByteMinus128(data[91])); + if (this->top88_sensor_) this->top88_sensor_->publish_state(PanasonicDecode::getByteMinus128(data[93])); + if (this->top89_sensor_) this->top89_sensor_->publish_state(PanasonicDecode::getByteMinus128(data[92])); + if (this->top90_sensor_) this->top90_sensor_->publish_state(PanasonicDecode::getWordMinus1(data[185], data[186])); + if (this->top91_sensor_) this->top91_sensor_->publish_state(PanasonicDecode::getWordMinus1(data[188], data[189])); + if (this->top93_sensor_) this->top93_sensor_->publish_state(PanasonicDecode::getByteMinus1(data[172])); + if (this->top95_sensor_) this->top95_sensor_->publish_state(PanasonicDecode::getByteMinus1(data[45])); + if (this->top96_sensor_) this->top96_sensor_->publish_state(PanasonicDecode::getByteMinus1(data[104])); + if (this->top97_sensor_) this->top97_sensor_->publish_state(PanasonicDecode::getByteMinus128(data[105])); + if (this->top98_sensor_) this->top98_sensor_->publish_state(PanasonicDecode::getByteMinus128(data[106])); + if (this->top102_sensor_) this->top102_sensor_->publish_state(PanasonicDecode::getByteMinus128(data[61])); + if (this->top103_sensor_) this->top103_sensor_->publish_state(PanasonicDecode::getByteMinus128(data[62])); + if (this->top104_sensor_) this->top104_sensor_->publish_state(PanasonicDecode::getByteMinus128(data[63])); + if (this->top105_sensor_) this->top105_sensor_->publish_state(PanasonicDecode::getByteMinus128(data[64])); + if (this->top113_sensor_) this->top113_sensor_->publish_state(PanasonicDecode::getByteMinus128(data[59])); + if (this->top115_sensor_) this->top115_sensor_->publish_state(PanasonicDecode::getByteMinus1Div50(data[125])); + if (this->top116_sensor_) this->top116_sensor_->publish_state(PanasonicDecode::getByteMinus128(data[126])); + if (this->top117_sensor_) this->top117_sensor_->publish_state(PanasonicDecode::getByteMinus128(data[127])); + if (this->top118_sensor_) this->top118_sensor_->publish_state(PanasonicDecode::getByteMinus128(data[128])); + if (this->top127_sensor_) this->top127_sensor_->publish_state(PanasonicDecode::getByteMinus1Div2(data[177])); + if (this->top128_sensor_) this->top128_sensor_->publish_state(PanasonicDecode::getByteMinus1Div2(data[178])); + if (this->top131_sensor_) this->top131_sensor_->publish_state(PanasonicDecode::getByteMinus128(data[65])); + if (this->top134_sensor_) this->top134_sensor_->publish_state(PanasonicDecode::getByteMinus128(data[66])); + if (this->top135_sensor_) this->top135_sensor_->publish_state(PanasonicDecode::getByteMinus128(data[68])); + if (this->top136_sensor_) this->top136_sensor_->publish_state(PanasonicDecode::getByteMinus1(data[67])); + if (this->top137_sensor_) this->top137_sensor_->publish_state(PanasonicDecode::getByteMinus1(data[69])); + if (this->top138_sensor_) this->top138_sensor_->publish_state(PanasonicDecode::getByteMinus1(data[70])); #endif } - void PanasonicHeatpumpComponent::publish_binary_sensor(std::vector bytes) + void PanasonicHeatpumpComponent::publish_binary_sensor(const std::vector& data) { #ifdef USE_BINARY_SENSOR - if (this->top0_binary_sensor_) this->top0_binary_sensor_->publish_state(PanasonicDecode::getBinaryState(PanasonicDecode::getBit7and8(bytes[4]))); - if (this->top2_binary_sensor_) this->top2_binary_sensor_->publish_state(PanasonicDecode::getBinaryState(PanasonicDecode::getBit1and2(bytes[4]))); - if (this->top3_binary_sensor_) this->top3_binary_sensor_->publish_state(PanasonicDecode::getBinaryState(PanasonicDecode::getBit1and2(bytes[7]))); - if (this->top13_binary_sensor_) this->top13_binary_sensor_->publish_state(PanasonicDecode::getBinaryState(PanasonicDecode::getBit1and2(bytes[5]))); - if (this->top26_binary_sensor_) this->top26_binary_sensor_->publish_state(PanasonicDecode::getBinaryState(PanasonicDecode::getBit5and6(bytes[111]))); - if (this->top60_binary_sensor_) this->top60_binary_sensor_->publish_state(PanasonicDecode::getBinaryState(PanasonicDecode::getBit7and8(bytes[112]))); - if (this->top61_binary_sensor_) this->top61_binary_sensor_->publish_state(PanasonicDecode::getBinaryState(PanasonicDecode::getBit5and6(bytes[112]))); - if (this->top68_binary_sensor_) this->top68_binary_sensor_->publish_state(PanasonicDecode::getBinaryState(PanasonicDecode::getBit5and6(bytes[5]))); - if (this->top69_binary_sensor_) this->top69_binary_sensor_->publish_state(PanasonicDecode::getBinaryState(PanasonicDecode::getBit5and6(bytes[117]))); - if (this->top99_binary_sensor_) this->top99_binary_sensor_->publish_state(PanasonicDecode::getBinaryState(PanasonicDecode::getBit5and6(bytes[24]))); - if (this->top100_binary_sensor_) this->top100_binary_sensor_->publish_state(PanasonicDecode::getBinaryState(PanasonicDecode::getBit7and8(bytes[24]))); - if (this->top108_binary_sensor_) this->top108_binary_sensor_->publish_state(PanasonicDecode::getBinaryState(PanasonicDecode::getBit3and4(bytes[20]))); - if (this->top109_binary_sensor_) this->top109_binary_sensor_->publish_state(PanasonicDecode::getBinaryState(PanasonicDecode::getBit5and6(bytes[20]))); - if (this->top110_binary_sensor_) this->top110_binary_sensor_->publish_state(PanasonicDecode::getBinaryState(PanasonicDecode::getBit7and8(bytes[20]))); - if (this->top119_binary_sensor_) this->top119_binary_sensor_->publish_state(PanasonicDecode::getBinaryState(PanasonicDecode::getBit7and8(bytes[23]))); - if (this->top120_binary_sensor_) this->top120_binary_sensor_->publish_state(PanasonicDecode::getBinaryState(PanasonicDecode::getBit5and6(bytes[23]))); - if (this->top121_binary_sensor_) this->top121_binary_sensor_->publish_state(PanasonicDecode::getBinaryState(PanasonicDecode::getBit3and4(bytes[23]))); - if (this->top122_binary_sensor_) this->top122_binary_sensor_->publish_state(PanasonicDecode::getBinaryState(PanasonicDecode::getBit1and2(bytes[23]))); - if (this->top123_binary_sensor_) this->top123_binary_sensor_->publish_state(PanasonicDecode::getBinaryState(PanasonicDecode::getBit1and2(bytes[116]))); - if (this->top124_binary_sensor_) this->top124_binary_sensor_->publish_state(PanasonicDecode::getBinaryState(PanasonicDecode::getBit3and4(bytes[116]))); - if (this->top129_binary_sensor_) this->top129_binary_sensor_->publish_state(PanasonicDecode::getBinaryState(PanasonicDecode::getBit7and8(bytes[26]))); - if (this->top132_binary_sensor_) this->top132_binary_sensor_->publish_state(PanasonicDecode::getBinaryState(PanasonicDecode::getBit3and4(bytes[26]))); - if (this->top133_binary_sensor_) this->top133_binary_sensor_->publish_state(PanasonicDecode::getBinaryState(PanasonicDecode::getBit1and2(bytes[26]))); + if (this->top0_binary_sensor_) this->top0_binary_sensor_->publish_state(PanasonicDecode::getBinaryState(PanasonicDecode::getBit7and8(data[4]))); + if (this->top2_binary_sensor_) this->top2_binary_sensor_->publish_state(PanasonicDecode::getBinaryState(PanasonicDecode::getBit1and2(data[4]))); + if (this->top3_binary_sensor_) this->top3_binary_sensor_->publish_state(PanasonicDecode::getBinaryState(PanasonicDecode::getBit1and2(data[7]))); + if (this->top13_binary_sensor_) this->top13_binary_sensor_->publish_state(PanasonicDecode::getBinaryState(PanasonicDecode::getBit1and2(data[5]))); + if (this->top26_binary_sensor_) this->top26_binary_sensor_->publish_state(PanasonicDecode::getBinaryState(PanasonicDecode::getBit5and6(data[111]))); + if (this->top60_binary_sensor_) this->top60_binary_sensor_->publish_state(PanasonicDecode::getBinaryState(PanasonicDecode::getBit7and8(data[112]))); + if (this->top61_binary_sensor_) this->top61_binary_sensor_->publish_state(PanasonicDecode::getBinaryState(PanasonicDecode::getBit5and6(data[112]))); + if (this->top68_binary_sensor_) this->top68_binary_sensor_->publish_state(PanasonicDecode::getBinaryState(PanasonicDecode::getBit5and6(data[5]))); + if (this->top69_binary_sensor_) this->top69_binary_sensor_->publish_state(PanasonicDecode::getBinaryState(PanasonicDecode::getBit5and6(data[117]))); + if (this->top99_binary_sensor_) this->top99_binary_sensor_->publish_state(PanasonicDecode::getBinaryState(PanasonicDecode::getBit5and6(data[24]))); + if (this->top100_binary_sensor_) this->top100_binary_sensor_->publish_state(PanasonicDecode::getBinaryState(PanasonicDecode::getBit7and8(data[24]))); + if (this->top108_binary_sensor_) this->top108_binary_sensor_->publish_state(PanasonicDecode::getBinaryState(PanasonicDecode::getBit3and4(data[20]))); + if (this->top109_binary_sensor_) this->top109_binary_sensor_->publish_state(PanasonicDecode::getBinaryState(PanasonicDecode::getBit5and6(data[20]))); + if (this->top110_binary_sensor_) this->top110_binary_sensor_->publish_state(PanasonicDecode::getBinaryState(PanasonicDecode::getBit7and8(data[20]))); + if (this->top119_binary_sensor_) this->top119_binary_sensor_->publish_state(PanasonicDecode::getBinaryState(PanasonicDecode::getBit7and8(data[23]))); + if (this->top120_binary_sensor_) this->top120_binary_sensor_->publish_state(PanasonicDecode::getBinaryState(PanasonicDecode::getBit5and6(data[23]))); + if (this->top121_binary_sensor_) this->top121_binary_sensor_->publish_state(PanasonicDecode::getBinaryState(PanasonicDecode::getBit3and4(data[23]))); + if (this->top122_binary_sensor_) this->top122_binary_sensor_->publish_state(PanasonicDecode::getBinaryState(PanasonicDecode::getBit1and2(data[23]))); + if (this->top123_binary_sensor_) this->top123_binary_sensor_->publish_state(PanasonicDecode::getBinaryState(PanasonicDecode::getBit1and2(data[116]))); + if (this->top124_binary_sensor_) this->top124_binary_sensor_->publish_state(PanasonicDecode::getBinaryState(PanasonicDecode::getBit3and4(data[116]))); + if (this->top129_binary_sensor_) this->top129_binary_sensor_->publish_state(PanasonicDecode::getBinaryState(PanasonicDecode::getBit7and8(data[26]))); + if (this->top132_binary_sensor_) this->top132_binary_sensor_->publish_state(PanasonicDecode::getBinaryState(PanasonicDecode::getBit3and4(data[26]))); + if (this->top133_binary_sensor_) this->top133_binary_sensor_->publish_state(PanasonicDecode::getBinaryState(PanasonicDecode::getBit1and2(data[26]))); #endif } - void PanasonicHeatpumpComponent::publish_text_sensor(std::vector bytes) + void PanasonicHeatpumpComponent::publish_text_sensor(const std::vector& data) { #ifdef USE_TEXT_SENSOR - if (this->top4_text_sensor_) this->top4_text_sensor_->publish_state(PanasonicDecode::getTextState(PanasonicDecode::OpModeDesc, PanasonicDecode::getOpMode(bytes[6]))); - if (this->top17_text_sensor_) this->top17_text_sensor_->publish_state(PanasonicDecode::getTextState(PanasonicDecode::Powerfulmode, PanasonicDecode::getBit6and7and8(bytes[7]))); - if (this->top18_text_sensor_) this->top18_text_sensor_->publish_state(PanasonicDecode::getTextState(PanasonicDecode::Quietmode, PanasonicDecode::getBit3and4and5(bytes[7]))); - if (this->top19_text_sensor_) this->top19_text_sensor_->publish_state(PanasonicDecode::getTextState(PanasonicDecode::HolidayState, PanasonicDecode::getBit3and4(bytes[5]))); - if (this->top20_text_sensor_) this->top20_text_sensor_->publish_state(PanasonicDecode::getTextState(PanasonicDecode::Valve, PanasonicDecode::getBit7and8(bytes[111]))); - if (this->top44_text_sensor_) this->top44_text_sensor_->publish_state(PanasonicDecode::getErrorInfo(bytes[113], bytes[114])); - if (this->top58_text_sensor_) this->top58_text_sensor_->publish_state(PanasonicDecode::getTextState(PanasonicDecode::BlockedFree, PanasonicDecode::getBit5and6(bytes[9]))); - if (this->top59_text_sensor_) this->top59_text_sensor_->publish_state(PanasonicDecode::getTextState(PanasonicDecode::BlockedFree, PanasonicDecode::getBit7and8(bytes[9]))); - if (this->top76_text_sensor_) this->top76_text_sensor_->publish_state(PanasonicDecode::getTextState(PanasonicDecode::HeatCoolModeDesc, PanasonicDecode::getBit7and8(bytes[28]))); - if (this->top81_text_sensor_) this->top81_text_sensor_->publish_state(PanasonicDecode::getTextState(PanasonicDecode::HeatCoolModeDesc, PanasonicDecode::getBit5and6(bytes[28]))); - if (this->top92_text_sensor_) this->top92_text_sensor_->publish_state(PanasonicDecode::getTextState(PanasonicDecode::ModelNames, PanasonicDecode::getModel(bytes, 129))); - if (this->top94_text_sensor_) this->top94_text_sensor_->publish_state(PanasonicDecode::getTextState(PanasonicDecode::ZonesState, PanasonicDecode::getBit1and2(bytes[6]))); - if (this->top101_text_sensor_) this->top101_text_sensor_->publish_state(PanasonicDecode::getTextState(PanasonicDecode::SolarModeDesc, PanasonicDecode::getBit3and4(bytes[24]))); - if (this->top106_text_sensor_) this->top106_text_sensor_->publish_state(PanasonicDecode::getTextState(PanasonicDecode::PumpFlowRateMode, PanasonicDecode::getBit3and4(bytes[29]))); - if (this->top107_text_sensor_) this->top107_text_sensor_->publish_state(PanasonicDecode::getTextState(PanasonicDecode::LiquidType, PanasonicDecode::getBit1(bytes[20]))); - if (this->top111_text_sensor_) this->top111_text_sensor_->publish_state(PanasonicDecode::getTextState(PanasonicDecode::ZonesSensorType, PanasonicDecode::getLowNibbleMinus1(bytes[22]))); - if (this->top112_text_sensor_) this->top112_text_sensor_->publish_state(PanasonicDecode::getTextState(PanasonicDecode::ZonesSensorType, PanasonicDecode::getHighNibbleMinus1(bytes[22]))); - if (this->top114_text_sensor_) this->top114_text_sensor_->publish_state(PanasonicDecode::getTextState(PanasonicDecode::ExtPadHeaterType, PanasonicDecode::getBit3and4(bytes[25]))); - if (this->top125_text_sensor_) this->top125_text_sensor_->publish_state(PanasonicDecode::getTextState(PanasonicDecode::Valve2, PanasonicDecode::getBit5and6(bytes[116]))); - if (this->top126_text_sensor_) this->top126_text_sensor_->publish_state(PanasonicDecode::getTextState(PanasonicDecode::Valve, PanasonicDecode::getBit7and8(bytes[116]))); - if (this->top130_text_sensor_) this->top130_text_sensor_->publish_state(PanasonicDecode::getTextState(PanasonicDecode::Bivalent, PanasonicDecode::getBit5and6(bytes[26]))); + if (this->top4_text_sensor_) this->top4_text_sensor_->publish_state(PanasonicDecode::getTextState(PanasonicDecode::OpModeDesc, PanasonicDecode::getOpMode(data[6]))); + if (this->top17_text_sensor_) this->top17_text_sensor_->publish_state(PanasonicDecode::getTextState(PanasonicDecode::Powerfulmode, PanasonicDecode::getBit6and7and8(data[7]))); + if (this->top18_text_sensor_) this->top18_text_sensor_->publish_state(PanasonicDecode::getTextState(PanasonicDecode::Quietmode, PanasonicDecode::getBit3and4and5(data[7]))); + if (this->top19_text_sensor_) this->top19_text_sensor_->publish_state(PanasonicDecode::getTextState(PanasonicDecode::HolidayState, PanasonicDecode::getBit3and4(data[5]))); + if (this->top20_text_sensor_) this->top20_text_sensor_->publish_state(PanasonicDecode::getTextState(PanasonicDecode::Valve, PanasonicDecode::getBit7and8(data[111]))); + if (this->top44_text_sensor_) this->top44_text_sensor_->publish_state(PanasonicDecode::getErrorInfo(data[113], data[114])); + if (this->top58_text_sensor_) this->top58_text_sensor_->publish_state(PanasonicDecode::getTextState(PanasonicDecode::BlockedFree, PanasonicDecode::getBit5and6(data[9]))); + if (this->top59_text_sensor_) this->top59_text_sensor_->publish_state(PanasonicDecode::getTextState(PanasonicDecode::BlockedFree, PanasonicDecode::getBit7and8(data[9]))); + if (this->top76_text_sensor_) this->top76_text_sensor_->publish_state(PanasonicDecode::getTextState(PanasonicDecode::HeatCoolModeDesc, PanasonicDecode::getBit7and8(data[28]))); + if (this->top81_text_sensor_) this->top81_text_sensor_->publish_state(PanasonicDecode::getTextState(PanasonicDecode::HeatCoolModeDesc, PanasonicDecode::getBit5and6(data[28]))); + if (this->top92_text_sensor_) this->top92_text_sensor_->publish_state(PanasonicDecode::getTextState(PanasonicDecode::ModelNames, PanasonicDecode::getModel(data, 129))); + if (this->top94_text_sensor_) this->top94_text_sensor_->publish_state(PanasonicDecode::getTextState(PanasonicDecode::ZonesState, PanasonicDecode::getBit1and2(data[6]))); + if (this->top101_text_sensor_) this->top101_text_sensor_->publish_state(PanasonicDecode::getTextState(PanasonicDecode::SolarModeDesc, PanasonicDecode::getBit3and4(data[24]))); + if (this->top106_text_sensor_) this->top106_text_sensor_->publish_state(PanasonicDecode::getTextState(PanasonicDecode::PumpFlowRateMode, PanasonicDecode::getBit3and4(data[29]))); + if (this->top107_text_sensor_) this->top107_text_sensor_->publish_state(PanasonicDecode::getTextState(PanasonicDecode::LiquidType, PanasonicDecode::getBit1(data[20]))); + if (this->top111_text_sensor_) this->top111_text_sensor_->publish_state(PanasonicDecode::getTextState(PanasonicDecode::ZonesSensorType, PanasonicDecode::getLowNibbleMinus1(data[22]))); + if (this->top112_text_sensor_) this->top112_text_sensor_->publish_state(PanasonicDecode::getTextState(PanasonicDecode::ZonesSensorType, PanasonicDecode::getHighNibbleMinus1(data[22]))); + if (this->top114_text_sensor_) this->top114_text_sensor_->publish_state(PanasonicDecode::getTextState(PanasonicDecode::ExtPadHeaterType, PanasonicDecode::getBit3and4(data[25]))); + if (this->top125_text_sensor_) this->top125_text_sensor_->publish_state(PanasonicDecode::getTextState(PanasonicDecode::Valve2, PanasonicDecode::getBit5and6(data[116]))); + if (this->top126_text_sensor_) this->top126_text_sensor_->publish_state(PanasonicDecode::getTextState(PanasonicDecode::Valve, PanasonicDecode::getBit7and8(data[116]))); + if (this->top130_text_sensor_) this->top130_text_sensor_->publish_state(PanasonicDecode::getTextState(PanasonicDecode::Bivalent, PanasonicDecode::getBit5and6(data[26]))); #endif } - void PanasonicHeatpumpComponent::publish_number(std::vector bytes) + void PanasonicHeatpumpComponent::publish_number(const std::vector& data) { #ifdef USE_NUMBER - if (this->set11_number_) this->set11_number_->publish_state(PanasonicDecode::getByteMinus128(bytes[42])); - if (this->set20_number_) this->set20_number_->publish_state(PanasonicDecode::getByteMinus128(bytes[99])); - if (this->set18_number_) this->set18_number_->publish_state(PanasonicDecode::getByteMinus128(bytes[84])); - if (this->set19_number_) this->set19_number_->publish_state(PanasonicDecode::getByteMinus128(bytes[94])); - if (this->set5_number_) this->set5_number_->publish_state(PanasonicDecode::getByteMinus128(bytes[38])); - if (this->set6_number_) this->set6_number_->publish_state(PanasonicDecode::getByteMinus128(bytes[39])); - if (this->set16_1_number_) this->set16_1_number_->publish_state(PanasonicDecode::getByteMinus128(bytes[75])); - if (this->set16_2_number_) this->set16_2_number_->publish_state(PanasonicDecode::getByteMinus128(bytes[76])); - if (this->set16_4_number_) this->set16_4_number_->publish_state(PanasonicDecode::getByteMinus128(bytes[78])); - if (this->set16_3_number_) this->set16_3_number_->publish_state(PanasonicDecode::getByteMinus128(bytes[77])); - if (this->set7_number_) this->set7_number_->publish_state(PanasonicDecode::getByteMinus128(bytes[40])); - if (this->set8_number_) this->set8_number_->publish_state(PanasonicDecode::getByteMinus128(bytes[41])); - if (this->set16_9_number_) this->set16_9_number_->publish_state(PanasonicDecode::getByteMinus128(bytes[86])); - if (this->set16_10_number_) this->set16_10_number_->publish_state(PanasonicDecode::getByteMinus128(bytes[87])); - if (this->set16_12_number_) this->set16_12_number_->publish_state(PanasonicDecode::getByteMinus128(bytes[89])); - if (this->set16_11_number_) this->set16_11_number_->publish_state(PanasonicDecode::getByteMinus128(bytes[88])); - if (this->set29_number_) this->set29_number_->publish_state(PanasonicDecode::getByteMinus128(bytes[83])); - if (this->set16_5_number_) this->set16_5_number_->publish_state(PanasonicDecode::getByteMinus128(bytes[79])); - if (this->set16_6_number_) this->set16_6_number_->publish_state(PanasonicDecode::getByteMinus128(bytes[80])); - if (this->set16_8_number_) this->set16_8_number_->publish_state(PanasonicDecode::getByteMinus128(bytes[82])); - if (this->set16_7_number_) this->set16_7_number_->publish_state(PanasonicDecode::getByteMinus128(bytes[81])); - if (this->set16_13_number_) this->set16_13_number_->publish_state(PanasonicDecode::getByteMinus128(bytes[90])); - if (this->set16_14_number_) this->set16_14_number_->publish_state(PanasonicDecode::getByteMinus128(bytes[91])); - if (this->set16_16_number_) this->set16_16_number_->publish_state(PanasonicDecode::getByteMinus128(bytes[93])); - if (this->set16_15_number_) this->set16_15_number_->publish_state(PanasonicDecode::getByteMinus128(bytes[92])); - if (this->set15_number_) this->set15_number_->publish_state(PanasonicDecode::getByteMinus1(bytes[45])); - if (this->set21_number_) this->set21_number_->publish_state(PanasonicDecode::getByteMinus1(bytes[104])); - if (this->set22_number_) this->set22_number_->publish_state(PanasonicDecode::getByteMinus128(bytes[105])); - if (this->set23_number_) this->set23_number_->publish_state(PanasonicDecode::getByteMinus128(bytes[106])); - if (this->set27_number_) this->set27_number_->publish_state(PanasonicDecode::getByteMinus128(bytes[59])); - if (this->set36_number_) this->set36_number_->publish_state(PanasonicDecode::getByteMinus128(bytes[65])); - if (this->set37_number_) this->set37_number_->publish_state(PanasonicDecode::getByteMinus128(bytes[66])); - if (this->set38_number_) this->set38_number_->publish_state(PanasonicDecode::getByteMinus128(bytes[68])); + if (this->set11_number_) this->set11_number_->publish_state(PanasonicDecode::getByteMinus128(data[42])); + if (this->set20_number_) this->set20_number_->publish_state(PanasonicDecode::getByteMinus128(data[99])); + if (this->set18_number_) this->set18_number_->publish_state(PanasonicDecode::getByteMinus128(data[84])); + if (this->set19_number_) this->set19_number_->publish_state(PanasonicDecode::getByteMinus128(data[94])); + if (this->set5_number_) this->set5_number_->publish_state(PanasonicDecode::getByteMinus128(data[38])); + if (this->set6_number_) this->set6_number_->publish_state(PanasonicDecode::getByteMinus128(data[39])); + if (this->set16_1_number_) this->set16_1_number_->publish_state(PanasonicDecode::getByteMinus128(data[75])); + if (this->set16_2_number_) this->set16_2_number_->publish_state(PanasonicDecode::getByteMinus128(data[76])); + if (this->set16_4_number_) this->set16_4_number_->publish_state(PanasonicDecode::getByteMinus128(data[78])); + if (this->set16_3_number_) this->set16_3_number_->publish_state(PanasonicDecode::getByteMinus128(data[77])); + if (this->set7_number_) this->set7_number_->publish_state(PanasonicDecode::getByteMinus128(data[40])); + if (this->set8_number_) this->set8_number_->publish_state(PanasonicDecode::getByteMinus128(data[41])); + if (this->set16_9_number_) this->set16_9_number_->publish_state(PanasonicDecode::getByteMinus128(data[86])); + if (this->set16_10_number_) this->set16_10_number_->publish_state(PanasonicDecode::getByteMinus128(data[87])); + if (this->set16_12_number_) this->set16_12_number_->publish_state(PanasonicDecode::getByteMinus128(data[89])); + if (this->set16_11_number_) this->set16_11_number_->publish_state(PanasonicDecode::getByteMinus128(data[88])); + if (this->set29_number_) this->set29_number_->publish_state(PanasonicDecode::getByteMinus128(data[83])); + if (this->set16_5_number_) this->set16_5_number_->publish_state(PanasonicDecode::getByteMinus128(data[79])); + if (this->set16_6_number_) this->set16_6_number_->publish_state(PanasonicDecode::getByteMinus128(data[80])); + if (this->set16_8_number_) this->set16_8_number_->publish_state(PanasonicDecode::getByteMinus128(data[82])); + if (this->set16_7_number_) this->set16_7_number_->publish_state(PanasonicDecode::getByteMinus128(data[81])); + if (this->set16_13_number_) this->set16_13_number_->publish_state(PanasonicDecode::getByteMinus128(data[90])); + if (this->set16_14_number_) this->set16_14_number_->publish_state(PanasonicDecode::getByteMinus128(data[91])); + if (this->set16_16_number_) this->set16_16_number_->publish_state(PanasonicDecode::getByteMinus128(data[93])); + if (this->set16_15_number_) this->set16_15_number_->publish_state(PanasonicDecode::getByteMinus128(data[92])); + if (this->set15_number_) this->set15_number_->publish_state(PanasonicDecode::getByteMinus1(data[45])); + if (this->set21_number_) this->set21_number_->publish_state(PanasonicDecode::getByteMinus1(data[104])); + if (this->set22_number_) this->set22_number_->publish_state(PanasonicDecode::getByteMinus128(data[105])); + if (this->set23_number_) this->set23_number_->publish_state(PanasonicDecode::getByteMinus128(data[106])); + if (this->set27_number_) this->set27_number_->publish_state(PanasonicDecode::getByteMinus128(data[59])); + if (this->set36_number_) this->set36_number_->publish_state(PanasonicDecode::getByteMinus128(data[65])); + if (this->set37_number_) this->set37_number_->publish_state(PanasonicDecode::getByteMinus128(data[66])); + if (this->set38_number_) this->set38_number_->publish_state(PanasonicDecode::getByteMinus128(data[68])); #endif } - void PanasonicHeatpumpComponent::publish_select(std::vector bytes) + void PanasonicHeatpumpComponent::publish_select(const std::vector& data) { #ifdef USE_SELECT - if (this->set9_select_) this->set9_select_->publish_state(PanasonicDecode::getTextState(PanasonicDecode::OpModeDesc, PanasonicDecode::getOpMode(bytes[6]))); - if (this->set4_select_) this->set4_select_->publish_state(PanasonicDecode::getTextState(PanasonicDecode::Powerfulmode, PanasonicDecode::getBit6and7and8(bytes[7]))); - if (this->set3_select_) this->set3_select_->publish_state(PanasonicDecode::getTextState(PanasonicDecode::Quietmode, PanasonicDecode::getBit3and4and5(bytes[7]))); - if (this->set2_select_) this->set2_select_->publish_state(PanasonicDecode::getTextState(PanasonicDecode::HolidayState, PanasonicDecode::getBit3and4(bytes[5]))); - if (this->set17_select_) this->set17_select_->publish_state(PanasonicDecode::getTextState(PanasonicDecode::ZonesState, PanasonicDecode::getBit1and2(bytes[6]))); - if (this->set26_select_) this->set26_select_->publish_state(PanasonicDecode::getTextState(PanasonicDecode::ExtPadHeaterType, PanasonicDecode::getBit3and4(bytes[25]))); - if (this->set35_select_) this->set35_select_->publish_state(PanasonicDecode::getTextState(PanasonicDecode::Bivalent, PanasonicDecode::getBit5and6(bytes[26]))); + if (this->set9_select_) this->set9_select_->publish_state(PanasonicDecode::getTextState(PanasonicDecode::OpModeDesc, PanasonicDecode::getOpMode(data[6]))); + if (this->set4_select_) this->set4_select_->publish_state(PanasonicDecode::getTextState(PanasonicDecode::Powerfulmode, PanasonicDecode::getBit6and7and8(data[7]))); + if (this->set3_select_) this->set3_select_->publish_state(PanasonicDecode::getTextState(PanasonicDecode::Quietmode, PanasonicDecode::getBit3and4and5(data[7]))); + if (this->set2_select_) this->set2_select_->publish_state(PanasonicDecode::getTextState(PanasonicDecode::HolidayState, PanasonicDecode::getBit3and4(data[5]))); + if (this->set17_select_) this->set17_select_->publish_state(PanasonicDecode::getTextState(PanasonicDecode::ZonesState, PanasonicDecode::getBit1and2(data[6]))); + if (this->set26_select_) this->set26_select_->publish_state(PanasonicDecode::getTextState(PanasonicDecode::ExtPadHeaterType, PanasonicDecode::getBit3and4(data[25]))); + if (this->set35_select_) this->set35_select_->publish_state(PanasonicDecode::getTextState(PanasonicDecode::Bivalent, PanasonicDecode::getBit5and6(data[26]))); #endif } - void PanasonicHeatpumpComponent::publish_switch(std::vector bytes) + void PanasonicHeatpumpComponent::publish_switch(const std::vector& data) { #ifdef USE_SWITCH - if (this->set1_switch_) this->set1_switch_->publish_state(PanasonicDecode::getBinaryState(PanasonicDecode::getBit7and8(bytes[4]))); - if (this->set10_switch_) this->set10_switch_->publish_state(PanasonicDecode::getBinaryState(PanasonicDecode::getBit1and2(bytes[4]))); - if (this->set24_switch_) this->set24_switch_->publish_state(PanasonicDecode::getBinaryState(PanasonicDecode::getBit1and2(bytes[5]))); - if (this->set12_switch_) this->set12_switch_->publish_state(PanasonicDecode::getBinaryState(PanasonicDecode::getBit5and6(bytes[111]))); - if (this->set13_switch_) this->set13_switch_->publish_state(PanasonicDecode::getBinaryState(PanasonicDecode::getBit5and6(bytes[117]))); - if (this->set28_switch_) this->set28_switch_->publish_state(PanasonicDecode::getBinaryState(PanasonicDecode::getBit5and6(bytes[24]))); - if (this->set30_switch_) this->set30_switch_->publish_state(PanasonicDecode::getBinaryState(PanasonicDecode::getBit7and8(bytes[23]))); - if (this->set33_switch_) this->set33_switch_->publish_state(PanasonicDecode::getBinaryState(PanasonicDecode::getBit5and6(bytes[23]))); - if (this->set31_switch_) this->set31_switch_->publish_state(PanasonicDecode::getBinaryState(PanasonicDecode::getBit3and4(bytes[23]))); - if (this->set32_switch_) this->set32_switch_->publish_state(PanasonicDecode::getBinaryState(PanasonicDecode::getBit1and2(bytes[23]))); - if (this->set34_switch_) this->set34_switch_->publish_state(PanasonicDecode::getBinaryState(PanasonicDecode::getBit7and8(bytes[26]))); + if (this->set1_switch_) this->set1_switch_->publish_state(PanasonicDecode::getBinaryState(PanasonicDecode::getBit7and8(data[4]))); + if (this->set10_switch_) this->set10_switch_->publish_state(PanasonicDecode::getBinaryState(PanasonicDecode::getBit1and2(data[4]))); + if (this->set24_switch_) this->set24_switch_->publish_state(PanasonicDecode::getBinaryState(PanasonicDecode::getBit1and2(data[5]))); + if (this->set12_switch_) this->set12_switch_->publish_state(PanasonicDecode::getBinaryState(PanasonicDecode::getBit5and6(data[111]))); + if (this->set13_switch_) this->set13_switch_->publish_state(PanasonicDecode::getBinaryState(PanasonicDecode::getBit5and6(data[117]))); + if (this->set28_switch_) this->set28_switch_->publish_state(PanasonicDecode::getBinaryState(PanasonicDecode::getBit5and6(data[24]))); + if (this->set30_switch_) this->set30_switch_->publish_state(PanasonicDecode::getBinaryState(PanasonicDecode::getBit7and8(data[23]))); + if (this->set33_switch_) this->set33_switch_->publish_state(PanasonicDecode::getBinaryState(PanasonicDecode::getBit5and6(data[23]))); + if (this->set31_switch_) this->set31_switch_->publish_state(PanasonicDecode::getBinaryState(PanasonicDecode::getBit3and4(data[23]))); + if (this->set32_switch_) this->set32_switch_->publish_state(PanasonicDecode::getBinaryState(PanasonicDecode::getBit1and2(data[23]))); + if (this->set34_switch_) this->set34_switch_->publish_state(PanasonicDecode::getBinaryState(PanasonicDecode::getBit7and8(data[26]))); #endif } @@ -500,22 +524,6 @@ namespace esphome else if (object == this->set8_number_) this->set_command_byte(PanasonicCommand::setPlus128(value), 41); else if (object == this->set11_number_) this->set_command_byte(PanasonicCommand::setPlus128(value), 42); else if (object == this->set15_number_) this->set_command_byte(PanasonicCommand::setPlus1(value), 45); - else if (object == this->set16_1_number_) this->set_command_byte(PanasonicCommand::setPlus128(value), 75); - else if (object == this->set16_2_number_) this->set_command_byte(PanasonicCommand::setPlus128(value), 76); - else if (object == this->set16_3_number_) this->set_command_byte(PanasonicCommand::setPlus128(value), 77); - else if (object == this->set16_4_number_) this->set_command_byte(PanasonicCommand::setPlus128(value), 78); - else if (object == this->set16_5_number_) this->set_command_byte(PanasonicCommand::setPlus128(value), 79); - else if (object == this->set16_6_number_) this->set_command_byte(PanasonicCommand::setPlus128(value), 80); - else if (object == this->set16_7_number_) this->set_command_byte(PanasonicCommand::setPlus128(value), 81); - else if (object == this->set16_8_number_) this->set_command_byte(PanasonicCommand::setPlus128(value), 82); - else if (object == this->set16_9_number_) this->set_command_byte(PanasonicCommand::setPlus128(value), 86); - else if (object == this->set16_10_number_) this->set_command_byte(PanasonicCommand::setPlus128(value), 87); - else if (object == this->set16_11_number_) this->set_command_byte(PanasonicCommand::setPlus128(value), 88); - else if (object == this->set16_12_number_) this->set_command_byte(PanasonicCommand::setPlus128(value), 89); - else if (object == this->set16_13_number_) this->set_command_byte(PanasonicCommand::setPlus128(value), 90); - else if (object == this->set16_14_number_) this->set_command_byte(PanasonicCommand::setPlus128(value), 91); - else if (object == this->set16_15_number_) this->set_command_byte(PanasonicCommand::setPlus128(value), 92); - else if (object == this->set16_16_number_) this->set_command_byte(PanasonicCommand::setPlus128(value), 93); else if (object == this->set18_number_) this->set_command_byte(PanasonicCommand::setPlus128(value), 84); else if (object == this->set19_number_) this->set_command_byte(PanasonicCommand::setPlus128(value), 94); else if (object == this->set20_number_) this->set_command_byte(PanasonicCommand::setPlus128(value), 99); @@ -527,6 +535,40 @@ namespace esphome else if (object == this->set36_number_) this->set_command_byte(PanasonicCommand::setPlus128(value), 65); else if (object == this->set37_number_) this->set_command_byte(PanasonicCommand::setPlus128(value), 66); else if (object == this->set38_number_) this->set_command_byte(PanasonicCommand::setPlus128(value), 68); + // Set zone 1 curve + if (object == this->set16_1_number_ || object == this->set16_2_number_ + || object == this->set16_3_number_ || object == this->set16_4_number_ + || object == this->set16_9_number_ || object == this->set16_10_number_ + || object == this->set16_11_number_ || object == this->set16_12_number_) + { + std::vector> curve; + curve.push_back(std::make_tuple(PanasonicCommand::setPlus128(this->set16_1_number_->state), 75)); + curve.push_back(std::make_tuple(PanasonicCommand::setPlus128(this->set16_2_number_->state), 76)); + curve.push_back(std::make_tuple(PanasonicCommand::setPlus128(this->set16_3_number_->state), 77)); + curve.push_back(std::make_tuple(PanasonicCommand::setPlus128(this->set16_4_number_->state), 78)); + curve.push_back(std::make_tuple(PanasonicCommand::setPlus128(this->set16_9_number_->state), 86)); + curve.push_back(std::make_tuple(PanasonicCommand::setPlus128(this->set16_10_number_->state), 87)); + curve.push_back(std::make_tuple(PanasonicCommand::setPlus128(this->set16_11_number_->state), 88)); + curve.push_back(std::make_tuple(PanasonicCommand::setPlus128(this->set16_12_number_->state), 89)); + this->set_command_bytes(curve); + } + // Set zone 2 curve + if (object == this->set16_5_number_ || object == this->set16_6_number_ + || object == this->set16_7_number_ || object == this->set16_8_number_ + || object == this->set16_13_number_ || object == this->set16_14_number_ + || object == this->set16_15_number_ || object == this->set16_16_number_) + { + std::vector> curve; + curve.push_back(std::make_tuple(PanasonicCommand::setPlus128(this->set16_5_number_->state), 79)); + curve.push_back(std::make_tuple(PanasonicCommand::setPlus128(this->set16_6_number_->state), 80)); + curve.push_back(std::make_tuple(PanasonicCommand::setPlus128(this->set16_7_number_->state), 81)); + curve.push_back(std::make_tuple(PanasonicCommand::setPlus128(this->set16_8_number_->state), 82)); + curve.push_back(std::make_tuple(PanasonicCommand::setPlus128(this->set16_13_number_->state), 90)); + curve.push_back(std::make_tuple(PanasonicCommand::setPlus128(this->set16_14_number_->state), 91)); + curve.push_back(std::make_tuple(PanasonicCommand::setPlus128(this->set16_15_number_->state), 92)); + curve.push_back(std::make_tuple(PanasonicCommand::setPlus128(this->set16_16_number_->state), 93)); + this->set_command_bytes(curve); + } } #endif diff --git a/components/panasonic_heatpump/panasonic_heatpump.h b/components/panasonic_heatpump/panasonic_heatpump.h index f479900..3fa4f8c 100644 --- a/components/panasonic_heatpump/panasonic_heatpump.h +++ b/components/panasonic_heatpump/panasonic_heatpump.h @@ -25,6 +25,7 @@ #include "decode.h" #include "commands.h" #include +#include #include @@ -37,7 +38,7 @@ namespace esphome UART_LOG_RX, UART_LOG_TX, }; - + class PanasonicHeatpumpComponent : public PollingComponent, public uart::UARTDevice { public: @@ -254,47 +255,48 @@ namespace esphome #endif PanasonicHeatpumpComponent() = default; + // base class functions float get_setup_priority() const override { return setup_priority::LATE; } void dump_config() override; void setup() override; void update() override; void loop() override; - - void set_uart_client(uart::UARTComponent *uart) { this->uart_client_ = uart; } + // option functions + void set_uart_client(uart::UARTComponent* uart) { this->uart_client_ = uart; } void set_log_uart_msg(bool enable) { this->log_uart_msg_ = enable; } - void set_polling_time(uint32_t time_sec) { this->polling_time_ = time_sec; } protected: - uart::UARTComponent* uart_client_{nullptr}; - bool log_uart_msg_{false}; - uint32_t polling_time_{1}; - + // options variables + uart::UARTComponent* uart_client_ { nullptr }; + bool log_uart_msg_ { false }; + // uart message variables std::vector response_message_; std::vector request_message_; std::vector command_message_; uint8_t response_payload_length_; uint8_t request_payload_length_; - bool response_receiving_{false}; - bool request_receiving_{false}; - bool trigger_request_{true}; - uint8_t next_request_{0}; // 0 = initial, 1 = polling, 2 = command + bool response_receiving_ { false }; + bool request_receiving_ { false }; + bool trigger_request_ { true }; + uint8_t next_request_ { 0 }; // 0 = initial, 1 = polling, 2 = command + // uart message functions void read_response(); void send_request(); void read_request(); - void decode_response(std::vector data); + void decode_response(const std::vector& data); void set_command_byte(uint8_t value, uint8_t index); - void publish_sensor(std::vector bytes); - void publish_binary_sensor(std::vector bytes); - void publish_text_sensor(std::vector bytes); - void publish_number(std::vector bytes); - void publish_select(std::vector bytes); - void publish_switch(std::vector bytes); - void log_uart_hex(UartLogDirection direction, const std::vector &data, uint8_t separator) - { - this->log_uart_hex(direction, &data[0], data.size(), separator); - } - void log_uart_hex(UartLogDirection direction, const uint8_t *data, size_t length, uint8_t separator); + void set_command_bytes(const std::vector>& data); + // sensor and control publish functions + void publish_sensor(const std::vector& data); + void publish_binary_sensor(const std::vector& data); + void publish_text_sensor(const std::vector& data); + void publish_number(const std::vector& data); + void publish_select(const std::vector& data); + void publish_switch(const std::vector& data); + // logger functions + void log_uart_hex(UartLogDirection direction, const std::vector& data, uint8_t separator); + void log_uart_hex(UartLogDirection direction, const uint8_t* data, size_t length, uint8_t separator); }; } // namespace panasonic_heatpump } // namespace esphome