PiBrewing / craftbeerpi4

GNU General Public License v3.0
57 stars 29 forks source link

New test branches for Server and UI #107

Closed avollkopf closed 1 year ago

avollkopf commented 1 year ago

@dereulenspiegel , @papauorg , @pascal1404 , @papauorg

I have created new branches for Server and UI with a small enhancement for the Settings page. There are now setting categories.

Default is currently All, craftbeerpi and steps. There is also hidden which is not shown in the settings. 'All' does only filter hidden category.

The installed plugins are also listed as categories.

Configupdate is adding the categories automatically after first start of the branches (plugin-settings-selection-test) to the existing settings. (steps, craftbeerpi, hidden).

Installed plugins are currently listed under craftbeerpi, but user can change the config file manually. Plugins that add global settings will require small updates (like it is done in the configupdate extension) to adapt the new settings 'source' parameter.

This will give better overview on the settings page. What do you guys think

image.

Example with manually adapted parameters for the cbpi4-LCDisplay Plugin: image

dimontau commented 1 year ago

Greetings. After the update, I lost everything. The server does not start. Gives such an error. I tried to put on a new system, the same error. I do everything as usual, before everything worked without problems. What can be wrong? I use Raspberry Pi Zero. 12341

avollkopf commented 1 year ago

@dimontau The new 'plugins-settings-selection-test' branches of Server and UI are only meant for development and not for usage. Please revert back to the main branch. Not sure what branch you were trying with the setup of a new system. If it is not this branch. Please open a new issue.

avollkopf commented 1 year ago

Setup.py will require an additional parameter for this functionality as it can be seen here

keywords='globalsettings'

is required as cbpi checks this parameter and adds then the plugin to the drop down menu on the settings page

avollkopf commented 1 year ago

When adding parameters, you need to do it now this way:

        if autoreboot is None:
            logger.info("INIT AutoReboot parameter")
            try:
                await self.cbpi.config.add("AutoReboot", "No", type=ConfigType.SELECT, description="Reboot Pi once a day at selected time",
                                                                                                    options=[{"label": "Yes", "value": "Yes"},
                                                                                                        {"label": "No", "value": "No"}],
                                                                                                        source="cbpi4-system")
            except:
                logger.warning('Unable to update config')

type, description, options and source need to be used in front of the values. Options can be also omitted if not required.

source must match your plugin name.

avollkopf commented 1 year ago

to update existing plugins I am using also an additional parameter related to the plugin version to check the update.

        plugin = await self.cbpi.plugin.load_plugin_list("cbpi4-system")
        self.version=plugin[0].get("Version","0.0.0")

        self.system_update = self.cbpi.config.get("system_update", None)

Plugin version is then later checked and plugin updates the parameter if flag is not in the settings or has an older version. In this case, the value of the parameter is used:

if autoreboot is None:
            logger.info("INIT AutoReboot parameter")
            try:
                await self.cbpi.config.add("AutoReboot", "No", type=ConfigType.SELECT, description="Reboot Pi once a day at selected time",
                                                                                                    options=[{"label": "Yes", "value": "Yes"},
                                                                                                        {"label": "No", "value": "No"}],
                                                                                                        source="cbpi4-system")
            except:
                logger.warning('Unable to update config')
        else:
            if self.system_update == None or self.system_update != self.version:
                try:
                    await self.cbpi.config.add("AutoReboot", autoreboot, type=ConfigType.SELECT, description="Reboot Pi once a day at selected time",
                                                                                                    options=[{"label": "Yes", "value": "Yes"},
                                                                                                        {"label": "No", "value": "No"}],
                                                                                                        source="cbpi4-system")
                except:
                    logger.warning('Unable to update config')               
avollkopf commented 1 year ago

Finally, plugin update parameter is added to the settings:

        if self.system_update == None or self.system_update != self.version:
            try:
                 await self.cbpi.config.add("system_update", self.version,type=ConfigType.STRING,description="cbpi4 system version update",source="hidden")         
            except Exception as e:
                logger.warning('Unable to update config') 
                logger. Warning(e)

source is set to 'hidden' -> Parameter does not show up un settings page (even with 'All')

This parameter can then be used for updates. (It is not really required for new plugins as there one can add the source parameter upfront)

avollkopf commented 1 year ago

Changed the plugins a bit and also craftbeerpi to allow for removal of obsolete parameters in case you remove a plugin.

Example is here

and here

This will update parameters in case of installation of plugin or new plugin version.

cbpi4 has the api option to remove obsolte parameters from the config.json file -> https://github.com/PiBrewing/craftbeerpi4/blob/f990e0e0a35ba9b4259d254abcdbfeef0ebade13/cbpi/http_endpoints/http_config.py#L107

avollkopf commented 1 year ago

merged into development