Skip to content

Commit

Permalink
Merge PR #15 - v0.0.13 changes
Browse files Browse the repository at this point in the history
v0.0.13 - Bug fixes for multiple printers, Home Assistant 2023.8, Resin printers
  • Loading branch information
WaresWichall authored Aug 25, 2024
2 parents 068c738 + fa75815 commit 314be17
Show file tree
Hide file tree
Showing 28 changed files with 2,313 additions and 1,546 deletions.
11 changes: 9 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,16 @@

## WORK IN PROGRESS

Component is working very well so far with Kobra 3 Combos and Kobra 2s but will still have bugs that I'll need help ironing out.
Component is working very well so far with:
- Kobra 3 Combo
- Kobra 2
- Photon Mono M5s (Basic support still)

Should also work with multiple printers but untested until someone buys me a second printer :)
If you have success with other printers please report it :)

It will still have bugs that I'll need help ironing out.

Should also work with multiple printers now, although I can't test this myself :)

## Gallery

Expand Down
1 change: 1 addition & 0 deletions Version
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@ Version: 0.0.9 20240807 - Minor bug fixes
Version: 0.0.10 20240811 - Bug fix for config flow, add more frontend buttons / option modals
Version: 0.0.11 20240813 - Frontend improvements to panel print pages, data refactor, work on Resin printer bugs
Version: 0.0.12 20240816 - Minor bug fix in MQTT reconnect, untested support for multiple ACE units, frontend refactoring
Version: 0.0.13 20240825 - Bug fixes for multiple printers, HomeAssistant 2024.8 and Resin printers
Original file line number Diff line number Diff line change
Expand Up @@ -2013,16 +2013,30 @@ async def list_all_projects(
data = list([AnycubicProject.from_list_json(self, x) for x in resp['data']])
return data

async def project_info_for_id(self, project_id):
async def project_info_for_id(
self,
project_id,
):
query = {
'id': str(project_id)
}
resp = await self._fetch_api_resp(endpoint=API_ENDPOINT.project_info, query=query)
return resp['data']

async def get_latest_project(self):
async def get_latest_project(
self,
printer_id=None,
):
projects = await self.list_all_projects()
latest_project = projects[0] if projects and len(projects) > 0 else None

latest_project = None

if projects and len(projects) > 0:
for proj in projects:
if printer_id is None or proj.printer_id == printer_id:
latest_project = proj
break

if latest_project:
extra_proj_data = await self.project_info_for_id(latest_project.id)
latest_project.update_extra_data(extra_proj_data)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ def __init__(
self,
*args,
mqtt_callback_printer_update=None,
mqtt_callback_printer_busy=None,
**kwargs,
):
self._api_username = None
Expand All @@ -53,6 +54,7 @@ def __init__(
self._mqtt_connected: asyncio.Event | None = None
self._mqtt_disconnected: asyncio.Event | None = None
self._mqtt_callback_printer_update = mqtt_callback_printer_update
self._mqtt_callback_printer_busy = mqtt_callback_printer_busy
super().__init__(*args, **kwargs)

@property
Expand Down Expand Up @@ -144,11 +146,20 @@ def _mqtt_message_router(self, message):

printer = self._mqtt_subscribed_printers[printer_key]

printer_was_available = printer.is_available

try:
printer.process_mqtt_update(topic, payload)

if self._mqtt_callback_printer_update:
self._mqtt_callback_printer_update()

if (
self._mqtt_callback_printer_busy and
printer_was_available and printer.is_busy
):
self._mqtt_callback_printer_busy()

except Exception as e:
tb = traceback.format_exc()
self._log_to_error(f"Anycubic MQTT Message error: {e}\n on MQTT topic: {topic}\n {payload}\n{tb}")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -303,8 +303,8 @@ def __init__(
is_dir,
):
self._filename = str(filename)
self._timestamp = int(timestamp)
self._size = int(size)
self._timestamp = int(timestamp) if timestamp is not None else 0
self._size = int(size) if size is not None else 0
self._is_dir = bool(is_dir)

@classmethod
Expand All @@ -314,8 +314,8 @@ def from_json(cls, data):

return cls(
filename=data['filename'],
timestamp=data['timestamp'],
size=data['size'],
timestamp=data.get('timestamp'),
size=data.get('size'),
is_dir=data['is_dir'],
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@

from .anycubic_enums import (
AnycubicFunctionID,
AnycubicPrinterMaterialType,
AnycubicPrintStatus,
)

Expand Down Expand Up @@ -112,7 +113,7 @@ def __init__(
self._last_update_time = last_update_time
self._set_machine_data(machine_data)
self._set_type_function_ids(type_function_ids)
self._material_type = material_type
self._set_material_type(material_type)
self._set_parameter(parameter)
self._set_fw_version(fw_version)
self._available = available
Expand Down Expand Up @@ -151,6 +152,17 @@ def _set_type_function_ids(self, type_function_ids):
else:
self._type_function_ids = list()

def _set_material_type(self, material_type):
if material_type and isinstance(material_type, str):
try:
self._material_type = AnycubicPrinterMaterialType(material_type.title())

except ValueError:
self._material_type = material_type

else:
self._material_type = None

def _set_local_file_list(self, file_list):
if file_list is None:
return
Expand Down Expand Up @@ -413,7 +425,7 @@ def update_from_info_json(self, data):
self._create_time = extra_data.get('create_time')
self._set_machine_data(data.get('machine_data'))
self._set_type_function_ids(data['type_function_ids'])
self._material_type = extra_data.get('material_type')
self._set_material_type(extra_data.get('material_type'))
self._set_parameter(data.get('parameter'))
self._update_fw_version_from_json(data['version'])
self._set_tools(data.get('tools'))
Expand Down Expand Up @@ -1600,6 +1612,69 @@ def latest_project_available_print_speed_modes_data_object(self):

return None

@property
def latest_project_print_model_height(self):
if self.latest_project:
return self.latest_project.print_model_height

return None

@property
def latest_project_print_anti_alias_count(self):
if self.latest_project:
return self.latest_project.print_anti_alias_count

return None

@property
def latest_project_print_on_time(self):
if self.latest_project:
return self.latest_project.print_on_time

return None

@property
def latest_project_print_off_time(self):
if self.latest_project:
return self.latest_project.print_off_time

return None

@property
def latest_project_print_bottom_time(self):
if self.latest_project:
return self.latest_project.print_bottom_time

return None

@property
def latest_project_print_bottom_layers(self):
if self.latest_project:
return self.latest_project.print_bottom_layers

return None

@property
def latest_project_print_z_up_height(self):
if self.latest_project:
return self.latest_project.print_z_up_height

return None

@property
def latest_project_print_z_up_speed(self):
if self.latest_project:
return self.latest_project.print_z_up_speed

return None

@property
def latest_project_print_z_down_speed(self):
if self.latest_project:
return self.latest_project.print_z_down_speed

return None

@property
def curr_nozzle_temp(self):
if self.parameter:
Expand Down Expand Up @@ -1646,7 +1721,7 @@ async def update_info_from_api(self, with_project=True):
await self._api_parent.printer_info_for_id(self._id, self)

if with_project:
self._latest_project = await self._api_parent.get_latest_project()
self._latest_project = await self._api_parent.get_latest_project(self.id)

async def request_local_file_list(
self,
Expand Down
Loading

0 comments on commit 314be17

Please sign in to comment.