code: def time_to_next_heartbeat(self):
          
          time_since_last_heartbeat = time.time() - max(self.last_send, self.last_reset)
          if self.heartbeat_failed:
              delay_to_next_heartbeat = self.config['retry_backoff_ms'] / 1000
          else:
              delay_to_next_heartbeat = self.config['heartbeat_interval_ms'] / 1000
          return max(0, delay_to_next_heartbeat - time_since_last_heartbeat)
docs: Returns seconds (float) remaining before next heartbeat should be sent