From ebf2eb4fc62dc4ff1c55cdd0a335a70dd4492083 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Richard=20Kub=C3=AD=C4=8Dek?= Date: Sun, 11 Aug 2024 10:31:07 +0200 Subject: [PATCH] Update HLW8032 formatting --- esphome/components/hlw8032/hlw8032.cpp | 42 ++++++++++++-------------- esphome/components/hlw8032/hlw8032.h | 5 +-- 2 files changed, 23 insertions(+), 24 deletions(-) diff --git a/esphome/components/hlw8032/hlw8032.cpp b/esphome/components/hlw8032/hlw8032.cpp index 8c1b595aaf..c3155f98fc 100644 --- a/esphome/components/hlw8032/hlw8032.cpp +++ b/esphome/components/hlw8032/hlw8032.cpp @@ -10,7 +10,6 @@ namespace hlw8032 { static const char *const TAG = "hlw8032"; void HLW8032Component::loop() { - if (!this->available()) return; @@ -44,14 +43,14 @@ void HLW8032Component::loop() { void HLW8032Component::parse_data_() { #if ESPHOME_LOG_LEVEL >= ESPHOME_LOG_LEVEL_VERY_VERBOSE -{ - std::stringstream ss; - ss << "Raw data:" << std::hex << std::uppercase << std::setfill('0'); - for (unsigned char i : this->raw_data_) { - ss << ' ' << std::setw(2) << static_cast(i); + { + std::stringstream ss; + ss << "Raw data:" << std::hex << std::uppercase << std::setfill('0'); + for (unsigned char i : this->raw_data_) { + ss << ' ' << std::setw(2) << static_cast(i); + } + ESP_LOGD(TAG, "%s", ss.str().c_str()); } - ESP_LOGD(TAG, "%s", ss.str().c_str()); -} #endif // Parse header @@ -112,7 +111,6 @@ void HLW8032Component::parse_data_() { float voltage = 0.0f; if (have_voltage) { - voltage = float(voltage_parameter) * this->voltage_divider_ / float(voltage_reg); if (this->voltage_sensor_ != nullptr) { this->voltage_sensor_->publish_state(voltage); @@ -162,20 +160,20 @@ void HLW8032Component::parse_data_() { } #if ESPHOME_LOG_LEVEL >= ESPHOME_LOG_LEVEL_VERY_VERBOSE -{ - std::stringstream ss; - ss << "Parsed:"; - if (have_voltage) { - ss << " V=" << voltage << "V"; + { + std::stringstream ss; + ss << "Parsed:"; + if (have_voltage) { + ss << " V=" << voltage << "V"; + } + if (have_current) { + ss << " I=" << current * 1000.0f << "mA"; + } + if (have_power) { + ss << " P=" << power << "W"; + } + ESP_LOGD(TAG, "%s", ss.str().c_str()); } - if (have_current) { - ss << " I=" << current * 1000.0f << "mA"; - } - if (have_power) { - ss << " P=" << power << "W"; - } - ESP_LOGD(TAG, "%s", ss.str().c_str()); -} #endif } diff --git a/esphome/components/hlw8032/hlw8032.h b/esphome/components/hlw8032/hlw8032.h index 914787cbbd..497a5b4598 100644 --- a/esphome/components/hlw8032/hlw8032.h +++ b/esphome/components/hlw8032/hlw8032.h @@ -12,7 +12,6 @@ namespace hlw8032 { class HLW8032Component : public Component, public uart::UARTDevice { public: - void loop() override; void dump_config() override; @@ -21,7 +20,9 @@ class HLW8032Component : public Component, public uart::UARTDevice { void set_voltage_sensor(sensor::Sensor *voltage_sensor) { voltage_sensor_ = voltage_sensor; } void set_current_sensor(sensor::Sensor *current_sensor) { current_sensor_ = current_sensor; } void set_power_sensor(sensor::Sensor *power_sensor) { power_sensor_ = power_sensor; } - void set_apparent_power_sensor(sensor::Sensor *apparent_power_sensor) { apparent_power_sensor_ = apparent_power_sensor; } + void set_apparent_power_sensor(sensor::Sensor *apparent_power_sensor) { + apparent_power_sensor_ = apparent_power_sensor; + } void set_power_factor_sensor(sensor::Sensor *power_factor_sensor) { power_factor_sensor_ = power_factor_sensor; } protected: