Added initial response

This commit is contained in:
ElVit
2025-02-17 20:20:17 +01:00
parent 2848c6dd34
commit 2194f3edf7
6 changed files with 35 additions and 28 deletions
+6 -3
View File
@@ -5,10 +5,13 @@ namespace esphome
{
namespace panasonic_heatpump
{
const uint8_t PanasonicCommand::InitialMessage[REQUEST_INIT_MSG_SIZE] = {
const uint8_t PanasonicCommand::InitialRequest[INIT_REQUEST_SIZE] = {
0x31, 0x05, 0x10, 0x01, 0x00, 0x00, 0x00, 0xB9
};
const uint8_t PanasonicCommand::PollingMessage[REQUEST_DATA_MSG_SIZE] = {
const uint8_t PanasonicCommand::InitialResponse[INIT_RESPONSE_SIZE] = {
0x31, 0x30, 0x01, 0x10, 0x1E, 0x6C, 0xC8, 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, 0x3C
};
const uint8_t PanasonicCommand::PollingMessage[DATA_MESSAGE_SIZE] = {
0x71, 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,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
@@ -18,7 +21,7 @@ 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::CommandMessage[REQUEST_DATA_MSG_SIZE] = {
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,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+8 -6
View File
@@ -2,9 +2,10 @@
#include <cmath>
#include <vector>
#define REQUEST_INIT_MSG_SIZE 8
#define REQUEST_DATA_MSG_SIZE 111
#define REQUEST_OPTIONAL_MSG_SIZE 20
#define INIT_REQUEST_SIZE 8
#define INIT_RESPONSE_SIZE 51
#define DATA_MESSAGE_SIZE 111
#define OPTIONAL_MESSAGE_SIZE 20
namespace esphome
@@ -31,9 +32,10 @@ namespace esphome
static uint8_t setByte6(uint8_t byte6, int val, int base, int bit);
static uint8_t setDemandControl(size_t input);
static const uint8_t InitialMessage[REQUEST_INIT_MSG_SIZE];
static const uint8_t PollingMessage[REQUEST_DATA_MSG_SIZE];
static const uint8_t CommandMessage[REQUEST_DATA_MSG_SIZE];
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 CommandMessage[DATA_MESSAGE_SIZE];
};
} // namespace panasonic_heatpump
} // namespace esphome
@@ -48,13 +48,14 @@ namespace esphome
// Read byte from heatpump and forward it directly to the client (CZ-TAW1)
this->read_byte(&byte);
if (this->uart_client_ != nullptr)
{
this->uart_client_->write_byte(byte);
}
// Message shall start with 0x31, 0x71 or 0xF1, if not skip this byte
if (!this->response_receiving_)
{
if (byte != 0x31 && byte != 0x71 && byte != 0xF1)
continue;
if (byte != 0x31 && byte != 0x71 && byte != 0xF1) continue;
this->response_receiving_ = true;
}
// Add current byte to message buffer
@@ -62,7 +63,9 @@ namespace esphome
// 2. bytes contains the payload size
if (this->response_message_.size() == 2)
{
this->response_payload_length_ = byte;
}
// Discard message if format is wrong
if ((this->response_message_.size() == 3 || this->response_message_.size() == 4)
&& byte != 0x01 && byte != 0x10)
@@ -103,14 +106,14 @@ namespace esphome
if (this->next_request_ == 0) // initial
{
// Probably not necessary but CZ-TAW1 sends this query on boot
this->log_uart_hex(UART_LOG_TX, PanasonicCommand::InitialMessage, REQUEST_INIT_MSG_SIZE, ',');
this->write_array(PanasonicCommand::InitialMessage, REQUEST_INIT_MSG_SIZE);
this->log_uart_hex(UART_LOG_TX, PanasonicCommand::InitialRequest, INIT_REQUEST_SIZE, ',');
this->write_array(PanasonicCommand::InitialRequest, INIT_REQUEST_SIZE);
this->flush();
}
else if (this->next_request_ == 1) // polling
{
this->log_uart_hex(UART_LOG_TX, PanasonicCommand::PollingMessage, REQUEST_DATA_MSG_SIZE, ',');
this->write_array(PanasonicCommand::PollingMessage, REQUEST_DATA_MSG_SIZE);
this->log_uart_hex(UART_LOG_TX, PanasonicCommand::PollingMessage, DATA_MESSAGE_SIZE, ',');
this->write_array(PanasonicCommand::PollingMessage, DATA_MESSAGE_SIZE);
this->flush();
}
}
@@ -124,13 +127,12 @@ namespace esphome
{
// Read byte from client and forward it directly to the heatpump
this->uart_client_->read_byte(&byte);
this->write_byte(byte);
this->write_byte(byte);
// Message shall start with 0x31, 0x71 or 0xF1, if not skip this byte
if (!this->request_receiving_)
{
if (byte != 0x31 && byte != 0x71 && byte != 0xF1)
continue;
if (byte != 0x31 && byte != 0x71 && byte != 0xF1) continue;
this->request_receiving_ = true;
}
// Add current byte to message buffer
@@ -138,8 +140,9 @@ namespace esphome
// 2. bytes contains the payload size
if (this->request_message_.size() == 2)
{
this->request_payload_length_ = byte;
}
// Discard message if format is wrong
if ((this->request_message_.size() == 3 || this->request_message_.size() == 4)
&& byte != 0x01 && byte != 0x10)
@@ -203,7 +206,7 @@ namespace esphome
size_t chunkSize = 90;
for (size_t i = 0; i < logStr.length(); i += chunkSize)
{
ESP_LOGD(TAG, "%s %s", msgDir.c_str(), logStr.substr(i, chunkSize).c_str());
ESP_LOGI(TAG, "%s %s", msgDir.c_str(), logStr.substr(i, chunkSize).c_str());
delay(10);
}
}
@@ -250,7 +253,7 @@ namespace esphome
// initialize the command
command_message_.clear();
command_message_.insert(this->command_message_.end(), PanasonicCommand::CommandMessage,
PanasonicCommand::CommandMessage + REQUEST_DATA_MSG_SIZE);
PanasonicCommand::CommandMessage + DATA_MESSAGE_SIZE);
}
// set command byte
command_message_[index] = value;
@@ -488,7 +491,6 @@ namespace esphome
#endif
}
#ifdef USE_NUMBER
void PanasonicHeatpumpComponent::control_number(number::Number* object, float value)
{
@@ -542,8 +544,10 @@ namespace esphome
#endif
#ifdef USE_SWITCH
void PanasonicHeatpumpComponent::control_switch(switch_::Switch* object, size_t value)
void PanasonicHeatpumpComponent::control_switch(switch_::Switch* object, bool state)
{
size_t value = state ? 1 : 0;
if (object == this->set1_switch_) this->set_command_byte(PanasonicCommand::setPlus1(value), 4);
else if (object == this->set10_switch_) this->set_command_byte(PanasonicCommand::setPlus1Multiply64(value), 4);
else if (object == this->set12_switch_) this->set_command_byte(PanasonicCommand::setMultiply2(value), 8);
@@ -250,7 +250,7 @@ namespace esphome
SUB_SWITCH(set33);
SUB_SWITCH(set34);
void control_switch(switch_::Switch* object, size_t value);
void control_switch(switch_::Switch* object, bool state);
#endif
PanasonicHeatpumpComponent() = default;
@@ -6,7 +6,6 @@ from esphome.const import (
)
from .. import CONF_PANASONIC_HEATPUMP_ID, PanasonicHeatpumpComponent, panasonic_heatpump_ns
CONF_SET1 = "set1" # Set Heatpump
CONF_SET10 = "set10" # Set Force DHW
CONF_SET12 = "set12" # Set Force Defrost
@@ -13,12 +13,11 @@ namespace esphome
LOG_SWITCH("", "Panasonic Heatpump Switch", this);
delay(10);
}
void PanasonicHeatpumpSwitch::write_state(bool state)
{
this->publish_state(state);
size_t value = state ? 1 : 0;
this->parent_->control_switch(this, value);
this->parent_->control_switch(this, state);
}
} // namespace panasonic_heatpump
} // namespace esphome