@@ -69,7 +69,9 @@ def send_control_api_request(self, target: str, headers: Optional[Dict[str, str]
69
69
_headers .update (headers )
70
70
return self .send_api_request (target , headers = _headers , method = method , body = body )
71
71
72
- def __enter__ (self ):
72
+ def open (self ):
73
+ if self .is_open :
74
+ raise ValueError ("Session is already open." )
73
75
self .__client = HTTPSConnection (self .__fci_hostname , timeout = 12 , context = ssl ._create_unverified_context ())
74
76
self .__client .connect ()
75
77
payload = json .dumps (
@@ -79,12 +81,20 @@ def __enter__(self):
79
81
body = payload ).decode ("utf-8" )
80
82
return self
81
83
82
- def __exit__ (self , type , value , traceback ):
84
+ def close (self ):
85
+ if not self .is_open :
86
+ raise ValueError ("Session is not open." )
83
87
if self .__control_token is not None :
84
88
self .release_control ()
85
89
self .__token = None
86
90
self .__client .close ()
87
91
92
+ def __enter__ (self ):
93
+ self .open ()
94
+
95
+ def __exit__ (self , type , value , traceback ):
96
+ self .close ()
97
+
88
98
def __check_control_token (self ):
89
99
if self .__control_token is None :
90
100
raise ValueError ("Client does not have control. Call take_control() first." )
@@ -148,9 +158,14 @@ def get_system_status(self):
148
158
return json .loads (self .send_api_request ("/admin/api/system-status" , method = "GET" ).decode ("utf-8" ))
149
159
150
160
@property
151
- def client (self ):
161
+ def client (self ) -> HTTPSConnection :
152
162
return self .__client
153
163
154
164
@property
155
165
def token (self ) -> str :
156
166
return self .__token
167
+
168
+ @property
169
+ def is_open (self ) -> bool :
170
+ return self .__token is not None
171
+
0 commit comments