Skip to content

Commit

Permalink
Merge pull request #581 from greghesp/develop
Browse files Browse the repository at this point in the history
Merge Develop -> Main
  • Loading branch information
AdrianGarside authored Aug 22, 2024
2 parents 440c413 + 64bac27 commit ef42cad
Show file tree
Hide file tree
Showing 4 changed files with 724 additions and 18 deletions.
11 changes: 6 additions & 5 deletions custom_components/bambu_lab/coordinator.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,8 @@ def event_handler(self, event):
self._eventloop.call_soon_threadsafe(self.event_handler_internal, event)

def event_handler_internal(self, event):
LOGGER.debug(f"EVENT: {event}")
if event != "event_printer_chamber_image_update":
LOGGER.debug(f"EVENT: {event}")
if event == "event_printer_info_update":
self._update_device_info()
if self.get_model().supports_feature(Features.EXTERNAL_SPOOL):
Expand Down Expand Up @@ -197,10 +198,10 @@ def _update_print_error(self):
"device_id": hadevice.id,
"type": "event_printer_error",
}
if 'Code' in device.print_error.errors:
event_data["Code"] = device.print_error.errors['Code']
if 'Error' in device.print_error.errors:
event_data["Error"] = device.print_error.errors['Error']
if 'Code' in device.print_error.error:
event_data["Code"] = device.print_error.error['Code']
if 'Error' in device.print_error.error:
event_data["Error"] = device.print_error.error['Error']
LOGGER.debug(f"EVENT: print_error: {event_data}")
self._hass.bus.async_fire(f"{DOMAIN}_event", event_data)

Expand Down
25 changes: 12 additions & 13 deletions custom_components/bambu_lab/pybambu/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -443,7 +443,7 @@ def print_update(self, data) -> bool:
if previous_gcode_state != self.gcode_state:
LOGGER.debug(f"GCODE_STATE: {previous_gcode_state} -> {self.gcode_state}")
if self.gcode_state.lower() not in GCODE_STATE_OPTIONS:
LOGGER.debug(f"Unknown gcode_state. Please log an issue : '{self.gcode_state}'")
LOGGER.error(f"Unknown gcode_state. Please log an issue : '{self.gcode_state}'")
self.gcode_state = "unknown"
if previous_gcode_state != self.gcode_state:
LOGGER.debug(f"GCODE_STATE: {previous_gcode_state} -> {self.gcode_state}")
Expand Down Expand Up @@ -1207,12 +1207,10 @@ def print_update(self, data) -> bool:
if print_error_code != 0:
hex_conversion = f'0{int(print_error_code):x}'
print_error_code_hex = hex_conversion[slice(0,4,1)] + "_" + hex_conversion[slice(4,8,1)]
errors = {}
errors[f"Code"] = f"{print_error_code_hex.upper()}"
errors[f"Error"] = f"{print_error_code_hex.upper()}: {get_print_error_text(print_error_code.upper())}"
self._error = errors
errors[f"Error"] = f"{print_error_code_hex.upper()}: {get_print_error_text(print_error_code)}"
# LOGGER.warning(f"PRINT ERRORS: {errors}") # This will emit a message to home assistant log every 1 second if enabled
else:
self._error = None

if self._error != errors:
self._error = errors
Expand All @@ -1228,7 +1226,7 @@ def error(self) -> dict:

@property
def on(self) -> int:
return self._error != None
return self._error is not None


@dataclass
Expand Down Expand Up @@ -1420,13 +1418,14 @@ def __init__(self, client):

def _load_custom_filaments(self, slicer_settings: dict):
self.custom_filaments = {}
for filament in slicer_settings['filament']['private']:
name = filament["name"]
if " @" in name:
name = name[:name.index(" @")]
if filament.get("filament_id", "") != "":
self.custom_filaments[filament["filament_id"]] = name
LOGGER.debug("Got custom filaments: %s", self.custom_filaments)
if 'private' in slicer_settings["filament"]:
for filament in slicer_settings['filament']['private']:
name = filament["name"]
if " @" in name:
name = name[:name.index(" @")]
if filament.get("filament_id", "") != "":
self.custom_filaments[filament["filament_id"]] = name
LOGGER.debug("Got custom filaments: %s", self.custom_filaments)

def update(self):
LOGGER.debug("Loading slicer settings")
Expand Down
Loading

0 comments on commit ef42cad

Please sign in to comment.