Compare commits

...

3 Commits

Author SHA1 Message Date
8af0f9e8a1 add support for M355 command to control chamber light, #67 2025-01-23 23:40:45 -05:00
ca30e0fe24 fix typo, #64 2024-12-29 12:58:04 -05:00
383f0c3cb3 fix new cloud verification process 2024-12-07 00:17:57 -05:00
6 changed files with 58 additions and 24 deletions

View File

@ -130,9 +130,7 @@ 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']}")
self._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"]
)
auth_response = self._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(
{ {

View File

@ -596,6 +596,17 @@ class BambuVirtualPrinter:
self._current_state.pause_print() self._current_state.pause_print()
return True return True
@gcode_executor.register("M355")
def _case_lights(self, data: str) -> bool:
if data == "M355 S1":
light_command = commands.CHAMBER_LIGHT_ON
elif data == "M355 S0":
light_command = commands.CHAMBER_LIGHT_OFF
else:
return False
return self.bambu_client.publish(light_command)
@gcode_executor.register("M524") @gcode_executor.register("M524")
def _cancel_print(self): def _cancel_print(self):
self._current_state.cancel_print() self._current_state.cancel_print()

View File

@ -192,12 +192,14 @@ class BambuCloud:
return ValueError(0) # FIXME return ValueError(0) # FIXME
elif loginType == 'verifyCode': elif loginType == 'verifyCode':
LOGGER.debug(f"Received verifyCode response") LOGGER.debug(f"Received verifyCode response")
raise EmailCodeRequiredError() # raise EmailCodeRequiredError()
return loginType
elif loginType == 'tfa': elif loginType == 'tfa':
# Store the tfaKey for later use # Store the tfaKey for later use
LOGGER.debug(f"Received tfa response") LOGGER.debug(f"Received tfa response")
self._tfaKey = auth_json.get("tfaKey") self._tfaKey = auth_json.get("tfaKey")
raise TfaCodeRequiredError() # raise TfaCodeRequiredError()
return loginType
else: else:
LOGGER.debug(f"Did not understand json. loginType = '{loginType}'") LOGGER.debug(f"Did not understand json. loginType = '{loginType}'")
LOGGER.error(f"Response not understood: '{response.text}'") LOGGER.error(f"Response not understood: '{response.text}'")
@ -358,18 +360,31 @@ class BambuCloud:
self._password = password self._password = password
result = self._get_authentication_token() result = self._get_authentication_token()
self._auth_token = result if result is None:
self._username = self._get_username_from_authentication_token() LOGGER.error("Unable to authenticate.")
return None
elif len(result) < 20:
return result
else:
self._auth_token = result
self._username = self._get_username_from_authentication_token()
return 'success'
# self._auth_token = result
# self._username = self._get_username_from_authentication_token()
def login_with_verification_code(self, code: str): def login_with_verification_code(self, code: str):
result = self._get_authentication_token_with_verification_code(code) result = self._get_authentication_token_with_verification_code(code)
self._auth_token = result self._auth_token = result
self._username = self._get_username_from_authentication_token() self._username = self._get_username_from_authentication_token()
if self._auth_token != "" and self._username != "" and self._auth_token != None and self._username != None:
return "success"
def login_with_2fa_code(self, code: str): def login_with_2fa_code(self, code: str):
result = self._get_authentication_token_with_2fa_code(code) result = self._get_authentication_token_with_2fa_code(code)
self._auth_token = result self._auth_token = result
self._username = self._get_username_from_authentication_token() self._username = self._get_username_from_authentication_token()
if self._auth_token != "" and self._username != "" and self._auth_token != None and self._username != None:
return "success"
def get_device_list(self) -> dict: def get_device_list(self) -> dict:
LOGGER.debug("Getting device list from Bambu Cloud") LOGGER.debug("Getting device list from Bambu Cloud")

View File

@ -48,6 +48,16 @@ $(function () {
return output_list; return output_list;
}; };
self.getAdditionalControls = function() {
var buttons = [
{ name: "Bambu", type: "section", layout: "horizontal", children: [
{type: "command", name: "Light On", enabled: "true", command: "M355 S1"},
{type: "command", name: "Light Off", enabled: "true", command: "M355 S0"}
]}
];
return buttons;
};
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(""); self.auth_type("");
@ -133,7 +143,7 @@ $(function () {
}; };
self.onAfterBinding = function () { self.onAfterBinding = function () {
console.log(self.ams_mapping_computed()); // console.log(self.ams_mapping_computed());
}; };
self.showTimelapseThumbnail = function(data) { self.showTimelapseThumbnail = function(data) {

View File

@ -16,7 +16,7 @@
</div> </div>
</div> </div>
<div class="row-fluid" data-bind="visible: settingsViewModel.settings.plugins.bambu_printer.use_ams"> <div class="row-fluid" data-bind="visible: settingsViewModel.settings.plugins.bambu_printer.use_ams">
{{ _('Filament Assighnment') }}: {{ _('Click') }} <a href="#">{{ _('here') }}</a> {{ _('for usage details.') }} {{ _('Filament Assignment') }}: {{ _('Click') }} <a href="#">{{ _('here') }}</a> {{ _('for usage details.') }}
</div> </div>
<div class="row-fluid" data-bind="visible: settingsViewModel.settings.plugins.bambu_printer.use_ams, sortable: {data: ams_mapping, options: {cancel: '.unsortable'}}"> <div class="row-fluid" data-bind="visible: settingsViewModel.settings.plugins.bambu_printer.use_ams, sortable: {data: ams_mapping, options: {cancel: '.unsortable'}}">
<div class="btn" data-bind="attr: {title: name}, event: {dblclick: $root.toggle_spool_active}, css: {disabled: (index()<0)}"> <div class="btn" data-bind="attr: {title: name}, event: {dblclick: $root.toggle_spool_active}, css: {disabled: (index()<0)}">

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.8rc13" plugin_version = "0.1.8rc15"
# 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