mirror of
https://github.com/esphome/esphome.git
synced 2024-11-28 12:46:22 +01:00
atm90e32: make the total_increasing class sensors actually be increasing totals. (#2459)
Co-authored-by: David Monro <david.monro@anu.edu.au>
This commit is contained in:
parent
3f2d9abfe6
commit
a1b28cb36e
@ -265,27 +265,57 @@ float ATM90E32Component::get_power_factor_c_() {
|
|||||||
}
|
}
|
||||||
float ATM90E32Component::get_forward_active_energy_a_() {
|
float ATM90E32Component::get_forward_active_energy_a_() {
|
||||||
uint16_t val = this->read16_(ATM90E32_REGISTER_APENERGYA);
|
uint16_t val = this->read16_(ATM90E32_REGISTER_APENERGYA);
|
||||||
return (float) val * 10 / 3200; // convert register value to WattHours
|
if ((UINT32_MAX - this->phase_[0].cumulative_forward_active_energy_) > val) {
|
||||||
|
this->phase_[0].cumulative_forward_active_energy_ += val;
|
||||||
|
} else {
|
||||||
|
this->phase_[0].cumulative_forward_active_energy_ = val;
|
||||||
|
}
|
||||||
|
return ((float) this->phase_[0].cumulative_forward_active_energy_ * 10 / 3200);
|
||||||
}
|
}
|
||||||
float ATM90E32Component::get_forward_active_energy_b_() {
|
float ATM90E32Component::get_forward_active_energy_b_() {
|
||||||
uint16_t val = this->read16_(ATM90E32_REGISTER_APENERGYB);
|
uint16_t val = this->read16_(ATM90E32_REGISTER_APENERGYB);
|
||||||
return (float) val * 10 / 3200;
|
if (UINT32_MAX - this->phase_[1].cumulative_forward_active_energy_ > val) {
|
||||||
|
this->phase_[1].cumulative_forward_active_energy_ += val;
|
||||||
|
} else {
|
||||||
|
this->phase_[1].cumulative_forward_active_energy_ = val;
|
||||||
|
}
|
||||||
|
return ((float) this->phase_[1].cumulative_forward_active_energy_ * 10 / 3200);
|
||||||
}
|
}
|
||||||
float ATM90E32Component::get_forward_active_energy_c_() {
|
float ATM90E32Component::get_forward_active_energy_c_() {
|
||||||
uint16_t val = this->read16_(ATM90E32_REGISTER_APENERGYC);
|
uint16_t val = this->read16_(ATM90E32_REGISTER_APENERGYC);
|
||||||
return (float) val * 10 / 3200;
|
if (UINT32_MAX - this->phase_[2].cumulative_forward_active_energy_ > val) {
|
||||||
|
this->phase_[2].cumulative_forward_active_energy_ += val;
|
||||||
|
} else {
|
||||||
|
this->phase_[2].cumulative_forward_active_energy_ = val;
|
||||||
|
}
|
||||||
|
return ((float) this->phase_[2].cumulative_forward_active_energy_ * 10 / 3200);
|
||||||
}
|
}
|
||||||
float ATM90E32Component::get_reverse_active_energy_a_() {
|
float ATM90E32Component::get_reverse_active_energy_a_() {
|
||||||
uint16_t val = this->read16_(ATM90E32_REGISTER_ANENERGYA);
|
uint16_t val = this->read16_(ATM90E32_REGISTER_ANENERGYA);
|
||||||
return (float) val * 10 / 3200;
|
if (UINT32_MAX - this->phase_[0].cumulative_reverse_active_energy_ > val) {
|
||||||
|
this->phase_[0].cumulative_reverse_active_energy_ += val;
|
||||||
|
} else {
|
||||||
|
this->phase_[0].cumulative_reverse_active_energy_ = val;
|
||||||
|
}
|
||||||
|
return ((float) this->phase_[0].cumulative_reverse_active_energy_ * 10 / 3200);
|
||||||
}
|
}
|
||||||
float ATM90E32Component::get_reverse_active_energy_b_() {
|
float ATM90E32Component::get_reverse_active_energy_b_() {
|
||||||
uint16_t val = this->read16_(ATM90E32_REGISTER_ANENERGYB);
|
uint16_t val = this->read16_(ATM90E32_REGISTER_ANENERGYB);
|
||||||
return (float) val * 10 / 3200;
|
if (UINT32_MAX - this->phase_[1].cumulative_reverse_active_energy_ > val) {
|
||||||
|
this->phase_[1].cumulative_reverse_active_energy_ += val;
|
||||||
|
} else {
|
||||||
|
this->phase_[1].cumulative_reverse_active_energy_ = val;
|
||||||
|
}
|
||||||
|
return ((float) this->phase_[1].cumulative_reverse_active_energy_ * 10 / 3200);
|
||||||
}
|
}
|
||||||
float ATM90E32Component::get_reverse_active_energy_c_() {
|
float ATM90E32Component::get_reverse_active_energy_c_() {
|
||||||
uint16_t val = this->read16_(ATM90E32_REGISTER_ANENERGYC);
|
uint16_t val = this->read16_(ATM90E32_REGISTER_ANENERGYC);
|
||||||
return (float) val * 10 / 3200;
|
if (UINT32_MAX - this->phase_[2].cumulative_reverse_active_energy_ > val) {
|
||||||
|
this->phase_[2].cumulative_reverse_active_energy_ += val;
|
||||||
|
} else {
|
||||||
|
this->phase_[2].cumulative_reverse_active_energy_ = val;
|
||||||
|
}
|
||||||
|
return ((float) this->phase_[2].cumulative_reverse_active_energy_ * 10 / 3200);
|
||||||
}
|
}
|
||||||
float ATM90E32Component::get_frequency_() {
|
float ATM90E32Component::get_frequency_() {
|
||||||
uint16_t freq = this->read16_(ATM90E32_REGISTER_FREQ);
|
uint16_t freq = this->read16_(ATM90E32_REGISTER_FREQ);
|
||||||
|
@ -77,6 +77,8 @@ class ATM90E32Component : public PollingComponent,
|
|||||||
sensor::Sensor *power_factor_sensor_{nullptr};
|
sensor::Sensor *power_factor_sensor_{nullptr};
|
||||||
sensor::Sensor *forward_active_energy_sensor_{nullptr};
|
sensor::Sensor *forward_active_energy_sensor_{nullptr};
|
||||||
sensor::Sensor *reverse_active_energy_sensor_{nullptr};
|
sensor::Sensor *reverse_active_energy_sensor_{nullptr};
|
||||||
|
uint32_t cumulative_forward_active_energy_{0};
|
||||||
|
uint32_t cumulative_reverse_active_energy_{0};
|
||||||
} phase_[3];
|
} phase_[3];
|
||||||
sensor::Sensor *freq_sensor_{nullptr};
|
sensor::Sensor *freq_sensor_{nullptr};
|
||||||
sensor::Sensor *chip_temperature_sensor_{nullptr};
|
sensor::Sensor *chip_temperature_sensor_{nullptr};
|
||||||
|
Loading…
Reference in New Issue
Block a user