Settings update "mystery"

Hello guys,

I'm developing my first plug-in that will connect to an Arduino through a user selected serial port (to avoid conflicts with the printer), so the only one setting i have on my plugin is this serial port.
In the settings.jinja I created this:

Default Serial Port:<select data-bind="options: availablePorts, optionsText: 'name', optionsValue: 'name', value: settingsViewModel.settings.plugins.SafetyPrinter.serialport"></select>

... in the .js i have this:

function SafetyprinterViewModel(parameters) {
        var self = this;
        self.settingsViewModel = parameters[0];

and in init.py this:

    def get_settings_defaults(self):
        return dict(
            serialport="AUTO"
        )

    def get_template_configs(self):
        return [
        dict(type="settings", custom_bindings=True),
        dict(type="sidebar", name="Safety Printer", custom_bindings=False, icon="fire"),
        ]

The config.yaml is updated correctly when I change the value and hit [SAVE], but the problem is: when i refresh the webpage and open the Plug-in Settings, it shows the default (AUTO) serial port, not the one on config.yaml. But if I close the settings tab (hitting [Cancel] button) and open it again, now I get the right one. Any ideas? I tried this on .js and the console showed the right info:

 self.onBeforeBinding = function() {
            self.serialport = self.settingsViewModel.settings.plugins.SafetyPrinter.serialport();
            console.log(self.serialport);
        }

The entire project is here:
https://github.com/SinisterRj/SafetyPrinter/tree/main/OctoprintPlugin

try adding valueAllowUnset: true to your select data-bind and see if that helps...

It works, Thank you!

1 Like