5
5
6
6
from thinq2 .controller .auth import ThinQAuth
7
7
from thinq2 .controller .thinq import ThinQ
8
- from thinq2 .client .objectstore import ObjectStoreClient
9
8
10
9
LANGUAGE_CODE = os .environ .get ("LANGUAGE_CODE" , "ko-KR" )
11
10
COUNTRY_CODE = os .environ .get ("COUNTRY_CODE" , "KR" )
12
11
STATE_FILE = os .environ .get ("STATE_FILE" , "state.json" )
13
12
14
- #################################################################################
15
- # load from existing state or create a new client #
16
- #################################################################################
13
+ #############################################################################
14
+ # load from existing state or create a new client #
15
+ #############################################################################
17
16
if os .path .exists (STATE_FILE ):
18
17
with open (STATE_FILE , "r" ) as f :
19
18
thinq = ThinQ (json .load (f ))
35
34
36
35
print ("\n " )
37
36
37
+
38
38
def save_state ():
39
39
with open (STATE_FILE , "w" ) as f :
40
40
json .dump (vars (thinq ), f )
41
41
42
+
42
43
save_state ()
43
44
44
- #################################################################################
45
- # state is easily serialized in dict form, as in this shutdown handler #
46
- #################################################################################
45
+ #############################################################################
46
+ # state is easily serialized in dict form, as in this shutdown handler #
47
+ #############################################################################
47
48
def shutdown (sig , frame ):
48
49
print ("\n Caught SIGINT, saving application state." )
49
50
exit (0 )
50
51
51
52
52
53
signal .signal (signal .SIGINT , shutdown )
53
54
54
- #################################################################################
55
- # display some information about the user's account/devices #
56
- #################################################################################
55
+ #############################################################################
56
+ # display some information about the user's account/devices #
57
+ #############################################################################
57
58
devices = thinq .mqtt .thinq_client .get_devices ()
58
59
59
60
if len (devices .items ) == 0 :
@@ -63,15 +64,15 @@ def shutdown(sig, frame):
63
64
64
65
print ("UserID: {}" .format (thinq .auth .profile .user_id ))
65
66
print ("User #: {}\n " .format (thinq .auth .profile .user_no ))
66
-
67
67
print ("Devices:\n " )
68
68
69
+
69
70
for device in devices .items :
70
71
print ("{}: {} (model {})" .format (device .device_id , device .alias , device .model_name ))
71
72
72
- #################################################################################
73
- # example of raw MQTT access #
74
- #################################################################################
73
+ #############################################################################
74
+ # example of raw MQTT access #
75
+ #############################################################################
75
76
76
77
print ("\n Listening for device events. Use Ctrl-C/SIGINT to quit.\n " )
77
78
0 commit comments