4e72815d45f93348435de768f10c541e94cb99d5
[smartthings-infrastructure.git] / Momentary / Momentary.groovy
1 //Create a class for momentory switch device
2 package Momentary
3 import SmartThing.SmartThing
4
5 public class Momentary extends SmartThing {
6         // id, label, and display name of the device
7         StringBuilder id = new StringBuilder()
8         StringBuilder label = new StringBuilder()
9         StringBuilder displayName = new StringBuilder()
10
11         Momentary(Closure sendEvent, StringBuilder id, StringBuilder label, StringBuilder displayName) {
12                 idSmartThing = id
13                 labelSmartThing = label
14                 displayNameSmartThing = displayName
15                 sendEventSmartThings = sendEvent
16
17                 // Initialization
18                 this.id = id
19                 this.label = label
20                 this.displayName = displayName
21         }
22
23         // Methods to set values
24         def push() {
25                 println("the momentary switch with id:$id is pushed!")
26                 sendEvent([name: "momentary", value: "pushed", deviceId: id, descriptionText: "",
27                            displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
28         }       
29 }