@@ -21,7 +21,7 @@ void SoyosourceVirtualMeter::setup() {
21
21
22
22
this ->last_power_demand_received_ = millis ();
23
23
24
- // if update intervall is set to never, trigger the update() method from here
24
+ // if update intervall is set to never, trigger the update() method from here
25
25
if (this ->get_update_interval () == -1 ) {
26
26
this ->update ();
27
27
}
@@ -112,7 +112,7 @@ int16_t SoyosourceVirtualMeter::calculate_power_demand_negative_measurements_(in
112
112
// -700 -690 10 500 -200 0
113
113
int16_t importing_now = consumption - this ->buffer_ ;
114
114
115
- reset_power_demand_compensation (importing_now);
115
+ reset_power_demand_compensation_ (importing_now);
116
116
117
117
int16_t power_demand = importing_now + last_power_demand - this ->power_demand_compensation_ ;
118
118
@@ -124,18 +124,20 @@ int16_t SoyosourceVirtualMeter::calculate_power_demand_negative_measurements_(in
124
124
power_demand = (this ->zero_output_on_min_power_demand_ ) ? 0 : this ->min_power_demand_ ;
125
125
}
126
126
127
- ESP_LOGD (TAG, " '%s': updated power_demand_compensation_ from %d" , this ->get_modbus_name (), this ->power_demand_compensation_ );
128
- // only reduction of compensation but keep old demand:
127
+ ESP_LOGD (TAG, " '%s': updated power_demand_compensation_ from %d" , this ->get_modbus_name (),
128
+ this ->power_demand_compensation_ );
129
+ // only reduction of compensation but keep old demand:
129
130
if (this ->power_demand_compensation_ != 0 && ((importing_now > 0 && power_demand < last_power_demand) ||
130
- (importing_now < 0 && power_demand > last_power_demand))) {
131
+ (importing_now < 0 && power_demand > last_power_demand))) {
131
132
this ->power_demand_compensation_ += power_demand - last_power_demand;
132
133
power_demand = last_power_demand;
133
134
ESP_LOGD (TAG, " '%s': Oscillation prevention, keeping previous demand: %d; reducing compensation" ,
134
135
this ->get_modbus_name (), last_power_demand);
135
136
} else {
136
137
this ->power_demand_compensation_ += power_demand - last_power_demand;
137
138
}
138
- ESP_LOGD (TAG, " '%s': updated power_demand_compensation_ to %d" , this ->get_modbus_name (), this ->power_demand_compensation_ );
139
+ ESP_LOGD (TAG, " '%s': updated power_demand_compensation_ to %d" , this ->get_modbus_name (),
140
+ this ->power_demand_compensation_ );
139
141
140
142
return power_demand;
141
143
}
@@ -222,13 +224,15 @@ void SoyosourceVirtualMeter::publish_state_(text_sensor::TextSensor *text_sensor
222
224
text_sensor->publish_state (state);
223
225
}
224
226
225
- void SoyosourceVirtualMeter::reset_power_demand_compensation (int16_t importing_now) {
226
- // reset on zero crossing or timeout
227
- if (importing_now == 0 || (this ->power_demand_compensation_ > 0 && importing_now < 0 )
228
- || (this ->power_demand_compensation_ < 0 && importing_now > 0 )
229
- || this ->power_demand_compensation_timestamp_ + this ->power_demand_compensation_timeout_ms_ < millis ()) {
227
+ void SoyosourceVirtualMeter::reset_power_demand_compensation_ (int16_t importing_now) {
228
+ // reset on zero crossing or timeout
229
+ if (importing_now == 0 || (this ->power_demand_compensation_ > 0 && importing_now < 0 ) ||
230
+ (this ->power_demand_compensation_ < 0 && importing_now > 0 ) ||
231
+ this ->power_demand_compensation_timestamp_ + this ->power_demand_compensation_timeout_ms_ < millis ()) {
230
232
ESP_LOGD (TAG, " '%s': reset power_demand_compensation_ to 0 %s" , this ->get_modbus_name (),
231
- this ->power_demand_compensation_timestamp_ + this ->power_demand_compensation_timeout_ms_ < millis () ? " after timout" : " after zero crossing" );
233
+ this ->power_demand_compensation_timestamp_ + this ->power_demand_compensation_timeout_ms_ < millis ()
234
+ ? " after timout"
235
+ : " after zero crossing" );
232
236
this ->power_demand_compensation_timestamp_ = millis ();
233
237
this ->power_demand_compensation_ = 0 ;
234
238
}
0 commit comments