Using virtual devices for Arduino Prototypes?

I’ve got the following device code which (appears) to work, basically to return commands interpreted from an IR reciever.  Currently, it’s hard-coded to just return the color of the tivo button pressed, once I get that working I can generalize it some more.  The arduino shield (i think) sends commands in the format “signalcommand: [color]”

The problem is, I can’t tell if my code to interpret these is working because I can’t use it as a virtual device.  I was previously able to create one, but the recent ide changes make one created by default, and it doesn’t seem to be registering min.

Here’s the device code (device is called IRShield):

metadata {
// Simulator metadata
simulator {
// status messages
status “yellow”: "signalcommand: yellow"
status “blue”: "signalcommand: blue"
status “red”: "signalcommand: red"
status “green”: "signalcommand: green"
status “none”: “signalcommand: none”
}

// UI tile definitions
tiles {
standardTile(“shield”, “device.shield”, width: 2, height: 2) {
state “default”, icon:“st.shields.shields.arduino”, backgroundColor:"#ffffff"
}

main "shield"
details “shield”
}
}

// Parse incoming device messages to generate events
def parse(String description) {
def result
if (description?.startsWith("signalcommand: ")) {
def raw = description - "signalcommand: "
result = createEvent(
name:  “signalcommand”,
value: raw
)
}
log.debug "Parse returned ${result?.descriptionText}"
return result
}

My app code is:

preferences {
section(“Reciver Name:”) {
input “irreciever”, “device.IRShield”, title: “What Reciever?”
}
section(“Yellow does…”) {
input “yellowswitch”, “capability.switch”   // need to make these not just switches
}
section(“Blue does…”) {
input “blueswitch”, “capability.switch”
}
section(“Red does…”) {
input “redswitch”, “capability.switch”
}
section(“Green does…”) {
input “greenswitch”, “capability.switch”
}
}

def installed()
{
//subscribe(irreciever.signalcommand)
//subscribe(motionSensors, “motion.active”, motionActive)  i think this is 'item, thing it can say, thing to call
subscribe(irreciever, “signalcommand”, signalHandler)

subscribe(yellowswitch.switch)
subscribe(blueswitch.switch)
subscribe(redswitch.switch)
subscribe(greenswitch.switch)

}

def updated()
{
unsubscribe()
subscribe(irreciever, “signalcommand”, signalCommand)
subscribe(yellowswitch.switch)
subscribe(blueswitch.switch)
subscribe(redswitch.switch)
subscribe(greenswitch.switch)
}

def signalHandler(evt) {   // this needs to be named properly and i believe it is the problem
//def infaredcommand = irreciever.signalcommand as String
log.debug "LOOK"
def infaredcommand = evt.value

switch (infaredcommand)
{
case “yellow”:
yellowswitch.toggle()
break
case “blue”:
blueswitch.toggle()
break
case “red”:
redswitch.toggle()
break
case “green”:
greenswitch.toggle()
break
default:
log.debug "unknown command or null command"
break
}
}

 

Is this going to work?  Am I making any obvious mistakes?  It didn’t seem to be working before the ide change and right now I can’t really test it with a virtual device.

The IDE should be creating the proper virtual device for you.  I think the problem may be in the device type name. The system converts the camel-cased name to one including spaces and then looks for a match. So when when you specify an input type of “device.IRShield” in your app, the system will be looking for a device with the name “IR Shield”.   If the name of the device type is something else, e.g. is missing the space, it will fail to find your device type and create a virtual unknown device.

If that’s not the problem, let me know, and we’ll look into it further.

ahh that did it, thanks!  now, to track down why the code itself doesn’t work.