So I have a code question about enum. I am configuring a list of variables to be selected in an enum list in an app. What's the best way to determine if they are selected? I'm using integers to make the enumerations easier to code logic for later.
input "whenToUnlock", "enum", title: "When to unlock? Default: '(Prevent unlocking under any circumstances)'",
options: [1:"${state.whenToUnlock1}", 2:"${state.whenToUnlock2}", 3:"${state.whenToUnlock3}", 4:"${state.whenToUnlock4}",
5:"${state.whenToUnlock5}", 6:"${state.whenToUnlock6}"],defaultValue: 6, required: false, multiple: true
def whenToUnlockOptions() {
state.whenToUnlock1 = "Bolt/frame strike protection"
state.whenToUnlock2 = "Presence unlock"
state.whenToUnlock3 = "Fire/medical panic unlock"
state.whenToUnlock4 = "Switch triggered unlock"
state.whenToUnlock5 = "State sync fix"
state.whenToUnlock6 = "Prevent unlocking under any circumstances"
Options 1 through 5 are selected, and 6 is omitted. Enumerating for each I can see it outputs the ones that are selected so I'm almost done. Just need a little help with converting this to the simplest possible testable logic:
Pretty sure something like this would work but seems way more work than should be necessary to accomplish this. Maybe there is a better way?
whenToUnlock.each { it ->
whenToUnlockEachSelected = it
if (whenToUnlockEachSelected == "1") {option1 = true} else {option1 = false}
if (whenToUnlockEachSelected == "2") {option2 = true} else {option2 = false}
if (whenToUnlockEachSelected == "3") {option3 = true} else {option3 = false}
if (whenToUnlockEachSelected == "4") {option4 = true} else {option4 = false}
if (whenToUnlockEachSelected == "5") {option5 = true} else {option5 = false}
if (whenToUnlockEachSelected == "6") {option6 = true} else {option6 = false}