Fixing bugs in classes
authoramiraj <amiraj.95@uci.edu>
Thu, 1 Aug 2019 20:15:14 +0000 (13:15 -0700)
committeramiraj <amiraj.95@uci.edu>
Thu, 1 Aug 2019 20:15:14 +0000 (13:15 -0700)
ContactSensor/ContactSensor.groovy
ContactSensor/ContactSensors.groovy
SwitchLevel/SwitchLevel.groovy
SwitchLevel/SwitchLevels.groovy
Thermostat/Thermostats.groovy

index 141faf2..413b58c 100644 (file)
@@ -29,19 +29,8 @@ public class ContactSensor {
                this.contactState = value
                this.currentContact = value
                this.latestValue = value
-               //this.events.add(eventDataMap)
-               //this.timeOfEvents.add(System.currentTimeMillis())
        }
 
-       /*def eventsSince(Date dateObj) {
-               def List happenedEvents = []
-               def sinceThen = dateObj.time
-               for (int i = 0;i < timeOfEvents.size();i++) {
-                       if (timeOfEvents[i]>=sinceThen)
-                               happenedEvents.add(events[i])
-               }
-               return happenedEvents
-       }*/
        
        def on() {
                println("the contact sensor with id:$id is armed!")
index c691853..74508a8 100644 (file)
@@ -25,23 +25,6 @@ public class ContactSensors {
                this.deviceNumbers = deviceNumbers
                this.contacts = []
 
-               /*def initSensor = Verify.getBoolean()
-               if (initSensor) {
-                       this.contactState = "closed"
-                       this.currentContact = "closed"
-                       this.latestValue = "closed"
-               } else {
-                       this.contactState = "open"
-                       this.currentContact = "open"
-                       this.latestValue = "open"
-               }
-
-               def initAlarm = Verify.getBoolean()
-               if (initAlarm) {
-                       this.alarmState = "armed"
-               } else {
-                       this.alarmState = "not armed"
-               }*/
                contacts.add(new ContactSensor(id, label, displayName, this.contactState, this.currentContact, this.alarmState, this.latestValue))
        }
 
index ff83a50..8782365 100644 (file)
@@ -96,9 +96,16 @@ public class SwitchLevel {
        }
 
        //By Model Checker
-       def setValue(String value) {
-               println("the switch with id:$id is setted to level $value!")
-               this.level = value.toInteger()
-               this.rate = value.toInteger()
+       def setValue(String value, String name) {
+               if (name == "switch") {
+                       println("the switch with id:$id is $value!")
+                       this.switchLatestValue = value
+                       this.switchState = value
+                       this.currentSwitch = value
+               } else if (name == "level") {
+                       println("the switch with id:$id is setted to level $value!")
+                       this.level = value.toInteger()
+                       this.rate = value.toInteger()
+               }
        }
 }
index 591611a..490e52d 100644 (file)
@@ -105,11 +105,21 @@ public class SwitchLevels {
 
        //By Model Checker
        def setValue(LinkedHashMap eventDataMap) {
-               if (eventDataMap["value"].toInteger() != switchLevels[0].level) {
-                       this.level = eventDataMap["value"].toInteger()
-                       this.rate = eventDataMap["value"].toInteger()
-                       switchLevels[0].setValue(eventDataMap["value"])
-                       sendEvent(eventDataMap)
+               if (eventDataMap["name"] == "switch") {
+                       if (eventDataMap["value"] != switchLevels[0].switchState) {
+                               this.switchState = eventDataMap["value"]
+                               this.switchLatestValue = eventDataMap["value"]
+                               this.currentSwitch = eventDataMap["value"]
+                               switchLevels[0].setValue(eventDataMap["value"], "switch")
+                               sendEvent(eventDataMap)
+                       }
+               } else if (eventDataMap["name"] == "level") {
+                       if (eventDataMap["value"].toInteger() != switchLevels[0].level) {
+                               this.level = eventDataMap["value"].toInteger()
+                               this.rate = eventDataMap["value"].toInteger()
+                               switchLevels[0].setValue(eventDataMap["value"], "level")
+                               sendEvent(eventDataMap)
+                       }
                }
        }
 
index 73a2148..b2abdcb 100644 (file)
@@ -228,7 +228,7 @@ public class Thermostats{
                        this.currentHeatingSetpoint = heatingSetpoint
                        this.heatingSetpoint = heatingSetpoint
                        this.latestCoolingSetPoint = coolingSetpoint
-                       this.latestHeatingSetpoint = heatingSetpoint
+                       this.latestHeatingSetPoint = heatingSetpoint
                        thermostats[0].setHold(info1, coolingSetpoint, heatingSetpoint, info2, info3)
                }
        }
@@ -244,7 +244,7 @@ public class Thermostats{
                        }
                } else if (eventDataMap["name"] == "heatingSetpoint") {
                        if (eventDataMap["value"].toInteger() != thermostats[0].heatingSetpoint) {
-                               this.latestHeatingSetpoint = eventDataMap["value"].toInteger()
+                               this.latestHeatingSetPoint = eventDataMap["value"].toInteger()
                                this.heatingSetpoint = eventDataMap["value"].toInteger()
                                thermostats[0].setValue(eventDataMap["value"], "heatingSetpoint")
                                sendEvent(eventDataMap)
@@ -258,7 +258,7 @@ public class Thermostats{
                        }
                } else if (eventDataMap["name"] == "thermostatSetpoint") {
                        if (eventDataMap["value"].toInteger() != thermostats[0].thermostatSetpoint) {
-                               this.latestThermostatSetpoint = eventDataMap["value"].toInteger()
+                               this.latestThermostatSetPoint = eventDataMap["value"].toInteger()
                                this.thermostatSetpoint = eventDataMap["value"].toInteger()
                                thermostats[0].setValue(eventDataMap["value"], "thermostatSetpoint")
                                sendEvent(eventDataMap)