Commit #7: Events thread-based + new easier Extractor.py + our own Timer class
[smartthings-infrastructure.git] / eventSimulator / eventSimulator.groovy
diff --git a/eventSimulator/eventSimulator.groovy b/eventSimulator/eventSimulator.groovy
new file mode 100644 (file)
index 0000000..c414b3a
--- /dev/null
@@ -0,0 +1,68 @@
+// Generate a random variable
+Random random = new Random(1131)
+int nextRandom = 10
+
+// Touch events
+new Thread() {
+       @Override
+       public void run() {
+               while(true) {
+                       appObject.setValue([name: "Touched", value: "Touched", deviceId: 0, descriptionText: "",
+                                          displayed: true, linkText: "", isStateChange: false, unit: "", data: []])
+                       Thread.sleep(random.nextInt(nextRandom));       
+                       
+               }
+       }
+}.start()
+
+// Lock events
+new Thread() {
+       
+       @Override
+       public void run() {
+               while(true) {
+                       lockObject.setValue([name: "lock", value: "locked", deviceId: 0, descriptionText: "",
+                                          displayed: true, linkText: "", isStateChange: false, unit: "", data: []])
+                       Thread.sleep(random.nextInt(nextRandom));       
+               }
+       }
+}.start()
+
+new Thread() {
+       
+       @Override
+       public void run() {
+               while(true) {
+                       lockObject.setValue([name: "unlock", value: "unlocked", deviceId: 0, descriptionText: "",
+                                          displayed: true, linkText: "", isStateChange: false, unit: "", data: []])
+                       Thread.sleep(random.nextInt(nextRandom));       
+               }
+       }
+}.start()
+
+// Contact sensor events
+new Thread() {
+       
+       @Override
+       public void run() {
+               while(true) {
+                       contactObject.setValue([name: "contact.open", value: "open", deviceId: 0, descriptionText: "",
+                                          displayed: true, linkText: "", isStateChange: false, unit: "", data: []])
+                       Thread.sleep(random.nextInt(nextRandom));       
+                       
+               }
+       }
+}.start()
+
+new Thread() {
+       
+       @Override
+       public void run() {
+               while(true) {
+                       contactObject.setValue([name: "contact.closed", value: "closed", deviceId: 0, descriptionText: "",
+                                          displayed: true, linkText: "", isStateChange: false, unit: "", data: []])
+                       Thread.sleep(random.nextInt(nextRandom));       
+                       
+               }
+       }
+}.start()