Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Minor cleanup #560

Merged
merged 2 commits into from
Jul 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion custom_components/bambu_lab/coordinator.py
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ def _update_print_error(self):
"device_id": hadevice.id,
"type": "event_printer_error_cleared",
}
LOGGER.debug(f"EVENT: print_error cleared: {event_data}")
#LOGGER.debug(f"EVENT: print_error cleared: {event_data}")
if 'Code' in device.print_error.errors:
event_data["Code"] = device.print_error.errors['Code']
else:
Expand Down
2 changes: 1 addition & 1 deletion custom_components/bambu_lab/definitions.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ class BambuLabBinarySensorEntityDescription(BinarySensorEntityDescription, Bambu
device_class=BinarySensorDeviceClass.PROBLEM,
entity_category=EntityCategory.DIAGNOSTIC,
is_on_fn=lambda self: self.coordinator.get_model().print_error.on != 0,
extra_attributes=lambda self: self.coordinator.get_model().print_error.errors
extra_attributes=lambda self: self.coordinator.get_model().print_error.error
),
BambuLabBinarySensorEntityDescription(
key="online",
Expand Down
29 changes: 13 additions & 16 deletions custom_components/bambu_lab/pybambu/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -1187,13 +1187,12 @@ def error_count(self) -> int:
@dataclass
class PrintErrorList:
"""Return all print_error related info"""
_errors: dict
_error: dict
_count: int

def __init__(self, client):
self._client = client
self._errors = {}
self._count = 0
self._error = None

def print_update(self, data) -> bool:
# Example payload:
Expand All @@ -1203,35 +1202,33 @@ def print_update(self, data) -> bool:
# 'Unable to feed filament into the extruder. This could be due to entangled filament or a stuck spool. If not, please check if the AMS PTFE tube is connected.'

if 'print_error' in data.keys():
errors = {}
errors = None
print_error_code = data.get('print_error')
if print_error_code != 0:
self._count = 1
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[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._errors = errors
self._error = errors
# LOGGER.warning(f"PRINT ERRORS: {errors}") # This will emit a message to home assistant log every 1 second if enabled
if self._client.callback is not None:
self._client.callback("event_print_error")
return True
else:
self._errors = errors
self._count = 0
self._error = None

if self._error != errors:
self._error = errors
if self._client.callback is not None:
self._client.callback("event_print_error")
return True


# We send the error event directly so always return False for the general data event.
return False

@property
def errors(self) -> dict:
return self._errors
def error(self) -> dict:
return self._error

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


@dataclass
Expand Down
Loading