From 07922ca948668ed1b4b294d414951b4e2aec802e Mon Sep 17 00:00:00 2001 From: amiraj Date: Thu, 1 Aug 2019 13:15:14 -0700 Subject: [PATCH] Fixing bugs in classes --- ContactSensor/ContactSensor.groovy | 11 ----------- ContactSensor/ContactSensors.groovy | 17 ----------------- SwitchLevel/SwitchLevel.groovy | 15 +++++++++++---- SwitchLevel/SwitchLevels.groovy | 20 +++++++++++++++----- Thermostat/Thermostats.groovy | 6 +++--- 5 files changed, 29 insertions(+), 40 deletions(-) diff --git a/ContactSensor/ContactSensor.groovy b/ContactSensor/ContactSensor.groovy index 141faf2..413b58c 100644 --- a/ContactSensor/ContactSensor.groovy +++ b/ContactSensor/ContactSensor.groovy @@ -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!") diff --git a/ContactSensor/ContactSensors.groovy b/ContactSensor/ContactSensors.groovy index c691853..74508a8 100644 --- a/ContactSensor/ContactSensors.groovy +++ b/ContactSensor/ContactSensors.groovy @@ -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)) } diff --git a/SwitchLevel/SwitchLevel.groovy b/SwitchLevel/SwitchLevel.groovy index ff83a50..8782365 100644 --- a/SwitchLevel/SwitchLevel.groovy +++ b/SwitchLevel/SwitchLevel.groovy @@ -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() + } } } diff --git a/SwitchLevel/SwitchLevels.groovy b/SwitchLevel/SwitchLevels.groovy index 591611a..490e52d 100644 --- a/SwitchLevel/SwitchLevels.groovy +++ b/SwitchLevel/SwitchLevels.groovy @@ -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) + } } } diff --git a/Thermostat/Thermostats.groovy b/Thermostat/Thermostats.groovy index 73a2148..b2abdcb 100644 --- a/Thermostat/Thermostats.groovy +++ b/Thermostat/Thermostats.groovy @@ -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) -- 2.34.1