Can I select a list of modes using an enum array?

In my parent app, I ask the user to select the modes.

Then, in my child app, I would like to have the user select the modes, BUT - only from the modes that were chosen in the parent app. I can get the array and from the parent, but I don’t know how to have the user select modes by using enum (instead of mode) for the type.

Any suggestions?

I’ve not tried this, but…
If the child app has a dynamic page for the mode input, thinking you may be able to assign the options parameter of the input using your array from the parent.
The name of the child input probably shouldn’t be modes to start with.
Let us know if this works, I’ve been meaning to try this to allow for a subset of device selections, and to prevent the same devices from being used in different sections of the same app.

@Mike_Maxwell is asking me for programming advice?

Hahahaha. You’re funny today.

But I’ll certainly let you know if I stumble onto something.

I had to solve something similar, and I did input modes from an enum. Ultimately, as you obviously know, modes are just strings.

def m = location.mode
def myModes = []
location.modes.each {myModes << "$it"}
input "modesX", "enum", multiple: true, title: "Select mode(s)", submitOnChange: true, options: myModes.sort(), defaultValue: [m]
1 Like

Thank you @bravenel!!! You win the interwebs today!

Using your suggested code above, I was able to achieve what I was try to do – specifically, limit the modes offered in a child App to the modes that the user had selected in the parent App.

So I first import the modes selected in the parent App into an array called “parentModes”:

def parentModes = []
parentModes = parent.sendChildTheModes()

Then I use your suggested code - modifying it to use the “parentModes” (instead of “location.modes”) to populate “myModes”:

    	def m = location.mode
	def myModes = []
	parentModes.each {myModes << "$it"}
            input "modesX", "enum", multiple: true, title: "Select mode(s)", submitOnChange: true, options: myModes.sort(), defaultValue: [m]

And the child App UI now only shows the modes that the user selected in the parent App UI!

1 Like

Another tidbit for you: There is a UI fail in ST wrt modes being input. If you select “modes” for the input type, you will get an input screen with All Modes checked by default, and then the list of modes. That particular screen only makes sense in the context of establishing a mode restriction, where the default All Modes means no restriction.

If you have a use model where you want some modes for a proactive reason, that is the wrong input screen. So I worked this one out. There is no All Modes option, because it makes no sense.