1
0
mirror of https://github.com/esphome/esphome.git synced 2025-02-20 20:08:20 +00:00

[cse7766] Remove stream dependency (#7720)

Co-authored-by: Keith Burzinski <kbx81x@gmail.com>
This commit is contained in:
Gábor Poczkodi 2025-02-13 04:07:14 +01:00 committed by Jesse Hills
parent 4740f12ce8
commit 35d303809e
No known key found for this signature in database
GPG Key ID: BEAAE804EFD8E83A

View File

@ -1,8 +1,5 @@
#include "cse7766.h" #include "cse7766.h"
#include "esphome/core/log.h" #include "esphome/core/log.h"
#include <cinttypes>
#include <iomanip>
#include <sstream>
namespace esphome { namespace esphome {
namespace cse7766 { namespace cse7766 {
@ -72,12 +69,8 @@ bool CSE7766Component::check_byte_() {
void CSE7766Component::parse_data_() { void CSE7766Component::parse_data_() {
#if ESPHOME_LOG_LEVEL >= ESPHOME_LOG_LEVEL_VERY_VERBOSE #if ESPHOME_LOG_LEVEL >= ESPHOME_LOG_LEVEL_VERY_VERBOSE
{ {
std::stringstream ss; std::string s = format_hex_pretty(this->raw_data_, sizeof(this->raw_data_));
ss << "Raw data:" << std::hex << std::uppercase << std::setfill('0'); ESP_LOGVV(TAG, "Raw data: %s", s.c_str());
for (uint8_t i = 0; i < 23; i++) {
ss << ' ' << std::setw(2) << static_cast<unsigned>(this->raw_data_[i]);
}
ESP_LOGVV(TAG, "%s", ss.str().c_str());
} }
#endif #endif
@ -211,21 +204,20 @@ void CSE7766Component::parse_data_() {
#if ESPHOME_LOG_LEVEL >= ESPHOME_LOG_LEVEL_VERY_VERBOSE #if ESPHOME_LOG_LEVEL >= ESPHOME_LOG_LEVEL_VERY_VERBOSE
{ {
std::stringstream ss; std::string buf = "Parsed:";
ss << "Parsed:";
if (have_voltage) { if (have_voltage) {
ss << " V=" << voltage << "V"; buf += str_sprintf(" V=%fV", voltage);
} }
if (have_current) { if (have_current) {
ss << " I=" << current * 1000.0f << "mA (~" << calculated_current * 1000.0f << "mA)"; buf += str_sprintf(" I=%fmA (~%fmA)", current * 1000.0f, calculated_current * 1000.0f);
} }
if (have_power) { if (have_power) {
ss << " P=" << power << "W"; buf += str_sprintf(" P=%fW", power);
} }
if (energy != 0.0f) { if (energy != 0.0f) {
ss << " E=" << energy << "kWh (" << cf_pulses << ")"; buf += str_sprintf(" E=%fkWh (%u)", energy, cf_pulses);
} }
ESP_LOGVV(TAG, "%s", ss.str().c_str()); ESP_LOGVV(TAG, "%s", buf.c_str());
} }
#endif #endif
} }