-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathmobileraker.py
89 lines (75 loc) · 3.01 KB
/
mobileraker.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
import argparse
import asyncio
import logging
import os
from mobileraker.client.mobileraker_fcm_client import MobilerakerFcmClient
from mobileraker.client.moonraker_client import MoonrakerClient
from mobileraker.client.snapshot_client import SnapshotClient
from mobileraker.mobileraker_companion import MobilerakerCompanion
from mobileraker.service.data_sync_service import DataSyncService
from mobileraker.util.configs import CompanionLocalConfig, printer_data_logs_dir
from mobileraker.util.functions import get_software_version
from mobileraker.util.logging import setup_logging
def main() -> None:
parser = argparse.ArgumentParser(
description="Mobileraker - Companion")
parser.add_argument(
"-l", "--logfile", default=os.path.join(printer_data_logs_dir if os.path.exists(printer_data_logs_dir) else '/tmp', "mobileraker.log"), metavar='<logfile>',
help="Log File Location or log file absolute path")
parser.add_argument(
"-n", "--nologfile", action='store_true',
help="disable logging to a file")
parser.add_argument(
"-c", "--configfile", default="~/Mobileraker.conf", metavar='<configfile>',
help="Location of the configuration file for Mobileraker Companion"
)
cmd_line_args = parser.parse_args()
version = get_software_version()
if not cmd_line_args.nologfile:
setup_logging(os.path.normpath(os.path.expanduser(
cmd_line_args.logfile)), version)
logging.info(f"MobilerakerCompanion version: {version}")
passed_config_location = os.path.normpath(
os.path.expanduser(cmd_line_args.configfile))
local_config = CompanionLocalConfig(passed_config_location)
event_loop = asyncio.new_event_loop()
asyncio.set_event_loop(event_loop)
fcmc = MobilerakerFcmClient(
# 'http://127.0.0.1:8080',
'https://mobileraker.eliteschw31n.de',
event_loop)
try:
printers = local_config.printers
for printer_name in printers:
p_config = printers[printer_name]
jrpc = MoonrakerClient(
p_config['moonraker_uri'],
p_config['moonraker_api_key'],
printer_name,
event_loop)
snc = SnapshotClient(
p_config['snapshot_uri'],
p_config['snapshot_rotation'],
)
dsd = DataSyncService(
jrpc=jrpc,
printer_name=printer_name,
loop=event_loop,
)
client = MobilerakerCompanion(
jrpc=jrpc,
data_sync_service=dsd,
fcm_client=fcmc,
snapshot_client=snc,
printer_name=printer_name,
loop=event_loop,
companion_config=local_config,
exclude_sensors=p_config['excluded_filament_sensors'],
)
event_loop.create_task(client.start())
event_loop.run_forever()
finally:
event_loop.close()
exit()
if __name__ == '__main__':
main()