@@ -513,71 +513,71 @@ def _update_log_direction(
513513 if self ._logs is None :
514514 return
515515
516- prev_timestamp = self ._check_prev_production (address , slot , timestamp )
517- next_timestamp = self ._check_next_production (address , slot , timestamp )
516+ def check_prev_production (
517+ self , address : int , slot : int , timestamp : datetime
518+ ) -> datetime | None :
519+ """Check the previous slot for production pulses."""
520+ prev_address , prev_slot = calc_log_address (address , slot , - 1 )
521+ if self ._log_exists (prev_address , prev_slot ):
522+ prev_timestamp = self ._logs [prev_address ][prev_slot ].timestamp
523+ if not self ._first_prev_log_processed :
524+ self ._first_prev_log_processed = True
525+ if prev_timestamp == timestamp :
526+ # Given log is the second log with same timestamp,
527+ # mark direction as production
528+ self ._logs [address ][slot ].is_consumption = False
529+ self ._logs [prev_address ][prev_slot ].is_consumption = True
530+ self ._log_production = True
531+ elif self ._log_production :
532+ self ._logs [address ][slot ].is_consumption = True
533+ if self ._logs [prev_address ][prev_slot ].is_consumption :
534+ self ._logs [prev_address ][prev_slot ].is_consumption = False
535+ self ._reset_log_references ()
536+ elif self ._log_production is None :
537+ self ._log_production = False
538+ return prev_timestamp
539+
540+ if self ._first_prev_log_processed :
541+ self ._first_prev_log_processed = False
542+ return None
543+
544+ def check_next_production (
545+ self , address : int , slot : int , timestamp : datetime
546+ ) -> datetime | None :
547+ """Check the next slot for production pulses."""
548+ next_address , next_slot = calc_log_address (address , slot , 1 )
549+ if self ._log_exists (next_address , next_slot ):
550+ next_timestamp = self ._logs [next_address ][next_slot ].timestamp
551+ if not self ._first_next_log_processed :
552+ self ._first_next_log_processed = True
553+ if next_timestamp == timestamp :
554+ # Given log is the first log with same timestamp,
555+ # mark direction as production of next log
556+ self ._logs [address ][slot ].is_consumption = True
557+ if self ._logs [next_address ][next_slot ].is_consumption :
558+ self ._logs [next_address ][next_slot ].is_consumption = False
559+ self ._reset_log_references ()
560+ self ._log_production = True
561+ elif self ._log_production :
562+ self ._logs [address ][slot ].is_consumption = False
563+ self ._logs [next_address ][next_slot ].is_consumption = True
564+ elif self ._log_production is None :
565+ self ._log_production = False
566+ return next_timestamp
567+
568+ if self ._first_next_log_processed :
569+ self ._first_next_log_processed = False
570+ return None
571+
572+ prev_timestamp = check_prev_production (self , address , slot , timestamp )
573+ next_timestamp = check_next_production (self , address , slot , timestamp )
518574 if self ._first_prev_log_processed and self ._first_next_log_processed :
519575 # _log_production is True when 2 out of 3 consecutive slots have
520576 # the same timestamp, otherwise it is False
521577 self ._log_production = (
522578 next_timestamp == timestamp and prev_timestamp != timestamp
523579 ) or (next_timestamp == prev_timestamp and next_timestamp != timestamp )
524580
525- def _check_prev_production (
526- self , address : int , slot : int , timestamp : datetime
527- ) -> datetime | None :
528- """Check the previous slot for production pulses."""
529- prev_address , prev_slot = calc_log_address (address , slot , - 1 )
530- if self ._log_exists (prev_address , prev_slot ):
531- prev_timestamp = self ._logs [prev_address ][prev_slot ].timestamp
532- if not self ._first_prev_log_processed :
533- self ._first_prev_log_processed = True
534- if prev_timestamp == timestamp :
535- # Given log is the second log with same timestamp,
536- # mark direction as production
537- self ._logs [address ][slot ].is_consumption = False
538- self ._logs [prev_address ][prev_slot ].is_consumption = True
539- self ._log_production = True
540- elif self ._log_production :
541- self ._logs [address ][slot ].is_consumption = True
542- if self ._logs [prev_address ][prev_slot ].is_consumption :
543- self ._logs [prev_address ][prev_slot ].is_consumption = False
544- self ._reset_log_references ()
545- elif self ._log_production is None :
546- self ._log_production = False
547- return prev_timestamp
548-
549- if self ._first_prev_log_processed :
550- self ._first_prev_log_processed = False
551- return None
552-
553- def _check_next_production (
554- self , address : int , slot : int , timestamp : datetime
555- ) -> datetime | None :
556- """Check the next slot for production pulses."""
557- next_address , next_slot = calc_log_address (address , slot , 1 )
558- if self ._log_exists (next_address , next_slot ):
559- next_timestamp = self ._logs [next_address ][next_slot ].timestamp
560- if not self ._first_next_log_processed :
561- self ._first_next_log_processed = True
562- if next_timestamp == timestamp :
563- # Given log is the first log with same timestamp,
564- # mark direction as production of next log
565- self ._logs [address ][slot ].is_consumption = True
566- if self ._logs [next_address ][next_slot ].is_consumption :
567- self ._logs [next_address ][next_slot ].is_consumption = False
568- self ._reset_log_references ()
569- self ._log_production = True
570- elif self ._log_production :
571- self ._logs [address ][slot ].is_consumption = False
572- self ._logs [next_address ][next_slot ].is_consumption = True
573- elif self ._log_production is None :
574- self ._log_production = False
575- return next_timestamp
576-
577- if self ._first_next_log_processed :
578- self ._first_next_log_processed = False
579- return None
580-
581581 def _update_log_interval (self ) -> None :
582582 """Update the detected log interval based on the most recent two logs."""
583583 if self ._logs is None or self ._log_production is None :
@@ -928,6 +928,7 @@ def _logs_missing(self, from_timestamp: datetime) -> list[int] | None:
928928 # We have an suspected interval, so try to calculate missing log addresses prior to first collected log
929929 _LOGGER .debug (
930930 "_logs_missing | %s | checking before range with log_interval=%s" ,
931+ self ._mac ,
931932 log_interval ,
932933 )
933934 calculated_timestamp = self ._logs [first_address ][
0 commit comments