Skip to content

Instantly share code, notes, and snippets.

@cjavad
Created January 23, 2025 11:17
Show Gist options
  • Select an option

  • Save cjavad/9db1cf14d1b8e44443c30d86827cbb4c to your computer and use it in GitHub Desktop.

Select an option

Save cjavad/9db1cf14d1b8e44443c30d86827cbb4c to your computer and use it in GitHub Desktop.
Migration guide for Meltingplot/duet-simplyprint-connector/

Migration guide

Based on https://github.com/Meltingplot/duet-simplyprint-connector/blob/main/meltingplot/duet_simplyprint_connector/virtual_client.py.

Usage changes

  • ClientApp has been overhauled majorly, now takes a ClientSettings instead of a ClientOptions
  • ClientApp load/unload removed in favor of add / remove (still sync).

Client class changes

  • Decorators for functions are now optional, we can extract the event name from the function name in the format on_{event_name}.
  • Argument for functions are now optional, we check the type of the argument to also derrive the event, and if nothing is specified no args will be used to call it.

For example:

from simplyprint_ws_client.client.protocol import Demands

@Demands.FileEvent.on
async def on_file(self, event: Demands.FileEvent) -> None:
    """Download a file from Simplyprint.io to the printer."""
    await self._download_file_from_sp_and_upload_to_duet(event=event)

Becomes, the function name can here be anything as we can infer the event type from FileDemandData, the class has the same fields as the old message:

from simplyprint_ws_client.core.ws_protocol.messages import *

async def on_file(self, event: FileDemandData) -> None:
    """Download a file from Simplyprint.io to the printer."""
    await self._download_file_from_sp_and_upload_to_duet(event=event)
    
# Example with no reference to the class
async def on_start_print(self) -> None:
    print("Start pending print!")
  • Client lifetime methods init, tick and stop have been changed to init, tick(timedelta), halt and teardown.
    • init is now called

Namespace / import changes

  • FileProgressState -> FileProgressStateEnum / This is a breaking change as FileProgressState is now the class, and the enum has another name

Now we support importing * with no namespace polution (__all__ is defined)

  • from simplyprint_ws_client.client.state.printer import FileProgressState, PrinterFilamentSensorEnum, PrinterStatus -> from simplyprint_ws_client.core.state import *

from simplyprint_ws_client.client.config -> from simplyprint_ws_client.core.config from simplyprint_ws_client.helpers.intervals -> from simplyprint_ws_client.core.state

Helpers moved into shared module

from simplyprint_ws_client.helpers.file_download -> from simplyprint_ws_client.shared.files.file_download from simplyprint_ws_client.helpers.physical_machine -> from simplyprint_ws_client.shared.hardware.physical_machine

  • ClientApp, ClientSettings now in core.
  • ClientCli in shared.cli.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment