Infrastructure that works for all the locks' group!
[smartthings-infrastructure.git] / SwitchLevel / SwitchLevel.groovy
1 //Create a class for switch level
2 package SwitchLevel
3 import Timer.SimulatedTimer
4
5 public class SwitchLevel {
6         private String id
7         private String label
8         private String displayName
9         private int level
10         private int rate
11         def sendEvent   
12         def timers
13         
14
15         SwitchLevel(Closure sendEvent, String id, String label, String displayName, int level) {
16                 this.sendEvent = sendEvent
17                 this.timers = new SimulatedTimer()
18                 this.id = id
19                 this.label = label
20                 this.displayName = displayName
21                 this.level = level
22                 this.rate = level
23         }
24
25         //By Apps
26         def setLevel(int level) {
27                 if (this.level != level) {
28                         println("the switch with id:$id is setted to level $level!")
29                         this.level = level
30                         this.rate = level
31                         sendEvent([name: "level", value: "50", deviceId: this.id, descriptionText: "",
32                                    displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
33                 }
34         }
35
36         //By Model Checker
37         def setValue(String value) {
38                 println("the switch with id:$id is setted to level $value!")
39                 this.level = value.toInteger()
40                 this.rate = value.toInteger()
41         }
42 }