Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Expand
titleEdit MatchRules.lua to extract the prefixes from the custom fields

Create a second function, APPidList(), to extract the ClientList prefixes from the custom fields and update MatchFile () to call APPidList().

You can replace the contents of the MatchRules.lua file with this new code:

Code Block
languagelua
function APPidList()
   local IdList = component.fields()["ClientList"]
   return IdList
end

function MatchFile(FileName)
   local IdList = APPidList()
   trace(IdList)
   local JustFileName = FILfilename(FileName)
   trace(JustFileName)
   return true
end

Concepts used:

Expand
titleBreak the comma delimited string into a list to get each prefix Id

We can quickly do this by adding one line to AppidList( ) after line 2:

Code Block
languagelua
IdList = IdList:split(",")

You should see something like:

Concepts used:

Expand
titleMake a matching function which takes the prefix and sees if the filename starts with it

Create a third function, APPmatchPrefix(), to determine if the filename matches the prefix. You can copy the code below:

Code Block
languagelua
function APPmatchPrefix(Prefix, FileName)
   local Part = FileName:sub(1, #Prefix)
   trace(Part, Prefix)
   return (Part == Prefix)
end

See the screenshot below and add a line to MatchFile() to call and invoke the AppmatchPrefix() function.

Concepts used:

Expand
titleNow change the matching code in MatchFile() so we go iterate through the entire prefix list

Let’s modify the code to go through the entire list of prefixes:

Code Block
languagelua
for i = 1, #IdList do
   if APPmatchPrefix(IdList[i], JustFileName) then 
      return true
   end
end
return false -- we didn't match anything

And this is what you should see:

Concepts used:

Expand
titleCommit your changes, alter the component to run on the new commit, and run it!

Commit and Push Changes to Git and go to the component card for Choosing the code to run for your component.

And You’re done! The next steps are how you could further refine the code

Expand
titleMake the configuration more robust by striping trimming the white space from the list ClientListof prefixes

This means refining the APPidList function.

That would involve looping through the list and removing white space from each ID:

Concepts:

See Custom Logging
Expand
titleCustomize the logging
using iguana.log*

Add intuitive Custom Logging for your component to increase visibility into processing and adding meaningful messages to help with troubleshooting.

You can see an example of this in main.lua on line 25:

Code Block
languagelua
iguana.log("Polling every "..Polltime.." seconds");

Try it for yourself!

See Custom Status
Expand
titleCustomize the status
using component.setStatus{data="Text"}

Add Custom Status for your component to have it display real time updates at the bottom of the component card as its running.

This component already creates custom status on lines 31-36 of main.lua.

Try it for yourself!

There is no limit to how you can streamline the usage of a custom component - if that helps address a bottleneck, then it is well worth it.  

...