diff --git a/esphome/components/cse7766/cse7766.cpp b/esphome/components/cse7766/cse7766.cpp index 1b6f0dc354..e4eb8b2c36 100644 --- a/esphome/components/cse7766/cse7766.cpp +++ b/esphome/components/cse7766/cse7766.cpp @@ -210,17 +210,21 @@ void CSE7766Component::parse_data_() { // Buffer: 7 + 14 + 31 + 14 + 24 = 90 chars max + null, rounded to 96 char buf[96]; int pos = snprintf(buf, sizeof(buf), "Parsed:"); // max 7: "Parsed:" - if (have_voltage) + if (have_voltage) { pos += snprintf(buf + pos, sizeof(buf) - pos, " V=%.4fV", voltage); // max 14: " V="(3) + float(10) + "V"(1) - if (have_current) + } + if (have_current) { pos += snprintf(buf + pos, sizeof(buf) - pos, " I=%.4fmA (~%.4fmA)", current * 1000.0f, calculated_current * 1000.0f); // max 31: " I="(3) + float(10) + "mA (~"(5) + float(10) + "mA)"(3) - if (have_power) + } + if (have_power) { pos += snprintf(buf + pos, sizeof(buf) - pos, " P=%.4fW", power); // max 14: " P="(3) + float(10) + "W"(1) - if (energy != 0.0f) - pos += snprintf(buf + pos, sizeof(buf) - pos, " E=%.4fkWh (%u)", energy, - cf_pulses); // max 24: " E="(3) + float(10) + "kWh ("(5) + uint16(5) + ")"(1) + } + if (energy != 0.0f) { + snprintf(buf + pos, sizeof(buf) - pos, " E=%.4fkWh (%u)", energy, + cf_pulses); // max 24: " E="(3) + float(10) + "kWh ("(5) + uint16(5) + ")"(1) + } ESP_LOGVV(TAG, "%s", buf); } #endif