Mode or Hello, Home Phrase contains commas


(Micheal ) #1

For any experienced SmartThings coders, I am new to this so excuse this if it is simplistic.

I have some modes and Hello, home phrases that contain punctuation. For example “Asleep, Sleep In” or “Good Bye, going out of town”.

When I have an input that allows for multiple entries of modes, then I go to the event and try to determine if the current mode is within the selection. I am using the ‘contains’ and ‘find’ options with the mode string, but this always seems to fail when there is this punctuation in the mode name. This makes sense in some respects; when I look at the ‘settings’ that are put forth, it appears to comma delimit the list. My obvious solution is to remove the punctuation, but if I want to publish this for others that seems like a hack work around…Any idea what I am doing wrong?


(Tim Slagle) #2

Please provide the code.


(Micheal ) #3

I knew you would ask :smile:

Here are the snippets:

preferences
input “mode”, “mode”, required: true, multiple: true, title: “Modes?”

def initialize() {
subscribe(location, “mode”, locationHandler)
}

def locationHandler(evt) {
if (mode.contains(evt.value)) {
Do something
}
}


(Tim Slagle) #4

Looks good to me. It may be an issue with the comma. Commas generally are considered seperators. Can you try removing the comma from one and test?


(Micheal ) #5

Sorry I wasn’t clear…when I remove them everything works great…using the code above, here is where I run into issues:

Modes:

Home
Away
Asleep
Asleep, Sleep in

On the input, I select Asleep, sleep in and Away,

When I change modes to Away, the conditions are met and everything is good. When I choose Asleep, sleep in the conditions ACT as they are not met, but if I do a debug it does show evt.value=Asleep, Sleep In. Removing the comma in the name works fine.

Now, I THINK this used to work in other code, and that the update done by ST in the last week changed this…I would be interested if you tested similar code (and modes with commas). This also seems to affect phases, but I am betting it is either HOW I am determining the mode is contained in the list.


(Micheal ) #6

As a follow up, the above issues seem to ONLY be in the IDE…when I publish the app, it seems to work with commas.

Can someone confirm this on their IDE. Again, I THINK this worked a couple weeks ago and then stopped working, but I could be wrong.


(Kris Schaller) #7

@MichaelS are you on iOS/Android/Windows?


(Micheal ) #8

Develop on the IDE on Windows and using Android for my mobile app.


(Kris Schaller) #9

Awesome thanks. You said you were no longer seeing any issues with this, right?


(Micheal ) #10

Well, kinda…I encountered this the other day with Hello, Home phrases (in the IDE when using the simulator), and now today (in the IDE) when developing an app dealing with modes…so when I am in the simulator using my modes or Hello Home phrases, it doesn’t seem to work with commas in the name…however, when I publish them and test is SEEMS to work with any of them. No one has confirmed what I am seeing, but assume there is an issue with the IDE in the recent platform updates that changed this behavior.


(Kris Schaller) #11

Can you add this code to your locationHandler method and tell me what you get for your debug when you try both “Asleep” and “Asleep, Sleep in”?

log.debug "evt.value : " + evt.value
log.debug "mode contents : " + mode
log.debug "mode length: " + mode.size()
if(mode.contains(evt.value.toString())) {
	sendPush evt.value
}

(Micheal ) #12

I created a separate test instance and a new mode “Mode, Test”.

When I choose this more here are the results:

1:35:03 PM: debug mode length: 4
1:35:03 PM: debug mode contents : mode
1:35:03 PM: debug evt.value : Mode, Test

When I do something like “Home” as the mode, I get this:

1:36:57 PM: debug mode length: 4
1:36:57 PM: debug mode contents : mode
1:36:57 PM: debug evt.value : Home

So, I believe it is using the comma as a hard stop, at least in the IDE.


(Kris Schaller) #13

I think you’re right that the comma is being used as a hard stop, but I’m also seeing it on my phone, so I wanted to see why yours was appearing correct.

Sorry just a few follow up questions:
How many modes were added to the SA?

Would you be comfortable messaging me your code privately so I can look at it?


(Micheal ) #14

Sent…sounds like you are seeing the same thing…so it isn’t my coding :wink:


(Kris Schaller) #15

Thanks! Yeah looks like it’s not your coding :frowning: