Skip to content

Commit

Permalink
Add optional protocol debug
Browse files Browse the repository at this point in the history
  • Loading branch information
joshbenner committed May 19, 2023
1 parent b4994fd commit 962506b
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 11 deletions.
3 changes: 3 additions & 0 deletions components/daikin_s21/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
CONF_TX_UART = "tx_uart"
CONF_RX_UART = "rx_uart"
CONF_S21_ID = "s21_id"
CONF_DEBUG_PROTOCOL = "debug_protocol"

daikin_s21_ns = cg.esphome_ns.namespace("daikin_s21")
DaikinS21 = daikin_s21_ns.class_("DaikinS21", cg.PollingComponent)
Expand All @@ -23,6 +24,7 @@
cv.GenerateID(): cv.declare_id(DaikinS21),
cv.Required(CONF_TX_UART): cv.use_id(UARTComponent),
cv.Required(CONF_RX_UART): cv.use_id(UARTComponent),
cv.Optional(CONF_DEBUG_PROTOCOL, default=False): cv.boolean,
}
).extend(cv.polling_component_schema("2s"))

Expand All @@ -40,3 +42,4 @@ async def to_code(config):
tx_uart = await cg.get_variable(config[CONF_TX_UART])
rx_uart = await cg.get_variable(config[CONF_RX_UART])
cg.add(var.set_uarts(tx_uart, rx_uart))
cg.add(var.set_debug_protocol(config[CONF_DEBUG_PROTOCOL]))
24 changes: 13 additions & 11 deletions components/daikin_s21/s21.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -289,8 +289,10 @@ bool DaikinS21::s21_query(std::vector<uint8_t> code) {

bool DaikinS21::parse_response(std::vector<uint8_t> rcode,
std::vector<uint8_t> payload) {
// ESP_LOGD(TAG, "S21: %s -> %s (%d)", str_repr(rcode).c_str(),
// str_repr(payload).c_str(), payload.size());
if (this->debug_protocol) {
ESP_LOGD(TAG, "S21: %s -> %s (%d)", str_repr(rcode).c_str(),
str_repr(payload).c_str(), payload.size());
}

switch (rcode[0]) {
case 'G': // F -> G
Expand Down Expand Up @@ -357,9 +359,11 @@ void DaikinS21::update() {
ESP_LOGI(TAG, "Daikin S21 Ready");
this->ready = true;
}
if (this->debug_protocol) {
this->dump_state();
}

#ifdef S21_EXPERIMENTS
this->dump_state();
ESP_LOGD(TAG, "** UNKNOWN QUERIES **");
// auto experiments = {"F2", "F3", "F4", "F8", "F9", "F0", "FA", "FB", "FC",
// "FD", "FE", "FF", "FG", "FH", "FI", "FJ", "FK", "FL",
Expand All @@ -375,7 +379,7 @@ void DaikinS21::update() {
void DaikinS21::dump_state() {
ESP_LOGD(TAG, "** BEGIN STATE *****************************");

ESP_LOGD(TAG, "Current S21 State:");
ESP_LOGD(TAG, " Power: %s", ONOFF(this->power_on));
ESP_LOGD(TAG, " Mode: %s (%s)",
daikin_climate_mode_to_string(this->mode).c_str(),
this->idle ? "idle" : "active");
Expand All @@ -384,8 +388,8 @@ void DaikinS21::dump_state() {
ESP_LOGD(TAG, " Target: %.1f C (%.1f F)", degc, degf);
ESP_LOGD(TAG, " Fan: %s (%d rpm)",
daikin_fan_mode_to_string(this->fan).c_str(), this->fan_rpm);
ESP_LOGD(TAG, " Swing: H:%s V:%s", this->swing_h ? "y" : "n",
this->swing_v ? "y" : "n");
ESP_LOGD(TAG, " Swing: H:%s V:%s", YESNO(this->swing_h),
YESNO(this->swing_h));
ESP_LOGD(TAG, " Inside: %.1f C (%.1f F)", c10_c(this->temp_inside),
c10_f(this->temp_inside));
ESP_LOGD(TAG, "Outside: %.1f C (%.1f F)", c10_c(this->temp_outside),
Expand Down Expand Up @@ -416,11 +420,9 @@ void DaikinS21::set_daikin_climate_settings(bool power_on,

void DaikinS21::set_swing_settings(bool swing_v, bool swing_h) {
std::vector<uint8_t> cmd = {
(uint8_t) ('0' + (swing_h ? 2 : 0) + (swing_v ? 1 : 0) +
(swing_h && swing_v ? 4 : 0)),
(uint8_t)(swing_v || swing_h ? '?' : '0'),
'0', '0'
};
(uint8_t) ('0' + (swing_h ? 2 : 0) + (swing_v ? 1 : 0) +
(swing_h && swing_v ? 4 : 0)),
(uint8_t) (swing_v || swing_h ? '?' : '0'), '0', '0'};
ESP_LOGD(TAG, "Sending swing CMD (D5): %s", str_repr(cmd).c_str());
if (!this->send_cmd({'D', '5'}, cmd)) {
ESP_LOGW(TAG, "Failed swing CMD");
Expand Down
2 changes: 2 additions & 0 deletions components/daikin_s21/s21.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ class DaikinS21 : public PollingComponent {
void update() override;
void dump_config() override;
void set_uarts(uart::UARTComponent *tx, uart::UARTComponent *rx);
void set_debug_protocol(bool set) { this->debug_protocol = set; }
bool is_ready() { return this->ready; }

bool is_power_on() { return this->power_on; }
Expand Down Expand Up @@ -66,6 +67,7 @@ class DaikinS21 : public PollingComponent {
uart::UARTComponent *tx_uart{nullptr};
uart::UARTComponent *rx_uart{nullptr};
bool ready = false;
bool debug_protocol = false;

bool power_on = false;
DaikinClimateMode mode = DaikinClimateMode::Disabled;
Expand Down

0 comments on commit 962506b

Please sign in to comment.