Infrastructure that works for all the locks' group!
authoramiraj <amiraj.95@uci.edu>
Mon, 29 Jul 2019 21:09:36 +0000 (14:09 -0700)
committeramiraj <amiraj.95@uci.edu>
Mon, 29 Jul 2019 21:09:36 +0000 (14:09 -0700)
126 files changed:
AccelerationSensor/AccelerationSensors.groovy
Alarm/Alarm.groovy
Alarm/Alarms.groovy
AllEvents [new file with mode: 0644]
AtomicState/AtomicState.groovy [new file with mode: 0644]
Battery/Batteries.groovy
Battery/Battery.groovy
BeaconSensor/BeaconSensors.groovy
CarbonMonoxideDetector/CarbonMonoxideDetectors.groovy
ColorControl/ColorControl.groovy
ColorControl/ColorControls.groovy
ContactSensor/ContactSensors.groovy
DoorControl/DoorControl.groovy
DoorControl/DoorControls.groovy
EnergyMeter/EnergyMeter.groovy
EnergyMeter/EnergyMeters.groovy
Event/Event.groovy
Extractor/App1/App1.groovy
Extractor/App1/extractedFunctionsApp1.groovy
Extractor/App1/extractedObjectsApp1.groovy
Extractor/App1/extractedObjectsConstructorApp1.groovy
Extractor/App2/App2.groovy
Extractor/App2/extractedFunctionsApp2.groovy
Extractor/App2/extractedObjectsApp2.groovy
Extractor/App2/extractedObjectsConstructorApp2.groovy
Extractor/Extractor.groovy
Extractor/ExtractorScript.py
Extractor/extractorFile.groovy
GlobalVariables/GlobalVariablesBothApps.groovy
IlluminanceMeasurement/IlluminanceMeasurement.groovy [new file with mode: 0644]
IlluminanceMeasurement/IlluminanceMeasurements.groovy [new file with mode: 0644]
ImageCapture/ImageCapture.groovy
ImageCapture/ImageCaptures.groovy
Location/LocationVar.groovy
Lock/Lock.groovy
Lock/Locks.groovy
Methods/canSchedule.groovy [new file with mode: 0644]
Methods/eventHandler.groovy
Methods/getTemperatureScale.groovy
Methods/httpPostJson.groovy [new file with mode: 0644]
Methods/runEvery15Minutes.groovy [new file with mode: 0644]
Methods/schedule.groovy
Methods/sendNotification.groovy [new file with mode: 0644]
Methods/timeToday.groovy [new file with mode: 0644]
MobilePresence/MobilePresence.groovy [new file with mode: 0644]
MobilePresence/MobilePresences.groovy [new file with mode: 0644]
ModelCheck.py
MotionSensor/MotionSensors.groovy
MusicPlayer/MusicPlayer.groovy
MusicPlayer/MusicPlayers.groovy
PowerMeter/PowerMeter.groovy [new file with mode: 0644]
PowerMeter/PowerMeters.groovy [new file with mode: 0644]
PresenceSensor/PresenceSensors.groovy
RelativeHumidityMeasurement/RelativeHumidityMeasurement.groovy [new file with mode: 0644]
RelativeHumidityMeasurement/RelativeHumidityMeasurements.groovy [new file with mode: 0644]
RelaySwitch/RelaySwitch.groovy [new file with mode: 0644]
RelaySwitch/RelaySwitches.groovy [new file with mode: 0644]
Runner.py
SleepSensor/SleepSensor.groovy [new file with mode: 0644]
SleepSensor/SleepSensors.groovy [new file with mode: 0644]
SmokeDetector/SmokeDetectors.groovy
SpeechSynthesis/SpeechSynthesis.groovy
SpeechSynthesis/SpeechSynthesises.groovy
StepSensor/StepSensor.groovy [new file with mode: 0644]
StepSensor/StepSensors.groovy [new file with mode: 0644]
Switch/Switch.groovy
Switch/Switches.groovy
SwitchLevel/SwitchLevel.groovy [new file with mode: 0644]
SwitchLevel/SwitchLevels.groovy [new file with mode: 0644]
TemperatureMeasurement/TemperatureMeasurement.groovy [new file with mode: 0644]
TemperatureMeasurement/TemperatureMeasurements.groovy [new file with mode: 0644]
Thermostat/Thermostat.groovy
Thermostat/Thermostats.groovy
Valve/Valve.groovy [new file with mode: 0644]
Valve/Valves.groovy [new file with mode: 0644]
Variables and events for each device
WaterSensor/WaterSensor.groovy [new file with mode: 0644]
WaterSensor/WaterSensors.groovy [new file with mode: 0644]
appTouch/Touched.groovy
eventSimulator/accelerationActiveEvent.groovy [new file with mode: 0644]
eventSimulator/accelerationInactiveEvent.groovy [new file with mode: 0644]
eventSimulator/appTouchEvent.groovy
eventSimulator/batteryChargeEvent.groovy
eventSimulator/beaconLeftEvent.groovy [new file with mode: 0644]
eventSimulator/beaconPresentEvent.groovy [new file with mode: 0644]
eventSimulator/buttonHeldEvent.groovy
eventSimulator/buttonPushedEvent.groovy
eventSimulator/carbonMonoxideClearEvent.groovy
eventSimulator/carbonMonoxideDetectedEvent.groovy
eventSimulator/carbonMonoxideTestedEvent.groovy
eventSimulator/colorChangedEvent.groovy [new file with mode: 0644]
eventSimulator/contactClosedEvent.groovy
eventSimulator/contactOpenEvent.groovy
eventSimulator/doorClosedEvent.groovy
eventSimulator/doorOpenEvent.groovy
eventSimulator/eventSimulator.groovy
eventSimulator/eventSwitchOff.groovy
eventSimulator/eventSwitchOn.groovy
eventSimulator/hueChangedEvent.groovy [new file with mode: 0644]
eventSimulator/locationAwayEvent.groovy
eventSimulator/locationHomeEvent.groovy
eventSimulator/locationNightEvent.groovy
eventSimulator/lockEvent.groovy
eventSimulator/motionActiveEvent.groovy
eventSimulator/motionInactiveEvent.groovy
eventSimulator/nfcTouchEvent.groovy
eventSimulator/presenceLeftEvent.groovy
eventSimulator/presencePresentEvent.groovy
eventSimulator/saturationChangedEvent.groovy [new file with mode: 0644]
eventSimulator/smokeCarbonMonoxideClearEvent.groovy [new file with mode: 0644]
eventSimulator/smokeCarbonMonoxideDetectedEvent.groovy [new file with mode: 0644]
eventSimulator/smokeCarbonMonoxideTestedEvent.groovy [new file with mode: 0644]
eventSimulator/smokeClearEvent.groovy
eventSimulator/smokeDetectedEvent.groovy
eventSimulator/smokeTestedEvent.groovy
eventSimulator/switchOffEvent.groovy
eventSimulator/switchOnEvent.groovy
eventSimulator/thermostatAutoModeEvent.groovy
eventSimulator/thermostatCoolModeEvent.groovy
eventSimulator/thermostatEmergencyHeatModeEvent.groovy
eventSimulator/thermostatHeatModeEvent.groovy
eventSimulator/thermostatOffModeEvent.groovy
eventSimulator/unlockEvent.groovy
main.groovy
prgs [deleted file]
test [deleted file]

index 0d3c14f..8c1992c 100644 (file)
@@ -2,6 +2,9 @@
 package AccelerationSensor
 import Timer.SimulatedTimer
 
+//JPF's Verify API
+import gov.nasa.jpf.vm.Verify
+
 public class AccelerationSensors {
        private int deviceNumbers
        private List accelerationSensors
@@ -21,6 +24,14 @@ public class AccelerationSensors {
                this.deviceNumbers = deviceNumbers
                this.accelerationSensors = []
 
+               def init = Verify.getBoolean()
+               if (init) {
+                       this.acceleration = "inactive"
+                       this.accelerationLatestValue = "inactive"
+               } else {
+                       this.acceleration = "active"
+                       this.accelerationLatestValue = "active"
+               }
                accelerationSensors.add(new AccelerationSensor(id, label, displayName, this.acceleration, this.accelerationLatestValue))
        }
 
index a78c3c2..d3834f1 100644 (file)
@@ -35,12 +35,14 @@ public class Alarm {
 
        //By Apps
        def both() {
-               println("the alarm with id:$id is changed to both!")
-               this.alarmLatestValue = this.alarm
-               this.alarm = "both"
-               this.currentAlarm = "both"
-               sendEvent([name: "alarm", value: "both", deviceId: this.id, descriptionText: "",
-                   displayed: true, linkText: "", isStateChange: false, unit: "", data: [value: "both"]])
+               if (alarm != "both") {
+                       println("the alarm with id:$id is changed to both!")
+                       this.alarmLatestValue = this.alarm
+                       this.alarm = "both"
+                       this.currentAlarm = "both"
+                       sendEvent([name: "alarm", value: "both", deviceId: this.id, descriptionText: "",
+                           displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
+               }
        }
 
        def on() {
@@ -48,30 +50,36 @@ public class Alarm {
        }
 
        def off() {
-               println("the alarm with id:$id is changed to off!")
-               this.alarmLatestValue = this.alarm
-               this.alarm = "off"
-               this.currentAlarm = "off"
-               sendEvent([name: "alarm", value: "off", deviceId: this.id, descriptionText: "",
-                   displayed: true, linkText: "", isStateChange: false, unit: "", data: [value: "off"]])
+               if (alarm != "off") {
+                       println("the alarm with id:$id is changed to off!")
+                       this.alarmLatestValue = this.alarm
+                       this.alarm = "off"
+                       this.currentAlarm = "off"
+                       sendEvent([name: "alarm", value: "off", deviceId: this.id, descriptionText: "",
+                           displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
+               }
        }
 
        def siren() {
-               println("the alarm with id:$id is changed to siren!")
-               this.alarmLatestValue = this.alarm
-               this.alarm = "siren"
-               this.currentAlarm = "siren"
-               sendEvent([name: "alarm", value: "siren", deviceId: this.id, descriptionText: "",
-                   displayed: true, linkText: "", isStateChange: false, unit: "", data: [value: "siren"]])
+               if (alarm != "siren") {
+                       println("the alarm with id:$id is changed to siren!")
+                       this.alarmLatestValue = this.alarm
+                       this.alarm = "siren"
+                       this.currentAlarm = "siren"
+                       sendEvent([name: "alarm", value: "siren", deviceId: this.id, descriptionText: "",
+                           displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
+               }
        }
 
        def strobe() {
-               println("the alarm with id:$id is changed to strobe!")
-               this.alarmLatestValue = this.alarm
-               this.alarm = "strobe"
-               this.currentAlarm = "strobe"
-               sendEvent([name: "alarm", value: "strobe", deviceId: this.id, descriptionText: "",
-                   displayed: true, linkText: "", isStateChange: false, unit: "", data: [value: "strobe"]])
+               if (alarm != "strobe") {
+                       println("the alarm with id:$id is changed to strobe!")
+                       this.alarmLatestValue = this.alarm
+                       this.alarm = "strobe"
+                       this.currentAlarm = "strobe"
+                       sendEvent([name: "alarm", value: "strobe", deviceId: this.id, descriptionText: "",
+                           displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
+               }
        }
 
        def currentValue(String deviceFeature) {
index 2eb775e..bc805e1 100644 (file)
@@ -2,6 +2,9 @@
 package Alarm
 import Timer.SimulatedTimer
 
+//JPF's Verify API
+import gov.nasa.jpf.vm.Verify
+
 public class Alarms {
        int deviceNumbers       
        List alarms
@@ -22,6 +25,16 @@ public class Alarms {
                this.deviceNumbers = deviceNumbers
                this.alarms = []
 
+               def init = Verify.getBoolean()
+               if (init) {
+                       this.alarm = "off"
+                       this.currentAlarm = "off"
+                       this.alarmLatestValue = "off"
+               } else {
+                       this.alarm = "on"
+                       this.currentAlarm = "on"
+                       this.alarmLatestValue = "on"
+               }
                alarms.add(new Alarm(sendEvent, id, label, displayName, this.alarm, this.currentAlarm, this.alarmLatestValue))
        }
                
@@ -55,17 +68,21 @@ public class Alarms {
 
        //By Apps
        def both() {
-               alarms[0].both()
-               alarmLatestValue = alarm
-               alarm = "both"
-               currentAlarm = "both"
+               if (alarm != "both") {
+                       alarms[0].both()
+                       alarmLatestValue = alarm
+                       alarm = "both"
+                       currentAlarm = "both"
+               }
        }
 
        def off() {
-               alarms[0].off()
-               alarmLatestValue = alarm
-               alarm = "off"
-               currentAlarm = "off"
+               if (alarm != "off") {
+                       alarms[0].off()
+                       alarmLatestValue = alarm
+                       alarm = "off"
+                       currentAlarm = "off"
+               }
        }
 
        def on() {
@@ -73,17 +90,21 @@ public class Alarms {
        }
 
        def siren() {
-               alarms[0].siren()
-               alarmLatestValue = alarm
-               alarm = "siren"
-               currentAlarm = "siren"
+               if (alarm != "siren") {
+                       alarms[0].siren()
+                       alarmLatestValue = alarm
+                       alarm = "siren"
+                       currentAlarm = "siren"
+               }
        }
 
        def strobe() {
-               alarms[0].strobe()
-               alarmLatestValue = alarm
-               alarm = "strobe"
-               currentAlarm = "strobe"
+               if (alarm != "strobe") {
+                       alarms[0].strobe()
+                       alarmLatestValue = alarm
+                       alarm = "strobe"
+                       currentAlarm = "strobe"
+               }
        }
 
        def currentValue(String deviceFeature) {
diff --git a/AllEvents b/AllEvents
new file mode 100644 (file)
index 0000000..f7a0eba
--- /dev/null
+++ b/AllEvents
@@ -0,0 +1,206 @@
+//
+alarmObject.setValue([name: "alarm", value: "both", deviceId: "alarmID0", descriptionText: "",
+displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
+alarmObject.setValue([name: "alarm", value: "siren", deviceId: "alarmID0", descriptionText: "",
+displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
+alarmObject.setValue([name: "alarm", value: "strobe", deviceId: "alarmID0", descriptionText: "",
+displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
+alarmObject.setValue([name: "alarm", value: "off", deviceId: "alarmID0", descriptionText: "",
+displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
+
+contactObject.setValue([name: "contact.closed", value: "closed", deviceId: "contactSensorID0", descriptionText: "",
+displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
+contactObject.setValue([name: "contact.open", value: "open", deviceId: "contactSensorID0", descriptionText: "",
+displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
+contactObject.setValue([name: "contact", value: "open", deviceId: "contactSensorID0", descriptionText: "",
+displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
+contactObject.setValue([name: "contact", value: "close[d", deviceId: "contactSensorID0", descriptionText: "",
+displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
+
+doorControlObject.setValue([name: "doorState", value: "closed", deviceId: "doorControlID0", descriptionText: "",
+displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
+doorControlObject.setValue([name: "doorState", value: "open", deviceId: "doorControlID0", descriptionText: "",
+displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
+
+locationObject.setValue([name: "Location", value: "away", deviceId: "locationID0", descriptionText: "",
+displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
+locationObject.setValue([name: "Location", value: "home", deviceId: "locationID0", descriptionText: "",
+displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
+locationObject.setValue([name: "Location", value: "night", deviceId: "locationID0", descriptionText: "",
+displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
+
+lockObject.setValue([name: "lock", value: "locked", deviceId: "lockID0", descriptionText: "",
+displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
+lockObject.setValue([name: "unlock", value: "unlocked ", deviceId: "lockID0", descriptionText: "",
+displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
+lockObject.setValue([name: "lock", value: "unlocked", deviceId: "lockID0", descriptionText: "",
+displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
+
+motionSensorObject.setValue([name: "motion", value: "active", deviceId: "motionSensorID0", descriptionText: "",
+displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
+motionSensorObject.setValue([name: "motion", value: "inactive", deviceId: "motionSensorID0", descriptionText: "",
+displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
+
+musicPlayerObject.setValue([name: "status", value: "playing", deviceId: "musicPlayerID0", descriptionText: "",
+displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
+musicPlayerObject.setValue([name: "status", value: "stopped", deviceId: "musicPlayerID0", descriptionText: "",
+displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
+musicPlayerObject.setValue([name: "status", value: "paused", deviceId: "musicPlayerID0", descriptionText: "",
+displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
+musicPlayerObject.setValue([name: "level", value: "36"/*A number between 0 to 100 as a charge*/, deviceId: "musicPlayerID0", descriptionText: "",
+displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
+musicPlayerObject.setValue([name: "trackDescription", value: "someDescriptions", deviceId: "musicPlayerID0", descriptionText: "",
+displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
+musicPlayerObject.setValue([name: "trackData", value: "someTrack", deviceId: "musicPlayerID0", descriptionText: "",
+displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
+musicPlayerObject.setValue([name: "mute", value: "umuted", deviceId: "musicPlayerID0", descriptionText: "",
+displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
+musicPlayerObject.setValue([name: "mute", value: "muted", deviceId: "musicPlayerID0", descriptionText: "",
+displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
+
+presenceSensorObject.setValue([name: "presence", value: "present", deviceId: "presenceSensorID0", descriptionText: "",
+displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"presence":"1","dni":"mobile0"}'])
+presenceSensorObject.setValue([name: "presence", value: "not present", deviceId: "presenceSensorID0", descriptionText: "",
+displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"presence":"1","dni":"mobile0"}'])
+presenceSensorObject.setValue([name: "presence", value: "presence.present", deviceId: "presenceSensorID0", descriptionText: "",
+displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"presence":"1","dni":"mobile0"}'])
+
+smokeDetectorObject.setValue([name: "smoke", value: "clear", deviceId: "smokeDetectorID0", descriptionText: "",
+displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
+smokeDetectorObject.setValue([name: "smoke", value: "detected", deviceId: "smokeDetectorID0", descriptionText: "",
+displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
+smokeDetectorObject.setValue([name: "smoke", value: "tested", deviceId: "smokeDetectorID0", descriptionText: "",
+displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
+smokeDetectorObject.setValue([name: "carbonMonoxide", value: "clear", deviceId: "smokeDetectorID0", descriptionText: "",
+displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
+smokeDetectorObject.setValue([name: "carbonMonoxide", value: "detected", deviceId: "smokeDetectorID0", descriptionText: "",
+displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
+smokeDetectorObject.setValue([name: "carbonMonoxide", value: "tested", deviceId: "smokeDetectorID0", descriptionText: "",
+displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
+smokeDetectorObject.setValue([name: "battery", value: "5"/*A number between 0 to 100 as a charge*/, deviceId: "smokeDetectorID0", descriptionText: "",
+displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
+
+thermostatObject.setValue([name: "thermostatMode", value: "auto", deviceId: "thermostatID0", descriptionText: "",
+displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
+thermostatObject.setValue([name: "thermostatMode", value: "cool", deviceId: "thermostatID0", descriptionText: "",
+displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
+thermostatObject.setValue([name: "thermostatMode", value: "emergencyHeat", deviceId: "thermostatID0", descriptionText: "",
+displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
+thermostatObject.setValue([name: "thermostatMode", value: "heat", deviceId: "thermostatID0", descriptionText: "",
+displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
+thermostatObject.setValue([name: "thermostatMode", value: "off", deviceId: "thermostatID0", descriptionText: "",
+displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
+thermostatObject.setValue([name: "temperature", value: "55", deviceId: "thermostatID0", descriptionText: "",
+displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
+thermostatObject.setValue([name: "heatingSetpoint", value: "40", deviceId: "thermostatID0", descriptionText: "",
+displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
+thermostatObject.setValue([name: "coolingSetpoint", value: "60", deviceId: "thermostatID0", descriptionText: "",
+displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
+thermostatObject.setValue([name: "thermostatSetpoint", value: "50", deviceId: "thermostatID0", descriptionText: "",
+displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
+thermostatObject.setValue([name: "thermostatFanMode", value: "auto", deviceId: "thermostatID0", descriptionText: "",
+displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
+thermostatObject.setValue([name: "thermostatFanMode", value: "fanCirculate", deviceId: "thermostatID0", descriptionText: "",
+displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
+thermostatObject.setValue([name: "thermostatFanMode", value: "circulate", deviceId: "thermostatID0", descriptionText: "",
+displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
+thermostatObject.setValue([name: "thermostatFanMode", value: "fanOn", deviceId: "thermostatID0", descriptionText: "",
+displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
+thermostatObject.setValue([name: "thermostatFanMode", value: "on", deviceId: "thermostatID0", descriptionText: "",
+displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
+thermostatObject.setValue([name: "thermostatOperatingState", value: "auto", deviceId: "thermostatID0", descriptionText: "",
+displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
+thermostatObject.setValue([name: "thermostatOperatingState", value: "cool", deviceId: "thermostatID0", descriptionText: "",
+displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
+thermostatObject.setValue([name: "thermostatOperatingState", value: "off", deviceId: "thermostatID0", descriptionText: "",
+displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
+thermostatObject.setValue([name: "thermostatOperatingState", value: "emergencyHeat", deviceId: "thermostatID0", descriptionText: "",
+displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
+thermostatObject.setValue([name: "thermostatOperatingState", value: "heat", deviceId: "thermostatID0", descriptionText: "",
+displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
+
+switchObject.setValue([name: "switch", value: "off", deviceId: "switchID0", descriptionText: "",
+displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
+switchObject.setValue([name: "switch", value: "on", deviceId: "switchID0", descriptionText: "",
+displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
+
+appObject.setValue([name: "Touched", value: "touched", deviceId: "touchedSensorID0", descriptionText: "",
+displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
+
+touchSensorObject.setValue([name: "nfcTouch", value: "touched", deviceId: "nfcSensorID0", descriptionText: "",
+displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
+
+aeonKeyFobObject.setValue([name: "button", value: "pushed", deviceId: "aeonKeyFobID0", descriptionText: "",
+displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
+aeonKeyFobObject.setValue([name: "button", value: "held", deviceId: "aeonKeyFobID0", descriptionText: "",
+displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
+
+accelerationSensorObject.setValue([name: "acceleration", value: "active", deviceId: "accelerationSensorID0", descriptionText: "",
+displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
+accelerationSensorObject.setValue([name: "acceleration", value: "inactive", deviceId: "accelerationSensorID0", descriptionText: "",
+displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
+
+batteryObject.setValue([name: "battery", value: "50"/*number between 0 to 100 as a string*/, deviceId: "batteryID0", descriptionText: "",
+displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
+
+beaconSensorObject.setValue([name: "presence", value: "present", deviceId: "beaconeSensorID0", descriptionText: "",
+displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"presence":"1","dni":"mobile0"}'])
+beaconSensorObject.setValue([name: "presence", value: "not present", deviceId: "beaconSensorID0", descriptionText: "",
+displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"presence":"1","dni":"mobile0"}'])
+
+carbonMonoxideDetectorObject.setValue([name: "carbonMonoxide", value: "clear", deviceId: "carbonMonoxideDetectorID0", descriptionText: "",
+displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
+carbonMonoxideDetectorObject.setValue([name: "carbonMonoxide", value: "detected", deviceId: "carbonMonoxideDetectorID0", descriptionText: "",
+displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
+carbonMonoxideDetectorObject.setValue([name: "carbonMonoxide", value: "tested", deviceId: "carbonMonoxideDetectorID0", descriptionText: "",
+displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
+
+colorControlObject.setValue([name: "color", value: "red", deviceId: "colorControlID0", descriptionText: "",
+displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
+colorControlObject.setValue([name: "hue", value: "50", deviceId: "colorControlID0", descriptionText: "",
+displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
+colorControlObject.setValue([name: "saturation", value: "50", deviceId: "colorControlID0", descriptionText: "",
+displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
+
+energyMeterObject.setValue([name: "energy", value: "45"/*A number between 0 to 100 as a charge*/, deviceId: "energyMeterID0", descriptionText: "",
+displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
+
+illuminanceMeasurementObject.setValue([name: "illuminance", value: "70"/*A number between 0 to 100 as a charge*/, deviceId: "illuminanceMeasurementID0", descriptionText: "",
+displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
+
+powerMeterObject.setValue([name: "power", value: "70"/*A number between 0 to 100 as a charge*/, deviceId: "powerMeterID0", descriptionText: "",
+displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
+
+humidityMeasurementObject.setValue([name: "humidity", value: "70"/*A number between 0 to 100 as a charge*/, deviceId: "humidityMeasurementID0", descriptionText: "",
+displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
+
+switchObject.setValue([name: "switch", value: "off", deviceId: "relaySwitchID0", descriptionText: "",
+displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
+switchObject.setValue([name: "switch", value: "on", deviceId: "relaySwitchID0", descriptionText: "",
+displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
+
+sleepSensorObject.setValue([name: "sleeping", value: "sleeping", deviceId: "sleepSensorID0", descriptionText: "",
+displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
+sleepSensorObject.setValue([name: "sleeping", value: "not sleeping", deviceId: "sleepSensorID0", descriptionText: "",
+displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
+
+stepSensorObject.setValue([name: "goal", value: "100"/*A number*/, deviceId: "stepSensorID0", descriptionText: "",
+displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
+stepSensorObject.setValue([name: "steps", value: "46"/*A number*/, deviceId: "stepSensorID0", descriptionText: "",
+displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
+
+switchLevelObject.setValue([name: "level", value: "45"/*A number between 0 to 100*/, deviceId: "switchLevelID0", descriptionText: "",
+displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
+
+temperatureMeasurementObject.setValue([name: "temperature", value: "45"/*A number between 0 to 100*/, deviceId: "temperatureMeasurementID0", descriptionText: "",
+displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
+
+valveObject.setValue([name: "contact", value: "closed", deviceId: "valveID0", descriptionText: "",
+displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
+valveObject.setValue([name: "contact", value: "open", deviceId: "valveID0", descriptionText: "",
+displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
+
+waterSensorObject.setValue([name: "water", value: "dry", deviceId: "waterSensorID0", descriptionText: "",
+displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
+waterSensorObject.setValue([name: "water", value: "wet", deviceId: "waterSensorID0", descriptionText: "",
+displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
diff --git a/AtomicState/AtomicState.groovy b/AtomicState/AtomicState.groovy
new file mode 100644 (file)
index 0000000..a57a4a3
--- /dev/null
@@ -0,0 +1,21 @@
+//Create a class for atomic state
+package AtomicState
+
+public class AtomicState {
+       def bucketKey
+       def accessKey
+       def bucketName
+       def isBucketCreated
+       def grokerSubdomain
+       def eventBuffer
+       def version
+       def isDisabled
+       def queue
+       def poll
+
+       AtomicState() {
+               this.version = "1.0"
+               this.accessKey = 15
+               this.bucketKey = 20
+       }
+}
index ce4a187..8aca5e2 100644 (file)
@@ -2,6 +2,9 @@
 package Battery
 import Timer.SimulatedTimer
 
+//JPF's Verify API
+import gov.nasa.jpf.vm.Verify
+
 public class Batteries {
        private int deviceNumbers
        private List batteries
@@ -12,7 +15,7 @@ public class Batteries {
        private String label = "battery0"
        private String displayName = "battery0"
        private int battery = 50
-       private String currentBattery = 50
+       private int currentBattery = 50
 
                
        Batteries(Closure sendEvent, int deviceNumbers) {
@@ -20,6 +23,9 @@ public class Batteries {
                this.deviceNumbers = deviceNumbers
                this.batteries = []
 
+               def init = Verify.getIntFromList(30, 50, 70)
+               this.battery = init
+
                batteries.add(new Battery(id, label, displayName, this.battery))
        }
 
index df299eb..5358fbd 100644 (file)
@@ -6,10 +6,10 @@ public class Battery {
        private String id
        private String label
        private String displayName
-       private String battery
-       private String currentBattery
+       private int battery
+       private int currentBattery
 
-       Battery(String id, String label, String displayName, String battery) {
+       Battery(String id, String label, String displayName, int battery) {
                this.id = id
                this.label = label
                this.displayName = displayName
index 24bcfc8..33dd1fe 100644 (file)
@@ -2,6 +2,9 @@
 package BeaconSensor
 import Timer.SimulatedTimer
 
+//JPF's Verify API
+import gov.nasa.jpf.vm.Verify
+
 public class BeaconSensors {
        private int deviceNumbers
        private List beaconSensors
@@ -21,6 +24,14 @@ public class BeaconSensors {
                this.deviceNumbers = deviceNumbers
                this.beaconSensors = []
 
+               def init = Verify.getBoolean()
+               if (init) {
+                       this.presence = "not present"
+                       this.presenceLatestValue = "not present"
+               } else {
+                       this.presence = "present"
+                       this.presenceLatestValue = "present"
+               }
                beaconSensors.add(new BeaconSensor(id, label, displayName, this.presence, this.presenceLatestValue))
        }
 
index 7e848e3..2eb9d74 100644 (file)
@@ -2,6 +2,9 @@
 package CarbonMonoxideDetector
 import Timer.SimulatedTimer
 
+//JPF's Verify API
+import gov.nasa.jpf.vm.Verify
+
 public class CarbonMonoxideDetectors {
        private int deviceNumbers
        private List carbonMonoxideDetectors
@@ -20,7 +23,18 @@ public class CarbonMonoxideDetectors {
                this.sendEvent = sendEvent              
                this.deviceNumbers = deviceNumbers
                this.carbonMonoxideDetectors = []
-
+               
+               def init = Verify.getInt(0,2)
+               if (init == 0) {
+                       this.carbonMonoxide = "clear"
+                       this.carbonMonoxideLatestValue = "clear"
+               } else if (init == 1) {
+                       this.carbonMonoxide = "detected"
+                       this.carbonMonoxideLatestValue = "detected"
+               } else {
+                       this.carbonMonoxide = "tested"
+                       this.carbonMonoxideLatestValue = "tested"               
+               }
                carbonMonoxideDetectors.add(new CarbonMonoxideDetector(id, label, displayName, this.currentCarbonMonoxideValue, this.carbonMonoxideLatestValue))
        }
 
index 1c2665c..ac80290 100644 (file)
@@ -22,13 +22,13 @@ public class ColorControl {
        
        //By model checker
        def setValue(String value, String name) {
-               if (name == "color") {
+               if ((name == "color") && (value != this.color)) {
                        this.color = value
                        println("the color of the light is changed to $value!")
-               } else if (name == "hue") {
+               } else if ((name == "hue") && (value != this.hue)) {
                        this.hue = value.toInteger()
                        println("The hue level of the light is changed to $value!")
-               } else {
+               } else if (value != this.saturation) {
                        this.saturation = value.toInteger()
                        println("The saturation level of the light is changed to $value!")
                }
@@ -36,24 +36,30 @@ public class ColorControl {
 
        //methods
        def setColor(String color) {
-               this.color = color
-               println("The color of the light is changed to $color!")
-               sendEvent([name: "color", value: "$color", deviceId: this.id, descriptionText: "",
-                          displayed: true, linkText: "", isStateChange: false, unit: "", data: [value: "$color"]]) 
+               if (color != this.color) {
+                       this.color = color
+                       println("The color of the light is changed to $color!")
+                       sendEvent([name: "color", value: "$color", deviceId: this.id, descriptionText: "",
+                                  displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
+               }
        }
 
        def setHue(int hue) {
-               this.hue = hue
-               println("The hue level of the light is changed to $hue!")
-               sendEvent([name: "hue", value: "$hue", deviceId: this.id, descriptionText: "",
-                          displayed: true, linkText: "", isStateChange: false, unit: "", data: [value: "$hue"]]) 
+               if (hue != this.hue) {
+                       this.hue = hue
+                       println("The hue level of the light is changed to $hue!")
+                       sendEvent([name: "hue", value: "$hue", deviceId: this.id, descriptionText: "",
+                                  displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
+               }
        }
 
        def setSaturation(int saturation) {
-               this.saturation = saturation
-               println("The saturation level of the light is changed to $saturation!")
-               sendEvent([name: "saturation", value: "$saturation", deviceId: this.id, descriptionText: "",
-                          displayed: true, linkText: "", isStateChange: false, unit: "", data: [value: "$saturation"]]) 
+               if (saturation != this.saturation) {
+                       this.saturation = saturation
+                       println("The saturation level of the light is changed to $saturation!")
+                       sendEvent([name: "saturation", value: "$saturation", deviceId: this.id, descriptionText: "",
+                                  displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
+               }
        }
 
        def currentValue(String deviceFeature) {
index b3a6471..d96b978 100644 (file)
@@ -2,6 +2,8 @@
 package ColorControl
 import Timer.SimulatedTimer
 
+//JPF's Verify API
+import gov.nasa.jpf.vm.Verify
 
 public class ColorControls {
        private int deviceNumbers
@@ -22,6 +24,19 @@ public class ColorControls {
                this.deviceNumbers = deviceNumbers
                this.colorControls = []
 
+               def initHue = Verify.getIntFromList(30, 50, 70)
+               this.hue = initHue
+               def initSat = Verify.getIntFromList(40, 50, 60)
+               this.saturation = initSat
+               def init = Verify.getInt(0,2)
+               if (init == 0) {
+                       this.color = "red"
+               } else if (init == 1) {
+                       this.color = "green"
+               } else {
+                       this.color = "blue"
+               }
+
                colorControls.add(new ColorControl(id, label, displayName, this.color, this.hue, this.saturation))
        }
 
@@ -68,18 +83,24 @@ public class ColorControls {
 
        //methods
        def setColor(String color) {
-               colorControls[0].setColor(color)
-               this.color = color      
+               if (color != this.color) {
+                       colorControls[0].setColor(color)
+                       this.color = color
+               }
        }
 
        def setHue(int hue) {
-               colorControls[0].setHue(hue)
-               this.hue = hue  
+               if (hue != this.hue) {          
+                       colorControls[0].setHue(hue)
+                       this.hue = hue
+               }
        }
 
        def setSaturation(int saturation) {
-               colorControls[0].setSaturation(saturation)
-               this.saturation = saturation    
+               if (saturation != this.saturation) {
+                       colorControls[0].setSaturation(saturation)
+                       this.saturation = saturation
+               }       
        }
 
        def currentValue(String deviceFeature) {
index 1de8c76..489200d 100644 (file)
@@ -2,6 +2,9 @@
 package ContactSensor
 import Timer.SimulatedTimer
 
+//JPF's Verify API
+import gov.nasa.jpf.vm.Verify
+
 public class ContactSensors {
        private int deviceNumbers
        private List contacts
@@ -22,6 +25,23 @@ 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 4317849..1830070 100644 (file)
@@ -23,38 +23,46 @@ public class DoorControl {
 
        //By Apps
        def open() {
-               println("the door with id:$id is open!")
-               this.doorLatestValue = this.doorState
-               this.doorState = "open"
-               sendEvent([name: "doorControl", value: "open", deviceId: this.id, descriptionText: "",
-                   displayed: true, linkText: "", isStateChange: false, unit: "", data: [value: "open"]])
-       }
-
-       def open(LinkedHashMap metaData) {
-               def task = timers.runAfter(metaData["delay"]) {
+               if (doorState != "open") {
                        println("the door with id:$id is open!")
                        this.doorLatestValue = this.doorState
                        this.doorState = "open"
                        sendEvent([name: "doorControl", value: "open", deviceId: this.id, descriptionText: "",
-                           displayed: true, linkText: "", isStateChange: false, unit: "", data: [value: "open"]])
+                           displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
                }
        }
 
-       def close() {
-               println("the door with id:$id is closed!")
-               this.doorLatestValue = this.doorState
-               this.doorState = "closed"
-               sendEvent([name: "doorControl", value: "closed", deviceId: this.id, descriptionText: "",
-                   displayed: true, linkText: "", isStateChange: false, unit: "", data: [value: "closed"]])
+       def open(LinkedHashMap metaData) {
+               if (doorState != "open") {
+                       def task = timers.runAfter(metaData["delay"]) {
+                               println("the door with id:$id is open!")
+                               this.doorLatestValue = this.doorState
+                               this.doorState = "open"
+                               sendEvent([name: "doorControl", value: "open", deviceId: this.id, descriptionText: "",
+                                   displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
+                       }
+               }
        }
 
-       def close(LinkedHashMap metaData) {
-               def task = timers.runAfter(metaData["delay"]) {
+       def close() {
+               if (doorState != "closed") {
                        println("the door with id:$id is closed!")
                        this.doorLatestValue = this.doorState
                        this.doorState = "closed"
                        sendEvent([name: "doorControl", value: "closed", deviceId: this.id, descriptionText: "",
-                           displayed: true, linkText: "", isStateChange: false, unit: "", data: [value: "closed"]])
+                           displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
+               }
+       }
+
+       def close(LinkedHashMap metaData) {
+               if (doorState != "closed") {
+                       def task = timers.runAfter(metaData["delay"]) {
+                               println("the door with id:$id is closed!")
+                               this.doorLatestValue = this.doorState
+                               this.doorState = "closed"
+                               sendEvent([name: "doorControl", value: "closed", deviceId: this.id, descriptionText: "",
+                                   displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
+                       }
                }
        }
 
index 9210899..2581800 100644 (file)
@@ -2,6 +2,9 @@
 package DoorControl
 import Timer.SimulatedTimer
 
+//JPF's Verify API
+import gov.nasa.jpf.vm.Verify
+
 public class DoorControls {
        int deviceNumbers       
        List doorControls
@@ -21,6 +24,14 @@ public class DoorControls {
                this.deviceNumbers = deviceNumbers
                this.doorControls = []
                
+               def init = Verify.getBoolean()
+               if (init) {
+                       this.doorState = "closed"
+                       this.doorLatestValue = "closed"
+               } else {
+                       this.doorState = "open"
+                       this.doorLatestValue = "open"
+               }
                doorControls.add(new DoorControl(sendEvent, id, label, displayName, this.doorState, this.doorLatestValue))
        }
 
@@ -43,22 +54,28 @@ public class DoorControls {
 
        //By Apps
        def open() {
-               doorControls[0].on()
+               if (doorState != "open")
+                       doorControls[0].open()
        }
 
        def open(LinkedHashMap metaData) {
-               def task = timers.runAfter(metaData["delay"]) {
-                       doorControls[0].on()
+               if (doorState != "open") {
+                       def task = timers.runAfter(metaData["delay"]) {
+                               doorControls[0].open()
+                       }
                }
        }
 
        def close() {
-               doorControls[0].off()
+               if (doorState != "closed")
+                       doorControls[0].close()
        }
 
        def close(LinkedHashMap metaData) {
-               def task = timers.runAfter(metaData["delay"]) {
-                       doorControls[0].off()
+               if (doorState != "closed") {
+                       def task = timers.runAfter(metaData["delay"]) {
+                               doorControls[0].close()
+                       }
                }
        }
 
index 0274eef..a0ab13e 100644 (file)
@@ -6,9 +6,10 @@ public class EnergyMeter {
        private String id
        private String label
        private String displayName
-       private String energy
+       private int energy
+       private int currentEnergy
 
-       EnergyMeter(String id, String label, String displayName, String energy) {
+       EnergyMeter(String id, String label, String displayName, int energy) {
                this.id = id
                this.label = label
                this.displayName = displayName
@@ -18,8 +19,8 @@ public class EnergyMeter {
        //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 currentValue(String deviceFeature) {
index caec875..a3f2b8d 100644 (file)
@@ -2,6 +2,9 @@
 package EnergyMeter
 import Timer.SimulatedTimer
 
+//JPF's Verify API
+import gov.nasa.jpf.vm.Verify
+
 public class EnergyMeters {
        private int deviceNumbers
        private List energyMeters
@@ -12,6 +15,7 @@ public class EnergyMeters {
        private String label = "energyMeter0"
        private String displayName = "energyMeter0"
        private int energy = 50
+       private int currentEnergy = 50
 
                
        EnergyMeters(Closure sendEvent, int deviceNumbers) {
@@ -19,6 +23,9 @@ public class EnergyMeters {
                this.deviceNumbers = deviceNumbers
                this.energyMeters = []
 
+               def init = Verify.getIntFromList(30, 50, 70)
+               this.energy = init
+
                energyMeters.add(new EnergyMeter(id, label, displayName, this.energy))
        }
 
@@ -27,6 +34,7 @@ public class EnergyMeters {
                if (eventDataMap["value"] != energyMeters[0].energy) {
                        energyMeters[0].setValue(eventDataMap["value"])
                        this.energy = energyMeters[0].energy
+                       this.currentEnergy = energyMeters[0].currentEnergy              
                        sendEvent(eventDataMap)
                }
        }
index 1ef8f77..816ea92 100644 (file)
@@ -11,11 +11,12 @@ public class Event {
        private String descriptionText
        private boolean isStateChange
        private String unit
-       private LinkedHashMap data
+       private String data
        private int integerValue
-       private List integerValues = ["battery", "hue", "saturation", "energy", "level", "temperature", "heatingSetpoint", "coolingSetpoint", "thermostatSetpoint"]
+       private List integerValues = ["battery", "hue", "saturation", "energy", "level", "temperature", 
+                                     "heatingSetpoint", "coolingSetpoint", "thermostatSetpoint", "illuminance"]
        
-       Event(String value, String name, String deviceId, String descriptionText, boolean displayed, String linkText, String displayName, boolean isStateChange, String unit, LinkedHashMap data) {
+       Event(String value, String name, String deviceId, String descriptionText, boolean displayed, String linkText, String displayName, boolean isStateChange, String unit, String data) {
                this.deviceId = deviceId
                this.linkText = linkText
                this.value = value
index 299b494..49a97c3 100644 (file)
 /**
- *  Lock it at a specific time
+ *  groveStreams
  *
- *  Copyright 2014 Erik Thayer
+ *  Copyright 2014 Yves Racine
  *
- *  Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
- *  in compliance with the License. You may obtain a copy of the License at:
+ *  LinkedIn profile: ca.linkedin.com/pub/yves-racine-m-sc-a/0/406/4b/
  *
- *      http://www.apache.org/licenses/LICENSE-2.0
+ *  Developer retains all right, title, copyright, and interest, including all copyright, patent rights, trade secret 
+ *  in the Background technology. May be subject to consulting fees under the Agreement between the Developer and the Customer. 
+ *  Developer grants a non exclusive perpetual license to use the Background technology in the Software developed for and delivered 
+ *  to Customer under this Agreement. However, the Customer shall make no commercial use of the Background technology without
+ *  Developer's written consent.
  *
  *  Unless required by applicable law or agreed to in writing, software distributed under the License is distributed
- *  on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License
- *  for the specific language governing permissions and limitations under the License.
+ *  on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 
+ *  Software Distribution is restricted and shall be done only with Developer's written approval.
  *
+ *  Based on code from Jason Steele & Minollo
+ *  Adapted to be compatible with MyEcobee and My Automatic devices which are available at my store:
+ *          http://www.ecomatiqhomes.com/#!store/tc3yr 
+ * 
  */
 definition(
-    name: "Lock it at a specific time",
-    namespace: "user8798",
-    author: "Erik Thayer",
-    description: "Make sure a door is locked at a specific time.  Option to add door contact sensor to only lock if closed.",
-    category: "Safety & Security",
-    iconUrl: "https://s3.amazonaws.com/smartapp-icons/Convenience/Cat-Convenience.png",
-    iconX2Url: "https://s3.amazonaws.com/smartapp-icons/Convenience/Cat-Convenience@2x.png"
+       name: "groveStreams",
+       namespace: "yracine",
+       author: "Yves Racine",
+       description: "Log to groveStreams and send data streams based on devices selection",
+       category: "My Apps",
+       iconUrl: "https://s3.amazonaws.com/smartapp-icons/Partner/ecobee.png",
+       iconX2Url: "https://s3.amazonaws.com/smartapp-icons/Partner/ecobee@2x.png"
 )
 
 
+
 preferences {
-  section("At this time every day") {
-    input "time", "time", title: "Time of Day"
-  }
-  section("Make sure this is locked") {
-    input "lock","capability.lock"
-  }
-  section("Make sure it's closed first..."){
-    input "contact", "capability.contactSensor", title: "Which contact sensor?", required: false
-  }
-  section( "Notifications" ) {
-    input "sendPushMessage", "enum", title: "Send a push notification?", metadata:[values:["Yes", "No"]], required: false
-    input "phone", "phone", title: "Send a text message?", required: false
-  } 
+       section("About") {
+               paragraph "groveStreams, the smartapp that sends your device states to groveStreams for data correlation"
+               paragraph "Version 2.2.2" 
+               paragraph "If you like this smartapp, please support the developer via PayPal and click on the Paypal link below " 
+                       href url: "https://www.paypal.me/ecomatiqhomes",
+                               title:"Paypal donation..."
+               paragraph "Copyright©2014 Yves Racine"
+                       href url:"http://github.com/yracine/device-type.myecobee", style:"embedded", required:false, title:"More information..."  
+                               description: "http://github.com/yracine"
+       }
+       section("Log devices...") {
+               input "temperatures", "capability.temperatureMeasurement", title: "Temperatures", required: false, multiple: true
+               input "thermostats", "capability.thermostat", title: "Thermostats", required: false, multiple: true
+               //input "ecobees", "device.myEcobeeDevice", title: "Ecobees", required: false, multiple: true
+               input "automatic", "capability.presenceSensor", title: "Automatic Connected Device(s)", required: false, multiple: true
+               input "detectors", "capability.smokeDetector", title: "Smoke/CarbonMonoxide Detectors", required: false, multiple: true
+               input "humidities", "capability.relativeHumidityMeasurement", title: "Humidity sensors", required: false, multiple: true
+               input "waters", "capability.waterSensor", title: "Water sensors", required: false, multiple: true
+               input "illuminances", "capability.illuminanceMeasurement", title: "Illuminance sensor", required: false, multiple: true
+               input "locks", "capability.lock", title: "Locks", required: false, multiple: true
+               input "contacts", "capability.contactSensor", title: "Doors open/close", required: false, multiple: true
+               input "accelerations", "capability.accelerationSensor", title: "Accelerations", required: false, multiple: true
+               input "motions", "capability.motionSensor", title: "Motions", required: false, multiple: true
+               input "presence", "capability.presenceSensor", title: "Presence", required: false, multiple: true
+               input "switches", "capability.switch", title: "Switches", required: false, multiple: true
+               input "dimmerSwitches", "capability.switchLevel", title: "Dimmer Switches", required: false, multiple: true
+               input "batteries", "capability.battery", title: "Battery-powered devices", required: false, multiple: true
+               input "powers", "capability.powerMeter", title: "Power Meters", required: false, multiple: true
+               input "energys", "capability.energyMeter", title: "Energy Meters", required: false, multiple: true
+
+       }
+
+       section("GroveStreams Feed PUT API key...") {
+               input "channelKey", "text", title: "API key"
+       }
+       section("Sending data at which interval in minutes (default=5)?") {
+               input "givenInterval", "number", title: 'Send Data Interval', required: false
+       }
 }
+
 def installed() {
-  schedule(time, "setTimeCallback")
-
-}
-
-def updated(settings) {
-  unschedule()
-  schedule(time, "setTimeCallback")
-}
-
-def setTimeCallback() {
-  if (contact) {
-    doorOpenCheck()
-  } else {
-    lockMessage()
-    lock.lock()
-  }
-}
-def doorOpenCheck() {
-  def currentState = contact.contactState
-  if (currentState?.value == "open") {
-    def msg = "${contact.displayName} is open.  Scheduled lock failed."
-    log.info msg
-    if (sendPushMessage) {
-      sendPush msg
-    }
-    if (phone) {
-      sendSms phone, msg
-    }
-  } else {
-    lockMessage()
-    lock.lock()
-  }
-}
-
-def lockMessage() {
-  def msg = "Locking ${lock.displayName} due to scheduled lock."
-  log.info msg
-  if (sendPushMessage) {
-    sendPush msg
-  }
-  if (phone) {
-    sendSms phone, msg
-  }
+       initialize()
+}
+
+def updated() {
+       unsubscribe()
+       unschedule()
+       initialize()
+}
+
+def initialize() {
+       subscribe(temperatures, "temperature", handleTemperatureEvent)
+       subscribe(humidities, "humidity", handleHumidityEvent)
+       subscribe(waters, "water", handleWaterEvent)
+       subscribe(waters, "water", handleWaterEvent)
+       subscribe(detectors, "smoke", handleSmokeEvent)
+       subscribe(detectors, "carbonMonoxide", handleCarbonMonoxideEvent)
+       subscribe(illuminances, "illuminance", handleIlluminanceEvent)
+       subscribe(contacts, "contact", handleContactEvent)
+       subscribe(locks, "lock", handleLockEvent)
+       subscribe(accelerations, "acceleration", handleAccelerationEvent)
+       subscribe(motions, "motion", handleMotionEvent)
+       subscribe(presence, "presence", handlePresenceEvent)
+       subscribe(switches, "switch", handleSwitchEvent)
+       subscribe(dimmerSwitches, "switch", handleSwitchEvent)
+       subscribe(dimmerSwitches, "level", handleSetLevelEvent)
+       subscribe(batteries, "battery", handleBatteryEvent)
+       subscribe(powers, "power", handlePowerEvent)
+       subscribe(energys, "energy", handleEnergyEvent)
+       subscribe(energys, "cost", handleCostEvent)
+       subscribe(thermostats, "heatingSetpoint", handleHeatingSetpointEvent)
+       subscribe(thermostats, "coolingSetpoint", handleCoolingSetpointEvent)
+       subscribe(thermostats, "thermostatMode", handleThermostatModeEvent)
+       subscribe(thermostats, "fanMode", handleFanModeEvent)
+       subscribe(thermostats, "thermostatOperatingState", handleThermostatOperatingStateEvent)
+       /*subscribe(ecobees, "dehumidifierMode", handleDehumidifierModeEvent)
+       subscribe(ecobees, "equipmentStatus", handleEquipmentStatusEvent)
+       subscribe(ecobees, "dehumidifierLevel", handleDehumidifierLevelEvent)
+       subscribe(ecobees, "humidifierMode", handleHumidifierModeEvent)
+       subscribe(ecobees, "humidifierLevel", handleHumidifierLevelEvent)
+       subscribe(ecobees, "fanMinOnTime", handleFanMinOnTimeEvent)
+       subscribe(ecobees, "ventilatorMode", handleVentilatorModeEvent)
+       subscribe(ecobees, "ventilatorMinOnTime", handleVentilatorMinOnTimeEvent)
+       subscribe(ecobees, "programScheduleName", handleProgramNameEvent)
+       subscribe(ecobees, "auxHeat1RuntimeDaily", handleDailyStats)
+       subscribe(ecobees, "auxHeat2RuntimeDaily", handleDailyStats)
+       subscribe(ecobees, "auxHeat3RuntimeDaily", handleDailyStats)
+       subscribe(ecobees, "compCool1RuntimeDaily", handleDailyStats)
+       subscribe(ecobees, "compCool2RuntimeDaily", handleDailyStats)
+       subscribe(ecobees, "fanRuntimeDaily", handleDailyStats)
+       subscribe(ecobees, "humidifierRuntimeDaily", handleDailyStats)
+       subscribe(ecobees, "dehumidifierRuntimeDaily", handleDailyStats)
+       subscribe(ecobees, "ventilatorRuntimeDaily", handleDailyStats)
+       subscribe(ecobees, "presence", handlePresenceEvent)
+       subscribe(ecobees, "compCool2RuntimeDaily", handleDailyStats)*/
+       subscribe(automatic, "yesterdayTripsAvgAverageKmpl",handleDailyStats)
+       subscribe(automatic, "yesterdayTripsAvgDistanceM",handleDailyStats)
+       subscribe(automatic, "yesterdayTripsAvgDurationS",handleDailyStats)
+       subscribe(automatic, "yesterdayTotalDistanceM",handleDailyStats)
+       subscribe(automatic, "yesterdayTripsAvgFuelVolumeL",handleDailyStats)
+       subscribe(automatic, "yesterdayTotalFuelVolumeL",handleDailyStats)
+       subscribe(automatic, "yesterdayTotalDurationS:",handleDailyStats)
+       subscribe(automatic, "yesterdayTotalNbTrips",handleDailyStats)
+       subscribe(automatic, "yesterdayTotalHardAccels",handleDailyStats)
+       subscribe(automatic, "yesterdayTotalHardBrakes:",handleDailyStats)
+       subscribe(automatic, "yesterdayTripsAvgScoreSpeeding",handleDailyStats)
+       subscribe(automatic, "yesterdayTripsAvgScoreEvents",handleDailyStats)
+       def queue = []
+       atomicState.queue=queue
+    
+       if (atomicState.queue==null) {
+               atomicState.queue = []
+       }    
+       atomicState?.poll = [ last: 0, rescheduled: now() ]
+
+       Integer delay  = givenInterval ?: 5 // By default, schedule processQueue every 5 min.
+       log.debug "initialize>scheduling processQueue every ${delay} minutes"
+
+       //Subscribe to different events (ex. sunrise and sunset events) to trigger rescheduling if needed
+       subscribe(location, "sunrise", rescheduleIfNeeded)
+       subscribe(location, "sunset", rescheduleIfNeeded)
+       subscribe(location, "mode", rescheduleIfNeeded)
+       subscribe(location, "sunriseTime", rescheduleIfNeeded)
+       subscribe(location, "sunsetTime", rescheduleIfNeeded)
+       subscribe(app, appTouch)
+
+       //rescheduleIfNeeded()   
+}
+
+def appTouch(evt) {
+       rescheduleIfNeeded(evt)
+       processQueue()
+       def queue = []
+       atomicState.queue=queue
+}
+
+
+def rescheduleIfNeeded(evt) {
+       if (evt) log.debug("rescheduleIfNeeded>$evt.name=$evt.value")
+       Integer delay  = givenInterval ?: 5 // By default, schedule processQueue every 5 min.
+       BigDecimal currentTime = now()    
+       BigDecimal lastPollTime = (currentTime - (atomicState?.poll["last"]?:0))  
+       if (lastPollTime != currentTime) {    
+               Double lastPollTimeInMinutes = (lastPollTime/60000).toDouble().round(1)      
+               log.info "rescheduleIfNeeded>last poll was  ${lastPollTimeInMinutes.toString()} minutes ago"
+       }
+       if (((atomicState?.poll["last"]?:0) + (delay * 60000) < currentTime) && canSchedule()) {
+               log.info "rescheduleIfNeeded>scheduling processQueue in ${delay} minutes.."
+               unschedule()  
+               schedule("14:00", processQueue)
+       }
+       // Update rescheduled state
+    
+       if (!evt) {
+               atomicState.poll["rescheduled"] = now()    
+       }        
+}    
+
+def handleTemperatureEvent(evt) {
+       queueValue(evt) {
+               it.toString()
+       }
 }
+
+def handleHumidityEvent(evt) {
+       queueValue(evt) {
+               it.toString()
+       }
+}
+
+def handleHeatingSetpointEvent(evt) {
+       queueValue(evt) {
+               it.toString()
+       }
+}
+def handleCoolingSetpointEvent(evt) {
+       queueValue(evt) {
+               it.toString()
+       }
+}
+
+def handleThermostatModeEvent(evt) {
+       queueValue(evt) {
+               it.toString()
+       }
+}
+def handleFanModeEvent(evt) {
+       queueValue(evt) {
+               it.toString()
+       }
+}
+def handleHumidifierModeEvent(evt) {
+       queueValue(evt) {
+               it.toString()
+       }
+}
+def handleHumidifierLevelEvent(evt) {
+       queueValue(evt) {
+               it.toString()
+       }
+}
+def handleDehumidifierModeEvent(evt) {
+       queueValue(evt) {
+               it.toString()
+       }
+}
+def handleDehumidifierLevelEvent(evt) {
+       queueValue(evt) {
+               it.toString()
+       }
+}
+def handleVentilatorModeEvent(evt) {
+       queueValue(evt) {
+               it.toString()
+       }
+}
+def handleFanMinOnTimeEvent(evt) {
+       queueValue(evt) {
+               it.toString()
+       }
+}
+def handleVentilatorMinOnTimeEvent(evt) {
+       queueValue(evt) {
+               it.toString()
+       }
+}
+
+def handleThermostatOperatingStateEvent(evt) {
+       queueValue(evt) {
+               it == "idle" ? 0 : (it == 'fan only') ? 1 : (it == 'heating') ? 2 : 3
+       }
+
+}
+def handleDailyStats(evt) {
+       queueValue(evt) {
+               it.toString()
+       }
+
+}
+def handleEquipmentStatusEvent(evt) {
+       queueValue(evt) {
+               it.toString()
+       }
+}
+
+def handleProgramNameEvent(evt) {
+       queueValue(evt) {
+               it.toString()
+       }
+}
+
+def handleWaterEvent(evt) {
+       queueValue(evt) {
+               it.toString()
+       }
+}
+def handleSmokeEvent(evt) {
+       queueValue(evt) {
+               it.toString()
+       }
+}
+def handleCarbonMonoxideEvent(evt) {
+       queueValue(evt) {
+               it.toString()
+       }
+}
+
+def handleIlluminanceEvent(evt) {
+       log.debug ("handleIlluminanceEvent> $evt.name= $evt.value")
+       queueValue(evt) {
+               it.toString()
+       }
+}
+
+def handleLockEvent(evt) {
+       queueValue(evt) {
+               it == "locked" ? 1 : 0
+       }
+}
+
+def handleBatteryEvent(evt) {
+       queueValue(evt) {
+               it.toString()
+       }
+}
+
+def handleContactEvent(evt) {
+       queueValue(evt) {
+               it == "open" ? 1 : 0
+       }
+}
+
+def handleAccelerationEvent(evt) {
+       queueValue(evt) {
+               it == "active" ? 1 : 0
+       }
+}
+
+def handleMotionEvent(evt) {
+       queueValue(evt) {
+               it == "active" ? 1 : 0
+       }
+}
+
+def handlePresenceEvent(evt) {
+       queueValue(evt) {
+               it == "present" ? 1 : 0
+       }
+}
+
+def handleSwitchEvent(evt) {
+       queueValue(evt) {
+               it == "on" ? 1 : 0
+       }
+}
+
+def handleSetLevelEvent(evt) {
+       queueValue(evt) {
+               it.toString()
+       }
+}
+
+def handlePowerEvent(evt) {
+       if (evt.value) {
+               queueValue(evt) {
+                       it.toString()
+               }
+       }
+}
+
+def handleEnergyEvent(evt) {
+       if (evt.value) {
+               queueValue(evt) {
+                       it.toString()
+               }
+       }
+}
+def handleCostEvent(evt) {
+       if (evt.value) {
+               queueValue(evt) {
+                       it.toString()
+               }
+       }
+}
+
+private queueValue(evt, Closure convert) {
+       def MAX_QUEUE_SIZE=95000
+       def jsonPayload = [compId: evt.displayName, streamId: evt.name, data: convert(evt.value), time: now()]
+       def queue
+
+       queue = atomicState.queue
+       queue << jsonPayload
+       atomicState.queue = queue    
+       def queue_size = queue.toString().length()
+       def last_item_in_queue = queue[queue.size() -1]    
+       log.debug "queueValue>queue size in chars=${queue_size}, appending ${jsonPayload} to queue, last item in queue= $last_item_in_queue"
+       if (queue_size >  MAX_QUEUE_SIZE) {
+               processQueue()
+       }
+}
+
+def processQueue() {
+       Integer delay  = givenInterval ?: 5 // By default, schedule processQueue every 5 min.
+       atomicState?.poll["last"] = now()
+
+       if (((atomicState?.poll["rescheduled"]?:0) + (delay * 60000)) < now()) {
+               log.info "processQueue>scheduling rescheduleIfNeeded() in ${delay} minutes.."
+               schedule("0 0/${delay} * * * ?", rescheduleIfNeeded)
+               // Update rescheduled state
+               atomicState?.poll["rescheduled"] = now()
+       }
+
+       def queue = atomicState.queue
+    
+   
+       def url = "https://grovestreams.com/api/feed?api_key=${channelKey}"
+       log.debug "processQueue"
+       if (queue != []) {
+               log.debug "Events to be sent to groveStreams: ${queue}"
+
+               /*try {
+                       httpPutJson([uri: url, body: queue]) {response ->
+                               if (response.status != 200) {
+                                       log.debug "GroveStreams logging failed, status = ${response.status}"
+                               } else {
+                                       log.debug "GroveStreams accepted event(s)"
+                                       // reset the queue 
+                                       queue =[]                         
+                                       atomicState.queue = queue                     
+                               }
+                       }
+               } catch (groovyx.net.http.ResponseParseException e) {
+                       // ignore error 200, bogus exception
+                       if (e.statusCode != 200) {
+                               log.error "Grovestreams: ${e}"
+                       } else {
+                               log.debug "GroveStreams accepted event(s)"
+                       }
+                       // reset the queue 
+                       queue =[]                         
+                       atomicState.queue = queue                      
+            
+               } catch (e) {
+                       def errorInfo = "Error sending value: ${e}"
+                       log.error errorInfo
+                       // reset the queue 
+                       queue =[]                         
+                       atomicState.queue = queue                        
+               }*/
+       }
+
+}
+
index 854ab60..3155b29 100644 (file)
@@ -3,8 +3,76 @@ def installed = this.&installed
 //Global Object for functions in subscribe method!
 def updated = this.&updated
 //Global Object for functions in subscribe method!
-def setTimeCallback = this.&setTimeCallback
+def initialize = this.&initialize
 //Global Object for functions in subscribe method!
-def doorOpenCheck = this.&doorOpenCheck
+def appTouch = this.&appTouch
 //Global Object for functions in subscribe method!
-def lockMessage = this.&lockMessage
+def rescheduleIfNeeded = this.&rescheduleIfNeeded
+//Global Object for functions in subscribe method!
+def handleTemperatureEvent = this.&handleTemperatureEvent
+//Global Object for functions in subscribe method!
+def handleHumidityEvent = this.&handleHumidityEvent
+//Global Object for functions in subscribe method!
+def handleHeatingSetpointEvent = this.&handleHeatingSetpointEvent
+//Global Object for functions in subscribe method!
+def handleCoolingSetpointEvent = this.&handleCoolingSetpointEvent
+//Global Object for functions in subscribe method!
+def handleThermostatModeEvent = this.&handleThermostatModeEvent
+//Global Object for functions in subscribe method!
+def handleFanModeEvent = this.&handleFanModeEvent
+//Global Object for functions in subscribe method!
+def handleHumidifierModeEvent = this.&handleHumidifierModeEvent
+//Global Object for functions in subscribe method!
+def handleHumidifierLevelEvent = this.&handleHumidifierLevelEvent
+//Global Object for functions in subscribe method!
+def handleDehumidifierModeEvent = this.&handleDehumidifierModeEvent
+//Global Object for functions in subscribe method!
+def handleDehumidifierLevelEvent = this.&handleDehumidifierLevelEvent
+//Global Object for functions in subscribe method!
+def handleVentilatorModeEvent = this.&handleVentilatorModeEvent
+//Global Object for functions in subscribe method!
+def handleFanMinOnTimeEvent = this.&handleFanMinOnTimeEvent
+//Global Object for functions in subscribe method!
+def handleVentilatorMinOnTimeEvent = this.&handleVentilatorMinOnTimeEvent
+//Global Object for functions in subscribe method!
+def handleThermostatOperatingStateEvent = this.&handleThermostatOperatingStateEvent
+//Global Object for functions in subscribe method!
+def handleDailyStats = this.&handleDailyStats
+//Global Object for functions in subscribe method!
+def handleEquipmentStatusEvent = this.&handleEquipmentStatusEvent
+//Global Object for functions in subscribe method!
+def handleProgramNameEvent = this.&handleProgramNameEvent
+//Global Object for functions in subscribe method!
+def handleWaterEvent = this.&handleWaterEvent
+//Global Object for functions in subscribe method!
+def handleSmokeEvent = this.&handleSmokeEvent
+//Global Object for functions in subscribe method!
+def handleCarbonMonoxideEvent = this.&handleCarbonMonoxideEvent
+//Global Object for functions in subscribe method!
+def handleIlluminanceEvent = this.&handleIlluminanceEvent
+//Global Object for functions in subscribe method!
+def handleLockEvent = this.&handleLockEvent
+//Global Object for functions in subscribe method!
+def handleBatteryEvent = this.&handleBatteryEvent
+//Global Object for functions in subscribe method!
+def handleContactEvent = this.&handleContactEvent
+//Global Object for functions in subscribe method!
+def handleAccelerationEvent = this.&handleAccelerationEvent
+//Global Object for functions in subscribe method!
+def handleMotionEvent = this.&handleMotionEvent
+//Global Object for functions in subscribe method!
+def handlePresenceEvent = this.&handlePresenceEvent
+//Global Object for functions in subscribe method!
+def handleSwitchEvent = this.&handleSwitchEvent
+//Global Object for functions in subscribe method!
+def handleSetLevelEvent = this.&handleSetLevelEvent
+//Global Object for functions in subscribe method!
+def handlePowerEvent = this.&handlePowerEvent
+//Global Object for functions in subscribe method!
+def handleEnergyEvent = this.&handleEnergyEvent
+//Global Object for functions in subscribe method!
+def handleCostEvent = this.&handleCostEvent
+//Global Object for functions in subscribe method!
+def queueValue = this.&queueValue
+//Global Object for functions in subscribe method!
+def processQueue = this.&processQueue
index 5d7c3e8..83899d9 100644 (file)
@@ -1,10 +1,38 @@
-//Global variable for time!
-def time = "15:00"
+//Object for class temperature measurement!
+def temperatures
+//Object for class thermostat!
+def thermostats
+//Object for class presence sensor!
+def automatic
+//Object for class smoke detector!
+def detectors
+//Object for class humidity measurement!
+def humidities
+//Object for class water sensor!
+def waters
+//Object for class illuminance measurement!
+def illuminances
 //Object for class lock!
-def lock
+def locks
 //Object for class contactSensor!
-def contact
-//Global variable for enum!
-def sendPushMessage = "Yes"
-//Global variable for phone!
-def phone = 9495379373
+def contacts
+//Object for class Acceleration Sensor!
+def accelerations
+//Object for class Motion Sensor!
+def motions
+//Object for class presence sensor!
+def presence
+//Object for class switch!
+def switches
+//Object for class switch level!
+def dimmerSwitches
+//Object for class Battery!
+def batteries
+//Object for class power meter!
+def powers
+//Object for class energy meter!
+def energys
+//Global variable for text!
+def channelKey = "This is just a text!"
+//Global variable for number!
+def givenInterval = 75
index 7c95ca5..53906e5 100644 (file)
@@ -1,4 +1,19 @@
-lock = obj.lockObject
-contact = obj.contactObject
+temperatures = obj.temperatureMeasurementObject
+thermostats = obj.thermostatObject
+automatic = obj.presenceSensorObject
+detectors = obj.smokeDetectorObject
+humidities = obj.humidityMeasurementObject
+waters = obj.waterSensorObject
+illuminances = obj.illuminanceMeasurementObject
+locks = obj.lockObject
+contacts = obj.contactObject
+accelerations = obj.accelerationSensorObject
+motions = obj.motionSensorObject
+presence = obj.presenceSensorObject
+switches = obj.switchObject
+dimmerSwitches = obj.switchLevelObject
+batteries = obj.batteryObject
+powers = obj.powerMeterObject
+energys = obj.energyMeterObject
 //Global variable for settings!
-settings = [app:app, time:time, lock:lock, contact:contact, sendPushMessage:sendPushMessage, phone:phone]
+settings = [app:app, temperatures:temperatures, thermostats:thermostats, automatic:automatic, detectors:detectors, humidities:humidities, waters:waters, illuminances:illuminances, locks:locks, contacts:contacts, accelerations:accelerations, motions:motions, presence:presence, switches:switches, dimmerSwitches:dimmerSwitches, batteries:batteries, powers:powers, energys:energys, channelKey:channelKey, givenInterval:givenInterval]
index 497be41..86096f4 100644 (file)
@@ -1,7 +1,7 @@
 /**
- *  NFC Tag Toggle
+ *  Notify If Left Unlocked
  *
- *  Copyright 2014 SmartThings
+ *  Copyright 2014 George Sudarkoff
  *
  *  Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
  *  in compliance with the License. You may obtain a copy of the License at:
  *  for the specific language governing permissions and limitations under the License.
  *
  */
+
 definition(
-    name: "NFC Tag Toggle",
-    namespace: "smartthings",
-    author: "SmartThings",
-    description: "Allows toggling of a switch, lock, or garage door based on an NFC Tag touch event",
-    category: "SmartThings Internal",
-    iconUrl: "https://s3.amazonaws.com/smartapp-icons/Developers/nfc-tag-executor.png",
-    iconX2Url: "https://s3.amazonaws.com/smartapp-icons/Developers/nfc-tag-executor@2x.png",
-    iconX3Url: "https://s3.amazonaws.com/smartapp-icons/Developers/nfc-tag-executor@2x.png")
+    name: "Notify If Left Unlocked",
+    namespace: "com.sudarkoff",
+    author: "George Sudarkoff",
+    description: "Send a push or SMS notification (and lock, if it's closed) if a door is left unlocked for a period of time.",
+    category: "Safety & Security",
+    iconUrl: "https://s3.amazonaws.com/smartapp-icons/Convenience/Cat-Convenience.png",
+    iconX2Url: "https://s3.amazonaws.com/smartapp-icons/Convenience/Cat-Convenience@2x.png")
 
 
 preferences {
-    page(name: "pageOne", title: "Device selection", uninstall: true, nextPage: "pageTwo") {
-        section("Select an NFC tag") {
-            input "tag", "capability.touchSensor", title: "NFC Tag"
-        }
-        section("Select devices to control") {
-            input "switch1", "capability.switch", title: "Light or switch", required: false, multiple: true
-            input "lock", "capability.lock", title: "Lock", required: false, multiple: true
-            input "garageDoor", "capability.doorControl", title: "Garage door controller", required: false, multiple: true
-        }
+    section("If this lock...") {
+        input "aLock", "capability.lock", multiple: false, required: true
+        input "openSensor", "capability.contactSensor", title: "Open/close sensor (optional)", multiple: false, required: false
     }
-    
-    page(name: "pageTwo", title: "Master devices", install: true, uninstall: true)
-}
-
-def pageTwo() {
-       dynamicPage(name: "pageTwo") {
-       section("If set, the state of these devices will be toggled each time the tag is touched, " + 
-                "e.g. a light that's on will be turned off and one that's off will be turned on, " +
-                "other devices of the same type will be set to the same state as their master device. " +
-                "If no master is designated then the majority of devices of the same type will be used " +
-                "to determine whether to turn on or off the devices.") {
-            
-            if (switch1 || masterSwitch) {
-                input "masterSwitch", "enum", title: "Master switch", options: switch1.collect{[(it.id): it.displayName]}, required: false
-            }
-            if (lock || masterLock) {
-                input "masterLock", "enum", title: "Master lock", options: lock.collect{[(it.id): it.displayName]}, required: false
-            }
-            if (garageDoor || masterDoor) {
-                input "masterDoor", "enum", title: "Master door", options: garageDoor.collect{[(it.id): it.displayName]}, required: false
-            }            
-               }
-               section([mobileOnly:true]) {
-                       label title: "Assign a name", required: false
-                       mode title: "Set for specific mode(s)", required: false
-               }        
+    section("Left unlocked for...") {
+        input "duration", "number", title: "How many minutes?", required: true
+    }
+    section("Notify me...") {
+        input "pushNotification", "bool", title: "Push notification"
+        input "phoneNumber", "phone", title: "Phone number (optional)", required: false
+        input "lockIfClosed", "bool", title: "Lock the door if it's closed?"
     }
 }
 
-def installed() {
-       log.debug "Installed with settings: ${settings}"
-
-       initialize()
+def installed()
+{
+    initialize()
 }
 
-def updated() {
-       log.debug "Updated with settings: ${settings}"
-
-       unsubscribe()
-       initialize()
+def updated()
+{
+    unsubscribe()
+    initialize()
 }
 
-def initialize() {
-       subscribe tag, "nfcTouch", touchHandler
-    subscribe app, touchHandler
+def initialize()
+{
+    log.trace "Initializing with: ${settings}"
+    subscribe(aLock, "lock", lockHandler)
 }
 
-private currentStatus(devices, master, attribute) {
-       log.trace "currentStatus($devices, $master, $attribute)"
-       def result = null
-       if (master) {
-       result = devices.find{it.id == master}?.currentValue(attribute)
+def lockHandler(evt)
+{
+    log.trace "${evt.name} is ${evt.value}."
+    if (evt.value == "locked") {
+        log.debug "Canceling lock check because the door is locked..."
+        unschedule(notifyUnlocked)
     }
     else {
-       def map = [:]
-        devices.each {
-               def value = it.currentValue(attribute)
-            map[value] = (map[value] ?: 0) + 1
-            log.trace "$it.displayName: $value"
-        }
-        log.trace map
-        result = map.collect{it}.sort{it.value}[-1].key
+        log.debug "Starting the countdown for ${duration} minutes..."
+        state.retries = 0
+        runIn(duration * 60, notifyUnlocked)
     }
-    log.debug "$attribute = $result"
-    result
 }
 
-def touchHandler(evt) {
-       log.trace "touchHandler($evt.descriptionText)"
-    if (switch1) {
-       def status = currentStatus(switch1, masterSwitch, "switch")
-        switch1.each {
-            if (status == "on") {
-                it.off()
-            }
-            else {
-                it.on()
-            }
+def notifyUnlocked()
+{
+    // if no open/close sensor specified, assume the door is closed
+    def open = openSensor?.latestValue("contact") ?: "closed"
+
+    def message = "${aLock.displayName} is left unlocked and ${open} for more than ${duration} minutes."
+    log.trace "Sending the notification: ${message}."
+    sendMessage(message)
+
+    if (lockIfClosed) {
+        if (open == "closed") {
+            log.trace "And locking the door."
+            sendMessage("Locking the ${aLock.displayName} as prescribed.")
+            aLock.lock()
         }
-    }
-    
-    if (lock) {
-       def status = currentStatus(lock, masterLock, "lock")
-        lock.each {
-            if (status == "locked") {
-                lock.unlock()
+        else {
+            if (state.retries++ < 3) {
+                log.trace "Door is open, can't lock. Rescheduling the check."
+                sendMessage("Can't lock the ${aLock.displayName} because the door is open. Will try again in ${duration} minutes.")
+                runIn(duration * 60, notifyUnlocked)
             }
             else {
-                lock.lock()
+                log.trace "The door is still open after ${state.retries} retries, giving up."
+                sendMessage("Unable to lock the ${aLock.displayName} after ${state.retries} retries, giving up.")
             }
         }
     }
-    
-    if (garageDoor) {
-        def status = currentStatus(garageDoor, masterDoor, "status")
-       garageDoor.each {
-               if (status == "open") {
-               it.close()
-            }
-            else {
-               it.open()
-            }
-        }
+}
+
+def sendMessage(msg) {
+    if (pushNotification) {
+        sendPush(msg)
+    }
+    if (phoneNumber) {
+        sendSMS(phoneNumber, msg)
     }
 }
+
index 058c880..c59c464 100644 (file)
@@ -1,10 +1,12 @@
 //Global Object for functions in subscribe method!
-def pageTwo = this.&pageTwo
-//Global Object for functions in subscribe method!
 def installed = this.&installed
 //Global Object for functions in subscribe method!
 def updated = this.&updated
 //Global Object for functions in subscribe method!
 def initialize = this.&initialize
 //Global Object for functions in subscribe method!
-def touchHandler = this.&touchHandler
+def lockHandler = this.&lockHandler
+//Global Object for functions in subscribe method!
+def notifyUnlocked = this.&notifyUnlocked
+//Global Object for functions in subscribe method!
+def sendMessage = this.&sendMessage
index e542362..09638b3 100644 (file)
@@ -1,14 +1,12 @@
-//Object for class Touch Sensor!
-def tag
-//Object for class switch!
-def switch1
 //Object for class lock!
-def lock
-//Object for class door control!
-def garageDoor
-//Global variable for enum!
-def masterSwitch = "Yes"
-//Global variable for enum!
-def masterLock = "Yes"
-//Global variable for enum!
-def masterDoor = "Yes"
+def aLock
+//Object for class contactSensor!
+def openSensor
+//Global variable for number!
+def duration = 47
+//Global variable for boolean!
+def pushNotification = "0"
+//Global variable for phone!
+def phoneNumber = 9495379373
+//Global variable for boolean!
+def lockIfClosed = "1"
index 6d5a754..cc84ca8 100644 (file)
@@ -1,6 +1,4 @@
-tag = obj.touchSensorObject
-switch1 = obj.switchObject
-lock = obj.lockObject
-garageDoor = obj.doorControlObject
+aLock = obj.lockObject
+openSensor = obj.contactObject
 //Global variable for settings!
-settings = [app:app, tag:tag, switch1:switch1, lock:lock, garageDoor:garageDoor, masterSwitch:masterSwitch, masterLock:masterLock, masterDoor:masterDoor]
+settings = [app:app, aLock:aLock, openSensor:openSensor, duration:duration, pushNotification:pushNotification, phoneNumber:phoneNumber, lockIfClosed:lockIfClosed]
index cf69fbb..309223d 100644 (file)
@@ -48,6 +48,28 @@ import ColorControl.ColorControl
 import ColorControl.ColorControls
 import EnergyMeter.EnergyMeter
 import EnergyMeter.EnergyMeters
+import IlluminanceMeasurement.IlluminanceMeasurement
+import IlluminanceMeasurement.IlluminanceMeasurements
+import PowerMeter.PowerMeter
+import PowerMeter.PowerMeters
+import RelativeHumidityMeasurement.RelativeHumidityMeasurement
+import RelativeHumidityMeasurement.RelativeHumidityMeasurements
+import RelaySwitch.RelaySwitch
+import RelaySwitch.RelaySwitches
+import SleepSensor.SleepSensor
+import SleepSensor.SleepSensors
+import StepSensor.StepSensor
+import StepSensor.StepSensors
+import SwitchLevel.SwitchLevel
+import SwitchLevel.SwitchLevels
+import TemperatureMeasurement.TemperatureMeasurement
+import TemperatureMeasurement.TemperatureMeasurements
+import WaterSensor.WaterSensor
+import WaterSensor.WaterSensors
+import Valve.Valve
+import Valve.Valves
+import MobilePresence.MobilePresence
+import MobilePresence.MobilePresences
 import Timer.SimulatedTimer
 
 //GlobalVariables
@@ -80,6 +102,17 @@ if (App == "App1") {
 
 
 
+//Some of methods-May be needed even in install
+/////////////////////////////////////////////////////////////////////
+def timeToday(String time, Object timeZone) {
+       def timeOfDay = new Date()
+       def _inputTime = time.split(':')
+       def inputTime = Integer.parseInt(_inputTime[0])*3600+Integer.parseInt(_inputTime[1])*60+1564191100415
+       timeOfDay.time = inputTime
+       return timeOfDay
+}
+
+
 
 //Global objects
 //Global Object for class Touch Sensor!
@@ -182,6 +215,61 @@ if (App == "App1") {
 @Field def energyMeterObject0
 @Field def energyMeterObject1
 @Field def energyMeterObject2
+//Global Object for class energy meter!
+@Field illuminanceMeasurementObjects = 0
+@Field def illuminanceMeasurementObject0
+@Field def illuminanceMeasurementObject1
+@Field def illuminanceMeasurementObject2
+//Global Object for class power meter!
+@Field powerMeterObjects = 0
+@Field def powerMeterObject0
+@Field def powerMeterObject1
+@Field def powerMeterObject2
+//Global Object for class power meter!
+@Field humidityMeasurementObjects = 0
+@Field def humidityMeasurementObject0
+@Field def humidityMeasurementObject1
+@Field def humidityMeasurementObject2
+//Global Object for class relay switch!
+@Field relaySwitchObjects = 0
+@Field def relaySwitchObject0
+@Field def relaySwitchObject1
+@Field def relaySwitchObject2
+//Global Object for class sleep sensor!
+@Field sleepSensorObjects = 0
+@Field def sleepSensorObject0
+@Field def sleepSensorObject1
+@Field def sleepSensorObject2
+//Global Object for class sleep sensor!
+@Field stepSensorObjects = 0
+@Field def stepSensorObject0
+@Field def stepSensorObject1
+@Field def stepSensorObject2
+//Global Object for class switch level!
+@Field switchLevelObjects = 0
+@Field def switchLevelObject0
+@Field def switchLevelObject1
+@Field def switchLevelObject2
+//Global Object for class temperature measurement!
+@Field temperatureMeasurementObjects = 0
+@Field def temperatureMeasurementObject0
+@Field def temperatureMeasurementObject1
+@Field def temperatureMeasurementObject2
+//Global Object for class temperature measurement!
+@Field waterSensorObjects = 0
+@Field def waterSensorObject0
+@Field def waterSensorObject1
+@Field def waterSensorObject2
+//Global Object for class valve!
+@Field valveObjects = 0
+@Field def valveObject0
+@Field def valveObject1
+@Field def valveObject2
+//Global Object for class valve!
+@Field mobilePresenceObjects = 0
+@Field def mobilePresenceObject0
+@Field def mobilePresenceObject1
+@Field def mobilePresenceObject2
 
 
 
@@ -528,6 +616,30 @@ def input(LinkedHashMap metaData) {
                        }
                        break
                case "capability.illuminanceMeasurement":
+                       if (illuminanceMeasurementObjects == 0) {
+                               illuminanceMeasurementObject0 = metaData['name']
+                               this[illuminanceMeasurementObject0] = new IlluminanceMeasurements({}, 1)
+                       } else if (illuminanceMeasurementObjects == 1) {
+                               illuminanceMeasurementObject1 = metaData['name']
+                               this[illuminanceMeasurementObject1] = new IlluminanceMeasurements({}, 1)
+                       } else if (illuminanceMeasurementObjects == 2) {
+                               illuminanceMeasurementObject2 = metaData['name']
+                               this[illuminanceMeasurementObject2] = new IlluminanceMeasurements({}, 1)
+                       }
+
+                       illuminanceMeasurementObjects=illuminanceMeasurementObjects+1
+
+                       settings.put(metaData['name'], metaData['name'])
+
+                       if (App == "App1") {
+                               extractedObjectsApp1.append("//Object for class illuminance measurement!\n")
+                               extractedObjectsApp1.append("def "+metaData['name']+"\n")
+                               extractedObjectsConstructorApp1.append(metaData['name']+" = obj.illuminanceMeasurementObject\n")                
+                       } else {
+                               extractedObjectsApp2.append("//Object for class illuminance measurement!\n")
+                               extractedObjectsApp2.append("def "+metaData['name']+"\n")
+                               extractedObjectsConstructorApp2.append(metaData['name']+" = obj.illuminanceMeasurementObject\n")
+                       }
                        break
                case "capability.accelerationSensor":
                        if (accelerationSensorObjects == 0) {
@@ -608,6 +720,30 @@ def input(LinkedHashMap metaData) {
                        }
                        break
                case "capability.powerMeter":
+                       if (powerMeterObjects == 0) {
+                               powerMeterObject0 = metaData['name']
+                               this[powerMeterObject0] = new PowerMeters({}, 1)
+                       } else if (powerMeterObjects == 1) {
+                               powerMeterObject1 = metaData['name']
+                               this[powerMeterObject1] = new PowerMeters({}, 1)
+                       } else if (powerMeterObjects == 2) {
+                               powerMeterObject2 = metaData['name']
+                               this[powerMeterObject2] = new PowerMeters({}, 1)
+                       }
+
+                       powerMeterObjects=powerMeterObjects+1
+
+                       settings.put(metaData['name'], metaData['name'])
+
+                       if (App == "App1") {
+                               extractedObjectsApp1.append("//Object for class power meter!\n")
+                               extractedObjectsApp1.append("def "+metaData['name']+"\n")
+                               extractedObjectsConstructorApp1.append(metaData['name']+" = obj.powerMeterObject\n")            
+                       } else {
+                               extractedObjectsApp2.append("//Object for class power meter!\n")
+                               extractedObjectsApp2.append("def "+metaData['name']+"\n")
+                               extractedObjectsConstructorApp2.append(metaData['name']+" = obj.powerMeterObject\n")
+                       }
                        break
                case "capability.presenceSensor":
                        if (presenceSensorObjects == 0) {
@@ -636,10 +772,82 @@ def input(LinkedHashMap metaData) {
                        }
                        break
                case "capability.relativeHumidityMeasurement":
+                       if (humidityMeasurementObjects == 0) {
+                               humidityMeasurementObject0 = metaData['name']
+                               this[humidityMeasurementObject0] = new RelativeHumidityMeasurements({}, 1)
+                       } else if (humidityMeasurementObjects == 1) {
+                               humidityMeasurementObject1 = metaData['name']
+                               this[humidityMeasurementObject1] = new RelativeHumidityMeasurements({}, 1)
+                       } else if (humidityMeasurementObjects == 2) {
+                               humidityMeasurementObject2 = metaData['name']
+                               this[humidityMeasurementObject2] = new RelativeHumidityMeasurements({}, 1)
+                       }
+
+                       humidityMeasurementObjects=humidityMeasurementObjects+1
+
+                       settings.put(metaData['name'], metaData['name'])
+
+                       if (App == "App1") {
+                               extractedObjectsApp1.append("//Object for class humidity measurement!\n")
+                               extractedObjectsApp1.append("def "+metaData['name']+"\n")
+                               extractedObjectsConstructorApp1.append(metaData['name']+" = obj.humidityMeasurementObject\n")           
+                       } else {
+                               extractedObjectsApp2.append("//Object for class humidity measurement!\n")
+                               extractedObjectsApp2.append("def "+metaData['name']+"\n")
+                               extractedObjectsConstructorApp2.append(metaData['name']+" = obj.humidityMeasurementObject\n")
+                       }
                        break
                case "capability.relaySwitch":
+                       if (relaySwitchObjects == 0) {
+                               relaySwitchObject0 = metaData['name']
+                               this[relaySwitchObject0] = new RelaySwitches({}, 1)
+                       } else if (relaySwitchObjects == 1) {
+                               relaySwitchObject1 = metaData['name']
+                               this[relaySwitchObject1] = new RelaySwitches({}, 1)
+                       } else if (relaySwitchObjects == 2) {
+                               relaySwitchObject2 = metaData['name']
+                               this[relaySwitchObject2] = new RelaySwitches({}, 1)
+                       }
+
+                       relaySwitchObjects=relaySwitchObjects+1
+                       
+                       settings.put(metaData['name'], metaData['name'])
+
+                       if (App == "App1") {
+                               extractedObjectsApp1.append("//Object for class relay switch!\n")
+                               extractedObjectsApp1.append("def "+metaData['name']+"\n")
+                               extractedObjectsConstructorApp1.append(metaData['name']+" = obj.relaySwitchObject\n")           
+                       } else {
+                               extractedObjectsApp2.append("//Object for class relay switch!\n")
+                               extractedObjectsApp2.append("def "+metaData['name']+"\n")
+                               extractedObjectsConstructorApp2.append(metaData['name']+" = obj.relaySwitchObject\n")
+                       }
                        break
                case "capability.sleepSensor":
+                       if (sleepSensorObjects == 0) {
+                               sleepSensorObject0 = metaData['name']
+                               this[sleepSensorObject0] = new SleepSensors({}, 1)
+                       } else if (sleepSensorObjects == 1) {
+                               sleepSensorObject1 = metaData['name']
+                               this[sleepSensorObject1] = new SleepSensors({}, 1)
+                       } else if (sleepSensorObjects == 2) {
+                               sleepSensorObject2 = metaData['name']
+                               this[sleepSensorObject2] = new SleepSensors({}, 1)
+                       }
+
+                       sleepSensorObjects=sleepSensorObjects+1
+                       
+                       settings.put(metaData['name'], metaData['name'])
+
+                       if (App == "App1") {
+                               extractedObjectsApp1.append("//Object for class sleep sensor!\n")
+                               extractedObjectsApp1.append("def "+metaData['name']+"\n")
+                               extractedObjectsConstructorApp1.append(metaData['name']+" = obj.sleepSensorObject\n")           
+                       } else {
+                               extractedObjectsApp2.append("//Object for class sleep sensor!\n")
+                               extractedObjectsApp2.append("def "+metaData['name']+"\n")
+                               extractedObjectsConstructorApp2.append(metaData['name']+" = obj.sleepSensorObject\n")
+                       }
                        break
                case "capability.smokeDetector":
                        if (smokeDetectorObjects == 0) {
@@ -668,6 +876,30 @@ def input(LinkedHashMap metaData) {
                        }
                        break
                case "capability.stepSensor":
+                       if (stepSensorObjects == 0) {
+                               stepSensorObject0 = metaData['name']
+                               this[stepSensorObject0] = new StepSensors({}, 1)
+                       } else if (stepSensorObjects == 1) {
+                               stepSensorObject1 = metaData['name']
+                               this[stepSensorObject1] = new StepSensors({}, 1)
+                       } else if (stepSensorObjects == 2) {
+                               stepSensorObject2 = metaData['name']
+                               this[stepSensorObject2] = new StepSensors({}, 1)
+                       }
+
+                       stepSensorObjects=stepSensorObjects+1
+                       
+                       settings.put(metaData['name'], metaData['name'])
+
+                       if (App == "App1") {
+                               extractedObjectsApp1.append("//Object for class step sensor!\n")
+                               extractedObjectsApp1.append("def "+metaData['name']+"\n")
+                               extractedObjectsConstructorApp1.append(metaData['name']+" = obj.stepSensorObject\n")            
+                       } else {
+                               extractedObjectsApp2.append("//Object for class step sensor!\n")
+                               extractedObjectsApp2.append("def "+metaData['name']+"\n")
+                               extractedObjectsConstructorApp2.append(metaData['name']+" = obj.stepSensorObject\n")
+                       }
                        break
                case "capability.switch":
                        if (switchObjects == 0) {
@@ -696,8 +928,56 @@ def input(LinkedHashMap metaData) {
                        }
                        break
                case "capability.switchLevel":
+                       if (switchLevelObjects == 0) {
+                               switchLevelObject0 = metaData['name']
+                               this[switchLevelObject0] = new SwitchLevels({}, 1)
+                       } else if (switchLevelObjects == 1) {
+                               switchLevelObject1 = metaData['name']
+                               this[switchLevelObject1] = new SwitchLevels({}, 1)
+                       } else if (switchLevelObjects == 2) {
+                               switchLevelObject2 = metaData['name']
+                               this[switchLevelObject2] = new SwitchLevels({}, 1)
+                       }
+
+                       switchLevelObjects=switchLevelObjects+1
+
+                       settings.put(metaData['name'], metaData['name'])
+
+                       if (App == "App1") {
+                               extractedObjectsApp1.append("//Object for class switch level!\n")
+                               extractedObjectsApp1.append("def "+metaData['name']+"\n")
+                               extractedObjectsConstructorApp1.append(metaData['name']+" = obj.switchLevelObject\n")           
+                       } else {
+                               extractedObjectsApp2.append("//Object for class switch level!\n")
+                               extractedObjectsApp2.append("def "+metaData['name']+"\n")
+                               extractedObjectsConstructorApp2.append(metaData['name']+" = obj.switchLevelObject\n")
+                       }
                        break
                case "capability.temperatureMeasurement":
+                       if (temperatureMeasurementObjects == 0) {
+                               temperatureMeasurementObject0 = metaData['name']
+                               this[temperatureMeasurementObject0] = new TemperatureMeasurements({}, 1)
+                       } else if (temperatureMeasurementObjects == 1) {
+                               temperatureMeasurementObject1 = metaData['name']
+                               this[temperatureMeasurementObject1] = new TemperatureMeasurements({}, 1)
+                       } else if (temperatureMeasurementObjects == 2) {
+                               temperatureMeasurementObject2 = metaData['name']
+                               this[temperatureMeasurementObject2] = new TemperatureMeasurements({}, 1)
+                       }
+
+                       temperatureMeasurementObjects=temperatureMeasurementObjects+1
+
+                       settings.put(metaData['name'], metaData['name'])
+
+                       if (App == "App1") {
+                               extractedObjectsApp1.append("//Object for class temperature measurement!\n")
+                               extractedObjectsApp1.append("def "+metaData['name']+"\n")
+                               extractedObjectsConstructorApp1.append(metaData['name']+" = obj.temperatureMeasurementObject\n")                
+                       } else {
+                               extractedObjectsApp2.append("//Object for class temperature measurement!\n")
+                               extractedObjectsApp2.append("def "+metaData['name']+"\n")
+                               extractedObjectsConstructorApp2.append(metaData['name']+" = obj.temperatureMeasurementObject\n")
+                       }
                        break
                case "capability.thermostat":
                        if (thermostatObjects == 0) {
@@ -726,6 +1006,30 @@ def input(LinkedHashMap metaData) {
                        }
                        break
                case "capability.valve":
+                       if (valveObjects == 0) {
+                               valveObject0 = metaData['name']
+                               this[valveObject0] = new Valves({}, 1)
+                       } else if (valveObjects == 1) {
+                               valveObject1 = metaData['name']
+                               this[valveObject1] = new Valves({}, 1)
+                       } else if (valveObjects == 2) {
+                               valveObject2 = metaData['name']
+                               this[valveObject2] = new Valves({}, 1)
+                       }
+
+                       valveObjects=valveObjects+1
+
+                       settings.put(metaData['name'], metaData['name'])
+
+                       if (App == "App1") {
+                               extractedObjectsApp1.append("//Object for class valve!\n")
+                               extractedObjectsApp1.append("def "+metaData['name']+"\n")
+                               extractedObjectsConstructorApp1.append(metaData['name']+" = obj.valveObject\n")         
+                       } else {
+                               extractedObjectsApp2.append("//Object for class valve!\n")
+                               extractedObjectsApp2.append("def "+metaData['name']+"\n")
+                               extractedObjectsConstructorApp2.append(metaData['name']+" = obj.valveObject\n")
+                       }
                        break
                case "capability.speechSynthesis":
                        if (speechSynthesisObjects == 0) {
@@ -754,6 +1058,30 @@ def input(LinkedHashMap metaData) {
                        }
                        break
                case "capability.waterSensor":
+                       if (waterSensorObjects == 0) {
+                               waterSensorObject0 = metaData['name']
+                               this[waterSensorObject0] = new WaterSensors({}, 1)
+                       } else if (waterSensorObjects == 1) {
+                               waterSensorObject1 = metaData['name']
+                               this[waterSensorObject1] = new WaterSensors({}, 1)
+                       } else if (waterSensorObjects == 2) {
+                               waterSensorObject2 = metaData['name']
+                               this[waterSensorObject2] = new WaterSensors({}, 1)
+                       }
+
+                       waterSensorObjects=waterSensorObjects+1
+
+                       settings.put(metaData['name'], metaData['name'])
+
+                       if (App == "App1") {
+                               extractedObjectsApp1.append("//Object for class water sensor!\n")
+                               extractedObjectsApp1.append("def "+metaData['name']+"\n")
+                               extractedObjectsConstructorApp1.append(metaData['name']+" = obj.waterSensorObject\n")           
+                       } else {
+                               extractedObjectsApp2.append("//Object for class water sensor!\n")
+                               extractedObjectsApp2.append("def "+metaData['name']+"\n")
+                               extractedObjectsConstructorApp2.append(metaData['name']+" = obj.waterSensorObject\n")
+                       }
                        break
                case "capability.touchSensor":
                        if (touchSensorObjects == 0) {
@@ -808,6 +1136,30 @@ def input(LinkedHashMap metaData) {
                        }
                        break
                case "device.mobilePresence":
+                       if (mobilePresenceObjects == 0) {
+                               mobilePresenceObject0 = metaData['name']
+                               this[mobilePresenceObject0] = new MobilePresences({}, 1)
+                       } else if (mobilePresenceObjects == 1) {
+                               mobilePresenceObject1 = metaData['name']
+                               this[mobilePresenceObject1] = new MobilePresences({}, 1)
+                       } else if (mobilePresenceObjects == 2) {
+                               mobilePresenceObject2 = metaData['name']
+                               this[mobilePresenceObject2] = new MobilePresences({}, 1)
+                       }
+
+                       mobilePresenceObjects=mobilePresenceObjects+1
+
+                       settings.put(metaData['name'], metaData['name'])
+
+                       if (App == "App1") {
+                               extractedObjectsApp1.append("//Object for class mobile presence!\n")
+                               extractedObjectsApp1.append("def "+metaData['name']+"\n")
+                               extractedObjectsConstructorApp1.append(metaData['name']+" = obj.mobilePresenceObject\n")                
+                       } else {
+                               extractedObjectsApp2.append("//Object for class mobile presence!\n")
+                               extractedObjectsApp2.append("def "+metaData['name']+"\n")
+                               extractedObjectsConstructorApp2.append(metaData['name']+" = obj.mobilePresenceObject\n")
+                       }
                        break
                case "device.aeonKeyFob":
                        if (aeonKeyFobObjects == 0) {
@@ -1013,11 +1365,10 @@ def input(LinkedHashMap metaData) {
                        }
                        break
                case "enum":
-                       def randomVariable = Math.abs(new Random().nextInt() % 2)
-                       def modes = ["Yes", "No"]
-                       //def userInput = modes[randomVariable]
-                       // TODO: We 
-                       //def modes = metaData['options']
+                       if (metaData['options'] != null)
+                               modes = metaData['options']
+                       else // If it is not named 'options' then it is captured as 'metadata'
+                               modes = metaData['metadata']
                        def userInput = modes[0]
        
                        if (enumVariables == 0) {
@@ -1187,6 +1538,10 @@ def mode(LinkedHashMap metaData) {
 def href(LinkedHashMap metaData) {
        println("//IGNORE--some data//")
 }
+
+def href(LinkedHashMap metaData, String name) {
+       println("//IGNORE--some data//")
+}
 /////Input Methods/////
 
 
@@ -1245,5 +1600,9 @@ def section(Closure inputData) {
 def section(LinkedHashMap metaData, Closure inputData) {
        find(inputData) //Run the closure to extract inputMethods
 }
+
+def mappings(Closure inputData) {
+       println("//IGNORE--some data//")
+}
 /////MethodsForExtraction/////
 
index 11486bc..5bd867a 100644 (file)
@@ -1,9 +1,13 @@
 import os
 readyToReturn = 0
 ToReturn = ""
-eventMap = []
+eventList = []
+eventVarMap = {}
+capabilityMap = {}
 app1Capabilities = []
 app2Capabilities = []
+app1Subscribe = False
+app2Subscribe = False
 
 def GetToken(f):
        global readyToReturn
@@ -36,13 +40,17 @@ def GetToken(f):
                        return "EOF"
 
 def ExtractFunctions(F, appName):
-       global eventMap
+       global eventList
+       global app1Subscribe
+       global app2Subscribe
        Temp = GetToken(F)
        while (Temp != "EOF"):
                if (Temp == "def" or Temp == "private"):
                        Temp = GetToken(F)
+                       if (Temp == "def" or Temp == "private"):
+                               Temp = GetToken(F)
                        NameofFunc = Temp
-                       if (GetToken(F) != "="): #We have a function to create object for
+                       if (GetToken(F) == "("): #We have a function to create object for
                                if (appName == "App1"):
                                        extractedFunctionsApp1.write("//Global Object for functions in subscribe method!\n")    
                                        extractedFunctionsApp1.write("def %s = this.&" % NameofFunc)
@@ -52,17 +60,37 @@ def ExtractFunctions(F, appName):
                                        extractedFunctionsApp2.write("def %s = this.&" % NameofFunc)
                                        extractedFunctionsApp2.write("%s\n" % NameofFunc)
                
+               #Check input capability
+               if (Temp == "input"):
+                       Temp = GetToken(F) #Get '"'
+                       variable = GetToken(F)
+                       Temp = GetToken(F) #Get '"'
+                       Temp = GetToken(F) #Get ','
+                       Temp = GetToken(F) #Get '"'
+                       Temp = GetToken(F) #Get capability...
+                       capability = Temp
+                       capabilityMap[variable] = capability
+               
                #Check subscribed events
                if (Temp == "subscribe"):
+                       if (appName == "App1"):
+                               app1Subscribe = True
+                       else:
+                               app2Subscribe = True
+                       Temp = GetToken(F)
+                       if (Temp == "("):
+                               Temp = GetToken(F)
+                       variable = Temp
                        while (Temp != "\"" and Temp != "app" and Temp != "location"):
                                Temp = GetToken(F)
                        if Temp == "\"":
                                Temp = GetToken(F)
-                       if Temp not in eventMap:
-                               eventMap.append(Temp)
+                       if Temp not in eventList:
+                               eventList.append(Temp)
+                               eventVarMap[Temp] = variable
 
                #Check and analyze capabilities for physical interaction
-               AnalyzeCapabilities(Temp, appName)
+               AnalyzeCapabilities(Temp, appName, F)
 
                Temp = GetToken(F)
        
@@ -70,15 +98,16 @@ def ExtractFunctions(F, appName):
        AnalyzePhysicalInteraction(app1Capabilities, app2Capabilities)
        AnalyzePhysicalInteraction(app2Capabilities, app1Capabilities)
 
-               
 
-def AnalyzeCapabilities(Temp, appName):
+def AnalyzeCapabilities(Temp, appName, F):
                        #Illuminance related
        if (Temp == "capability.switch" or
                        Temp == "capability.switchLevel" or
                        Temp == "capability.illuminanceMeasurement" or
+                       Temp == "capability.colorControl" or
                        #Motion related
                        Temp == "capability.motionSensor" or
+                       Temp == "capability.accelerationSensor" or
                        #Water related
                        Temp == "capability.valve" or
                        Temp == "capability.waterSensor" or
@@ -91,14 +120,24 @@ def AnalyzeCapabilities(Temp, appName):
                        app1Capabilities.append(Temp)
                else:
                        app2Capabilities.append(Temp)
+       if (Temp == "capability"):
+               Temp = GetToken(F) #Get '"'
+               Temp = GetToken(F) #Get 'Music'
+               Temp = Temp + GetToken(F) #Get 'Player'
+               if (Temp == "MusicPlayer"):
+                       if (appName == "App1"):
+                               app1Capabilities.append("capability.musicPlayer")
+                       else:
+                               app2Capabilities.append("capability.musicPlayer")
                        
 def AnalyzePhysicalInteraction(app1Capab, app2Capab):
        #Light
        if ("capability.illuminanceMeasurement" in app1Capab) and ("capability.switch" in app2Capab or 
-                       "capability.switchLevel" in app2Capab):
+                       "capability.switchLevel" in app2Capab or "capability.colorControl" in app2Capab):
                print ("\nWARNING: Potential PHYSICAL CONFLICT (light) detected between App1 and App2!\n")
        #Motion
-       if ("capability.motionSensor" in app1Capab):
+       # TODO: Technically this is not entirely precise since we need to be able to detect that the other app creates motion
+       if ("capability.motionSensor" in app1Capab) or ("capability.accelerationSensor" in app1Capab):
                print ("\nWARNING: Potential PHYSICAL CONFLICT (motion) detected between App1 and App2!\n")             
        #Water
        if ("capability.waterSensor" in app1Capab) and ("capability.valve" in app2Capab or 
@@ -110,44 +149,45 @@ def AnalyzePhysicalInteraction(app1Capab, app2Capab):
                print ("\nWARNING: Potential PHYSICAL CONFLICT (sound) detected between App1 and App2!\n")
 
 def ExtractEvents(extractedEvents):
-       global eventMap
-       #extractedEvents.write("while(true) {\n")
-       extractedEvents.write("for(int i=0; i<100; i++) {\n")
-       extractedEvents.write("\tdef eventNumber = Verify.getInt(0,%d)\n" % (len(eventMap) - 1))
+       global eventList
+       global eventVarMap
+       global capabilityMap
+       extractedEvents.write("while(true) {\n")
+       extractedEvents.write("\tdef eventNumber = Verify.getInt(0,%d)\n" % (len(eventList) - 1))
        extractedEvents.write("\tswitch(eventNumber) {\n")
-       for i in range(len(eventMap)):
+       for i in range(len(eventList)):
                extractedEvents.write("\t\tcase %d:\n" % i)
-               if eventMap[i] == "lock":
+               if eventList[i] == "lock":
                        event = open("eventSimulator/lockEvent.groovy", "r")
                        for line in event:
                                extractedEvents.write(line)
                        event.close()
-               elif eventMap[i] == "unlock":
+               elif eventList[i] == "unlock":
                        event = open("eventSimulator/unlockEvent.groovy", "r")
                        for line in event:
                                extractedEvents.write(line)
                        event.close()
-               elif eventMap[i] == "contact.open":
+               elif eventList[i] == "contact.open":
                        event = open("eventSimulator/contactOpenEvent.groovy", "r")
                        for line in event:
                                extractedEvents.write(line)
                        event.close()
-               elif eventMap[i] == "contact.closed":
+               elif eventList[i] == "contact.closed":
                        event = open("eventSimulator/contactClosedEvent.groovy", "r")
                        for line in event:
                                extractedEvents.write(line)
                        event.close()
-               elif eventMap[i] == "nfcTouch":
+               elif eventList[i] == "nfcTouch":
                        event = open("eventSimulator/nfcTouchEvent.groovy", "r")
                        for line in event:
                                extractedEvents.write(line)
                        event.close()
-               elif eventMap[i] == "app": #Case for Touched event
+               elif eventList[i] == "app": #Case for Touched event
                        event = open("eventSimulator/appTouchEvent.groovy", "r")
                        for line in event:
                                extractedEvents.write(line)
                        event.close()
-               elif eventMap[i] == "button":
+               elif eventList[i] == "button":
                        #Write two events subsequently
                        extractedEvents.write("\t\t\tdef event = Verify.getInt(0,1)\n")
                        extractedEvents.write("\t\t\tif (event == 0) {\n")
@@ -161,7 +201,7 @@ def ExtractEvents(extractedEvents):
                                extractedEvents.write("\t\t" + line)
                        event.close()
                        extractedEvents.write("\t\t\t}\n")
-               elif eventMap[i] == "presence":
+               elif eventList[i] == "presence":
                        #Write two events subsequently
                        extractedEvents.write("\t\t\tdef event = Verify.getInt(0,1)\n")
                        extractedEvents.write("\t\t\tif (event == 0) {\n")
@@ -175,7 +215,7 @@ def ExtractEvents(extractedEvents):
                                extractedEvents.write("\t\t" + line)
                        event.close()
                        extractedEvents.write("\t\t\t}\n")
-               elif eventMap[i] == "doorState":
+               elif eventList[i] == "doorState":
                        #Write two events subsequently
                        extractedEvents.write("\t\t\tdef event = Verify.getInt(0,1)\n")
                        extractedEvents.write("\t\t\tif (event == 0) {\n")
@@ -189,7 +229,7 @@ def ExtractEvents(extractedEvents):
                                extractedEvents.write("\t\t" + line)
                        event.close()
                        extractedEvents.write("\t\t\t}\n")
-               elif eventMap[i] == "motion":
+               elif eventList[i] == "motion":
                        #Write two events subsequently
                        extractedEvents.write("\t\t\tdef event = Verify.getInt(0,1)\n")
                        extractedEvents.write("\t\t\tif (event == 0) {\n")
@@ -203,7 +243,7 @@ def ExtractEvents(extractedEvents):
                                extractedEvents.write("\t\t" + line)
                        event.close()
                        extractedEvents.write("\t\t\t}\n")
-               elif eventMap[i] == "smoke":
+               elif eventList[i] == "smoke":
                        #Write three events subsequently
                        extractedEvents.write("\t\t\tdef event = Verify.getInt(0,2)\n")
                        extractedEvents.write("\t\t\tif (event == 0) {\n")
@@ -222,31 +262,44 @@ def ExtractEvents(extractedEvents):
                                extractedEvents.write("\t\t" + line)
                        event.close()
                        extractedEvents.write("\t\t\t}\n")
-               elif eventMap[i] == "carbonMonoxide":
+               elif eventList[i] == "carbonMonoxide":
+                       #Check which capability
+                       variable = eventVarMap[eventList[i]]
+                       capability = capabilityMap[variable]
+
                        #Write three events subsequently
                        extractedEvents.write("\t\t\tdef event = Verify.getInt(0,2)\n")
-                       extractedEvents.write("\t\t\tif (event == 0) {\n")
-                       event = open("eventSimulator/carbonMonoxideClearEvent.groovy", "r")                     
+                       extractedEvents.write("\t\t\tif (event == 0) {\n")                      
+                       if capability == "capability.smokeDetector":
+                               event = open("eventSimulator/smokeCarbonMonoxideClearEvent.groovy", "r")
+                       elif capability == "capability.carbonMonoxideDetector":
+                               event = open("eventSimulator/carbonMonoxideClearEvent.groovy", "r")
                        for line in event:
                                extractedEvents.write("\t\t" + line)
                        event.close()
                        extractedEvents.write("\t\t\t} else if (event == 1) {\n")
-                       event = open("eventSimulator/carbonMonoxideDetectedEvent.groovy", "r")
+                       if capability == "capability.smokeDetector":
+                               event = open("eventSimulator/smokeCarbonMonoxideDetectedEvent.groovy", "r")
+                       elif capability == "capability.carbonMonoxideDetector":
+                               event = open("eventSimulator/carbonMonoxideDetectedEvent.groovy", "r")
                        for line in event:
                                extractedEvents.write("\t\t" + line)
                        event.close()
                        extractedEvents.write("\t\t\t} else {\n")
-                       event = open("eventSimulator/carbonMonoxideTestedEvent.groovy", "r")
+                       if capability == "capability.smokeDetector":
+                               event = open("eventSimulator/smokeCarbonMonoxideTestedEvent.groovy", "r")
+                       elif capability == "capability.carbonMonoxideDetector":
+                               event = open("eventSimulator/carbonMonoxideTestedEvent.groovy", "r")
                        for line in event:
                                extractedEvents.write("\t\t" + line)
                        event.close()
                        extractedEvents.write("\t\t\t}\n")
-               elif eventMap[i] == "battery":
+               elif eventList[i] == "battery":
                        event = open("eventSimulator/batteryChargeEvent.groovy", "r")
                        for line in event:
                                extractedEvents.write(line)
                        event.close()
-               elif eventMap[i] == "thermostatMode":
+               elif eventList[i] == "thermostatMode":
                        #Write five events subsequently
                        extractedEvents.write("\t\t\tdef event = Verify.getInt(0,4)\n")
                        extractedEvents.write("\t\t\tif (event == 0) {\n")
@@ -275,7 +328,7 @@ def ExtractEvents(extractedEvents):
                                extractedEvents.write("\t\t" + line)
                        event.close()
                        extractedEvents.write("\t\t\t}\n")
-               elif eventMap[i] == "switch":
+               elif eventList[i] == "switch":
                        #Write two events subsequently
                        extractedEvents.write("\t\t\tdef event = Verify.getInt(0,1)\n")
                        extractedEvents.write("\t\t\tif (event == 0) {\n")
@@ -289,7 +342,7 @@ def ExtractEvents(extractedEvents):
                                extractedEvents.write("\t\t" + line)
                        event.close()
                        extractedEvents.write("\t\t\t}\n")
-               elif eventMap[i] == "location": #Case for Location event
+               elif eventList[i] == "location": #Case for Location event
                        #Write three events subsequently
                        extractedEvents.write("\t\t\tdef event = Verify.getInt(0,2)\n")
                        extractedEvents.write("\t\t\tif (event == 0) {\n")
@@ -308,13 +361,66 @@ def ExtractEvents(extractedEvents):
                                extractedEvents.write("\t\t" + line)
                        event.close()
                        extractedEvents.write("\t\t\t}\n")
+               elif eventList[i] == "acceleration":
+                       #Write two events subsequently
+                       extractedEvents.write("\t\t\tdef event = Verify.getInt(0,1)\n")
+                       extractedEvents.write("\t\t\tif (event == 0) {\n")
+                       event = open("eventSimulator/accelerationActiveEvent.groovy", "r")                      
+                       for line in event:
+                               extractedEvents.write("\t\t" + line)
+                       event.close()
+                       extractedEvents.write("\t\t\t} else {\n")
+                       event = open("eventSimulator/accelerationInactiveEvent.groovy", "r")
+                       for line in event:
+                               extractedEvents.write("\t\t" + line)
+                       event.close()
+                       extractedEvents.write("\t\t\t}\n")
+               elif eventList[i] == "beacon":
+                       #Write two events subsequently
+                       extractedEvents.write("\t\t\tdef event = Verify.getInt(0,1)\n")
+                       extractedEvents.write("\t\t\tif (event == 0) {\n")
+                       event = open("eventSimulator/beaconPresenceEvent.groovy", "r")                  
+                       for line in event:
+                               extractedEvents.write("\t\t" + line)
+                       event.close()
+                       extractedEvents.write("\t\t\t} else {\n")
+                       event = open("eventSimulator/beaconLeftEvent.groovy", "r")
+                       for line in event:
+                               extractedEvents.write("\t\t" + line)
+                       event.close()
+                       extractedEvents.write("\t\t\t}\n")
+               elif eventList[i] == "color":
+                       event = open("eventSimulator/colorChangeEvent.groovy", "r")
+                       for line in event:
+                               extractedEvents.write(line)
+                       event.close()
+               elif eventList[i] == "hue":
+                       event = open("eventSimulator/hueChangeEvent.groovy", "r")
+                       for line in event:
+                               extractedEvents.write(line)
+                       event.close()
+               elif eventList[i] == "saturation":
+                       event = open("eventSimulator/saturationChangeEvent.groovy", "r")
+                       for line in event:
+                               extractedEvents.write(line)
+                       event.close()
 
                ###TODO: Add more events later
                extractedEvents.write("\t\t\tbreak\n")
        extractedEvents.write("\t}\n")
-       #extractedEvents.write("\tcounter--\n")
        extractedEvents.write("}\n")
-               
+       
+def CheckIfOnlyTouchEvents():
+       #Check and throw an error if it is all touch events
+       #This is called Direct-Direct interaction and we do not model-check for this case
+       onlyTouchEvents = True
+       for item in eventList:
+               if item != "nfcTouch" and item != "app":
+                       onlyTouchEvents = False
+       if onlyTouchEvents is True and app1Subscribe is True and app2Subscribe is True:
+               raise Exception("\n\nDirect-Direct Interaction detected: we are skipping this pair...\n\n")
+
+
 #Extract objects to call functions from App1
 F1 = open("Extractor/App1/App1.groovy", "r")
 extractedFunctionsApp1 = open("Extractor/App1/extractedFunctionsApp1.groovy", "w+")
@@ -329,6 +435,7 @@ F2.close()
 
 #Prepare eventSimulator file while parsing the App1 and App2 files
 extractedEvents = open("eventSimulator/eventSimulator.groovy", "w+")
+CheckIfOnlyTouchEvents()
 ExtractEvents(extractedEvents)
 extractedEvents.close()
 
@@ -350,7 +457,7 @@ extractorFile.close()
 Extractor.close()
 F1.close()
 #Run the file to extract the objects
-os.system("groovy Extractor/extractorFile.groovy")
+os.system("groovy -classpath lib/jpf.jar Extractor/extractorFile.groovy")
 
 
 #Save the extracted methods and app2 in a same file to extract information
@@ -371,8 +478,6 @@ for line in F2:
 extractorFile.close()
 Extractor.close()
 F2.close()
-os.system("groovy Extractor/extractorFile.groovy")
-
-
+os.system("groovy -classpath lib/jpf.jar Extractor/extractorFile.groovy")
 
 
index 5d14fb1..5e4d0e3 100644 (file)
@@ -39,6 +39,40 @@ import Alarm.Alarm
 import Alarm.Alarms
 import SpeechSynthesis.SpeechSynthesis
 import SpeechSynthesis.SpeechSynthesises
+import AccelerationSensor.AccelerationSensor
+import AccelerationSensor.AccelerationSensors
+import Battery.Battery
+import Battery.Batteries
+import BeaconSensor.BeaconSensor
+import BeaconSensor.BeaconSensors
+import CarbonMonoxideDetector.CarbonMonoxideDetector
+import CarbonMonoxideDetector.CarbonMonoxideDetectors
+import ColorControl.ColorControl
+import ColorControl.ColorControls
+import EnergyMeter.EnergyMeter
+import EnergyMeter.EnergyMeters
+import IlluminanceMeasurement.IlluminanceMeasurement
+import IlluminanceMeasurement.IlluminanceMeasurements
+import PowerMeter.PowerMeter
+import PowerMeter.PowerMeters
+import RelativeHumidityMeasurement.RelativeHumidityMeasurement
+import RelativeHumidityMeasurement.RelativeHumidityMeasurements
+import RelaySwitch.RelaySwitch
+import RelaySwitch.RelaySwitches
+import SleepSensor.SleepSensor
+import SleepSensor.SleepSensors
+import StepSensor.StepSensor
+import StepSensor.StepSensors
+import SwitchLevel.SwitchLevel
+import SwitchLevel.SwitchLevels
+import TemperatureMeasurement.TemperatureMeasurement
+import TemperatureMeasurement.TemperatureMeasurements
+import WaterSensor.WaterSensor
+import WaterSensor.WaterSensors
+import Valve.Valve
+import Valve.Valves
+import MobilePresence.MobilePresence
+import MobilePresence.MobilePresences
 import Timer.SimulatedTimer
 
 //GlobalVariables
@@ -71,6 +105,16 @@ if (App == "App1") {
 
 
 
+//Some of methods-May be needed even in install
+/////////////////////////////////////////////////////////////////////
+def timeToday(String time, Object timeZone) {
+       def timeOfDay = new Date()
+       def _inputTime = time.split(':')
+       def inputTime = Integer.parseInt(_inputTime[0])*3600+Integer.parseInt(_inputTime[1])*60+1564191100415
+       timeOfDay.time = inputTime
+       return timeOfDay
+}
+
 
 
 //Global objects
@@ -114,7 +158,7 @@ if (App == "App1") {
 @Field def musicPlayerObject0
 @Field def musicPlayerObject1
 @Field def musicPlayerObject2
-//Global Object for class music player!
+//Global Object for class aeon key fob!
 @Field aeonKeyFobObjects = 0
 @Field def aeonKeyFobObject0
 @Field def aeonKeyFobObject1
@@ -139,11 +183,97 @@ if (App == "App1") {
 @Field def alarmObject0
 @Field def alarmObject1
 @Field def alarmObject2
-//Global Object for class alarm!
+//Global Object for class speech synthesis!
 @Field speechSynthesisObjects = 0
 @Field def speechSynthesisObject0
 @Field def speechSynthesisObject1
 @Field def speechSynthesisObject2
+//Global Object for class acceleration sensor!
+@Field accelerationSensorObjects = 0
+@Field def accelerationSensorObject0
+@Field def accelerationSensorObject1
+@Field def accelerationSensorObject2
+//Global Object for class battery!
+@Field batteryObjects = 0
+@Field def batteryObject0
+@Field def batteryObject1
+@Field def batteryObject2
+//Global Object for class beacon sensor!
+@Field beaconSensorObjects = 0
+@Field def beaconSensorObject0
+@Field def beaconSensorObject1
+@Field def beaconSensorObject2
+//Global Object for class carbon monoxide detector!
+@Field carbonMonoxideDetectorObjects = 0
+@Field def carbonMonoxideDetectorObject0
+@Field def carbonMonoxideDetectorObject1
+@Field def carbonMonoxideDetectorObject2
+//Global Object for class color control!
+@Field colorControlObjects = 0
+@Field def colorControlObject0
+@Field def colorControlObject1
+@Field def colorControlObject2
+//Global Object for class energy meter!
+@Field energyMeterObjects = 0
+@Field def energyMeterObject0
+@Field def energyMeterObject1
+@Field def energyMeterObject2
+//Global Object for class energy meter!
+@Field illuminanceMeasurementObjects = 0
+@Field def illuminanceMeasurementObject0
+@Field def illuminanceMeasurementObject1
+@Field def illuminanceMeasurementObject2
+//Global Object for class power meter!
+@Field powerMeterObjects = 0
+@Field def powerMeterObject0
+@Field def powerMeterObject1
+@Field def powerMeterObject2
+//Global Object for class power meter!
+@Field humidityMeasurementObjects = 0
+@Field def humidityMeasurementObject0
+@Field def humidityMeasurementObject1
+@Field def humidityMeasurementObject2
+//Global Object for class relay switch!
+@Field relaySwitchObjects = 0
+@Field def relaySwitchObject0
+@Field def relaySwitchObject1
+@Field def relaySwitchObject2
+//Global Object for class sleep sensor!
+@Field sleepSensorObjects = 0
+@Field def sleepSensorObject0
+@Field def sleepSensorObject1
+@Field def sleepSensorObject2
+//Global Object for class sleep sensor!
+@Field stepSensorObjects = 0
+@Field def stepSensorObject0
+@Field def stepSensorObject1
+@Field def stepSensorObject2
+//Global Object for class switch level!
+@Field switchLevelObjects = 0
+@Field def switchLevelObject0
+@Field def switchLevelObject1
+@Field def switchLevelObject2
+//Global Object for class temperature measurement!
+@Field temperatureMeasurementObjects = 0
+@Field def temperatureMeasurementObject0
+@Field def temperatureMeasurementObject1
+@Field def temperatureMeasurementObject2
+//Global Object for class temperature measurement!
+@Field waterSensorObjects = 0
+@Field def waterSensorObject0
+@Field def waterSensorObject1
+@Field def waterSensorObject2
+//Global Object for class valve!
+@Field valveObjects = 0
+@Field def valveObject0
+@Field def valveObject1
+@Field def valveObject2
+//Global Object for class valve!
+@Field mobilePresenceObjects = 0
+@Field def mobilePresenceObject0
+@Field def mobilePresenceObject1
+@Field def mobilePresenceObject2
+
 
 
 //Global variables
@@ -307,12 +437,108 @@ def input(LinkedHashMap metaData) {
                        }
                        break
                case "capability.battery":
+                       if (batteryObjects == 0) {
+                               batteryObject0 = metaData['name']
+                               this[batteryObject0] = new Batteries({}, 1)
+                       } else if (batteryObjects == 1) {
+                               batteryObject1 = metaData['name']
+                               this[batteryObject1] = new Batteries({}, 1)
+                       } else if (batteryObjects == 2) {
+                               batteryObject2 = metaData['name']
+                               this[batteryObject2] = new Batteries({}, 1)
+                       }
+
+                       batteryObjects=batteryObjects+1
+
+                       settings.put(metaData['name'], metaData['name'])
+
+                       if (App == "App1") {
+                               extractedObjectsApp1.append("//Object for class Battery!\n")
+                               extractedObjectsApp1.append("def "+metaData['name']+"\n")
+                               extractedObjectsConstructorApp1.append(metaData['name']+" = obj.batteryObject\n")               
+                       } else {
+                               extractedObjectsApp2.append("//Object for class Battery!\n")
+                               extractedObjectsApp2.append("def "+metaData['name']+"\n")
+                               extractedObjectsConstructorApp2.append(metaData['name']+" = obj.batteryObject\n")
+                       }
                        break
                case "capability.beacon":
+                       if (beaconSensorObjects == 0) {
+                               beaconSensorObject0 = metaData['name']
+                               this[beaconSensorObject0] = new BeaconSensors({}, 1)
+                       } else if (beaconSensorObjects == 1) {
+                               beaconSensorObject1 = metaData['name']
+                               this[beaconSensorObject1] = new BeaconSensors({}, 1)
+                       } else if (beaconSensorObjects == 2) {
+                               beaconSensorObject2 = metaData['name']
+                               this[beaconSensorObject2] = new BeaconSensors({}, 1)
+                       }
+
+                       beaconSensorObjects=beaconSensorObjects+1
+
+                       settings.put(metaData['name'], metaData['name'])
+
+                       if (App == "App1") {
+                               extractedObjectsApp1.append("//Object for class beacon sensor!\n")
+                               extractedObjectsApp1.append("def "+metaData['name']+"\n")
+                               extractedObjectsConstructorApp1.append(metaData['name']+" = obj.beaconSensorObject\n")          
+                       } else {
+                               extractedObjectsApp2.append("//Object for class beacon sensor!\n")
+                               extractedObjectsApp2.append("def "+metaData['name']+"\n")
+                               extractedObjectsConstructorApp2.append(metaData['name']+" = obj.beaconSensorObject\n")
+                       }
                        break
                case "capability.carbonMonoxideDetector":
+                       if (carbonMonoxideDetectorObjects == 0) {
+                               carbonMonoxideDetectorObject0 = metaData['name']
+                               this[carbonMonoxideDetectorObject0] = new CarbonMonoxideDetectors({}, 1)
+                       } else if (carbonMonoxideDetectorObjects == 1) {
+                               carbonMonoxideDetectorObject1 = metaData['name']
+                               this[carbonMonoxideDetectorObject1] = new CarbonMonoxideDetectors({}, 1)
+                       } else if (carbonMonoxideDetectorObjects == 2) {
+                               carbonMonoxideDetectorObject2 = metaData['name']
+                               this[carbonMonoxideDetectorObject2] = new CarbonMonoxideDetectors({}, 1)
+                       }
+
+                       carbonMonoxideDetectorObjects=carbonMonoxideDetectorObjects+1
+                       
+                       settings.put(metaData['name'], metaData['name'])
+
+                       if (App == "App1") {
+                               extractedObjectsApp1.append("//Object for class carbon monoxide detector!\n")
+                               extractedObjectsApp1.append("def "+metaData['name']+"\n")
+                               extractedObjectsConstructorApp1.append(metaData['name']+" = obj.carbonMonoxideDetectorObject\n")                
+                       } else {
+                               extractedObjectsApp2.append("//Object for class carbon monoxide detector!\n")
+                               extractedObjectsApp2.append("def "+metaData['name']+"\n")
+                               extractedObjectsConstructorApp2.append(metaData['name']+" = obj.carbonMonoxideDetectorObject\n")
+                       }
                        break
                case "capability.colorControl":
+                       if (colorControlObjects == 0) {
+                               colorControlObject0 = metaData['name']
+                               this[colorControlObject0] = new ColorControls({}, 1)
+                       } else if (colorControlObjects == 1) {
+                               colorControlObject1 = metaData['name']
+                               this[colorControlObject1] = new ColorControls({}, 1)
+                       } else if (colorControlObjects == 2) {
+                               colorControlObject2 = metaData['name']
+                               this[colorControlObject2] = new ColorControls({}, 1)
+                       }
+
+                       colorControlObjects=colorControlObjects+1
+
+                       settings.put(metaData['name'], metaData['name'])
+
+                       if (App == "App1") {
+                               extractedObjectsApp1.append("//Object for class color control!\n")
+                               extractedObjectsApp1.append("def "+metaData['name']+"\n")
+                               extractedObjectsConstructorApp1.append(metaData['name']+" = obj.colorControlObject\n")          
+                       } else {
+                               extractedObjectsApp2.append("//Object for class color control!\n")
+                               extractedObjectsApp2.append("def "+metaData['name']+"\n")
+                               extractedObjectsConstructorApp2.append(metaData['name']+" = obj.colorControlObject\n")
+                       }
                        break
                case "capability.contactSensor":
                        if (contactObjects == 0) {
@@ -367,10 +593,82 @@ def input(LinkedHashMap metaData) {
                        }
                        break
                case "capability.energyMeter":
+                       if (energyMeterObjects == 0) {
+                               energyMeterObject0 = metaData['name']
+                               this[energyMeterObject0] = new EnergyMeters({}, 1)
+                       } else if (energyMeterObjects == 1) {
+                               energyMeterObject1 = metaData['name']
+                               this[energyMeterObject1] = new EnergyMeters({}, 1)
+                       } else if (energyMeterObjects == 2) {
+                               energyMeterObject2 = metaData['name']
+                               this[energyMeterObject2] = new EnergyMeters({}, 1)
+                       }
+
+                       energyMeterObjects=energyMeterObjects+1
+
+                       settings.put(metaData['name'], metaData['name'])
+
+                       if (App == "App1") {
+                               extractedObjectsApp1.append("//Object for class energy meter!\n")
+                               extractedObjectsApp1.append("def "+metaData['name']+"\n")
+                               extractedObjectsConstructorApp1.append(metaData['name']+" = obj.energyMeterObject\n")           
+                       } else {
+                               extractedObjectsApp2.append("//Object for class energy meter!\n")
+                               extractedObjectsApp2.append("def "+metaData['name']+"\n")
+                               extractedObjectsConstructorApp2.append(metaData['name']+" = obj.energyMeterObject\n")
+                       }
                        break
                case "capability.illuminanceMeasurement":
+                       if (illuminanceMeasurementObjects == 0) {
+                               illuminanceMeasurementObject0 = metaData['name']
+                               this[illuminanceMeasurementObject0] = new IlluminanceMeasurements({}, 1)
+                       } else if (illuminanceMeasurementObjects == 1) {
+                               illuminanceMeasurementObject1 = metaData['name']
+                               this[illuminanceMeasurementObject1] = new IlluminanceMeasurements({}, 1)
+                       } else if (illuminanceMeasurementObjects == 2) {
+                               illuminanceMeasurementObject2 = metaData['name']
+                               this[illuminanceMeasurementObject2] = new IlluminanceMeasurements({}, 1)
+                       }
+
+                       illuminanceMeasurementObjects=illuminanceMeasurementObjects+1
+
+                       settings.put(metaData['name'], metaData['name'])
+
+                       if (App == "App1") {
+                               extractedObjectsApp1.append("//Object for class illuminance measurement!\n")
+                               extractedObjectsApp1.append("def "+metaData['name']+"\n")
+                               extractedObjectsConstructorApp1.append(metaData['name']+" = obj.illuminanceMeasurementObject\n")                
+                       } else {
+                               extractedObjectsApp2.append("//Object for class illuminance measurement!\n")
+                               extractedObjectsApp2.append("def "+metaData['name']+"\n")
+                               extractedObjectsConstructorApp2.append(metaData['name']+" = obj.illuminanceMeasurementObject\n")
+                       }
                        break
                case "capability.accelerationSensor":
+                       if (accelerationSensorObjects == 0) {
+                               accelerationSensorObject0 = metaData['name']
+                               this[accelerationSensorObject0] = new AccelerationSensors({}, 1)
+                       } else if (accelerationSensorObjects == 1) {
+                               accelerationSensorObject1 = metaData['name']
+                               this[accelerationSensorObject1] = new AccelerationSensors({}, 1)
+                       } else if (accelerationSensorObjects == 2) {
+                               accelerationSensorObject2 = metaData['name']
+                               this[accelerationSensorObject2] = new AccelerationSensors({}, 1)
+                       }
+
+                       accelerationSensorObjects=accelerationSensorObjects+1
+
+                       settings.put(metaData['name'], metaData['name'])
+
+                       if (App == "App1") {
+                               extractedObjectsApp1.append("//Object for class Acceleration Sensor!\n")
+                               extractedObjectsApp1.append("def "+metaData['name']+"\n")
+                               extractedObjectsConstructorApp1.append(metaData['name']+" = obj.accelerationSensorObject\n")            
+                       } else {
+                               extractedObjectsApp2.append("//Object for class Acceleration Sensor!\n")
+                               extractedObjectsApp2.append("def "+metaData['name']+"\n")
+                               extractedObjectsConstructorApp2.append(metaData['name']+" = obj.accelerationSensorObject\n")
+                       }
                        break
                case "capability.motionSensor":
                        if (motionSensorObjects == 0) {
@@ -425,6 +723,30 @@ def input(LinkedHashMap metaData) {
                        }
                        break
                case "capability.powerMeter":
+                       if (powerMeterObjects == 0) {
+                               powerMeterObject0 = metaData['name']
+                               this[powerMeterObject0] = new PowerMeters({}, 1)
+                       } else if (powerMeterObjects == 1) {
+                               powerMeterObject1 = metaData['name']
+                               this[powerMeterObject1] = new PowerMeters({}, 1)
+                       } else if (powerMeterObjects == 2) {
+                               powerMeterObject2 = metaData['name']
+                               this[powerMeterObject2] = new PowerMeters({}, 1)
+                       }
+
+                       powerMeterObjects=powerMeterObjects+1
+
+                       settings.put(metaData['name'], metaData['name'])
+
+                       if (App == "App1") {
+                               extractedObjectsApp1.append("//Object for class power meter!\n")
+                               extractedObjectsApp1.append("def "+metaData['name']+"\n")
+                               extractedObjectsConstructorApp1.append(metaData['name']+" = obj.powerMeterObject\n")            
+                       } else {
+                               extractedObjectsApp2.append("//Object for class power meter!\n")
+                               extractedObjectsApp2.append("def "+metaData['name']+"\n")
+                               extractedObjectsConstructorApp2.append(metaData['name']+" = obj.powerMeterObject\n")
+                       }
                        break
                case "capability.presenceSensor":
                        if (presenceSensorObjects == 0) {
@@ -453,10 +775,82 @@ def input(LinkedHashMap metaData) {
                        }
                        break
                case "capability.relativeHumidityMeasurement":
+                       if (humidityMeasurementObjects == 0) {
+                               humidityMeasurementObject0 = metaData['name']
+                               this[humidityMeasurementObject0] = new RelativeHumidityMeasurements({}, 1)
+                       } else if (humidityMeasurementObjects == 1) {
+                               humidityMeasurementObject1 = metaData['name']
+                               this[humidityMeasurementObject1] = new RelativeHumidityMeasurements({}, 1)
+                       } else if (humidityMeasurementObjects == 2) {
+                               humidityMeasurementObject2 = metaData['name']
+                               this[humidityMeasurementObject2] = new RelativeHumidityMeasurements({}, 1)
+                       }
+
+                       humidityMeasurementObjects=humidityMeasurementObjects+1
+
+                       settings.put(metaData['name'], metaData['name'])
+
+                       if (App == "App1") {
+                               extractedObjectsApp1.append("//Object for class humidity measurement!\n")
+                               extractedObjectsApp1.append("def "+metaData['name']+"\n")
+                               extractedObjectsConstructorApp1.append(metaData['name']+" = obj.humidityMeasurementObject\n")           
+                       } else {
+                               extractedObjectsApp2.append("//Object for class humidity measurement!\n")
+                               extractedObjectsApp2.append("def "+metaData['name']+"\n")
+                               extractedObjectsConstructorApp2.append(metaData['name']+" = obj.humidityMeasurementObject\n")
+                       }
                        break
                case "capability.relaySwitch":
+                       if (relaySwitchObjects == 0) {
+                               relaySwitchObject0 = metaData['name']
+                               this[relaySwitchObject0] = new RelaySwitches({}, 1)
+                       } else if (relaySwitchObjects == 1) {
+                               relaySwitchObject1 = metaData['name']
+                               this[relaySwitchObject1] = new RelaySwitches({}, 1)
+                       } else if (relaySwitchObjects == 2) {
+                               relaySwitchObject2 = metaData['name']
+                               this[relaySwitchObject2] = new RelaySwitches({}, 1)
+                       }
+
+                       relaySwitchObjects=relaySwitchObjects+1
+                       
+                       settings.put(metaData['name'], metaData['name'])
+
+                       if (App == "App1") {
+                               extractedObjectsApp1.append("//Object for class relay switch!\n")
+                               extractedObjectsApp1.append("def "+metaData['name']+"\n")
+                               extractedObjectsConstructorApp1.append(metaData['name']+" = obj.relaySwitchObject\n")           
+                       } else {
+                               extractedObjectsApp2.append("//Object for class relay switch!\n")
+                               extractedObjectsApp2.append("def "+metaData['name']+"\n")
+                               extractedObjectsConstructorApp2.append(metaData['name']+" = obj.relaySwitchObject\n")
+                       }
                        break
                case "capability.sleepSensor":
+                       if (sleepSensorObjects == 0) {
+                               sleepSensorObject0 = metaData['name']
+                               this[sleepSensorObject0] = new SleepSensors({}, 1)
+                       } else if (sleepSensorObjects == 1) {
+                               sleepSensorObject1 = metaData['name']
+                               this[sleepSensorObject1] = new SleepSensors({}, 1)
+                       } else if (sleepSensorObjects == 2) {
+                               sleepSensorObject2 = metaData['name']
+                               this[sleepSensorObject2] = new SleepSensors({}, 1)
+                       }
+
+                       sleepSensorObjects=sleepSensorObjects+1
+                       
+                       settings.put(metaData['name'], metaData['name'])
+
+                       if (App == "App1") {
+                               extractedObjectsApp1.append("//Object for class sleep sensor!\n")
+                               extractedObjectsApp1.append("def "+metaData['name']+"\n")
+                               extractedObjectsConstructorApp1.append(metaData['name']+" = obj.sleepSensorObject\n")           
+                       } else {
+                               extractedObjectsApp2.append("//Object for class sleep sensor!\n")
+                               extractedObjectsApp2.append("def "+metaData['name']+"\n")
+                               extractedObjectsConstructorApp2.append(metaData['name']+" = obj.sleepSensorObject\n")
+                       }
                        break
                case "capability.smokeDetector":
                        if (smokeDetectorObjects == 0) {
@@ -485,6 +879,30 @@ def input(LinkedHashMap metaData) {
                        }
                        break
                case "capability.stepSensor":
+                       if (stepSensorObjects == 0) {
+                               stepSensorObject0 = metaData['name']
+                               this[stepSensorObject0] = new StepSensors({}, 1)
+                       } else if (stepSensorObjects == 1) {
+                               stepSensorObject1 = metaData['name']
+                               this[stepSensorObject1] = new StepSensors({}, 1)
+                       } else if (stepSensorObjects == 2) {
+                               stepSensorObject2 = metaData['name']
+                               this[stepSensorObject2] = new StepSensors({}, 1)
+                       }
+
+                       stepSensorObjects=stepSensorObjects+1
+                       
+                       settings.put(metaData['name'], metaData['name'])
+
+                       if (App == "App1") {
+                               extractedObjectsApp1.append("//Object for class step sensor!\n")
+                               extractedObjectsApp1.append("def "+metaData['name']+"\n")
+                               extractedObjectsConstructorApp1.append(metaData['name']+" = obj.stepSensorObject\n")            
+                       } else {
+                               extractedObjectsApp2.append("//Object for class step sensor!\n")
+                               extractedObjectsApp2.append("def "+metaData['name']+"\n")
+                               extractedObjectsConstructorApp2.append(metaData['name']+" = obj.stepSensorObject\n")
+                       }
                        break
                case "capability.switch":
                        if (switchObjects == 0) {
@@ -513,8 +931,56 @@ def input(LinkedHashMap metaData) {
                        }
                        break
                case "capability.switchLevel":
+                       if (switchLevelObjects == 0) {
+                               switchLevelObject0 = metaData['name']
+                               this[switchLevelObject0] = new SwitchLevels({}, 1)
+                       } else if (switchLevelObjects == 1) {
+                               switchLevelObject1 = metaData['name']
+                               this[switchLevelObject1] = new SwitchLevels({}, 1)
+                       } else if (switchLevelObjects == 2) {
+                               switchLevelObject2 = metaData['name']
+                               this[switchLevelObject2] = new SwitchLevels({}, 1)
+                       }
+
+                       switchLevelObjects=switchLevelObjects+1
+
+                       settings.put(metaData['name'], metaData['name'])
+
+                       if (App == "App1") {
+                               extractedObjectsApp1.append("//Object for class switch level!\n")
+                               extractedObjectsApp1.append("def "+metaData['name']+"\n")
+                               extractedObjectsConstructorApp1.append(metaData['name']+" = obj.switchLevelObject\n")           
+                       } else {
+                               extractedObjectsApp2.append("//Object for class switch level!\n")
+                               extractedObjectsApp2.append("def "+metaData['name']+"\n")
+                               extractedObjectsConstructorApp2.append(metaData['name']+" = obj.switchLevelObject\n")
+                       }
                        break
                case "capability.temperatureMeasurement":
+                       if (temperatureMeasurementObjects == 0) {
+                               temperatureMeasurementObject0 = metaData['name']
+                               this[temperatureMeasurementObject0] = new TemperatureMeasurements({}, 1)
+                       } else if (temperatureMeasurementObjects == 1) {
+                               temperatureMeasurementObject1 = metaData['name']
+                               this[temperatureMeasurementObject1] = new TemperatureMeasurements({}, 1)
+                       } else if (temperatureMeasurementObjects == 2) {
+                               temperatureMeasurementObject2 = metaData['name']
+                               this[temperatureMeasurementObject2] = new TemperatureMeasurements({}, 1)
+                       }
+
+                       temperatureMeasurementObjects=temperatureMeasurementObjects+1
+
+                       settings.put(metaData['name'], metaData['name'])
+
+                       if (App == "App1") {
+                               extractedObjectsApp1.append("//Object for class temperature measurement!\n")
+                               extractedObjectsApp1.append("def "+metaData['name']+"\n")
+                               extractedObjectsConstructorApp1.append(metaData['name']+" = obj.temperatureMeasurementObject\n")                
+                       } else {
+                               extractedObjectsApp2.append("//Object for class temperature measurement!\n")
+                               extractedObjectsApp2.append("def "+metaData['name']+"\n")
+                               extractedObjectsConstructorApp2.append(metaData['name']+" = obj.temperatureMeasurementObject\n")
+                       }
                        break
                case "capability.thermostat":
                        if (thermostatObjects == 0) {
@@ -543,6 +1009,30 @@ def input(LinkedHashMap metaData) {
                        }
                        break
                case "capability.valve":
+                       if (valveObjects == 0) {
+                               valveObject0 = metaData['name']
+                               this[valveObject0] = new Valves({}, 1)
+                       } else if (valveObjects == 1) {
+                               valveObject1 = metaData['name']
+                               this[valveObject1] = new Valves({}, 1)
+                       } else if (valveObjects == 2) {
+                               valveObject2 = metaData['name']
+                               this[valveObject2] = new Valves({}, 1)
+                       }
+
+                       valveObjects=valveObjects+1
+
+                       settings.put(metaData['name'], metaData['name'])
+
+                       if (App == "App1") {
+                               extractedObjectsApp1.append("//Object for class valve!\n")
+                               extractedObjectsApp1.append("def "+metaData['name']+"\n")
+                               extractedObjectsConstructorApp1.append(metaData['name']+" = obj.valveObject\n")         
+                       } else {
+                               extractedObjectsApp2.append("//Object for class valve!\n")
+                               extractedObjectsApp2.append("def "+metaData['name']+"\n")
+                               extractedObjectsConstructorApp2.append(metaData['name']+" = obj.valveObject\n")
+                       }
                        break
                case "capability.speechSynthesis":
                        if (speechSynthesisObjects == 0) {
@@ -571,6 +1061,30 @@ def input(LinkedHashMap metaData) {
                        }
                        break
                case "capability.waterSensor":
+                       if (waterSensorObjects == 0) {
+                               waterSensorObject0 = metaData['name']
+                               this[waterSensorObject0] = new WaterSensors({}, 1)
+                       } else if (waterSensorObjects == 1) {
+                               waterSensorObject1 = metaData['name']
+                               this[waterSensorObject1] = new WaterSensors({}, 1)
+                       } else if (waterSensorObjects == 2) {
+                               waterSensorObject2 = metaData['name']
+                               this[waterSensorObject2] = new WaterSensors({}, 1)
+                       }
+
+                       waterSensorObjects=waterSensorObjects+1
+
+                       settings.put(metaData['name'], metaData['name'])
+
+                       if (App == "App1") {
+                               extractedObjectsApp1.append("//Object for class water sensor!\n")
+                               extractedObjectsApp1.append("def "+metaData['name']+"\n")
+                               extractedObjectsConstructorApp1.append(metaData['name']+" = obj.waterSensorObject\n")           
+                       } else {
+                               extractedObjectsApp2.append("//Object for class water sensor!\n")
+                               extractedObjectsApp2.append("def "+metaData['name']+"\n")
+                               extractedObjectsConstructorApp2.append(metaData['name']+" = obj.waterSensorObject\n")
+                       }
                        break
                case "capability.touchSensor":
                        if (touchSensorObjects == 0) {
@@ -625,6 +1139,30 @@ def input(LinkedHashMap metaData) {
                        }
                        break
                case "device.mobilePresence":
+                       if (mobilePresenceObjects == 0) {
+                               mobilePresenceObject0 = metaData['name']
+                               this[mobilePresenceObject0] = new MobilePresences({}, 1)
+                       } else if (mobilePresenceObjects == 1) {
+                               mobilePresenceObject1 = metaData['name']
+                               this[mobilePresenceObject1] = new MobilePresences({}, 1)
+                       } else if (mobilePresenceObjects == 2) {
+                               mobilePresenceObject2 = metaData['name']
+                               this[mobilePresenceObject2] = new MobilePresences({}, 1)
+                       }
+
+                       mobilePresenceObjects=mobilePresenceObjects+1
+
+                       settings.put(metaData['name'], metaData['name'])
+
+                       if (App == "App1") {
+                               extractedObjectsApp1.append("//Object for class mobile presence!\n")
+                               extractedObjectsApp1.append("def "+metaData['name']+"\n")
+                               extractedObjectsConstructorApp1.append(metaData['name']+" = obj.mobilePresenceObject\n")                
+                       } else {
+                               extractedObjectsApp2.append("//Object for class mobile presence!\n")
+                               extractedObjectsApp2.append("def "+metaData['name']+"\n")
+                               extractedObjectsConstructorApp2.append(metaData['name']+" = obj.mobilePresenceObject\n")
+                       }
                        break
                case "device.aeonKeyFob":
                        if (aeonKeyFobObjects == 0) {
@@ -830,11 +1368,10 @@ def input(LinkedHashMap metaData) {
                        }
                        break
                case "enum":
-                       def randomVariable = Math.abs(new Random().nextInt() % 2)
-                       def modes = ["Yes", "No"]
-                       //def userInput = modes[randomVariable]
-                       // TODO: We 
-                       //def modes = metaData['options']
+                       if (metaData['options'] != null)
+                               modes = metaData['options']
+                       else // If it is not named 'options' then it is captured as 'metadata'
+                               modes = metaData['metadata']
                        def userInput = modes[0]
        
                        if (enumVariables == 0) {
@@ -1004,6 +1541,10 @@ def mode(LinkedHashMap metaData) {
 def href(LinkedHashMap metaData) {
        println("//IGNORE--some data//")
 }
+
+def href(LinkedHashMap metaData, String name) {
+       println("//IGNORE--some data//")
+}
 /////Input Methods/////
 
 
@@ -1062,12 +1603,18 @@ def section(Closure inputData) {
 def section(LinkedHashMap metaData, Closure inputData) {
        find(inputData) //Run the closure to extract inputMethods
 }
+
+def mappings(Closure inputData) {
+       println("//IGNORE--some data//")
+}
 /////MethodsForExtraction/////
 
 
 
 /**
- *  Copyright 2015 SmartThings
+ *  Notify If Left Unlocked
+ *
+ *  Copyright 2014 George Sudarkoff
  *
  *  Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
  *  in compliance with the License. You may obtain a copy of the License at:
@@ -1078,128 +1625,99 @@ def section(LinkedHashMap metaData, Closure inputData) {
  *  on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License
  *  for the specific language governing permissions and limitations under the License.
  *
- *  Make it So
- *
- *  Author: SmartThings
- *  Date: 2013-03-06
  */
+
 definition(
-    name: "Make It So",
-    namespace: "smartthings",
-    author: "SmartThings",
-    description: "Saves the states of a specified set switches and thermostat setpoints and restores them at each mode change. To use 1) Set the mode, 2) Change switches and setpoint to where you want them for that mode, and 3) Install or update the app. Changing to that mode or touching the app will set the devices to the saved state.",
-    category: "Convenience",
-    iconUrl: "https://s3.amazonaws.com/smartapp-icons/Meta/light_thermo-switch.png",
-    iconX2Url: "https://s3.amazonaws.com/smartapp-icons/Meta/light_thermo-switch@2x.png"
-)
+    name: "Notify If Left Unlocked",
+    namespace: "com.sudarkoff",
+    author: "George Sudarkoff",
+    description: "Send a push or SMS notification (and lock, if it's closed) if a door is left unlocked for a period of time.",
+    category: "Safety & Security",
+    iconUrl: "https://s3.amazonaws.com/smartapp-icons/Convenience/Cat-Convenience.png",
+    iconX2Url: "https://s3.amazonaws.com/smartapp-icons/Convenience/Cat-Convenience@2x.png")
 
-preferences {
-       section("Switches") {
-               input "switches", "capability.switch", multiple: true, required: false
-       }
-       section("Thermostats") {
-               input "thermostats", "capability.thermostat", multiple: true, required: false
-       }
-       section("Locks") {
-               input "locks", "capability.lock", multiple: true, required: false
-       }
-}
 
-def installed() {
-       subscribe(location, changedLocationMode)
-       subscribe(app, appTouch)
-       saveState()
+preferences {
+    section("If this lock...") {
+        input "aLock", "capability.lock", multiple: false, required: true
+        input "openSensor", "capability.contactSensor", title: "Open/close sensor (optional)", multiple: false, required: false
+    }
+    section("Left unlocked for...") {
+        input "duration", "number", title: "How many minutes?", required: true
+    }
+    section("Notify me...") {
+        input "pushNotification", "bool", title: "Push notification"
+        input "phoneNumber", "phone", title: "Phone number (optional)", required: false
+        input "lockIfClosed", "bool", title: "Lock the door if it's closed?"
+    }
 }
 
-def updated() {
-       unsubscribe()
-       subscribe(location, changedLocationMode)
-       subscribe(app, appTouch)
-       saveState()
+def installed()
+{
+    initialize()
 }
 
-def appTouch(evt)
+def updated()
 {
-       restoreState(currentMode)
+    unsubscribe()
+    initialize()
 }
 
-def changedLocationMode(evt)
+def initialize()
 {
-       restoreState(evt.value)
+    log.trace "Initializing with: ${settings}"
+    subscribe(aLock, "lock", lockHandler)
 }
 
-private restoreState(mode)
+def lockHandler(evt)
 {
-       log.info "restoring state for mode '$mode'"
-       def map = state[mode] ?: [:]
-       switches?.each {
-               def value = map[it.id]
-               if (value?.switch == "on") {
-                       def level = value.level
-                       if (level) {
-                               log.debug "setting $it.label level to $level"
-                               it.setLevel(level)
-                       }
-                       else {
-                               log.debug "turning $it.label on"
-                               it.on()
-                       }
-               }
-               else if (value?.switch == "off") {
-                       log.debug "turning $it.label off"
-                       it.off()
-               }
-       }
-
-       thermostats?.each {
-               def value = map[it.id]
-               if (value?.coolingSetpoint) {
-                       log.debug "coolingSetpoint = $value.coolingSetpoint"
-                       it.setCoolingSetpoint(value.coolingSetpoint)
-               }
-               if (value?.heatingSetpoint) {
-                       log.debug "heatingSetpoint = $value.heatingSetpoint"
-                       it.setHeatingSetpoint(value.heatingSetpoint)
-               }
-       }
-
-       locks?.each {
-               def value = map[it.id]
-               if (value) {
-                       if (value?.locked) {
-                               it.lock()
-                       }
-                       else {
-                               it.unlock()
-                       }
-               }
-       }
+    log.trace "${evt.name} is ${evt.value}."
+    if (evt.value == "locked") {
+        log.debug "Canceling lock check because the door is locked..."
+        unschedule(notifyUnlocked)
+    }
+    else {
+        log.debug "Starting the countdown for ${duration} minutes..."
+        state.retries = 0
+        runIn(duration * 60, notifyUnlocked)
+    }
 }
 
-
-private saveState()
+def notifyUnlocked()
 {
-       def mode = currentMode
-       def map = state[mode] ?: [:]
-
-       switches?.each {
-               map[it.id] = [switch: it.currentSwitch, level: it.currentLevel]
-       }
-
-       thermostats?.each {
-               map[it.id] = [coolingSetpoint: it.currentCoolingSetpoint, heatingSetpoint: it.currentHeatingSetpoint]
-       }
-
-       locks?.each {
-               map[it.id] = [locked: it.currentLock == "locked"]
-       }
+    // if no open/close sensor specified, assume the door is closed
+    def open = openSensor?.latestValue("contact") ?: "closed"
+
+    def message = "${aLock.displayName} is left unlocked and ${open} for more than ${duration} minutes."
+    log.trace "Sending the notification: ${message}."
+    sendMessage(message)
+
+    if (lockIfClosed) {
+        if (open == "closed") {
+            log.trace "And locking the door."
+            sendMessage("Locking the ${aLock.displayName} as prescribed.")
+            aLock.lock()
+        }
+        else {
+            if (state.retries++ < 3) {
+                log.trace "Door is open, can't lock. Rescheduling the check."
+                sendMessage("Can't lock the ${aLock.displayName} because the door is open. Will try again in ${duration} minutes.")
+                runIn(duration * 60, notifyUnlocked)
+            }
+            else {
+                log.trace "The door is still open after ${state.retries} retries, giving up."
+                sendMessage("Unable to lock the ${aLock.displayName} after ${state.retries} retries, giving up.")
+            }
+        }
+    }
+}
 
-       state[mode] = map
-       log.debug "saved state for mode ${mode}: ${state[mode]}"
-       log.debug "state: $state"
+def sendMessage(msg) {
+    if (pushNotification) {
+        sendPush(msg)
+    }
+    if (phoneNumber) {
+        sendSMS(phoneNumber, msg)
+    }
 }
 
-private getCurrentMode()
-{
-       location.mode ?: "_none_"
-}
\ No newline at end of file
index 6621df4..998778b 100644 (file)
@@ -7,7 +7,9 @@
 //Object for touch to call function
 @Field def appObject = new Touched(sendEvent, 0)
 //Create a global list for events
-@Field def evt = []
+//@Field def evt = []
+//Global Object for class AtomicState!
+@Field def atomicState = new AtomicState()
 //Global Object for class Touch Sensor!
 @Field def touchSensorObject = new NfcTouch(sendEvent, 1)
 //Global Object for class switch!
 @Field def colorControlObject = new ColorControls(sendEvent, 1)
 //Global Object for class energy meter!
 @Field def energyMeterObject = new EnergyMeters(sendEvent, 1)
+//Global Object for class illuminance measurement!
+@Field def illuminanceMeasurementObject = new IlluminanceMeasurements(sendEvent, 1)
+//Global Object for class power meter!
+@Field def powerMeterObject = new PowerMeters(sendEvent, 1)
+//Global Object for class humidity measurement!
+@Field def humidityMeasurementObject = new RelativeHumidityMeasurements(sendEvent, 1)
+//Global Object for class relay switch!
+@Field def relaySwitchObject = new RelaySwitches(sendEvent, 1)
+//Global Object for class sleep sensor!
+@Field def sleepSensorObject = new SleepSensors(sendEvent, 1)
+//Global Object for class step sensor!
+@Field def stepSensorObject = new StepSensors(sendEvent, 1)
+//Global Object for class switch level!
+@Field def switchLevelObject = new SwitchLevels(sendEvent, 1)
+//Global Object for class temperature measurement!
+@Field def temperatureMeasurementObject = new TemperatureMeasurements(sendEvent, 1)
+//Global Object for class water sensor!
+@Field def waterSensorObject = new WaterSensors(sendEvent, 1)
+//Global Object for class valves!
+@Field def valveObject = new Valves(sendEvent, 1)
+//Global Object for class mobile presence!
+@Field def mobilePresenceObject = new MobilePresences(sendEvent, 1)
diff --git a/IlluminanceMeasurement/IlluminanceMeasurement.groovy b/IlluminanceMeasurement/IlluminanceMeasurement.groovy
new file mode 100644 (file)
index 0000000..c73576b
--- /dev/null
@@ -0,0 +1,33 @@
+//Create a class for illuminance measurement
+package IlluminanceMeasurement
+import Timer.SimulatedTimer
+
+public class IlluminanceMeasurement {
+       private String id
+       private String label
+       private String displayName
+       private int illuminance
+       private int currentIlluminance
+
+       IlluminanceMeasurement(String id, String label, String displayName, int illuminance) {
+               this.id = id
+               this.label = label
+               this.displayName = displayName
+               this.illuminance = illuminance
+               this.currentIlluminance = illuminance
+       }
+
+       //By Model Checker
+       def setValue(String value) {
+               println("the illuminance level is changed to $value!")
+               this.illuminance = value.toInteger()
+               this.currentIlluminance = value.toInteger()
+       }
+
+       def currentValue(String deviceFeature) {
+               if (deviceFeature == "illuminance") {
+                       return illuminance
+               }
+       }
+
+}
diff --git a/IlluminanceMeasurement/IlluminanceMeasurements.groovy b/IlluminanceMeasurement/IlluminanceMeasurements.groovy
new file mode 100644 (file)
index 0000000..4511001
--- /dev/null
@@ -0,0 +1,61 @@
+//Create a class for illuminance measurement
+package IlluminanceMeasurement
+import Timer.SimulatedTimer
+
+public class IlluminanceMeasurements {
+       private int deviceNumbers
+       private List illuminanceMeasurements
+       def sendEvent
+
+       //For one device(We cannot have obj.id)-> We should have obj[0].id
+       private String id = "illuminanceMeasurementsID0"
+       private String label = "illuminanceMeasurements0"
+       private String displayName = "illuminanceMeasurements0"
+       private int illuminance = 50000
+       private int currentIlluminance = 50000
+
+               
+       IlluminanceMeasurements(Closure sendEvent, int deviceNumbers) {
+               this.sendEvent = sendEvent              
+               this.deviceNumbers = deviceNumbers
+               this.illuminanceMeasurements = []
+
+               illuminanceMeasurements.add(new IlluminanceMeasurement(id, label, displayName, this.illuminance))
+       }
+
+       //By Model Checker
+       def setValue(LinkedHashMap eventDataMap) {
+               if (eventDataMap["value"] != illuminanceMeasurements[0].illuminance) {
+                       illuminanceMeasurements[0].setValue(eventDataMap["value"])
+                       this.illuminance = illuminanceMeasurements[0].illuminance
+                       this.currentIlluminance = illuminanceMeasurements[0].illuminance
+                       sendEvent(eventDataMap)
+               }
+       }
+
+       //Methods for closures
+       def count(Closure Input) {
+               illuminanceMeasurements.count(Input)
+       }
+       def size() {
+               illuminanceMeasurements.size()
+       }
+       def each(Closure Input) {
+               illuminanceMeasurements.each(Input)
+       }
+       def find(Closure Input) {
+               illuminanceMeasurements.find(Input)
+       }
+       def collect(Closure Input) {
+               illuminanceMeasurements.collect(Input)
+       }
+
+
+       def currentValue(String deviceFeature) {
+               illuminanceMeasurements[0].currentValue(deviceFeature)//It is called if we have only one device
+       }
+
+       def getAt(int ix) {
+               illuminanceMeasurements[ix]
+       }
+}
index 5d9f945..5e8748b 100644 (file)
@@ -18,13 +18,17 @@ public class ImageCapture {
        }
        
        def alarmOn() {
-               println("The camera with id:$id is armed!")
-               this.alarmState = "armed"
+               if (alarmState != "armed") {
+                       println("The camera with id:$id is armed!")
+                       this.alarmState = "armed"
+               }
        }
 
        def alarmOff() {
-               println("The camera with id:$id is not armed!")
-               this.alarmState = "not armed"
+               if (alarmState != "not armed") {
+                       println("The camera with id:$id is not armed!")
+                       this.alarmState = "not armed"
+               }
        }
 
        def take() {
index 2a63a3e..661e870 100644 (file)
@@ -2,15 +2,18 @@
 package ImageCapture
 import Timer.SimulatedTimer
 
+//JPF's Verify API
+import gov.nasa.jpf.vm.Verify
+
 public class ImageCaptures {
        private int deviceNumbers
        private List imageCaptureSensors
        def sendEvent
 
        //For one device(We cannot have obj.id)-> We should have obj[0].id
-       private String id = "motionSensorID0"
-       private String label = "motionSensor0"
-       private String displayName = "motionSensor0"
+       private String id = "imageCaptureID0"
+       private String label = "imageCapture0"
+       private String displayName = "imageCapture0"
        private String image = "imageData"
        private String alarmState = "armed"
 
@@ -20,6 +23,12 @@ public class ImageCaptures {
                this.deviceNumbers = deviceNumbers
                this.imageCaptureSensors = []
 
+               def initAlarm = Verify.getBoolean()
+               if (initAlarm) {
+                       this.alarmState = "armed"
+               } else {
+                       this.alarmState = "not armed"
+               }
                imageCaptureSensors.add(new ImageCapture(id, label, displayName, this.image, this.alarmState))
        }
 
@@ -42,13 +51,17 @@ public class ImageCaptures {
        }
 
        def alarmOn() {
-               imageCaptureSensors[0].alarmOn()
-               this.alarmState = "armed"
+               if (alarmState != "armed") {
+                       imageCaptureSensors[0].alarmOn()
+                       this.alarmState = "armed"
+               }
        }
 
        def alarmOff() {
-               imageCaptureSensors[0].alarmOff()
-               this.alarmState = "not armed"
+               if (alarmState != "not armed") {
+                       imageCaptureSensors[0].alarmOff()
+                       this.alarmState = "not armed"
+               }
        }
 
        def take() {
index b2016e8..d10206b 100644 (file)
@@ -4,6 +4,7 @@ package Location
 class LocationVar {
        private int contactBookEnabled
        private def modes
+       private def timeZone
        private String mode
        private List contacts
        private List phoneNumbers
@@ -19,6 +20,7 @@ class LocationVar {
                this.contacts = ['AJ']
                this.phoneNumbers = [9495379373]
                this.sendEvent = sendEvent
+               this.timeZone = TimeZone.getTimeZone("America/New_York")
        }
 
        //By Model Checker
index ada1d82..76482b4 100644 (file)
@@ -26,42 +26,50 @@ public class Lock {
 
        //By Apps
        def lock() {
-               println("the door with id:$id is locked!")
-               this.lockLatestValue = this.lockState
-               this.lockState = "locked"
-               this.currentLock = "locked"
-               sendEvent([name: "lock", value: "locked", deviceId: this.id, descriptionText: "",
-                         displayed: true, linkText: "", isStateChange: false, unit: "", data: [value: "locked"]])
-       }
-
-       def lock(LinkedHashMap metaData) {
-               def task = timers.runAfter(metaData["delay"]) {
+               if (lockState != "locked") {
                        println("the door with id:$id is locked!")
                        this.lockLatestValue = this.lockState
                        this.lockState = "locked"
                        this.currentLock = "locked"
                        sendEvent([name: "lock", value: "locked", deviceId: this.id, descriptionText: "",
-                                 displayed: true, linkText: "", isStateChange: false, unit: "", data: [value: "locked"]])
+                                 displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
+               }
+       }
+
+       def lock(LinkedHashMap metaData) {
+               if (lockState != "locked") {
+                       def task = timers.runAfter(metaData["delay"]) {
+                               println("the door with id:$id is locked!")
+                               this.lockLatestValue = this.lockState
+                               this.lockState = "locked"
+                               this.currentLock = "locked"
+                               sendEvent([name: "lock", value: "locked", deviceId: this.id, descriptionText: "",
+                                         displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
+                       }
                }
        }
        
        def unlock() {
-               println("the door with id:$id is unlocked!")
-               this.lockLatestValue = this.lockState
-               this.lockState = "unlocked"
-               this.currentLock = "unlocked"
-               sendEvent([name: "unlock", value: "unlocked", deviceId: this.id, descriptionText: "",
-                         displayed: true, linkText: "", isStateChange: false, unit: "", data: [value: "unlocked"]])
+               if (lockState != "unlocked") {
+                       println("the door with id:$id is unlocked!")
+                       this.lockLatestValue = this.lockState
+                       this.lockState = "unlocked"
+                       this.currentLock = "unlocked"
+                       sendEvent([name: "unlock", value: "unlocked", deviceId: this.id, descriptionText: "",
+                                 displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
+               }
        }
 
        def unlock(LinkedHashMap metaData) {
-               def task = timers.runAfter(metaData["delay"]) {
-                       println("the door with id:$id is locked!")
-                       this.lockLatestValue = this.lockState
-                       this.lockState = "locked"
-                       this.currentLock = "locked"
-                       sendEvent([name: "unlock", value: "unlocked", deviceId: this.id, descriptionText: "",
-                                 displayed: true, linkText: "", isStateChange: false, unit: "", data: [value: "unlocked"]])
+               if (lockState != "unlocked") {
+                       def task = timers.runAfter(metaData["delay"]) {
+                               println("the door with id:$id is locked!")
+                               this.lockLatestValue = this.lockState
+                               this.lockState = "locked"
+                               this.currentLock = "locked"
+                               sendEvent([name: "unlock", value: "unlocked", deviceId: this.id, descriptionText: "",
+                                         displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
+                       }
                }
        }
 
index f792c6c..ea75ef3 100644 (file)
@@ -2,6 +2,9 @@
 package Lock
 import Timer.SimulatedTimer
 
+//JPF's Verify API
+import gov.nasa.jpf.vm.Verify
+
 public class Locks{
        int deviceNumbers       
        List locks      
@@ -22,19 +25,20 @@ public class Locks{
                this.deviceNumbers = deviceNumbers
                this.locks = []
 
+               def init = Verify.getBoolean()
+               if (init) {
+                       this.lockState = "locked"
+                       this.lockLatestValue = "locked"
+               } else {
+                       this.lockState = "unlocked"
+                       this.lockLatestValue = "unlocked"
+               }
                locks.add(new Lock(sendEvent,id, label, displayName, this.lockState, this.lockLatestValue))
        }
 
        //By Apps
        def lock() {
-               locks[0].lock()
-               lockLatestValue = lockState
-               lockState = "locked"
-               currentLock = "locked"
-       }
-
-       def lock(LinkedHashMap metaData) {
-               def task = timers.runAfter(metaData["delay"]) {
+               if (lockState != "locked") {
                        locks[0].lock()
                        lockLatestValue = lockState
                        lockState = "locked"
@@ -42,16 +46,19 @@ public class Locks{
                }
        }
 
-       def unlock() {
-               locks[0].unlock()
-               lockLatestValue = lockState
-               lockState = "unlocked"
-               currentLock = "unlocked"
+       def lock(LinkedHashMap metaData) {
+               if (lockState != "locked") {
+                       def task = timers.runAfter(metaData["delay"]) {
+                               locks[0].lock()
+                               lockLatestValue = lockState
+                               lockState = "locked"
+                               currentLock = "locked"
+                       }
+               }
        }
 
-
-       def unlock(LinkedHashMap metaData) {
-               def task = timers.runAfter(metaData["delay"]) {
+       def unlock() {
+               if (lockState != "unlocked") {
                        locks[0].unlock()
                        lockLatestValue = lockState
                        lockState = "unlocked"
@@ -59,6 +66,18 @@ public class Locks{
                }
        }
 
+
+       def unlock(LinkedHashMap metaData) {
+               if (lockState != "unlocked") {
+                       def task = timers.runAfter(metaData["delay"]) {
+                               locks[0].unlock()
+                               lockLatestValue = lockState
+                               lockState = "unlocked"
+                               currentLock = "unlocked"
+                       }
+               }
+       }
+
        //Methods for closures
        def count(Closure Input) {
                locks.count(Input)
diff --git a/Methods/canSchedule.groovy b/Methods/canSchedule.groovy
new file mode 100644 (file)
index 0000000..ff0aa67
--- /dev/null
@@ -0,0 +1,4 @@
+/////////////////////////////////////////////////////////////////////
+def canSchedule() {
+       return true
+}
index 4df7675..b838418 100644 (file)
@@ -13,7 +13,6 @@ def eventHandler(LinkedHashMap eventDataMap) {
        for (int i = 0;i < app2.eventList.size();i++) {
                if (app2.eventList[i] == name) {
                        def event = new Event(value, name, deviceId, descriptionText, displayed, linkText, linkText, isStateChange, unit, data)
-                       evt.add(event)
                        app2.functionList[i](event)
                }
        }
@@ -21,7 +20,6 @@ def eventHandler(LinkedHashMap eventDataMap) {
        for (int i = 0;i < app1.eventList.size();i++) {
                if (app1.eventList[i] == name) {
                        def event = new Event(value, name, deviceId, descriptionText, displayed, linkText, linkText, isStateChange, unit, data)
-                       evt.add(event)
                        app1.functionList[i](event)
                }
        }
index 8fb2560..ddd7098 100644 (file)
@@ -1,5 +1,5 @@
 /////////////////////////////////////////////////////////////////////
 def getTemperatureScale() {
-       return 'C' //Celsius for now
+       return 'F' //Celsius for now
 }
 
diff --git a/Methods/httpPostJson.groovy b/Methods/httpPostJson.groovy
new file mode 100644 (file)
index 0000000..e53be72
--- /dev/null
@@ -0,0 +1,4 @@
+/////////////////////////////////////////////////////////////////////
+def httpPostJson(LinkedHashMap metaData, Closure inputData) {
+       inputData(metaData)
+}
diff --git a/Methods/runEvery15Minutes.groovy b/Methods/runEvery15Minutes.groovy
new file mode 100644 (file)
index 0000000..960b27c
--- /dev/null
@@ -0,0 +1,4 @@
+/////////////////////////////////////////////////////////////////////
+def runEvery15Minutes(Closure inputData) {
+       inputData()
+}
index 3981f54..fef90b4 100644 (file)
@@ -41,10 +41,10 @@ def schedule(String time, Closure nameOfFunction) {
 
        if (timersFuncList.contains(nameOfFunction)) {
                timersList[timersFuncList.indexOf(nameOfFunction)].cancel()
-               def task = timersList[timersFuncList.indexOf(nameOfFunction)].runAfter(delay*seconds*0, nameOfFunction)
+               def task = timersList[timersFuncList.indexOf(nameOfFunction)].runAfter(delay*0, nameOfFunction)
        } else {
                timersFuncList.add(nameOfFunction)
                timersList.add(new SimulatedTimer())
-               def task = timersList[timersFuncList.indexOf(nameOfFunction)].runAfter(delay*seconds*0, nameOfFunction)
+               def task = timersList[timersFuncList.indexOf(nameOfFunction)].runAfter(delay*0, nameOfFunction)
        }
 }
diff --git a/Methods/sendNotification.groovy b/Methods/sendNotification.groovy
new file mode 100644 (file)
index 0000000..3aefbda
--- /dev/null
@@ -0,0 +1,4 @@
+/////////////////////////////////////////////////////////////////////
+def sendNotification(String text, LinkedHashMap metaData) {
+       println("Sending \""+text+"\" to "+metaData.phone.toString())
+}
diff --git a/Methods/timeToday.groovy b/Methods/timeToday.groovy
new file mode 100644 (file)
index 0000000..0b975ce
--- /dev/null
@@ -0,0 +1,8 @@
+/////////////////////////////////////////////////////////////////////
+def timeToday(String time, Object timeZone) {
+       def timeOfDay = new Date()
+       def _inputTime = time.split(':')
+       def inputTime = Integer.parseInt(_inputTime[0])*3600+Integer.parseInt(_inputTime[1])*60+1564191100415
+       timeOfDay.time = inputTime
+       return timeOfDay
+}
diff --git a/MobilePresence/MobilePresence.groovy b/MobilePresence/MobilePresence.groovy
new file mode 100644 (file)
index 0000000..f78bbec
--- /dev/null
@@ -0,0 +1,17 @@
+//Create a class for mobile presence
+package MobilePresence
+import Timer.SimulatedTimer
+
+public class MobilePresence {
+       private String id
+       private String label
+       private String displayName
+       private String deviceNetworkId
+
+       MobilePresence(String id, String label, String displayName, String deviceNetworkId) {
+               this.id = id
+               this.label = label
+               this.displayName = displayName
+               this.deviceNetworkId = deviceNetworkId
+       }
+}
diff --git a/MobilePresence/MobilePresences.groovy b/MobilePresence/MobilePresences.groovy
new file mode 100644 (file)
index 0000000..e264cae
--- /dev/null
@@ -0,0 +1,47 @@
+//Create a class for mobile presence
+package MobilePresence
+import Timer.SimulatedTimer
+
+public class MobilePresences {
+       private int deviceNumbers
+       private List mobilePresences
+       private String deviceNetworkId
+       def sendEvent
+
+       //For one device(We cannot have obj.id)-> We should have obj[0].id
+       private String id = "mobilePresenceID0"
+       private String label = "mobilePresence0"
+       private String displayName = "mobilePresence0"
+       
+               
+       MobilePresences(Closure sendEvent, int deviceNumbers) {
+               this.sendEvent = sendEvent              
+               this.deviceNumbers = deviceNumbers
+               this.mobilePresences = []
+               this.deviceNetworkId = "mobile0"
+
+               mobilePresences.add(new MobilePresence(id, label, displayName, deviceNetworkId))
+       }
+
+       //Methods for closures
+       def count(Closure Input) {
+               mobilePresences.count(Input)
+       }
+       def size() {
+               mobilePresences.size()
+       }
+       def each(Closure Input) {
+               mobilePresences.each(Input)
+       }
+       def find(Closure Input) {
+               mobilePresences.find(Input)
+       }
+       def collect(Closure Input) {
+               mobilePresences.collect(Input)
+       }
+
+
+       def getAt(int ix) {
+               mobilePresences[ix]
+       }
+}
index 82c6adf..d00c699 100644 (file)
@@ -4,6 +4,23 @@ import itertools
 import sys
 import os
 
+# Helper methods
+# Check the result in the log and print a summary
+def checkResult(logDirName):
+       extractResult = open(logDirName, "r")
+       result = "other errors--PLEASE CHECK!"
+       
+       for line in extractResult:
+               if "no errors detected" in line:
+                       result = "no conflict"
+                       break
+               elif "java.lang.RuntimeException: Conflict between apps App1 and App2:" in line:
+                       result = "conflict"
+                       break
+       
+       return result
+
+
 # Input parameters:
 # - JPF directory
 # - JPF logs directory
@@ -17,6 +34,7 @@ jpfLogDir = sys.argv[2]
 appDir = sys.argv[3]
 firstList = sys.argv[4]
 
+
 # PART 1: Generate the permutations of app pairs
 print "PHASE 1: Extracting the app pairs from the app lists ...\n"
 appList1 = []
@@ -30,6 +48,7 @@ extractAppList.close()
 
 # Try to create pairs
 appPairs = []
+useSecondList = False
 # Extract the second list if provided (this is for combinations between two lists)
 if (len(sys.argv) == 6):
        secondList = sys.argv[5]
@@ -38,22 +57,35 @@ if (len(sys.argv) == 6):
                if '#' not in app:
                        appList2.append(app.strip())
        extractAppList.close()
+       useSecondList = True
 # Just copy the first list to the second list
 else:
        appList2 = appList1
 
-# Generate the permutations of pairs
-for i in range(len(appList1)):
-       for j in range(i + 1, len(appList2)):
-               appPairs.append((appList1[i], appList2[j]))
+if useSecondList is False:
+       # Generate the permutations of pairs
+       for i in range(len(appList1)):
+               for j in range(i + 1, len(appList2)):
+                       appPairs.append((appList1[i], appList2[j]))
+else:
+       # Generate pairs from 2 lists
+       for i in range(len(appList1)):
+               for j in range(len(appList2)):
+                       # Skip if both are the same
+                       if appList1[i] == appList2[j]:
+                               continue
+                       appPairs.append((appList1[i], appList2[j]))
 
+               
 # PART 2: 
 print "PHASE 2: Running JPF ...\n"
 # List down all the log file names
 writeLogList = open(jpfLogDir + "logList", "w+")
 for item in appPairs:
 
-       # Copy apps into Extractor/App1 and Extractor/App2      
+       # Copy apps into Extractor/App1 and Extractor/App2
+       print "==> First app: %s" % item[0]
+       print "==> Second app: %s" % item[1]            
        os.system("cp " + appDir + item[0] + " Extractor/App1/App1.groovy")
        os.system("cp " + appDir + item[1] + " Extractor/App2/App2.groovy")
        
@@ -64,8 +96,24 @@ for item in appPairs:
        
        # Call JPF
        print "==> Calling JPF and generate logs ...\n"
-       logName = jpfLogDir + item[0] + "--" + item[1] + ".log"
-       writeLogList.write(logName + "\n")
-       os.system("cd " + jpfDir + ";./run.sh " + logName + " main.jpf")
-       
+       logName = item[0] + "--" + item[1] + ".log"
+       os.system("cd " + jpfDir + ";./run.sh " + jpfLogDir + logName + " main.jpf")
+       result = checkResult(jpfLogDir + logName)
+       writeLogList.write(logName + "\t\t" + result + "\n")
+
 writeLogList.close()
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
index 863903c..8516713 100644 (file)
@@ -2,6 +2,9 @@
 package MotionSensor
 import Timer.SimulatedTimer
 
+//JPF's Verify API
+import gov.nasa.jpf.vm.Verify
+
 public class MotionSensors {
        private int deviceNumbers
        private List motionSensors
@@ -21,6 +24,14 @@ public class MotionSensors {
                this.deviceNumbers = deviceNumbers
                this.motionSensors = []
 
+               def init = Verify.getBoolean()
+               if (init) {
+                       this.motion = "inactive"
+                       this.motionLatestValue = "inactive"
+               } else {
+                       this.motion = "active"
+                       this.motionLatestValue = "active"
+               }
                motionSensors.add(new MotionSensor(id, label, displayName, this.motion, this.motionLatestValue))
        }
 
index 1e4d62c..675f47a 100644 (file)
@@ -28,19 +28,19 @@ public class MusicPlayer {
 
        //By model checker
        def setValue(String value, String name) {
-               if (name == "status") {
+               if ((name == "status") && (value != this.status)) {
                        this.status = value
                        println("the status of the music player with id:$id is changed to $value!")
-               } else if (name == "level") {
+               } else if ((name == "level") && (value != this.level)) {
                        this.level = value.toInteger()
                        println("the level sound of the music player with id:$id is changed to $value!")
-               } else if (name == "trackDescription") {
+               } else if ((name == "trackDescription") && (value != this.trackDescription)) {
                        this.trackDescription = value
                        println("the trackDescription of the music player with id:$id is changed to $value!")
-               } else if (name == "trackData") {
+               } else if ((name == "trackData") && (value != this.trackData)) {
                        this.trackData = value
                        println("the trackData of the music player with id:$id is changed to $value!")
-               } else if (name == "mute") {
+               } else if ((name == "mute") && (value != this.mute)) {
                        this.mute = value
                        println("the mute state of the music player with id:$id is changed to $value!")
                }
@@ -48,58 +48,70 @@ public class MusicPlayer {
 
        //methods
        def mute() {
-               println("the music player with id:$id is muted!")
-               this.mute = "muted"
-               sendEvent([name: "mute", value: "mute", deviceId: this.id, descriptionText: "",
-                          displayed: true, linkText: "", isStateChange: false, unit: "", data: [value: "mute"]])
+               if (mute != "muted") {
+                       println("the music player with id:$id is muted!")
+                       this.mute = "muted"
+                       sendEvent([name: "mute", value: "mute", deviceId: this.id, descriptionText: "",
+                                  displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
+               }
        }
        def nextTrack() {
                trackNumber = trackNumber+1
                def trackPlaying = trackData
                println("the $trackPlaying is selected!")
-               this.status = "playing"
-               sendEvent([name: "status", value: "playing", deviceId: this.id, descriptionText: "",
-                          displayed: true, linkText: "", isStateChange: false, unit: "", data: [value: "playing"]])
+               if (status != "playing") {
+                       this.status = "playing"
+                       sendEvent([name: "status", value: "playing", deviceId: this.id, descriptionText: "",
+                                  displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
+               }
                sendEvent([name: "trackDescription", value: "someDescriptions", deviceId: this.id, descriptionText: "",
-                          displayed: true, linkText: "", isStateChange: false, unit: "", data: [value: "someDescriptions"]])
+                          displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
                sendEvent([name: "trackData", value: "someTrack", deviceId: this.id, descriptionText: "",
-                          displayed: true, linkText: "", isStateChange: false, unit: "", data: [value: "someTrack"]])
+                          displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
        }
        def pause() {
-               println("the music player with id:$id is paused!")
-               this.status = "paused"
-               sendEvent([name: "status", value: "paused", deviceId: this.id, descriptionText: "",
-                          displayed: true, linkText: "", isStateChange: false, unit: "", data: [value: "paused"]])
+               if (status != "paused") {
+                       println("the music player with id:$id is paused!")
+                       this.status = "paused"
+                       sendEvent([name: "status", value: "paused", deviceId: this.id, descriptionText: "",
+                                  displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
+               }
        }
        def play() {
-               println("the music player with id:$id is starting to play!")
-               this.status = "playing"
-               sendEvent([name: "status", value: "playing", deviceId: this.id, descriptionText: "",
-                          displayed: true, linkText: "", isStateChange: false, unit: "", data: [value: "playing"]])
+               if (status != "playing") {
+                       println("the music player with id:$id is starting to play!")
+                       this.status = "playing"
+                       sendEvent([name: "status", value: "playing", deviceId: this.id, descriptionText: "",
+                                  displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
+               }
        }
        def playTrack(String trackToPlay) {
                def trackPlaying = trackData
                println("the $trackPlaying is selected to play!")
-               this.status = "playing"
-               sendEvent([name: "status", value: "playing", deviceId: this.id, descriptionText: "",
-                          displayed: true, linkText: "", isStateChange: false, unit: "", data: [value: "playing"]])
+               if (status != "playing") {              
+                       this.status = "playing"
+                       sendEvent([name: "status", value: "playing", deviceId: this.id, descriptionText: "",
+                                  displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
+               }
                sendEvent([name: "trackDescription", value: "someDescriptions", deviceId: this.id, descriptionText: "",
-                          displayed: true, linkText: "", isStateChange: false, unit: "", data: [value: "someDescriptions"]])
+                          displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
                sendEvent([name: "trackData", value: "someTrack", deviceId: this.id, descriptionText: "",
-                          displayed: true, linkText: "", isStateChange: false, unit: "", data: [value: "someTrack"]])
+                          displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
        }
        def previousTrack() {
                if (trackNumber != 1)
                        trackNumber = trackNumber-1
                def trackPlaying = trackData
                println("the $trackPlaying is selected!")
-               this.status = "playing"
-               sendEvent([name: "status", value: "playing", deviceId: this.id, descriptionText: "",
-                          displayed: true, linkText: "", isStateChange: false, unit: "", data: [value: "playing"]])
+               if (status != "playing") {
+                       this.status = "playing"
+                       sendEvent([name: "status", value: "playing", deviceId: this.id, descriptionText: "",
+                                  displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
+               }
                sendEvent([name: "trackDescription", value: "someDescriptions", deviceId: this.id, descriptionText: "",
-                          displayed: true, linkText: "", isStateChange: false, unit: "", data: [value: "someDescriptions"]])
+                          displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
                sendEvent([name: "trackData", value: "someTrack", deviceId: this.id, descriptionText: "",
-                          displayed: true, linkText: "", isStateChange: false, unit: "", data: [value: "someTrack"]])
+                          displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
        }
        /*def restoreTrack(String trackToRestore) {
                musicPlayers*.restoreTrack(trackToRestore)
@@ -107,32 +119,40 @@ public class MusicPlayer {
        def resumeTrack(String trackToResume) {
                def trackPlaying = trackData
                println("the $trackPlaying is resumed!")
-               this.status = "playing"
-               sendEvent([name: "status", value: "playing", deviceId: this.id, descriptionText: "",
-                          displayed: true, linkText: "", isStateChange: false, unit: "", data: [value: "playing"]])
+               if (status != "playing") {
+                       this.status = "playing"
+                       sendEvent([name: "status", value: "playing", deviceId: this.id, descriptionText: "",
+                                  displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
+               }
        }
        def setLevel(int level) {
-               this.level = level
-               println("the level of sound is changed to $level!")
-               sendEvent([name: "level", value: "$level", deviceId: this.id, descriptionText: "",
-                          displayed: true, linkText: "", isStateChange: false, unit: "", data: [value: "$level"]])
+               if (level != this.level) {
+                       this.level = level
+                       println("the level of sound is changed to $level!")
+                       sendEvent([name: "level", value: "$level", deviceId: this.id, descriptionText: "",
+                                  displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
+               }
        }
        def setTrack(String trackToSet) {
                def trackPlaying = trackData
                println("the $trackPlaying is set!")
-               this.status = "playing"
-               sendEvent([name: "status", value: "playing", deviceId: this.id, descriptionText: "",
-                          displayed: true, linkText: "", isStateChange: false, unit: "", data: [value: "playing"]])
+               if (status != "playing") {
+                       this.status = "playing"
+                       sendEvent([name: "status", value: "playing", deviceId: this.id, descriptionText: "",
+                                  displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
+               }
                sendEvent([name: "trackDescription", value: "someDescriptions", deviceId: this.id, descriptionText: "",
-                          displayed: true, linkText: "", isStateChange: false, unit: "", data: [value: "someDescriptions"]])
+                          displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
                sendEvent([name: "trackData", value: "someTrack", deviceId: this.id, descriptionText: "",
-                          displayed: true, linkText: "", isStateChange: false, unit: "", data: [value: "someTrack"]])
+                          displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
        }
        def stop() {
-               println("the music player with id:$id is stopped!")
-               this.status = "stopped"
-               sendEvent([name: "status", value: "stopped", deviceId: this.id, descriptionText: "",
-                          displayed: true, linkText: "", isStateChange: false, unit: "", data: [value: "stopped"]])
+               if (status != "stopped") {
+                       println("the music player with id:$id is stopped!")
+                       this.status = "stopped"
+                       sendEvent([name: "status", value: "stopped", deviceId: this.id, descriptionText: "",
+                                  displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
+               }
        }
 
        def currentValue(String deviceFeature) {
index bf733db..63a213b 100644 (file)
@@ -2,6 +2,8 @@
 package MusicPlayer
 import Timer.SimulatedTimer
 
+//JPF's Verify API
+import gov.nasa.jpf.vm.Verify
 
 public class MusicPlayers {
        private int deviceNumbers
@@ -14,7 +16,7 @@ public class MusicPlayers {
        private String displayName = "musicPlayer0"
        private int level = 20
        private String mute = "unmuted"
-       private String status = "pause"
+       private String status = "paused"
        private int trackNumber = 1
        private String trackData = "someTrack"
        private String trackDescription = "someDescriptions"
@@ -26,6 +28,21 @@ public class MusicPlayers {
                this.deviceNumbers = deviceNumbers
                this.musicPlayers = []
 
+               def initLevel = Verify.getIntFromList(10, 20, 30)
+               this.level = initLevel
+               def initMute = Verify.getBoolean()
+               if (initMute) {
+                       this.mute = "unmuted"
+               } else {
+                       this.mute = "mute"
+               }
+               def initStatus = Verify.getBoolean()
+               if (initStatus) {
+                       this.status = "paused"
+               } else {
+                       this.status = "playing"
+               }
+
                musicPlayers.add(new MusicPlayer(id, label, displayName, this.level, this.mute, this.status, this.trackNumber, this.trackData, this.trackDescription))
        }
 
@@ -83,30 +100,42 @@ public class MusicPlayers {
 
        //methods
        def mute() {
-               musicPlayers[0].mute()
-               this.mute = "muted"
+               if (mute != "muted") {
+                       musicPlayers[0].mute()
+                       this.mute = "muted"
+               }
        }
        def nextTrack() {
                musicPlayers[0].nextTrack()
-               this.status = "playing"
+               if (status != "playing") {
+                       this.status = "playing"
+               }
                this.trackNumber = musicPlayers[0].trackNumber
        }
        def pause() {
-               musicPlayers[0].pause()
-               this.status = "paused"
+               if (status != "paused") {
+                       musicPlayers[0].pause()
+                       this.status = "paused"
+               }
        }
        def play() {
-               musicPlayers[0].play()
-               this.status = "playing"
+               if (status != "playing") {
+                       musicPlayers[0].play()
+                       this.status = "playing"
+               }
        }
        def playTrack(String trackToPlay) {
                musicPlayers[0].playTrack(trackToPlay)
-               this.status = "playing"
+               if (status != "playing") {
+                       this.status = "playing"
+               }
                this.trackNumber = musicPlayers[0].trackNumber
        }
        def previousTrack() {
                musicPlayers[0].previousTrack()
-               this.status = "playing"
+               if (status != "playing") {
+                       this.status = "playing"
+               }
                this.trackNumber = musicPlayers[0].trackNumber
        }
        def restoreTrack(String trackToRestore) {
@@ -114,20 +143,28 @@ public class MusicPlayers {
        }
        def resumeTrack(String trackToResume) {
                musicPlayers[0].resumeTrack(trackToResume)
-               this.status = "playing"
+               if (status != "playing") {
+                       this.status = "playing"
+               }
        }
        def setLevel(int level) {
-               musicPlayers[0].setLevel(level)
-               this.level = level
+               if (level != this.level) {              
+                       musicPlayers[0].setLevel(level)
+                       this.level = level
+               }
        }
        def setTrack(String trackToSet) {
                musicPlayers[0].setTrack(trackToSet)
-               this.status = "playing"
+               if (status != "playing") {
+                       this.status = "playing"
+               }
                this.trackNumber = musicPlayers[0].trackNumber
        }
        def stop() {
-               musicPlayers[0].stop()
-               this.status = "stopped"
+               if (status != "stopped") {
+                       musicPlayers[0].stop()
+                       this.status = "stopped"
+               }
        }
 
        def currentValue(String deviceFeature) {
diff --git a/PowerMeter/PowerMeter.groovy b/PowerMeter/PowerMeter.groovy
new file mode 100644 (file)
index 0000000..212d5fa
--- /dev/null
@@ -0,0 +1,32 @@
+//Create a class for power meter
+package PowerMeter
+import Timer.SimulatedTimer
+
+public class PowerMeter {
+       private String id
+       private String label
+       private String displayName
+       private int power
+       private int currentPower
+
+       PowerMeter(String id, String label, String displayName, int power) {
+               this.id = id
+               this.label = label
+               this.displayName = displayName
+               this.power = power
+       }
+
+       //By Model Checker
+       def setValue(String value) {
+               println("the power is changed to $value!")
+               this.power = value.toInteger()
+               this.currentPower = value.toInteger()
+       }
+
+       def currentValue(String deviceFeature) {
+               if (deviceFeature == "power") {
+                       return power
+               }
+       }
+
+}
diff --git a/PowerMeter/PowerMeters.groovy b/PowerMeter/PowerMeters.groovy
new file mode 100644 (file)
index 0000000..b452ec8
--- /dev/null
@@ -0,0 +1,61 @@
+//Create a class for power meter
+package PowerMeter
+import Timer.SimulatedTimer
+
+public class PowerMeters {
+       private int deviceNumbers
+       private List powerMeters
+       def sendEvent
+
+       //For one device(We cannot have obj.id)-> We should have obj[0].id
+       private String id = "powerMeterID0"
+       private String label = "powerMeter0"
+       private String displayName = "powerMeter0"
+       private int power = 50
+       private int currentPower = 50
+
+               
+       PowerMeters(Closure sendEvent, int deviceNumbers) {
+               this.sendEvent = sendEvent              
+               this.deviceNumbers = deviceNumbers
+               this.powerMeters = []
+
+               powerMeters.add(new PowerMeter(id, label, displayName, this.power))
+       }
+
+       //By Model Checker
+       def setValue(LinkedHashMap eventDataMap) {
+               if (eventDataMap["value"] != powerMeters[0].power) {
+                       powerMeters[0].setValue(eventDataMap["value"])
+                       this.power = powerMeters[0].power
+                       this.currentPower = powerMeters[0].currentPower
+                       sendEvent(eventDataMap)
+               }
+       }
+
+       //Methods for closures
+       def count(Closure Input) {
+               powerMeters.count(Input)
+       }
+       def size() {
+               powerMeters.size()
+       }
+       def each(Closure Input) {
+               powerMeters.each(Input)
+       }
+       def find(Closure Input) {
+               powerMeters.find(Input)
+       }
+       def collect(Closure Input) {
+               powerMeters.collect(Input)
+       }
+
+
+       def currentValue(String deviceFeature) {
+               powerMeters[0].currentValue(deviceFeature)//It is called if we have only one device
+       }
+
+       def getAt(int ix) {
+               powerMeters[ix]
+       }
+}
index 2408a5a..cb13242 100644 (file)
@@ -2,6 +2,9 @@
 package PresenceSensor
 import Timer.SimulatedTimer
 
+//JPF's Verify API
+import gov.nasa.jpf.vm.Verify
+
 public class PresenceSensors {
        private int deviceNumbers
        private List presenceSensors
@@ -20,6 +23,14 @@ public class PresenceSensors {
                this.sendEvent = sendEvent              
                this.deviceNumbers = deviceNumbers
                this.presenceSensors = []
+               def init = Verify.getBoolean()
+               if (init) {
+                       this.presence = "not present"
+                       this.presenceLatestValue = "not present"
+               } else {
+                       this.presence = "present"
+                       this.presenceLatestValue = "present"
+               }
 
                presenceSensors.add(new PresenceSensor(id, label, displayName, this.presence, this.presenceLatestValue))
        }
diff --git a/RelativeHumidityMeasurement/RelativeHumidityMeasurement.groovy b/RelativeHumidityMeasurement/RelativeHumidityMeasurement.groovy
new file mode 100644 (file)
index 0000000..083bd8f
--- /dev/null
@@ -0,0 +1,32 @@
+//Create a class for relative humidity measurement
+package RelativeHumidityMeasurement
+import Timer.SimulatedTimer
+
+public class RelativeHumidityMeasurement {
+       private String id
+       private String label
+       private String displayName
+       private int humidity
+       private int currentHumidity
+
+       RelativeHumidityMeasurement(String id, String label, String displayName, int humidity) {
+               this.id = id
+               this.label = label
+               this.displayName = displayName
+               this.humidity = humidity
+       }
+
+       //By Model Checker
+       def setValue(String value) {
+               println("the humidity is changed to $value!")
+               this.humidity = value.toInteger()
+               this.currentHumidity = value.toInteger()
+       }
+
+       def currentValue(String deviceFeature) {
+               if (deviceFeature == "humidity") {
+                       return humidity
+               }
+       }
+
+}
diff --git a/RelativeHumidityMeasurement/RelativeHumidityMeasurements.groovy b/RelativeHumidityMeasurement/RelativeHumidityMeasurements.groovy
new file mode 100644 (file)
index 0000000..bb5390a
--- /dev/null
@@ -0,0 +1,61 @@
+//Create a class for relative humidity measurement
+package RelativeHumidityMeasurement
+import Timer.SimulatedTimer
+
+public class RelativeHumidityMeasurements {
+       private int deviceNumbers
+       private List humidityMeasurements
+       def sendEvent
+
+       //For one device(We cannot have obj.id)-> We should have obj[0].id
+       private String id = "humidityMeasurementID0"
+       private String label = "humidityMeasurement0"
+       private String displayName = "humidityMeasurement0"
+       private int humidity = 50
+       private int currentHumidity = 50
+
+               
+       RelativeHumidityMeasurements(Closure sendEvent, int deviceNumbers) {
+               this.sendEvent = sendEvent              
+               this.deviceNumbers = deviceNumbers
+               this.humidityMeasurements = []
+
+               humidityMeasurements.add(new RelativeHumidityMeasurement(id, label, displayName, this.humidity))
+       }
+
+       //By Model Checker
+       def setValue(LinkedHashMap eventDataMap) {
+               if (eventDataMap["value"] != humidityMeasurements[0].humidity) {
+                       humidityMeasurements[0].setValue(eventDataMap["value"])
+                       this.humidity = humidityMeasurements[0].humidity
+                       this.currentHumidity = humidityMeasurements[0].currentHumidity          
+                       sendEvent(eventDataMap)
+               }
+       }
+
+       //Methods for closures
+       def count(Closure Input) {
+               humidityMeasurements.count(Input)
+       }
+       def size() {
+               humidityMeasurements.size()
+       }
+       def each(Closure Input) {
+               humidityMeasurements.each(Input)
+       }
+       def find(Closure Input) {
+               humidityMeasurements.find(Input)
+       }
+       def collect(Closure Input) {
+               humidityMeasurements.collect(Input)
+       }
+
+
+       def currentValue(String deviceFeature) {
+               humidityMeasurements[0].currentValue(deviceFeature)//It is called if we have only one device
+       }
+
+       def getAt(int ix) {
+               humidityMeasurements[ix]
+       }
+}
diff --git a/RelaySwitch/RelaySwitch.groovy b/RelaySwitch/RelaySwitch.groovy
new file mode 100644 (file)
index 0000000..b418477
--- /dev/null
@@ -0,0 +1,95 @@
+//Create a class for relay switch device
+package RelaySwitch
+import Timer.SimulatedTimer
+
+public class RelaySwitch {
+       private String id
+       private String label
+       private String displayName
+       private String switchState
+       private String currentSwitch
+       private String switchLatestValue
+       def sendEvent   
+       def timers
+       
+
+       RelaySwitch(Closure sendEvent, String id, String label, String displayName, String switchState, String currentSwitch, String switchLatestValue) {
+               this.sendEvent = sendEvent
+               this.timers = new SimulatedTimer()
+               this.currentSwitch = currentSwitch
+               this.id = id
+               this.label = label
+               this.displayName = displayName
+               this.switchState = switchState
+               this.switchLatestValue = switchLatestValue
+       }
+
+       //By Apps
+       def on() {
+               if (switchState != "on") {
+                       println("the relay switch with id:$id is on!")
+                       this.switchLatestValue = this.switchState
+                       this.switchState = "on"
+                       this.currentSwitch = "on"
+                       sendEvent([name: "switch", value: "on", deviceId: this.id, descriptionText: "",
+                                 displayed: true, linkText: "", isStateChange: false, unit: "", data: [value: "on"]])
+               }
+       }
+
+       def on(LinkedHashMap metaData) {
+               if (switchState != "on") {
+                       def task = timers.runAfter(metaData["delay"]) {
+                               println("the relay switch with id:$id is on!")
+                               this.switchLatestValue = this.switchState
+                               this.switchState = "on"
+                               this.currentSwitch = "on"
+                               sendEvent([name: "switch", value: "on", deviceId: this.id, descriptionText: "",
+                                         displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
+                       }
+               }
+       }
+
+       def off() {
+               if (switchState != "off") {
+                       println("the relay switch with id:$id is off!")
+                       this.switchLatestValue = this.switchState
+                       this.switchState = "off"
+                       this.currentSwitch = "off"
+                       sendEvent([name: "switch", value: "off", deviceId: this.id, descriptionText: "",
+                                 displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
+               }
+       }
+
+       def off(LinkedHashMap metaData) {
+               if (switchState != "off") {
+                       def task = timers.runAfter(metaData["delay"]) {
+                               println("the relay switch with id:$id is off!")
+                               this.switchLatestValue = this.switchState
+                               this.switchState = "off"
+                               this.currentSwitch = "off"
+                               sendEvent([name: "switch", value: "off", deviceId: this.id, descriptionText: "",
+                                         displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
+                       }
+               }
+       }
+
+       //By Model Checker
+       def setValue(String value) {
+               println("the relay switch with id:$id is $value!")
+               this.switchLatestValue = this.switchState
+               this.switchState = value
+               this.currentSwitch = value
+       }
+       
+       def currentValue(String deviceFeature) {
+               if (deviceFeature == "switch") {
+                       return switchState
+               }
+       }
+
+       def latestValue(String deviceFeature) {
+               if (deviceFeature == "switch") {
+                       return switchLatestValue
+               }
+       }
+}
diff --git a/RelaySwitch/RelaySwitches.groovy b/RelaySwitch/RelaySwitches.groovy
new file mode 100644 (file)
index 0000000..afb3ace
--- /dev/null
@@ -0,0 +1,108 @@
+//Create a class for relay switch device
+package RelaySwitch
+import Timer.SimulatedTimer
+
+public class RelaySwitches {
+       int deviceNumbers       
+       List relaySwitches
+       def timers
+       def sendEvent
+
+       //If we have only one device
+       private String id = "relaySwitchID0"
+       private String label = "relaySwitch0"
+       private String displayName = "relaySwitch0"
+       private String switchState = "off"
+       private String currentSwitch = "off"
+       private String switchLatestValue = "off"
+
+       RelaySwitches(Closure sendEvent, int deviceNumbers) {
+               this.sendEvent = sendEvent
+               this.timers = new SimulatedTimer()
+               this.deviceNumbers = deviceNumbers
+               this.relaySwitches = []
+
+               relaySwitches.add(new RelaySwitch(sendEvent, id, label, displayName, this.switchState, this.currentSwitch, this.switchLatestValue))
+       }
+
+       //Methods for closures
+       def count(Closure Input) {
+               relaySwitches.count(Input)
+       }
+       def size() {
+               relaySwitches.size()
+       }
+       def each(Closure Input) {
+               relaySwitches.each(Input)
+       }
+       def find(Closure Input) {
+               relaySwitches.find(Input)
+       }
+       def collect(Closure Input) {
+               relaySwitches.collect(Input)
+       }
+
+       //By Apps
+       def on() {
+               if (switchState != "on") {
+                       relaySwitches[0].on()
+                       switchLatestValue = switchState
+                       switchState = "on"
+                       currentSwitch = "on"
+               }
+       }
+
+       def on(LinkedHashMap metaData) {
+               if (switchState != "on") {
+                       def task = timers.runAfter(metaData["delay"]) {
+                               relaySwitches[0].on()
+                               switchLatestValue = switchState
+                               switchState = "on"
+                               currentSwitch = "on"
+                       }
+               }
+       }
+
+       def off() {
+               if (switchState != "off") {
+                       relaySwitches[0].off()
+                       switchLatestValue = switchState
+                       switchState = "off"
+                       currentSwitch = "off"
+               }
+       }
+
+       def off(LinkedHashMap metaData) {
+               if (switchState != "off") {
+                       def task = timers.runAfter(metaData["delay"]) {
+                               relaySwitches[0].off()
+                               switchLatestValue = switchState
+                               switchState = "off"
+                               currentSwitch = "off"
+                       }
+               }
+       }
+
+       //By Model Checker
+       def setValue(LinkedHashMap eventDataMap) {
+               if (eventDataMap["value"] != relaySwitches[0].switchState) {
+                       relaySwitches[0].setValue(eventDataMap["value"])
+                       this.switchState = relaySwitches[0].switchState
+                       this.switchLatestValue = relaySwitches[0].switchLatestValue
+                       sendEvent(eventDataMap)
+               }
+       }
+
+
+       def currentValue(String deviceFeature) {
+               relaySwitches[0].currentValue(deviceFeature)
+       }
+
+       def latestValue(String deviceFeature) {
+               relaySwitches[0].latestValue(deviceFeature)
+       }
+
+       def getAt(int ix) {
+               relaySwitches[ix]
+       }
+}
index 9c2da70..d72844d 100644 (file)
--- a/Runner.py
+++ b/Runner.py
@@ -21,9 +21,14 @@ sendSms = open("Methods/"+"sendSms.groovy", "r")
 sendPush = open("Methods/"+"sendPush.groovy", "r")
 eventHandler = open("Methods/"+"eventHandler.groovy", "r")
 schedule = open("Methods/"+"schedule.groovy", "r")
+httpPostJson = open("Methods/"+"httpPostJson.groovy", "r")
 now = open("Methods/"+"now.groovy", "r")
 getTemperatureScale = open("Methods/"+"getTemperatureScale.groovy", "r")
 getSunriseAndSunset = open("Methods/"+"getSunriseAndSunset.groovy", "r")
+runEvery15Minutes = open("Methods/"+"runEvery15Minutes.groovy", "r")
+timeToday = open("Methods/"+"timeToday.groovy", "r")
+sendNotification = open("Methods/"+"sendNotification.groovy", "r")
+canSchedule = open("Methods/"+"canSchedule.groovy", "r")
 App1 = open("Extractor/"+"App1/App1.groovy", "r")
 extractedObjectsApp1 = open("Extractor/"+"App1/extractedObjectsApp1.groovy", "r")
 extractedObjectsConstructorApp1 = open("Extractor/"+"App1/extractedObjectsConstructorApp1.groovy", "r")
@@ -35,6 +40,7 @@ extractedFunctionsApp1 = open("Extractor/"+"App1/extractedFunctionsApp1.groovy",
 Out.write("//Infrastructure for SmartThings Application\n")
 Out.write("//Importing Libraries\n")
 Out.write("import groovy.transform.Field\n")
+Out.write("import groovy.json.JsonSlurper\n")
 Out.write("\n")
 Out.write("//Importing Classes\n")
 Out.write("import ContactSensor.ContactSensor\n")
@@ -80,7 +86,30 @@ Out.write("import ColorControl.ColorControl\n")
 Out.write("import ColorControl.ColorControls\n")
 Out.write("import EnergyMeter.EnergyMeter\n")
 Out.write("import EnergyMeter.EnergyMeters\n")
+Out.write("import IlluminanceMeasurement.IlluminanceMeasurement\n")
+Out.write("import IlluminanceMeasurement.IlluminanceMeasurements\n")
+Out.write("import PowerMeter.PowerMeter\n")
+Out.write("import PowerMeter.PowerMeters\n")
+Out.write("import RelativeHumidityMeasurement.RelativeHumidityMeasurement\n")
+Out.write("import RelativeHumidityMeasurement.RelativeHumidityMeasurements\n")
+Out.write("import RelaySwitch.RelaySwitch\n")
+Out.write("import RelaySwitch.RelaySwitches\n")
+Out.write("import SleepSensor.SleepSensor\n")
+Out.write("import SleepSensor.SleepSensors\n")
+Out.write("import StepSensor.StepSensor\n")
+Out.write("import StepSensor.StepSensors\n")
+Out.write("import SwitchLevel.SwitchLevel\n")
+Out.write("import SwitchLevel.SwitchLevels\n")
+Out.write("import TemperatureMeasurement.TemperatureMeasurement\n")
+Out.write("import TemperatureMeasurement.TemperatureMeasurements\n")
+Out.write("import WaterSensor.WaterSensor\n")
+Out.write("import WaterSensor.WaterSensors\n")
+Out.write("import Valve.Valve\n")
+Out.write("import Valve.Valves\n")
+Out.write("import MobilePresence.MobilePresence\n")
+Out.write("import MobilePresence.MobilePresences\n")
 Out.write("import Event.Event\n")
+Out.write("import AtomicState.AtomicState\n")
 Out.write("import Timer.SimulatedTimer\n")
 Out.write("\n")
 Out.write("//JPF's Verify API\n")
@@ -99,6 +128,7 @@ Out.write("class App1 {\n")
 Out.write("\tdef reference\n")
 Out.write("\tdef location\n")
 Out.write("\tdef app\n")
+Out.write("\tdef atomicState\n")
 Out.write("\n")
 Out.write("\t//Extracted objects for App1\n")
 for line in extractedObjectsApp1:
@@ -112,6 +142,7 @@ Out.write("\tApp1(Object obj) {\n")
 Out.write("\t\treference = obj\n")
 Out.write("\t\tlocation = obj.locationObject\n")
 Out.write("\t\tapp = obj.appObject\n")
+Out.write("\t\tatomicState = obj.atomicState\n")
 for line in extractedObjectsConstructorApp1:
        Out.write("\t\t"+line)
 Out.write("\t}\n")
@@ -142,6 +173,16 @@ for line in getTemperatureScale:
        Out.write("\t"+line)
 for line in getSunriseAndSunset:
        Out.write("\t"+line)
+for line in httpPostJson:
+       Out.write("\t"+line)
+for line in runEvery15Minutes:
+       Out.write("\t"+line)
+for line in timeToday:
+       Out.write("\t"+line)
+for line in sendNotification:
+       Out.write("\t"+line)
+for line in canSchedule:
+       Out.write("\t"+line)
 Out.write("\n")
 Start = 0
 for line in App1:
@@ -162,11 +203,17 @@ runIn = open("Methods/"+"runIn.groovy", "r")
 unschedule = open("Methods/"+"unschedule.groovy", "r")
 sendNotificationToContacts = open("Methods/"+"sendNotificationToContacts.groovy", "r")
 sendSms = open("Methods/"+"sendSms.groovy", "r")
+sendPush = open("Methods/"+"sendPush.groovy", "r")
 eventHandler = open("Methods/"+"eventHandler.groovy", "r")
 schedule = open("Methods/"+"schedule.groovy", "r")
 now = open("Methods/"+"now.groovy", "r")
 getTemperatureScale = open("Methods/"+"getTemperatureScale.groovy", "r")
 getSunriseAndSunset = open("Methods/"+"getSunriseAndSunset.groovy", "r")
+httpPostJson = open("Methods/"+"httpPostJson.groovy", "r")
+runEvery15Minutes = open("Methods/"+"runEvery15Minutes.groovy", "r")
+timeToday = open("Methods/"+"timeToday.groovy", "r")
+sendNotification = open("Methods/"+"sendNotification.groovy", "r")
+canSchedule = open("Methods/"+"canSchedule.groovy", "r")
 App2 = open("Extractor/"+"App2/App2.groovy", "r")
 extractedObjectsApp2 = open("Extractor/"+"App2/extractedObjectsApp2.groovy", "r")
 extractedObjectsConstructorApp2 = open("Extractor/"+"App2/extractedObjectsConstructorApp2.groovy", "r")
@@ -177,6 +224,7 @@ Out.write("class App2 {\n")
 Out.write("\tdef reference\n")
 Out.write("\tdef location\n")
 Out.write("\tdef app\n")
+Out.write("\tdef atomicState\n")
 Out.write("\n")
 Out.write("\t//Extracted objects for App2\n")
 for line in extractedObjectsApp2:
@@ -190,6 +238,7 @@ Out.write("\tApp2(Object obj) {\n")
 Out.write("\t\treference = obj\n")
 Out.write("\t\tlocation = obj.locationObject\n")
 Out.write("\t\tapp = obj.appObject\n")
+Out.write("\t\tatomicState = obj.atomicState\n")
 for line in extractedObjectsConstructorApp2:
        Out.write("\t\t"+line)
 Out.write("\t}\n")
@@ -220,6 +269,16 @@ for line in getTemperatureScale:
        Out.write("\t"+line)
 for line in getSunriseAndSunset:
        Out.write("\t"+line)
+for line in httpPostJson:
+       Out.write("\t"+line)
+for line in runEvery15Minutes:
+       Out.write("\t"+line)
+for line in timeToday:
+       Out.write("\t"+line)
+for line in sendNotification:
+       Out.write("\t"+line)
+for line in canSchedule:
+       Out.write("\t"+line)
 Out.write("\n")
 Start = 0
 for line in App2:
@@ -229,11 +288,24 @@ for line in App2:
                Out.write("\t"+line)
 Out.write("}\n")
 Out.write("\n")
-Out.write("@Field def app1 = new App1(this)\n")
-Out.write("@Field def app2 = new App2(this)\n")
-Out.write("app1.installed()\n")
-Out.write("app2.installed()\n")
-Out.write("\n")
+Out.write("@Field def app1\n")
+Out.write("@Field def app2\n")
+Out.write("def initOrder = Verify.getBoolean()\n")
+Out.write("if (initOrder) {\n")
+Out.write("\tapp1 = new App1(this)\n")
+Out.write("\tapp2 = new App2(this)\n")
+Out.write("} else {\n")
+Out.write("\tapp2 = new App2(this)\n")
+Out.write("\tapp1 = new App1(this)\n")
+Out.write("}\n\n")
+Out.write("def installOrder = Verify.getBoolean()\n")
+Out.write("if (installOrder) {\n")
+Out.write("\tapp1.installed()\n")
+Out.write("\tapp2.installed()\n")
+Out.write("} else {\n")
+Out.write("\tapp2.installed()\n")
+Out.write("\tapp1.installed()\n")
+Out.write("}\n\n")
 for line in eventSimulator:
        Out.write(line)
 Out.close()
diff --git a/SleepSensor/SleepSensor.groovy b/SleepSensor/SleepSensor.groovy
new file mode 100644 (file)
index 0000000..5f6ff9e
--- /dev/null
@@ -0,0 +1,23 @@
+//Create a class for sleep sensor
+package SleepSensor
+import Timer.SimulatedTimer
+
+public class SleepSensor {
+       private String id
+       private String label
+       private String displayName
+       private String sleeping
+
+       SleepSensor(String id, String label, String displayName, String sleeping) {
+               this.id = id
+               this.label = label
+               this.displayName = displayName
+               this.sleeping = sleeping
+       }
+
+       //By Model Checker
+       def setValue(String value) {
+               println("the sleeping state is changed to $value!")
+               this.sleeping = value
+       }
+}
diff --git a/SleepSensor/SleepSensors.groovy b/SleepSensor/SleepSensors.groovy
new file mode 100644 (file)
index 0000000..269a419
--- /dev/null
@@ -0,0 +1,54 @@
+//Create a class for sleep sensor
+package SleepSensor
+import Timer.SimulatedTimer
+
+public class SleepSensors {
+       private int deviceNumbers
+       private List sleepSensors
+       def sendEvent
+
+       //For one device(We cannot have obj.id)-> We should have obj[0].id
+       private String id = "sleepSensorID0"
+       private String label = "sleepSensor0"
+       private String displayName = "sleepSensor0"
+       private String sleeping = "sleeping"
+
+               
+       SleepSensors(Closure sendEvent, int deviceNumbers) {
+               this.sendEvent = sendEvent              
+               this.deviceNumbers = deviceNumbers
+               this.sleepSensors = []
+
+               sleepSensors.add(new SleepSensor(id, label, displayName, this.sleeping))
+       }
+
+       //By Model Checker
+       def setValue(LinkedHashMap eventDataMap) {
+               if (eventDataMap["value"] != sleepSensors[0].sleeping) {
+                       sleepSensors[0].setValue(eventDataMap["value"])
+                       this.sleeping = sleepSensors[0].sleeping
+                       sendEvent(eventDataMap)
+               }
+       }
+
+       //Methods for closures
+       def count(Closure Input) {
+               sleepSensors.count(Input)
+       }
+       def size() {
+               sleepSensors.size()
+       }
+       def each(Closure Input) {
+               sleepSensors.each(Input)
+       }
+       def find(Closure Input) {
+               sleepSensors.find(Input)
+       }
+       def collect(Closure Input) {
+               sleepSensors.collect(Input)
+       }
+
+       def getAt(int ix) {
+               sleepSensors[ix]
+       }
+}
index 95bcb3c..e9d5da2 100644 (file)
@@ -2,6 +2,9 @@
 package SmokeDetector
 import Timer.SimulatedTimer
 
+//JPF's Verify API
+import gov.nasa.jpf.vm.Verify
+
 public class SmokeDetectors {
        private int deviceNumbers
        private List smokeDetectors
@@ -21,6 +24,17 @@ public class SmokeDetectors {
                this.deviceNumbers = deviceNumbers
                this.smokeDetectors = []
 
+               def init = Verify.getInt(0,2)
+               if (init == 0) {
+                       this.currentSmokeValue = "clear"
+                       this.smokeLatestValue = "clear"
+               } else if (init == 1) {
+                       this.currentSmokeValue = "detected"
+                       this.smokeLatestValue = "detected"
+               } else {
+                       this.currentSmokeValue = "tested"
+                       this.smokeLatestValue = "tested"                
+               }
                smokeDetectors.add(new SmokeDetector(id, label, displayName, this.currentSmokeValue, this.smokeLatestValue))
        }
 
index a13e7f7..acc2d80 100644 (file)
@@ -17,8 +17,10 @@ public class SpeechSynthesis {
        }
 
        def setLevel(int level) {
-               println("The level of speech synthesis with id:$id is changed to $level")
-               this.level = level
+               if (level != this.level) {
+                       println("The level of speech synthesis with id:$id is changed to $level")
+                       this.level = level
+               }
        }
 
        def speak(String message) {
index 033db31..2ef8cec 100644 (file)
@@ -2,6 +2,9 @@
 package SpeechSynthesis
 import Timer.SimulatedTimer
 
+//JPF's Verify API
+import gov.nasa.jpf.vm.Verify
+
 public class SpeechSynthesises {
        private int deviceNumbers
        private List speechSynthesises
@@ -19,6 +22,9 @@ public class SpeechSynthesises {
                this.deviceNumbers = deviceNumbers
                this.speechSynthesises = []
 
+               def init = Verify.getIntFromList(30, 50, 70)
+               this.level = init
+
                speechSynthesises.add(new SpeechSynthesis(id, label, displayName, this.level))
        }
 
@@ -40,8 +46,10 @@ public class SpeechSynthesises {
        }
 
        def setLevel(int level) {
-               speechSynthesises[0].setLevel(level)
-               this.level = level
+               if (level != this.level) {
+                       speechSynthesises[0].setLevel(level)
+                       this.level = level
+               }
        }
 
        def speak(String message) {
diff --git a/StepSensor/StepSensor.groovy b/StepSensor/StepSensor.groovy
new file mode 100644 (file)
index 0000000..4a408ad
--- /dev/null
@@ -0,0 +1,30 @@
+//Create a class for step sensor
+package StepSensor
+import Timer.SimulatedTimer
+
+public class StepSensor {
+       private String id
+       private String label
+       private String displayName
+       private int goal
+       private int steps
+
+       StepSensor(String id, String label, String displayName, int steps, int goal) {
+               this.id = id
+               this.label = label
+               this.displayName = displayName
+               this.steps = steps
+               this.goal = goal
+       }
+
+       //By Model Checker
+       def setValue(String value, String name) {
+               if (name == "steps") {
+                       println("the number of steps is changed to $value!")
+                       this.steps = value.toInteger()
+               } else if (name == "goal") {
+                       println("the goal is changed to $value!")
+                       this.goal = value.toInteger()
+               }
+       }
+}
diff --git a/StepSensor/StepSensors.groovy b/StepSensor/StepSensors.groovy
new file mode 100644 (file)
index 0000000..8f0f165
--- /dev/null
@@ -0,0 +1,68 @@
+//Create a class for step sensor
+package StepSensor
+import Timer.SimulatedTimer
+
+public class StepSensors {
+       private int deviceNumbers
+       private List stepSensors
+       def sendEvent
+
+       //For one device(We cannot have obj.id)-> We should have obj[0].id
+       private String id = "stepSensorID0"
+       private String label = "stepSensor0"
+       private String displayName = "stepSensor0"
+       private int goal = 1000
+       private int steps = 0
+
+               
+       StepSensors(Closure sendEvent, int deviceNumbers) {
+               this.sendEvent = sendEvent              
+               this.deviceNumbers = deviceNumbers
+               this.stepSensors = []
+
+               stepSensors.add(new StepSensor(id, label, displayName, this.steps, this.goal))
+       }
+
+       //By Model Checker
+       def setValue(LinkedHashMap eventDataMap) {
+               if (eventDataMap["name"] == "steps") {
+                       if (eventDataMap["value"] != stepSensors[0].steps) {
+                               stepSensors[0].setValue(eventDataMap["value"], "steps")
+                               this.steps = stepSensors[0].steps
+                               sendEvent(eventDataMap)
+                       }
+               } else if (eventDataMap["value"] == "goal") {
+                       if (eventDataMap["value"] != stepSensors[0].goal) {
+                               stepSensors[0].setValue(eventDataMap["value"], "goal")
+                               this.goal = stepSensors[0].goal
+                               sendEvent(eventDataMap)
+                       }
+               }
+       }
+
+       //Methods for closures
+       def count(Closure Input) {
+               stepSensors.count(Input)
+       }
+       def size() {
+               stepSensors.size()
+       }
+       def each(Closure Input) {
+               stepSensors.each(Input)
+       }
+       def find(Closure Input) {
+               stepSensors.find(Input)
+       }
+       def collect(Closure Input) {
+               stepSensors.collect(Input)
+       }
+
+
+       def currentValue(String deviceFeature) {
+               stepSensors[0].currentValue(deviceFeature)//It is called if we have only one device
+       }
+
+       def getAt(int ix) {
+               stepSensors[ix]
+       }
+}
index b9c0a81..d01d27b 100644 (file)
@@ -33,42 +33,50 @@ public class Switch {
        }
 
        def on() {
-               println("the switch with id:$id is on!")
-               this.switchLatestValue = this.switchState
-               this.switchState = "on"
-               this.currentSwitch = "on"
-               sendEvent([name: "switch", value: "on", deviceId: this.id, descriptionText: "",
-                   displayed: true, linkText: "", isStateChange: false, unit: "", data: [value: "on"]])
-       }
-
-       def on(LinkedHashMap metaData) {
-               def task = timers.runAfter(metaData["delay"]) {
+               if (this.switchState != "on") {
                        println("the switch with id:$id is on!")
                        this.switchLatestValue = this.switchState
                        this.switchState = "on"
                        this.currentSwitch = "on"
                        sendEvent(