telefonicaid / iotagent-node-lib

Module to enable IoT Agent developers to build custom agents for their devices that can easily connect to NGSI Context Brokers
https://iotagent-node-lib.rtfd.io/
GNU Affero General Public License v3.0
60 stars 85 forks source link

Add value picker JEXL function #1626

Closed mapedraza closed 4 weeks ago

mapedraza commented 1 month ago

This function picks all keys of a certain object and includes the name of the key into an array.

For a given expression like this:

{a:1,b:2,c:3}|valuePicker(1)

The output result will be ["a"]

Same for valuePickerMulti, that uses an array with possibles match:

{a:1,b:true,c:'on',d:'nok',e:false,f:0,g:'off',h:'ok'}|valuePickerMulti([true,1,'on','nok'])

The output result will be ["a","b","c","d"]

This is util in scenarios in which you need to write into an attribute activated flag or alarms. I.E:

{
  "alertA":false,
  "alertB":true,
  "alertC":true,
}

Then you can have {"alerts":["alertB","alertC"]}

fgalan commented 1 month ago

CHANGES_NEXT_RELEASE entry should be added.

fgalan commented 1 month ago

Unit test covering the functionality should be added.

mapedraza commented 1 month ago

Unit test covering the functionality should be added.

Done here: https://github.com/telefonicaid/iotagent-node-lib/pull/1626/commits/12c7d52e51e490eb4f620ee63349a0516dcdb620