7
7
import rumps
8
8
import control
9
9
import config
10
+ import json
10
11
11
12
class Harmenubar (rumps .App ):
12
13
def __init__ (self ):
13
14
super (Harmenubar ,self ).__init__ ('Harmenubar' ,icon = 'resources/icon.png' )
14
- print 'Logging in to Logitech'
15
- self .
session_token = control .
login_to_logitech (
'[email protected] ' ,
'ankeborg' ,
'192.168.0.158' )
16
- print 'Connecting client'
17
- client = control .get_client ('192.168.0.158' , self .session_token )
18
- print 'Getting current activity'
19
- self .activity = client .get_current_activity () # 5337127
20
15
self .activity = 5337127
21
- client .disconnect (send_close = True )
16
+ self .auth ()
17
+
18
+ cfg = self .get_and_store_config ()
22
19
23
- self .cfg = config .HarmonyConfig ('harmony.json' )
20
+ self .cfg = config .HarmonyConfig (cfg )
24
21
self .activities = self .cfg .get_activities ()
25
22
self .devices = self .cfg .get_devices ()
26
23
activity_menu = self .build_activity_menu ()
@@ -35,6 +32,24 @@ def __init__(self):
35
32
]
36
33
self .update_current_activity (self .activity )
37
34
35
+ def auth (self ):
36
+ print 'Logging in to Logitech'
37
+ self .
session_token = control .
login_to_logitech (
'[email protected] ' ,
'ankeborg' ,
'192.168.0.158' )
38
+ print 'Connecting client'
39
+ client = control .get_client ('192.168.0.158' , self .session_token )
40
+ print 'Getting current activity'
41
+ self .activity = client .get_current_activity () # 5337127
42
+ client .disconnect (send_close = True )
43
+
44
+ def get_and_store_config (self ):
45
+ client = control .get_client ('192.168.0.158' , self .session_token )
46
+ print 'Getting configuration'
47
+ cfg = client .get_config ()
48
+ client .disconnect (send_close = True )
49
+ with self .open ('config.json' ,'w' ) as f :
50
+ f .write (json .dumps (cfg ))
51
+ return cfg
52
+
38
53
def build_activity_menu (self ):
39
54
menu = []
40
55
for key ,value in self .activities .iteritems ():
0 commit comments