Update HLW8032 formatting

This commit is contained in:
Richard Kubíček 2024-08-11 10:31:07 +02:00
parent 746ecc56d1
commit ebf2eb4fc6
2 changed files with 23 additions and 24 deletions

View file

@ -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<unsigned>(i);
}
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,7 +160,7 @@ void HLW8032Component::parse_data_() {
}
#if ESPHOME_LOG_LEVEL >= ESPHOME_LOG_LEVEL_VERY_VERBOSE
{
{
std::stringstream ss;
ss << "Parsed:";
if (have_voltage) {
@ -175,7 +173,7 @@ void HLW8032Component::parse_data_() {
ss << " P=" << power << "W";
}
ESP_LOGD(TAG, "%s", ss.str().c_str());
}
}
#endif
}

View file

@ -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: