mirror of
https://github.com/esphome/esphome.git
synced 2024-11-27 17:27:59 +01:00
Update HLW8032 formatting
This commit is contained in:
parent
746ecc56d1
commit
ebf2eb4fc6
2 changed files with 23 additions and 24 deletions
|
@ -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);
|
||||
{
|
||||
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());
|
||||
}
|
||||
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
|
||||
}
|
||||
|
||||
|
|
|
@ -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:
|
||||
|
|
Loading…
Reference in a new issue