1010
1111@dataclass
1212class BambuCloud :
13-
13+
1414 def __init__ (self , region : str , email : str , username : str , auth_token : str ):
1515 self ._region = region
1616 self ._email = email
@@ -23,7 +23,7 @@ def _get_authentication_token(self) -> dict:
2323 url = 'https://api.bambulab.cn/v1/user-service/user/login'
2424 else :
2525 url = 'https://api.bambulab.com/v1/user-service/user/login'
26- headers = {'User-Agent' : "HA Bambulab " }
26+ headers = {'User-Agent' : "OctoPrint Plugin " }
2727 data = {'account' : self ._email , 'password' : self ._password }
2828 with httpx .Client (http2 = True ) as client :
2929 response = client .post (url , headers = headers , json = data , timeout = 10 )
@@ -40,7 +40,7 @@ def _get_username_from_authentication_token(self) -> str:
4040 jsonAuthToken = json .loads (base64 .b64decode (b64_string ))
4141 # Gives json payload with "username":"u_<digits>" within it
4242 return jsonAuthToken ['username' ]
43-
43+
4444 # Retrieves json description of devices in the form:
4545 # {
4646 # 'message': 'success',
@@ -79,7 +79,7 @@ def _get_username_from_authentication_token(self) -> str:
7979 # }
8080 # ]
8181 # }
82-
82+
8383 def test_authentication (self , region : str , email : str , username : str , auth_token : str ) -> bool :
8484 self ._region = region
8585 self ._email = email
@@ -105,7 +105,7 @@ def get_device_list(self) -> dict:
105105 url = 'https://api.bambulab.cn/v1/iot-service/api/user/bind'
106106 else :
107107 url = 'https://api.bambulab.com/v1/iot-service/api/user/bind'
108- headers = {'Authorization' : 'Bearer ' + self ._auth_token , 'User-Agent' : "HA Bambulab " }
108+ headers = {'Authorization' : 'Bearer ' + self ._auth_token , 'User-Agent' : "OctoPrint Plugin " }
109109 with httpx .Client (http2 = True ) as client :
110110 response = client .get (url , headers = headers , timeout = 10 )
111111 if response .status_code >= 400 :
@@ -186,14 +186,14 @@ def get_slicer_settings(self) -> dict:
186186 url = 'https://api.bambulab.cn/v1/iot-service/api/slicer/setting?version=undefined'
187187 else :
188188 url = 'https://api.bambulab.com/v1/iot-service/api/slicer/setting?version=undefined'
189- headers = {'Authorization' : 'Bearer ' + self ._auth_token , 'User-Agent' : "HA Bambulab " }
189+ headers = {'Authorization' : 'Bearer ' + self ._auth_token , 'User-Agent' : "OctoPrint Plugin " }
190190 with httpx .Client (http2 = True ) as client :
191191 response = client .get (url , headers = headers , timeout = 10 )
192192 if response .status_code >= 400 :
193193 LOGGER .error (f"Slicer settings load failed: { response .status_code } " )
194194 return None
195195 return response .json ()
196-
196+
197197 # The task list is of the following form with a 'hits' array with typical 20 entries.
198198 #
199199 # "total": 531,
@@ -241,14 +241,14 @@ def get_tasklist(self) -> dict:
241241 url = 'https://api.bambulab.cn/v1/user-service/my/tasks'
242242 else :
243243 url = 'https://api.bambulab.com/v1/user-service/my/tasks'
244- headers = {'Authorization' : 'Bearer ' + self ._auth_token , 'User-Agent' : "HA Bambulab " }
244+ headers = {'Authorization' : 'Bearer ' + self ._auth_token , 'User-Agent' : "OctoPrint Plugin " }
245245 with httpx .Client (http2 = True ) as client :
246246 response = client .get (url , headers = headers , timeout = 10 )
247247 if response .status_code >= 400 :
248248 LOGGER .debug (f"Received error: { response .status_code } " )
249249 raise ValueError (response .status_code )
250250 return response .json ()
251-
251+
252252 def get_latest_task_for_printer (self , deviceId : str ) -> dict :
253253 LOGGER .debug (f"Getting latest task from Bambu Cloud for Printer: { deviceId } " )
254254 data = self .get_tasklist_for_printer (deviceId )
@@ -283,11 +283,11 @@ def download(self, url: str) -> bytearray:
283283 @property
284284 def username (self ):
285285 return self ._username
286-
286+
287287 @property
288288 def auth_token (self ):
289289 return self ._auth_token
290-
290+
291291 @property
292292 def cloud_mqtt_host (self ):
293293 return "cn.mqtt.bambulab.com" if self ._region == "China" else "us.mqtt.bambulab.com"
0 commit comments