Skip to content

Commit

Permalink
feat!: switched config format to toml (#49)
Browse files Browse the repository at this point in the history
* feat!: switched config format to toml
* build(deps): updated aw-client

BREAKING CHANGE: changes the config file used
  • Loading branch information
ErikBjare committed Jun 15, 2021
1 parent 2f108d5 commit ccf6b12
Show file tree
Hide file tree
Showing 3 changed files with 81 additions and 24 deletions.
12 changes: 8 additions & 4 deletions aw_watcher_afk/afk.py
Expand Up @@ -27,9 +27,9 @@
class Settings:
def __init__(self, config_section):
# Time without input before we're considering the user as AFK
self.timeout = config_section.getfloat("timeout")
self.timeout = config_section["timeout"]
# How often we should poll for input activity
self.poll_time = config_section.getfloat("poll_time")
self.poll_time = config_section["poll_time"]

assert self.timeout >= self.poll_time

Expand All @@ -41,7 +41,9 @@ def __init__(self, testing=False):
self.settings = Settings(watcher_config[configsection])

self.client = ActivityWatchClient("aw-watcher-afk", testing=testing)
self.bucketname = "{}_{}".format(self.client.client_name, self.client.client_hostname)
self.bucketname = "{}_{}".format(
self.client.client_name, self.client.client_hostname
)

def ping(self, afk: bool, timestamp: datetime, duration: float = 0):
data = {"status": "afk" if afk else "not-afk"}
Expand Down Expand Up @@ -93,7 +95,9 @@ def heartbeat_loop(self):
# Send a heartbeat if no state change was made
else:
if afk:
self.ping(afk, timestamp=last_input, duration=seconds_since_input)
self.ping(
afk, timestamp=last_input, duration=seconds_since_input
)
else:
self.ping(afk, timestamp=last_input)

Expand Down
25 changes: 11 additions & 14 deletions aw_watcher_afk/config.py
@@ -1,16 +1,13 @@
from configparser import ConfigParser
from aw_core.config import load_config
from aw_core.config import load_config_toml

default_settings = {
"timeout": "180",
"poll_time": "5",
}
default_testing_settings = {
"timeout": "20",
"poll_time": "1",
}
default_config = """
[aw-watcher-afk]
timeout = 180
poll_time = 5
default_config = ConfigParser()
default_config['aw-watcher-afk'] = default_settings
default_config['aw-watcher-afk-testing'] = default_testing_settings
watcher_config = load_config("aw-watcher-afk", default_config)
[aw-watcher-afk-testing]
timeout = 20
poll_time = 1
""".strip()

watcher_config = load_config_toml("aw-watcher-afk", default_config)
68 changes: 62 additions & 6 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit ccf6b12

Please sign in to comment.