Compare commits
8 Commits
Author | SHA1 | Date | |
---|---|---|---|
884101c0ba | |||
7c87ba9482 | |||
1d9f874560 | |||
21e30034d0 | |||
3c8b904a26 | |||
55ad4c1718 | |||
4ef8e40702 | |||
2537bc8f57 |
@ -685,7 +685,7 @@ class BambuVirtualPrinter:
|
|||||||
self._state_change_queue.join()
|
self._state_change_queue.join()
|
||||||
|
|
||||||
def _printer_worker(self):
|
def _printer_worker(self):
|
||||||
self._create_client_connection_async()
|
# self._create_client_connection_async()
|
||||||
self.sendIO("Printer connection complete")
|
self.sendIO("Printer connection complete")
|
||||||
while self._running:
|
while self._running:
|
||||||
try:
|
try:
|
||||||
|
@ -87,7 +87,7 @@ class CachedFileView:
|
|||||||
def _get_file_by_stem_cached(self, file_stem: str, allowed_suffixes: list[str]):
|
def _get_file_by_stem_cached(self, file_stem: str, allowed_suffixes: list[str]):
|
||||||
for file_path_str in list(self._file_data_cache.keys()) + list(self._file_alias_cache.keys()):
|
for file_path_str in list(self._file_data_cache.keys()) + list(self._file_alias_cache.keys()):
|
||||||
file_path = Path(file_path_str)
|
file_path = Path(file_path_str)
|
||||||
if file_stem == file_path.with_suffix("").stem and all(
|
if file_stem == file_path.with_suffix("").stem and any(
|
||||||
suffix in allowed_suffixes for suffix in file_path.suffixes
|
suffix in allowed_suffixes for suffix in file_path.suffixes
|
||||||
):
|
):
|
||||||
return self.get_file_data_cached(file_path)
|
return self.get_file_data_cached(file_path)
|
||||||
|
@ -10,7 +10,7 @@ from .const import LOGGER
|
|||||||
|
|
||||||
@dataclass
|
@dataclass
|
||||||
class BambuCloud:
|
class BambuCloud:
|
||||||
|
|
||||||
def __init__(self, region: str, email: str, username: str, auth_token: str):
|
def __init__(self, region: str, email: str, username: str, auth_token: str):
|
||||||
self._region = region
|
self._region = region
|
||||||
self._email = email
|
self._email = email
|
||||||
@ -23,7 +23,7 @@ class BambuCloud:
|
|||||||
url = 'https://api.bambulab.cn/v1/user-service/user/login'
|
url = 'https://api.bambulab.cn/v1/user-service/user/login'
|
||||||
else:
|
else:
|
||||||
url = 'https://api.bambulab.com/v1/user-service/user/login'
|
url = 'https://api.bambulab.com/v1/user-service/user/login'
|
||||||
headers = {'User-Agent' : "HA Bambulab"}
|
headers = {'User-Agent' : "OctoPrint Plugin"}
|
||||||
data = {'account': self._email, 'password': self._password}
|
data = {'account': self._email, 'password': self._password}
|
||||||
with httpx.Client(http2=True) as client:
|
with httpx.Client(http2=True) as client:
|
||||||
response = client.post(url, headers=headers, json=data, timeout=10)
|
response = client.post(url, headers=headers, json=data, timeout=10)
|
||||||
@ -40,7 +40,7 @@ class BambuCloud:
|
|||||||
jsonAuthToken = json.loads(base64.b64decode(b64_string))
|
jsonAuthToken = json.loads(base64.b64decode(b64_string))
|
||||||
# Gives json payload with "username":"u_<digits>" within it
|
# Gives json payload with "username":"u_<digits>" within it
|
||||||
return jsonAuthToken['username']
|
return jsonAuthToken['username']
|
||||||
|
|
||||||
# Retrieves json description of devices in the form:
|
# Retrieves json description of devices in the form:
|
||||||
# {
|
# {
|
||||||
# 'message': 'success',
|
# 'message': 'success',
|
||||||
@ -79,7 +79,7 @@ class BambuCloud:
|
|||||||
# }
|
# }
|
||||||
# ]
|
# ]
|
||||||
# }
|
# }
|
||||||
|
|
||||||
def test_authentication(self, region: str, email: str, username: str, auth_token: str) -> bool:
|
def test_authentication(self, region: str, email: str, username: str, auth_token: str) -> bool:
|
||||||
self._region = region
|
self._region = region
|
||||||
self._email = email
|
self._email = email
|
||||||
@ -105,7 +105,7 @@ class BambuCloud:
|
|||||||
url = 'https://api.bambulab.cn/v1/iot-service/api/user/bind'
|
url = 'https://api.bambulab.cn/v1/iot-service/api/user/bind'
|
||||||
else:
|
else:
|
||||||
url = 'https://api.bambulab.com/v1/iot-service/api/user/bind'
|
url = 'https://api.bambulab.com/v1/iot-service/api/user/bind'
|
||||||
headers = {'Authorization': 'Bearer ' + self._auth_token, 'User-Agent' : "HA Bambulab"}
|
headers = {'Authorization': 'Bearer ' + self._auth_token, 'User-Agent' : "OctoPrint Plugin"}
|
||||||
with httpx.Client(http2=True) as client:
|
with httpx.Client(http2=True) as client:
|
||||||
response = client.get(url, headers=headers, timeout=10)
|
response = client.get(url, headers=headers, timeout=10)
|
||||||
if response.status_code >= 400:
|
if response.status_code >= 400:
|
||||||
@ -186,14 +186,14 @@ class BambuCloud:
|
|||||||
url = 'https://api.bambulab.cn/v1/iot-service/api/slicer/setting?version=undefined'
|
url = 'https://api.bambulab.cn/v1/iot-service/api/slicer/setting?version=undefined'
|
||||||
else:
|
else:
|
||||||
url = 'https://api.bambulab.com/v1/iot-service/api/slicer/setting?version=undefined'
|
url = 'https://api.bambulab.com/v1/iot-service/api/slicer/setting?version=undefined'
|
||||||
headers = {'Authorization': 'Bearer ' + self._auth_token, 'User-Agent' : "HA Bambulab"}
|
headers = {'Authorization': 'Bearer ' + self._auth_token, 'User-Agent' : "OctoPrint Plugin"}
|
||||||
with httpx.Client(http2=True) as client:
|
with httpx.Client(http2=True) as client:
|
||||||
response = client.get(url, headers=headers, timeout=10)
|
response = client.get(url, headers=headers, timeout=10)
|
||||||
if response.status_code >= 400:
|
if response.status_code >= 400:
|
||||||
LOGGER.error(f"Slicer settings load failed: {response.status_code}")
|
LOGGER.error(f"Slicer settings load failed: {response.status_code}")
|
||||||
return None
|
return None
|
||||||
return response.json()
|
return response.json()
|
||||||
|
|
||||||
# The task list is of the following form with a 'hits' array with typical 20 entries.
|
# The task list is of the following form with a 'hits' array with typical 20 entries.
|
||||||
#
|
#
|
||||||
# "total": 531,
|
# "total": 531,
|
||||||
@ -241,14 +241,14 @@ class BambuCloud:
|
|||||||
url = 'https://api.bambulab.cn/v1/user-service/my/tasks'
|
url = 'https://api.bambulab.cn/v1/user-service/my/tasks'
|
||||||
else:
|
else:
|
||||||
url = 'https://api.bambulab.com/v1/user-service/my/tasks'
|
url = 'https://api.bambulab.com/v1/user-service/my/tasks'
|
||||||
headers = {'Authorization': 'Bearer ' + self._auth_token, 'User-Agent' : "HA Bambulab"}
|
headers = {'Authorization': 'Bearer ' + self._auth_token, 'User-Agent' : "OctoPrint Plugin"}
|
||||||
with httpx.Client(http2=True) as client:
|
with httpx.Client(http2=True) as client:
|
||||||
response = client.get(url, headers=headers, timeout=10)
|
response = client.get(url, headers=headers, timeout=10)
|
||||||
if response.status_code >= 400:
|
if response.status_code >= 400:
|
||||||
LOGGER.debug(f"Received error: {response.status_code}")
|
LOGGER.debug(f"Received error: {response.status_code}")
|
||||||
raise ValueError(response.status_code)
|
raise ValueError(response.status_code)
|
||||||
return response.json()
|
return response.json()
|
||||||
|
|
||||||
def get_latest_task_for_printer(self, deviceId: str) -> dict:
|
def get_latest_task_for_printer(self, deviceId: str) -> dict:
|
||||||
LOGGER.debug(f"Getting latest task from Bambu Cloud for Printer: {deviceId}")
|
LOGGER.debug(f"Getting latest task from Bambu Cloud for Printer: {deviceId}")
|
||||||
data = self.get_tasklist_for_printer(deviceId)
|
data = self.get_tasklist_for_printer(deviceId)
|
||||||
@ -283,11 +283,11 @@ class BambuCloud:
|
|||||||
@property
|
@property
|
||||||
def username(self):
|
def username(self):
|
||||||
return self._username
|
return self._username
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def auth_token(self):
|
def auth_token(self):
|
||||||
return self._auth_token
|
return self._auth_token
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def cloud_mqtt_host(self):
|
def cloud_mqtt_host(self):
|
||||||
return "cn.mqtt.bambulab.com" if self._region == "China" else "us.mqtt.bambulab.com"
|
return "cn.mqtt.bambulab.com" if self._region == "China" else "us.mqtt.bambulab.com"
|
||||||
|
@ -25,7 +25,7 @@ class IdleState(APrinterState):
|
|||||||
filesystem_root = (
|
filesystem_root = (
|
||||||
"file:///mnt/sdcard/"
|
"file:///mnt/sdcard/"
|
||||||
if self._printer._settings.get(["device_type"]) in ["X1", "X1C"]
|
if self._printer._settings.get(["device_type"]) in ["X1", "X1C"]
|
||||||
else "file:///"
|
else "file:///sdcard/"
|
||||||
)
|
)
|
||||||
|
|
||||||
print_command = {
|
print_command = {
|
||||||
|
2
setup.py
2
setup.py
@ -14,7 +14,7 @@ plugin_package = "octoprint_bambu_printer"
|
|||||||
plugin_name = "OctoPrint-BambuPrinter"
|
plugin_name = "OctoPrint-BambuPrinter"
|
||||||
|
|
||||||
# The plugin's version. Can be overwritten within OctoPrint's internal data via __plugin_version__ in the plugin module
|
# The plugin's version. Can be overwritten within OctoPrint's internal data via __plugin_version__ in the plugin module
|
||||||
plugin_version = "0.1.8rc3"
|
plugin_version = "0.1.8rc6"
|
||||||
|
|
||||||
# The plugin's description. Can be overwritten within OctoPrint's internal data via __plugin_description__ in the plugin
|
# The plugin's description. Can be overwritten within OctoPrint's internal data via __plugin_description__ in the plugin
|
||||||
# module
|
# module
|
||||||
|
Reference in New Issue
Block a user