How to 'Disable' a Switch in the Device Handler Code?

What do I need to do to the code of a Device Handler to make it simply not work?

e.g. an on/off switch of some kind. I want to do to the code whatever would need to be done to prevent the switch from actually switching to either ON or OFF, ever; especially not the first time.

Why?, because I want the initial state of the fields ‘Data’ and Current States’ to remain exactly as they are when the Device gets created, and before it ever gets turned ON or OFF.

Why would anybody want this? I need the switch to have those fields like that for maintaining some other thing, and I want to prevent an accidental turning ON or OFF to break it.

So, can anybody tell me the easy way of accomplishing this?

EDIT: Another related question is, where can I get a copy of the code for the ‘built-in’ Simulated Switch? ANSWER = HERE.

p.s. I have done some code-hacking, and can find my way around in there, but I still haven’t taken the time to learn the whole flow of Groovy.

1 Like

This is pretty trivial. Stub out the code…

Drop me a PM and we’ll put the DTH together to test.

1 Like

As per Terry’s (@tgauchat) guidance, I simply blanked out the {} for the ON and OFF defs, and it works great!

Thanks, man. :slight_smile:

1 Like

Are you making a blank tile? :slight_smile:

2 Likes

DING-DING-DING-DING!!!

Yes. :slight_smile:

EDIT: Here is what I came up with…

/**
 *  Copyright 2015 SmartThings
 *
 *  Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
 *  in compliance with the License. You may obtain a copy of the License at:
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 *  Unless required by applicable law or agreed to in writing, software distributed under the License is distributed
 *  on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License
 *  for the specific language governing permissions and limitations under the License.
 *
 */
metadata {
	
    definition (name: "Blank-Tile-for-ActionTiles", namespace: "sgnihttrams", author: "sgni") {
		capability "Switch"
}

	tiles {
		standardTile("switch", "device.switch", width: 3, height: 3, canChangeIcon: true) {
			state "off", label: 'Blank Tile', action: "switch.on", backgroundColor: "#000000"
			state "on", label: 'ActionTiles', action: "switch.off", backgroundColor: "#000000"
		}
        main "switch"
		details(["switch"])
	}
}


def on() {}

def off() {}

private getVersion() {
	"PUBLISHED"
}

.
.
.
.
.
.
.

2 Likes

I will have to give it a try after work. Thanks!

Oh and did you make multiples or can you re-use a device?

I was going to make bunches and bunches of them until I found out that we can add more than one copy of any particular ‘Thing’ to a Tileset. So, just one and you should be good to go. :slight_smile:

2 Likes