87671dae30ec520f244879e16c42bef2bdf88a7d
[smartthings-infrastructure.git] / Lock / locks.groovy
1 //Create a class for lock device
2 package Lock
3
4 public class locks {
5         private int id = 0
6         private String displayName
7         private String currentLock
8         private String lockLatestValue
9
10         locks(int id, String displayName, String currentLock, String lockLatestValue) {
11                 this.id = id
12                 this.displayName = displayName
13                 this.currentLock = currentLock
14                 this.lockLatestValue = lockLatestValue
15         }
16
17         def lock() {
18                 println("the door with id:$id is locked!")
19                 this.lockLatestValue = this.currentLock
20                 this.currentLock = "locked"
21         }
22         
23         def unlock() {
24                 println("the door with id:$id is unlocked!")
25                 this.lockLatestValue = this.currentLock
26                 this.currentLock = "unlocked"
27         }
28         
29         def currentValue(String S) {
30                 if (S == "lock") {
31                         return currentLock
32                 }
33         }
34
35         def latestValue(String S) {
36                 if (S == "lock") {
37                         return lockLatestValue
38                 }
39         }
40 }