df4b01a4eb26b43ffc75fb59ab718711240000af
[smartthings-infrastructure.git] / Battery / Battery.groovy
1 //Create a class for battery
2 package Battery
3 import Timer.SimulatedTimer
4
5 public class Battery {
6         private String id
7         private String label
8         private String displayName
9         private int battery
10         private int currentBattery
11         private int batteryLatestValue
12
13         Battery(String id, String label, String displayName, int battery) {
14                 this.id = id
15                 this.label = label
16                 this.displayName = displayName
17                 this.battery = battery
18                 this.currentBattery = battery
19                 this.batteryLatestValue = battery
20         }
21
22         //By Model Checker
23         def setValue(String value) {
24                 println("the battery level with id:$id is changed to $value!")
25                 this.battery = value.toInteger()
26                 this.currentBattery = value.toInteger()
27                 this.batteryLatestValue = value.toInteger()
28         }
29
30         def currentValue(String deviceFeature) {
31                 if (deviceFeature == "battery") {
32                         return battery
33                 }
34         }
35
36         def latestValue(String deviceFeature) {
37                 if (deviceFeature == "battery") {
38                         return batteryLatestValue
39                 }
40         }
41
42 }