From 206562bebf91932dcf46d36acdf8a396ca3ee1b2 Mon Sep 17 00:00:00 2001 From: patagona Date: Sun, 29 Sep 2024 19:19:28 +0200 Subject: [PATCH] DALY Modbus BMS: add log messages for modbus response --- esphome/components/daly_hkms_bms/daly_hkms_bms.cpp | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/esphome/components/daly_hkms_bms/daly_hkms_bms.cpp b/esphome/components/daly_hkms_bms/daly_hkms_bms.cpp index 7451b8b88b..38af977094 100644 --- a/esphome/components/daly_hkms_bms/daly_hkms_bms.cpp +++ b/esphome/components/daly_hkms_bms/daly_hkms_bms.cpp @@ -62,13 +62,17 @@ void DalyHkmsBmsComponent::update() { void DalyHkmsBmsComponent::on_modbus_data(const std::vector &data) { // Other components might be sending commands to our device. But we don't get called with enough // context to know what is what. So if we didn't do a send, we ignore the data. - if (!this->last_send_) + if (!this->last_send_) { + ESP_LOGD(TAG, "Got data without requesting it first"); return; + } this->last_send_ = 0; // Also ignore the data if the message is too short. Otherwise we will publish invalid values. - if (data.size() < DALY_MODBUS_REGISTER_COUNT * 2) + if (data.size() < DALY_MODBUS_REGISTER_COUNT * 2) { + ESP_LOGD(TAG, "Not enough data in modbus response"); return; + } auto get_register = [&](size_t i) -> uint16_t { return encode_uint16(data[i * 2], data[i * 2 + 1]);