@@ -202,8 +202,12 @@ def collected_pulses(
202202 pulses = self ._pulses_consumption + self ._hourly_reset_cons_pulses
203203 self ._pulsecounter_reset = False
204204 else :
205- pulses = self ._prev_pulses_consumption + self ._hourly_reset_cons_pulses + delta_cons_pulses
206- if self ._prev_pulses_consumption == 0 :
205+ pulses = (
206+ self ._prev_pulses_consumption
207+ + self ._hourly_reset_cons_pulses
208+ + delta_cons_pulses
209+ )
210+ if self ._prev_pulses_consumption == 0 : # handle initial situation
207211 pulses = self ._pulses_consumption + self ._hourly_reset_cons_pulses
208212
209213 self ._prev_pulses_consumption = self ._pulses_consumption
@@ -223,8 +227,12 @@ def collected_pulses(
223227 pulses = self ._pulses_production + self ._hourly_reset_prod_pulses
224228 self ._pulsecounter_reset = False
225229 else :
226- pulses = self ._prev_pulses_production + self ._hourly_reset_prod_pulses + delta_prod_pulses
227- if self ._prev_pulses_production == 0 :
230+ pulses = (
231+ self ._prev_pulses_production
232+ + self ._hourly_reset_prod_pulses
233+ + delta_prod_pulses
234+ )
235+ if self ._prev_pulses_production == 0 : # handle initial situation
228236 pulses = self ._pulses_production + self ._hourly_reset_prod_pulses
229237
230238 self ._prev_pulses_production = self ._pulses_production
@@ -278,8 +286,11 @@ def _collect_pulses_from_logs(
278286
279287 timestamp = self ._last_log_production_timestamp
280288
281- if from_timestamp > timestamp and not self ._hourly_reset_passed and not self ._pulsecounter_reset and (
282- self ._rollover_consumption or self ._rollover_production
289+ if (
290+ from_timestamp > timestamp
291+ and not self ._hourly_reset_passed
292+ and not self ._pulsecounter_reset
293+ and (self ._rollover_consumption or self ._rollover_production )
283294 ):
284295 self ._hourly_reset = True
285296
@@ -387,12 +398,16 @@ def _update_rollover(self) -> None:
387398 self ._last_log_consumption_timestamp
388399 < self ._pulses_timestamp
389400 < self ._next_log_consumption_timestamp
401+ ) and (
402+ self ._rollover_consumption
403+ and not (
404+ self ._hourly_reset
405+ or self ._hourly_reset_passed
406+ or self ._pulsecounter_reset
407+ )
390408 ):
391- if self ._rollover_consumption and not (
392- self ._hourly_reset or self ._hourly_reset_passed or self ._pulsecounter_reset
393- ):
394- _LOGGER .debug ("_update_rollover | %s | reset consumption" , self ._mac )
395- self ._rollover_consumption = False
409+ _LOGGER .debug ("_update_rollover | %s | reset consumption" , self ._mac )
410+ self ._rollover_consumption = False
396411 else :
397412 _LOGGER .debug ("_update_rollover | %s | unexpected consumption" , self ._mac )
398413
@@ -425,9 +440,15 @@ def _update_rollover(self) -> None:
425440 self ._last_log_production_timestamp
426441 < self ._pulses_timestamp
427442 < self ._next_log_production_timestamp
443+ ) and (
444+ self ._rollover_consumption
445+ and not (
446+ self ._hourly_reset
447+ or self ._hourly_reset_passed
448+ or self ._pulsecounter_reset
449+ )
428450 ):
429- if self ._rollover_production :
430- _LOGGER .debug ("_update_rollover | %s | reset production" , self ._mac )
451+ _LOGGER .debug ("_update_rollover | %s | reset production" , self ._mac )
431452 self ._rollover_production = False
432453 else :
433454 _LOGGER .debug ("_update_rollover | %s | unexpected production" , self ._mac )
0 commit comments