Infrastructure compatible with 2 types of switches.(Normal switches and otherVsGeneri...
[smartthings-infrastructure.git] / EnergyMeter / EnergyMeter.groovy
index 0274eefd4a7d666d6b5b4c6b18fc3230ed944345..83f2283c3bdae185c2f27dd7ae8373717c863dbe 100644 (file)
@@ -6,20 +6,37 @@ public class EnergyMeter {
        private String id
        private String label
        private String displayName
-       private String energy
+       private int energy
+       private int currentEnergy
+       private String status
 
-       EnergyMeter(String id, String label, String displayName, String energy) {
+       EnergyMeter(String id, String label, String displayName, int energy, String status) {
                this.id = id
                this.label = label
                this.displayName = displayName
                this.energy = energy
+               this.status = status
        }
 
        //By Model Checker
        def setValue(String value) {
                println("the enery is changed to $value!")
-               this.battery = value.toInteger()
-               this.currentBattery = value.toInteger()
+               this.energy = value.toInteger()
+               this.currentEnergy = value.toInteger()
+       }
+
+       def reset() {
+               if (status != "on") {
+                       status = "on"
+                       println("the energy meter is on!")
+               }
+       }
+
+       def off() {
+               if (status != "off") {
+                       status = "off"
+                       println("the energy meter is off!")
+               }
        }
 
        def currentValue(String deviceFeature) {
@@ -28,4 +45,9 @@ public class EnergyMeter {
                }
        }
 
+       def latestValue(String deviceFeature) {
+               if (deviceFeature == "energy") {
+                       return energy
+               }
+       }
 }