Skip to content

Machine integration - #4824

Merged
SchrodingersGat merged 105 commits into
inventree:masterfrom
wolflu05:feature/machines
Feb 14, 2024
Merged

SchrodingersGat merged 105 commits into
inventree:masterfrom
wolflu05:feature/machines

Conversation

@wolflu05

@wolflu05 wolflu05 commented May 15, 2023 •

Copy link
Copy Markdown
Member

This PR adds the machines feature described in #4789 .

image
image

fixes #4789


# 📝 Todos
- [x] 🚚 driver errors
- [x] 🚚 handle error function for machines and registry
- [x] 🚚 Init driver function
- [x] 🚚 Machine update hook function (only partially working)
- [x] 🚚 Machine has unapplied changes (restart required)
- [x] 🚚 Machine restart hook
- [x] 🚚 get_machines should by default only return initialized machines
- [x] 🚚 funtion to check if all required settings are defined
- [x] 🚚 Machine States (Ready, Connecting, …) (waiting on #4857)
- [x] 🚚 export everything required from the plugin app
- [x] 🚚 get all machines, can be maybe used in combination with event mixin
- [x] 🚚 get_machines function for driver to return all machines belonging to that driver
- [x] 🚚 separate machine type and base driver
- [x] 📫 API GET available machine types / drivers
- [x] 📫 API CRUD machines
- [x] 📫 API CRUD machine settings
- [x] 📫 API Permissions
- [x] 💄 PUI Settings Page
- [x] 💄 PUI machine list: table
- [x] 💄 PUI machine list: registry errors
- [x] 💄 PUI machine list: add machine
- [x] 💄 PUI machine detail: view
- [x] 💄 PUI machine type table with detail drawer: showing machine type info and list available drivers and Which plugin provides that type
- [x] 💄 PUI machine driver drawer with some info about it
- [x] 💄 PUI driver drawer error stack + show all machines
- [x] 🎰 LABEL PRINTING machine type
- [x] 🎰 LABEL PRINTING: print_label
- [x] 🎰 LABEL PRINTING: print_labels
- [x] 🎰 LABEL PRINTING: location setting (useful for basic location scoping)
- [x] 🎰 LABEL PRINTING: get_printers (implement at driver level, useful for filtering the printers based on certain hardware aspects)
- [x] 🎰 LABEL PRINTING: number of copies printing option
- [x] 🎰 LABEL PRINTING: include request in get_printers kwargs
- [x] 🎰 LABEL PRINTING: remember last used printer machine per user
- [x] ✨ Add Machine Settings and separat from driver settings (Machine settings could be used for e.g. printer location)
- [x] ✨ Machine active
- [x] ✨ Sync machine registry with creating/updating/deleting of machines
- [x] 🚒 dont initialize if machine is not fully configured (error handeling)
- [x] 🚒 Check if machine initialized without error (error handeling)
- [x] 🚒 Check if driver implements all required functions (error handeling)
- [x] ♻️ refactor to mixin for override detection (add/check required configuration to classes, required_{attributed,overrides})
- [x] ♻️ refactor machine pk should be UUID
- [x] ♻️ refactor rename base_driver to machine_type
- [x] ♻️ refactor move check into own check function isPlgRegistryLoaded (Prevent MachineConfig.ready to be executed twice)
# ⚠️ Before merge
- [x] check `TODO:` comments
- [x] fix style (precommit)
- [x] remove debug messages
- [x] Remove badly working django admin interface for machine integration
- [x] Cups plugin providing a fully working example driver (https://github.com/wolflu05/inventree-cups-plugin/pull/6)
- [x] Docs
- [x] Tests
- [x] bump api version
# ♻️ External PRs/Refactors
- [ ] https://github.com/inventree/InvenTree/pull/5005
- [ ] https://github.com/inventree/InvenTree/pull/5251
- [ ] https://github.com/inventree/InvenTree/pull/4834
- [ ] https://github.com/inventree/InvenTree/pull/4927
- [ ] https://github.com/inventree/InvenTree/pull/5224
- [ ] https://github.com/inventree/InvenTree/pull/5786
- [ ] https://github.com/inventree/InvenTree/pull/5837

💡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
Comment thread InvenTree/common/models.py Resolved
@wolflu05 wolflu05 changed the title [WIP] Machines feature [WIP] Machines integration May 15, 2023
Comment thread InvenTree/machine/apps.py Resolved
Comment thread InvenTree/common/models.py Resolved
Comment thread InvenTree/machine/apps.py Resolved
Comment thread InvenTree/machine/driver.py Resolved
Comment thread InvenTree/machine/driver.py Resolved
Comment thread InvenTree/machine/driver.py Resolved
Comment thread InvenTree/machine/models.py Resolved
Comment thread InvenTree/machine/registry.py Resolved
Comment thread InvenTree/machine/registry.py Resolved
Comment thread InvenTree/machine/__init__.py Resolved
@wolflu05

Copy link
Copy Markdown
Member 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

matmair commented May 15, 2023

Copy link
Copy Markdown
Member

@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
Copy Markdown
Member 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

matmair commented May 18, 2023

Copy link
Copy Markdown
Member

@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")

Comment thread InvenTree/machine/models.py Resolved
Comment thread InvenTree/machine/registry.py Resolved
Comment thread InvenTree/machine/machine_type.py Resolved
Comment thread InvenTree/machine/registry.py Resolved
Comment thread InvenTree/machine/registry.py 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

wolflu05 commented Feb 7, 2024 •

Copy link
Copy Markdown
Member Author

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.

@matmair matmair left a comment

Copy link
Copy Markdown
Member

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
Copy Markdown
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
@SchrodingersGat

Copy link
Copy Markdown
Member

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

@wolflu05

Copy link
Copy Markdown
Member 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 mentioned this pull request Feb 14, 2024
3 of 18 tasks
@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
@wolflu05 wolflu05 mentioned this pull request Apr 3, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

feature plugin Plugin ecosystem User Interface Related to the frontend / User Interface

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