Skip to content

Commit

Permalink
fix: added 1ms spacing when two consecutive events share same timesta…
Browse files Browse the repository at this point in the history
…mp (#51)
  • Loading branch information
ErikBjare committed Oct 14, 2021
1 parent 30b6d27 commit 7ce0d6b
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions aw_watcher_afk/afk.py
Expand Up @@ -22,6 +22,7 @@


logger = logging.getLogger(__name__)
td1ms = timedelta(milliseconds=1)


class Settings:
Expand Down Expand Up @@ -85,13 +86,17 @@ def heartbeat_loop(self):
logger.info("No longer AFK")
self.ping(afk, timestamp=last_input)
afk = False
self.ping(afk, timestamp=last_input)
# ping with timestamp+1ms with the next event (to ensure the latest event gets retreived by get_event)
self.ping(afk, timestamp=last_input + td1ms)
# If becomes AFK
elif not afk and seconds_since_input >= self.settings.timeout:
logger.info("Became AFK")
self.ping(afk, timestamp=last_input)
afk = True
self.ping(afk, timestamp=last_input, duration=seconds_since_input)
# ping with timestamp+1ms with the next event (to ensure the latest event gets retreived by get_event)
self.ping(
afk, timestamp=last_input + td1ms, duration=seconds_since_input
)
# Send a heartbeat if no state change was made
else:
if afk:
Expand Down

0 comments on commit 7ce0d6b

Please sign in to comment.