Skip to content

Config value retrieval too naive  #54

Open
@erodewald

Description

@erodewald

Is your feature request related to a problem? Please describe.
util/endpoint-context.js includes several "config value" retrieval methods, which are very handy, but they only pull out the first value in the array. For arrays larger than 1, you are out of luck.

Describe the solution you'd like
I have thought of several use cases that these needs to support:

1. Raw data
  • you are building a config page and you want a list of the raw values in an array
  • e.g., deviceId, or modeId, etc.
2. Building strings with label/name
  • you are building a config page and you want to use the device Ids as a template
    • e.g., setting the description as Light Bulb 1, Light Bulb 2, Rear door lock
  • this cannot be done because you have no API access token to look up the labels, so Strongman can replace values
  • Strongman sees the literal string {{deviceId:81e3bbf5-b63e-4c18-af21-51f72520fe40}} and it will transform it into Light Bulb 1

IMHO, the responsibility of the function should be to:

  1. Return a singular string value, or to return an array of strings
  2. Not assume the user wants to do anything in particular with those strings
  3. Take flexible arguments:
  • you pass in a string argument, it finds that value and returns the un-templated value
  • you pass in an object like { name: 'modes', templated: true }, then it returns the templated value (it would also respect if you sent false)

Proposed usage

context.configStringValue('modes')

// returns 
// [ 
//    '81e3bbf5-b63e-4c18-af21-51f72520fe40', 
//    '26c972d5-40f5-413c-82d9-46da38f01a47' 
// ]
context.configStringValue({name: 'modes', templated: true})

// returns 
// [ 
//    '{{modeId:81e3bbf5-b63e-4c18-af21-51f72520fe40}}', 
//    '{{modeId:26c972d5-40f5-413c-82d9-46da38f01a47}}' 
// ]

Describe alternatives you've considered
n/a

Additional context
n/a

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions