Need some advice for my first plugin

Hello

I have been working on my first plugin and could use some implementation advice.

Basically I have created a plugin that requests data (wget) from an I/O board at a periodic rate to retrieve the current input status. The status from the board is reflected in variables within the plugin. Currently there are about 20 variables. To better help with the viewing of variables, virtual devices are created for each input variable.

The need I have now is to reflect the status of the plugin variables in each of the appropriate virtual devices.

To handle this I see these options;

[ol][li]As the plugin requests the status for the I/O board, reflect the state on both the local and virtual device variables at the same time. The only thing is that it seems to couple the plugin directly with the virtual devices but I am not sure that is a big deal anyway.[/li]
[li]When the virtual device is created also create a ?variable_watch? to update the virtual device variable when the plugin variable gets changed. The issue here is that it seems I have to expose the plugin variables through UpnP which I have not done at this point and I am not sure I want to anyway.[/li]
[li]Skip having local plugin variables as they are not needed if they are reflected in virtual devices anyway. Which seems to be a variation of option 1, with similar coupling concerns.[/li][/ol]

I hope someone might have the background to give me some advices and I thank you very much for any input.

-Mark

mnaz,

I wouldn’t mirror the data. If you are using wget I assume you are getting data for multiple target devices all at once. Simply loop through the devices table within your plugin while checking the parent. This will indicate whether it is one of your offspring. I assume you are using a luup.chdev.start — luup.chdev.sync loop to create the kids.

For instance, below all my child pool circuits are parented to the plugin and have an altId that is formatted like Circuit-XX.

  for k, v in pairs(luup.devices) do
    if (v.device_num_parent == luup.device) then
        if(string.find(v.id, "Circuit") == 1) then
           -- I have one of my circuits.  Set the variables for it on the device.
            ...

rstrouse,

I agree that is a good way to do it and I came to this point because I created the plugin first with local variables. After which I thought it would be nice to use standard device types do represent the data because more remote viewing apps already support rendering the standard device types.

Once I finalize on this I would like to post my plugin and hopefully I can convince someone to give me a code review. :slight_smile:

thanks for your input.