Looks good to me. I’m certainly not the most skilled developer here, but I’ve written a handful of programs and this one look good. I only have two suggestions (and minor ones at that) and one question:
Suggestion A.) Put in some documentation. I’m a big fan of this as it’s how I’ve learned to write anything I’ve written in SmartThings. Just looking at other programs, modifying them, and then seeing what happens. If you’re sharing you program with others (which you seem to be willing to do given that you posted it here) it’s always nice to see information in it to help others learn. For example I would do stuff like this:
subscribe(contact1, "contact", contactHandler) // We're subscribing to the door sensor so we can tell if anything happens to it.
and
def contactHandler(evt) { // This is the procedure that runs when the door sensor reports that something has happened.
and
if (evt.value == "closed") { // We're checking to see if the door close. If the sensor reports anything other than "closed" we're ignoring it.
Just my personal preference of course.
Suggestion B.) the log.debug line is useful when trying to trouble shoot what’s going on. But what you have here is perhaps a little too light on information. I would put something more like:
log.debug "${contact1.displayName} reported: $evt.value"
Like the documentation, this just helps to understand a little better what’s going on.
Both of these suggestions I totally a personal preference and really make no difference on the program’s operation of course.
Question: Did you intend to allow this program to lock multiple doors when one sensor is closed? In the preferences you’re allowing multiple locks to be selected. Nothing wrong with this if that is the intention, but just be aware that if you select multiple locks, then “lock1” represents ALL of the locks selected and the command lock1.lock() will lock all of them.
Finally:
Also, if the app works well how can I go about getting it published?
At some point SmartThings plans to have an sort of "app store" where you can publish your apps and allow others to use (or possibly buy) them. This isn't possible yet, unfortunately. You can share them with others, but there are two things be know about this:
1.) Others will have full access to see your code. Obviously you’re not really concerned with this one as you’ve posted it already here. But if you work on something later and don’t want others to have your direct code, then don’t share it.
2.) Others will have to copy you code into their own program in order to use it. We talked about this in the thread about a Hallway night light if you’ll recall. So it isn’t as easy as just sharing it and others run it.
If you want to share you code, after publishing the program for your own use, go back to the the App Settings. This is where we gave the program a name and description. You’ll see a new option: "Program is shared? " Check the box here and then it’ll show up in the Shared SmartApps area of the IDE.