Infrastructure compatible with 2 types of switches.(Normal switches and otherVsGeneri...
[smartthings-infrastructure.git] / EnergyMeter / EnergyMeter.groovy
1 //Create a class for energy meter
2 package EnergyMeter
3 import Timer.SimulatedTimer
4
5 public class EnergyMeter {
6         private String id
7         private String label
8         private String displayName
9         private int energy
10         private int currentEnergy
11         private String status
12
13         EnergyMeter(String id, String label, String displayName, int energy, String status) {
14                 this.id = id
15                 this.label = label
16                 this.displayName = displayName
17                 this.energy = energy
18                 this.status = status
19         }
20
21         //By Model Checker
22         def setValue(String value) {
23                 println("the enery is changed to $value!")
24                 this.energy = value.toInteger()
25                 this.currentEnergy = value.toInteger()
26         }
27
28         def reset() {
29                 if (status != "on") {
30                         status = "on"
31                         println("the energy meter is on!")
32                 }
33         }
34
35         def off() {
36                 if (status != "off") {
37                         status = "off"
38                         println("the energy meter is off!")
39                 }
40         }
41
42         def currentValue(String deviceFeature) {
43                 if (deviceFeature == "energy") {
44                         return energy
45                 }
46         }
47
48         def latestValue(String deviceFeature) {
49                 if (deviceFeature == "energy") {
50                         return energy
51                 }
52         }
53 }