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

Machine integration #4824

Merged
merged 105 commits into from Feb 14, 2024
Merged

Conversation

wolflu05
Copy link
Contributor

@wolflu05 wolflu05 commented May 15, 2023

This PR adds the machines feature described in #4789 .

image
image

fixes #4789


πŸ“ Todos

Edit tasklist title
Beta Give feedback Tasklist πŸ“ Todos, more options

Delete tasklist

Delete tasklist block?
Are you sure? All relationships in this tasklist will be removed.
  1. 🚚 driver errors
    Options
  2. 🚚 handle error function for machines and registry
    Options
  3. 🚚 Init driver function
    Options
  4. 🚚 Machine update hook function (only partially working)
    Options
  5. 🚚 Machine has unapplied changes (restart required)
    Options
  6. 🚚 Machine restart hook
    Options
  7. 🚚 get_machines should by default only return initialized machines
    Options
  8. 🚚 funtion to check if all required settings are defined
    Options
  9. 🚚 Machine States (Ready, Connecting, …) (waiting on Refactor states/statusΒ #4857)
    Options
  10. 🚚 export everything required from the plugin app
    Options
  11. 🚚 get all machines, can be maybe used in combination with event mixin
    Options
  12. 🚚 get_machines function for driver to return all machines belonging to that driver
    Options
  13. 🚚 separate machine type and base driver
    Options
  14. πŸ“« API GET available machine types / drivers
    Options
  15. πŸ“« API CRUD machines
    Options
  16. πŸ“« API CRUD machine settings
    Options
  17. πŸ“« API Permissions
    Options
  18. πŸ’„ PUI Settings Page
    Options
  19. πŸ’„ PUI machine list: table
    Options
  20. πŸ’„ PUI machine list: registry errors
    Options
  21. πŸ’„ PUI machine list: add machine
    Options
  22. πŸ’„ PUI machine detail: view
    Options
  23. πŸ’„ PUI machine type table with detail drawer: showing machine type info and list available drivers and Which plugin provides that type
    Options
  24. πŸ’„ PUI machine driver drawer with some info about it
    Options
  25. πŸ’„ PUI driver drawer error stack + show all machines
    Options
  26. 🎰 LABEL PRINTING machine type
    Options
  27. 🎰 LABEL PRINTING: print_label
    Options
  28. 🎰 LABEL PRINTING: print_labels
    Options
  29. 🎰 LABEL PRINTING: location setting (useful for basic location scoping)
    Options
  30. 🎰 LABEL PRINTING: get_printers (implement at driver level, useful for filtering the printers based on certain hardware aspects)
    Options
  31. 🎰 LABEL PRINTING: number of copies printing option
    Options
  32. 🎰 LABEL PRINTING: include request in get_printers kwargs
    Options
  33. 🎰 LABEL PRINTING: remember last used printer machine per user
    Options
  34. ✨ Add Machine Settings and separat from driver settings (Machine settings could be used for e.g. printer location)
    Options
  35. ✨ Machine active
    Options
  36. ✨ Sync machine registry with creating/updating/deleting of machines
    Options
  37. πŸš’ dont initialize if machine is not fully configured (error handeling)
    Options
  38. πŸš’ Check if machine initialized without error (error handeling)
    Options
  39. πŸš’ Check if driver implements all required functions (error handeling)
    Options
  40. ♻️ refactor to mixin for override detection (add/check required configuration to classes, required_{attributed,overrides})
    Options
  41. ♻️ refactor machine pk should be UUID
    Options
  42. ♻️ refactor rename base_driver to machine_type
    Options
  43. ♻️ refactor move check into own check function isPlgRegistryLoaded (Prevent MachineConfig.ready to be executed twice)
    Options

⚠️ Before merge

Edit tasklist title
Beta Give feedback Tasklist ⚠️ Before merge, more options

Delete tasklist

Delete tasklist block?
Are you sure? All relationships in this tasklist will be removed.
  1. check TODO: comments
    Options
  2. fix style (precommit)
    Options
  3. remove debug messages
    Options
  4. Remove badly working django admin interface for machine integration
    Options
  5. Cups plugin providing a fully working example driver (Refactor to use machine driver APIΒ wolflu05/inventree-cups-plugin#6)
    Options
  6. Docs
    Options
  7. Tests
    Options
  8. bump api version
    Options

♻️ External PRs/Refactors

Edit tasklist title
Beta Give feedback Tasklist ♻️ External PRs/Refactors, more options

Delete tasklist

Delete tasklist block?
Are you sure? All relationships in this tasklist will be removed.
  1. breaking enhancement plugin
    Edit...
  2. api breaking enhancement plugin report
    Edit...
  3. refactor
    wolflu05
    Edit...
  4. refactor
    wolflu05
    Edit...
  5. enhancement plugin refactor
    Edit...
  6. api enhancement plugin
    Edit...
  7. enhancement user interface
    Edit...

πŸ’‘Further ideas (Not this PR)

Moved to #6486

@wolflu05 wolflu05 added enhancement This is an suggested enhancement or new feature plugin Plugin ecosystem labels May 15, 2023
InvenTree/common/models.py Outdated Show resolved Hide resolved
@wolflu05 wolflu05 changed the title [WIP] Machines feature [WIP] Machines integration May 15, 2023
InvenTree/machine/apps.py Outdated Show resolved Hide resolved
InvenTree/common/models.py Outdated Show resolved Hide resolved
InvenTree/machine/apps.py Outdated Show resolved Hide resolved
InvenTree/machine/base_drivers/BaseLabelPrintingDriver.py Outdated Show resolved Hide resolved
InvenTree/machine/driver.py Outdated Show resolved Hide resolved
InvenTree/machine/driver.py Outdated Show resolved Hide resolved
InvenTree/machine/driver.py Outdated Show resolved Hide resolved
InvenTree/machine/models.py Outdated Show resolved Hide resolved
InvenTree/machine/registry.py Show resolved Hide resolved
InvenTree/machine/registry.py Outdated Show resolved Hide resolved
InvenTree/machine/__init__.py Outdated Show resolved Hide resolved
@wolflu05
Copy link
Contributor Author

@matmair Do you think the Base Drivers should be exported from the machine or plugin app? (The notification adapters defined in common are exported through the plugin app)

@matmair
Copy link
Member

matmair commented May 15, 2023

@wolflu05 if you are not against it I would suggest it. The idea is that there always is a simple and steady path for the things we expose for plugins while we are free to refactor the inner workings and structure without breaking plugins.

@wolflu05
Copy link
Contributor Author

I'm planning on add the ability that machines can expose their current states. E.g. for a label printer: Ready, Printing, Disconnected, ... do you think this makes sense to define per Machine Type or per CustomMachineDriver? (Want to have a proper Interface with Enums).

Per MachineType has the ability that they are equal across all label printers. However something custom like "out of labels", "machine opened" ... is not possible. I guess there are more different states on other machine types like PnP. What about having both abilities? MachineType specific states and a machine status that's just a simple string?

@matmair
Copy link
Member

matmair commented May 18, 2023

@wolflu05 status/state, in general, needs a bit of a refactor (see #4289, #4589). To keep this PR somewhat my suggestion would be to add enums to the machine type and enable drivers to define current state (the enum from machine) and state text (free text, by default from machine type state but can be set to "anything")

InvenTree/machine/models.py Outdated Show resolved Hide resolved
InvenTree/machine/registry.py Outdated Show resolved Hide resolved
InvenTree/machine/machine_type.py Outdated Show resolved Hide resolved
InvenTree/machine/registry.py Show resolved Hide resolved
InvenTree/machine/registry.py Show resolved Hide resolved
@wolflu05 wolflu05 marked this pull request as ready for review February 7, 2024 22:46
@wolflu05 wolflu05 changed the title [WIP] Machine integration Machine integration Feb 7, 2024
@wolflu05
Copy link
Contributor Author

wolflu05 commented Feb 7, 2024

9 months passed now, this is my biggest PR and I learned a lot about InvenTree and Django during that time. Now this PR is finally ready for review πŸš€ . @SchrodingersGat @matmair

I can recommend to start reviewing this by reading the docs to understand how the machine registry, custom drivers and types work before taking a deeper look into the code.

As an example, I adapted my cups label printer plugin to use the new driver interface. You can find it here if you want to see a real driver actually being implemented.
EDIT: I now also implemented a dedicated Dymo driver that uses native printer commands in inventree-dymo-plugin. (That driver is simpler than the cups driver.)

During this PR I collected a list of related things that can be further improvements (see initial comment) which I will post in a new issue once this is merged.

If you have any questions, feel free to comment, I'm really curious about your feedback.

Copy link
Member

@matmair matmair left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM; huge work effort, thanks @wolflu05

@SchrodingersGat SchrodingersGat added the enhancement This is an suggested enhancement or new feature label Feb 14, 2024
@SchrodingersGat
Copy link
Member

@wolflu05 this is a massive effort to get this up and running, apologies for any road blocks along the way :)

This all looks good, but please appreciate that with such a large contribution, there are going to be some teething issue and bugs we have not spotted. It all appears to be in order and I am happy to merge now, so that we have some time before the next release to spot any obvious issues.

Without any machines to fill in myself, it is hard to create any test data to work with.

As we progress, it would be great to work on some more examples for the documentation of different types of machines, as we build those up.

No doubt you will be tagged in a number of issues / questions around all this :)

BTW regarding the style issue - once #6481 is merged, please merge master back in to your branch and we should be good to go.

@SchrodingersGat SchrodingersGat enabled auto-merge (squash) February 14, 2024 13:38
@wolflu05 wolflu05 added this to the 0.14.0 milestone Feb 14, 2024
@SchrodingersGat SchrodingersGat merged commit aa7eaaa into inventree:master Feb 14, 2024
25 checks passed
@SchrodingersGat
Copy link
Member

Congrats and thanks @wolflu05 - let's hope it is a smooth integration from here!

@wolflu05
Copy link
Contributor Author

This all looks good, but please appreciate that with such a large contribution, there are going to be some teething issue and bugs we have not spotted. [...] No doubt you will be tagged in a number of issues / questions around all this :)

This is actually the largest PR I've ever done. All good, feel free to ping me if there is anything I can help with. Hopefully we don't find to much issues πŸ˜†.

Without any machines to fill in myself, it is hard to create any test data to work with.

If you want to test it, you can create a simple driver and place it anywhere in the code like this:

Testing driver
from plugin.machine.machine_types import LabelPrinterBaseDriver

class TestLabelPrinterDriver(LabelPrinterBaseDriver):
    """Label printer driver for Dymo printers."""

    SLUG = "test-driver"
    NAME = "Test Driver"
    DESCRIPTION = "Test label printing driver for InvenTree"

    MACHINE_SETTINGS = {
        "CONNECTION_URL": {
            "name": "Connection url",
            "description": "Connection url for the machine in format user@server:port/route",
            "required": True,
        }
    }

    def print_labels(self, machine, label, items, request, **kwargs):
        print("==== Print label")
        print(machine, label, items, request, kwargs)
        print(machine.get_setting('CONNECTION_URL', 'D'))
        print("="*10)

As we progress, it would be great to work on some more examples for the documentation of different types of machines, as we build those up.

Definitely, I think the documentation around this has big potential, also the generated part from the docstrings.

Congrats and thanks @wolflu05 - let's hope it is a smooth integration from here!

Thank you very much for merging, this is a great step forward, I actually really hadn't expected to get this merged that quick. And yes, let's hope it is a smooth integration πŸ˜† .

@wolflu05 wolflu05 deleted the feature/machines branch February 15, 2024 14:06
@wolflu05 wolflu05 removed the enhancement This is an suggested enhancement or new feature label Feb 15, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature Platform UI Related to the React based User Interface plugin Plugin ecosystem
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[FR] Support multiple Label printers within the same label plugin
3 participants