Compare commits

...

2 Commits

Author SHA1 Message Date
76f706df19 0.1.8rc9
* check for filename in cache subfolder for files started through cloud connected printers
* send 0% progress when in prepare state and progress is 100
* minor UI tweaks
2024-11-09 21:57:17 -05:00
5c8a9787d4 0.1.8rc8
* updates to pybambu module
* update cloud login workflow, #59
2024-11-09 20:01:41 -05:00
9 changed files with 117 additions and 44 deletions

View File

@ -61,6 +61,7 @@ class BambuPrintPlugin(
_plugin_manager: octoprint.plugin.PluginManager _plugin_manager: octoprint.plugin.PluginManager
_bambu_file_system: RemoteSDCardFileList _bambu_file_system: RemoteSDCardFileList
_timelapse_files_view: CachedFileView _timelapse_files_view: CachedFileView
_bambu_cloud: None
def on_settings_initialized(self): def on_settings_initialized(self):
self._bambu_file_system = RemoteSDCardFileList(self._settings) self._bambu_file_system = RemoteSDCardFileList(self._settings)
@ -117,7 +118,8 @@ class BambuPrintPlugin(
return True return True
def get_api_commands(self): def get_api_commands(self):
return {"register": ["email", "password", "region", "auth_token"]} return {"register": ["email", "password", "region", "auth_token"],
"verify": ["auth_type", "password"]}
def on_api_command(self, command, data): def on_api_command(self, command, data):
if command == "register": if command == "register":
@ -128,14 +130,42 @@ class BambuPrintPlugin(
and "auth_token" in data and "auth_token" in data
): ):
self._logger.info(f"Registering user {data['email']}") self._logger.info(f"Registering user {data['email']}")
bambu_cloud = BambuCloud( self._bambu_cloud = BambuCloud(
data["region"], data["email"], data["password"], data["auth_token"] data["region"], data["email"], data["password"], data["auth_token"]
) )
bambu_cloud.login(data["region"], data["email"], data["password"]) auth_response = self._bambu_cloud.login(data["region"], data["email"], data["password"])
return flask.jsonify( return flask.jsonify(
{ {
"auth_token": bambu_cloud.auth_token, "auth_response": auth_response,
"username": bambu_cloud.username, }
)
elif command == "verify":
auth_response = None
if (
"auth_type" in data
and "password" in data
and self._bambu_cloud is not None
):
self._logger.info(f"Verifying user {self._bambu_cloud._email}")
if data["auth_type"] == "verifyCode":
auth_response = self._bambu_cloud.login_with_verification_code(data["password"])
elif data["auth_type"] == "tfa":
auth_response = self._bambu_cloud.login_with_2fa_code(data["password"])
else:
self._logger.warning(f"Unknown verification type: {data['auth_type']}")
if auth_response == "success":
return flask.jsonify(
{
"auth_token": self._bambu_cloud.auth_token,
"username": self._bambu_cloud.username
}
)
else:
self._logger.info(f"Error verifying: {auth_response}")
return flask.jsonify(
{
"error": "Unable to verify"
} }
) )

View File

@ -286,7 +286,7 @@ class BambuVirtualPrinter:
local_mqtt=self._settings.get_boolean(["local_mqtt"]), local_mqtt=self._settings.get_boolean(["local_mqtt"]),
region=self._settings.get(["region"]), region=self._settings.get(["region"]),
email=self._settings.get(["email"]), email=self._settings.get(["email"]),
auth_token=self._settings.get(["auth_token"]), auth_token=self._settings.get(["auth_token"]) if self._settings.get_boolean(["local_mqtt"]) is False else "",
) )
bambu_client.on_disconnect = self.on_disconnect(bambu_client.on_disconnect) bambu_client.on_disconnect = self.on_disconnect(bambu_client.on_disconnect)
bambu_client.on_connect = self.on_connect(bambu_client.on_connect) bambu_client.on_connect = self.on_connect(bambu_client.on_connect)

View File

@ -86,6 +86,10 @@ class CachedFileView:
file_name = f"{file_name}.3mf" file_name = f"{file_name}.3mf"
elif f"{file_name}.gcode.3mf" in file_list: elif f"{file_name}.gcode.3mf" in file_list:
file_name = f"{file_name}.gcode.3mf" file_name = f"{file_name}.gcode.3mf"
elif f"cache/{file_name}.3mf" in file_list:
file_name = f"cache/{file_name}.3mf"
elif f"cache/{file_name}.gcode.3mf" in file_list:
file_name = f"cache/{file_name}.gcode.3mf"
file_data = self.get_file_data_cached(file_name) file_data = self.get_file_data_cached(file_name)
if file_data is None: if file_data is None:

View File

@ -237,7 +237,7 @@ class MqttThread(threading.Thread):
exceptionSeen = "" exceptionSeen = ""
while True: while True:
try: try:
host = self._client.host if self._client._local_mqtt else self._client.bambu_cloud.cloud_mqtt_host host = self._client.host if self._client.local_mqtt else self._client.bambu_cloud.cloud_mqtt_host
LOGGER.debug(f"Connect: Attempting Connection to {host}") LOGGER.debug(f"Connect: Attempting Connection to {host}")
self._client.client.connect(host, self._client._port, keepalive=5) self._client.client.connect(host, self._client._port, keepalive=5)
@ -289,7 +289,7 @@ class BambuClient:
username: str, auth_token: str, access_code: str, usage_hours: float = 0, manual_refresh_mode: bool = False, chamber_image: bool = True): username: str, auth_token: str, access_code: str, usage_hours: float = 0, manual_refresh_mode: bool = False, chamber_image: bool = True):
self.callback = None self.callback = None
self.host = host self.host = host
self._local_mqtt = local_mqtt self.local_mqtt = local_mqtt
self._serial = serial self._serial = serial
self._auth_token = auth_token self._auth_token = auth_token
self._access_code = access_code self._access_code = access_code
@ -342,7 +342,7 @@ class BambuClient:
self.setup_tls() self.setup_tls()
self._port = 8883 self._port = 8883
if self._local_mqtt: if self.local_mqtt:
self.client.username_pw_set("bblp", password=self._access_code) self.client.username_pw_set("bblp", password=self._access_code)
else: else:
self.client.username_pw_set(self._username, password=self._auth_token) self.client.username_pw_set(self._username, password=self._auth_token)
@ -532,7 +532,7 @@ class BambuClient:
loop = asyncio.get_event_loop() loop = asyncio.get_event_loop()
await loop.run_in_executor(None, self.setup_tls) await loop.run_in_executor(None, self.setup_tls)
if self._local_mqtt: if self.local_mqtt:
self.client.username_pw_set("bblp", password=self._access_code) self.client.username_pw_set("bblp", password=self._access_code)
else: else:
self.client.username_pw_set(self._username, password=self._auth_token) self.client.username_pw_set(self._username, password=self._auth_token)

View File

@ -666,7 +666,7 @@ class Info:
self.sw_ver = "unknown" self.sw_ver = "unknown"
self.online = False self.online = False
self.new_version_state = 0 self.new_version_state = 0
self.mqtt_mode = "local" if self._client._local_mqtt else "bambu_cloud" self.mqtt_mode = "local" if self._client.local_mqtt else "bambu_cloud"
self.nozzle_diameter = 0 self.nozzle_diameter = 0
self.nozzle_type = "unknown" self.nozzle_type = "unknown"
self.usage_hours = client._usage_hours self.usage_hours = client._usage_hours
@ -1449,7 +1449,7 @@ class SlicerSettings:
def update(self): def update(self):
self.custom_filaments = {} self.custom_filaments = {}
if self._client.bambu_cloud.auth_token != "": if self._client.bambu_cloud.auth_token != "" and self._client.local_mqtt is False:
LOGGER.debug("Loading slicer settings") LOGGER.debug("Loading slicer settings")
slicer_settings = self._client.bambu_cloud.get_slicer_settings() slicer_settings = self._client.bambu_cloud.get_slicer_settings()
if slicer_settings is not None: if slicer_settings is not None:

View File

@ -81,6 +81,8 @@ class PrintingState(APrinterState):
return return
progress = print_job_info.print_percentage progress = print_job_info.print_percentage
if print_job_info.gcode_state == "PREPARE" and progress == 100:
progress = 0
self._printer.current_print_job = PrintJob(project_file_info, progress, print_job_info.remaining_time, print_job_info.current_layer, print_job_info.total_layers) self._printer.current_print_job = PrintJob(project_file_info, progress, print_job_info.remaining_time, print_job_info.current_layer, print_job_info.total_layers)
self._printer.select_project_file(project_file_info.path.as_posix()) self._printer.select_project_file(project_file_info.path.as_posix())

View File

@ -20,6 +20,16 @@ $(function () {
self.job_info = ko.observable(); self.job_info = ko.observable();
self.auth_type = ko.observable("");
self.show_password = ko.pureComputed(function(){
return self.settingsViewModel.settings.plugins.bambu_printer.auth_token() === '';
});
self.show_verification = ko.pureComputed(function(){
return self.auth_type() !== '';
});
self.ams_mapping_computed = function(){ self.ams_mapping_computed = function(){
var output_list = []; var output_list = [];
var index = 0; var index = 0;
@ -40,16 +50,34 @@ $(function () {
self.getAuthToken = function (data) { self.getAuthToken = function (data) {
self.settingsViewModel.settings.plugins.bambu_printer.auth_token(""); self.settingsViewModel.settings.plugins.bambu_printer.auth_token("");
self.auth_type("");
OctoPrint.simpleApiCommand("bambu_printer", "register", { OctoPrint.simpleApiCommand("bambu_printer", "register", {
"email": self.settingsViewModel.settings.plugins.bambu_printer.email(), "email": self.settingsViewModel.settings.plugins.bambu_printer.email(),
"password": $("#bambu_cloud_password").val(), "password": $("#bambu_cloud_password").val(),
"region": self.settingsViewModel.settings.plugins.bambu_printer.region(), "region": self.settingsViewModel.settings.plugins.bambu_printer.region(),
"auth_token": self.settingsViewModel.settings.plugins.bambu_printer.auth_token() "auth_token": self.settingsViewModel.settings.plugins.bambu_printer.auth_token()
})
.done(function (response) {
self.auth_type(response.auth_response);
});
};
self.verifyCode = function (data) {
self.settingsViewModel.settings.plugins.bambu_printer.auth_token("");
OctoPrint.simpleApiCommand("bambu_printer", "verify", {
"password": $("#bambu_cloud_verify_code").val(),
"auth_type": self.auth_type(),
}) })
.done(function (response) { .done(function (response) {
console.log(response); console.log(response);
if (response.auth_token) {
self.settingsViewModel.settings.plugins.bambu_printer.auth_token(response.auth_token); self.settingsViewModel.settings.plugins.bambu_printer.auth_token(response.auth_token);
self.settingsViewModel.settings.plugins.bambu_printer.username(response.username); self.settingsViewModel.settings.plugins.bambu_printer.username(response.username);
self.auth_type("");
} else if (response.error) {
self.settingsViewModel.settings.plugins.bambu_printer.auth_token("");
$("#bambu_cloud_verify_code").val("");
}
}); });
}; };

View File

@ -40,15 +40,24 @@
<div class="control-group" data-bind="visible: !settingsViewModel.settings.plugins.bambu_printer.local_mqtt()"> <div class="control-group" data-bind="visible: !settingsViewModel.settings.plugins.bambu_printer.local_mqtt()">
<label class="control-label">{{ _('Email') }}</label> <label class="control-label">{{ _('Email') }}</label>
<div class="controls"> <div class="controls">
<input type="text" class="input-block-level" data-bind="value: settingsViewModel.settings.plugins.bambu_printer.email" title="{{ _('Registered email address') }}"></input> <input type="text" class="input-block-level" data-bind="value: settingsViewModel.settings.plugins.bambu_printer.email" title="{{ _('Registered email address') }}" autocomplete="off"></input>
</div> </div>
</div> </div>
<div class="control-group" data-bind="visible: !settingsViewModel.settings.plugins.bambu_printer.local_mqtt()"> <div class="control-group" data-bind="visible: !settingsViewModel.settings.plugins.bambu_printer.local_mqtt() && show_password()">
<label class="control-label">{{ _('Password') }}</label> <label class="control-label">{{ _('Password') }}</label>
<div class="controls"> <div class="controls">
<div class="input-block-level input-append" data-bind="css: {'input-append': !show_verification()}">
<input id="bambu_cloud_password" type="password" class="input-text input-block-level" title="{{ _('Password to generate verification code') }}" autocomplete="new-password"></input>
<span class="btn btn-primary add-on" data-bind="visible: !show_verification(), click: getAuthToken">{{ _('Login') }}</span>
</div>
</div>
</div>
<div class="control-group" data-bind="visible: show_verification()">
<label class="control-label">{{ _('Verify') }}</label>
<div class="controls">
<div class="input-block-level input-append"> <div class="input-block-level input-append">
<input id="bambu_cloud_password" type="password" class="input-text input-block-level" title="{{ _('Password to generate Auth Token') }}"></input> <input id="bambu_cloud_verify_code" type="password" class="input-text input-block-level" title="{{ _('Verification code to generate auth token') }}"></input>
<span class="btn btn-primary add-on" data-bind="click: getAuthToken">{{ _('Login') }}</span> <span class="btn btn-primary add-on" data-bind="click: verifyCode">{{ _('Verify') }}</span>
</div> </div>
</div> </div>
</div> </div>

View File

@ -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.8rc7" plugin_version = "0.1.8rc9"
# 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