package AccelerationSensor
import Timer.SimulatedTimer
+//JPF's Verify API
+import gov.nasa.jpf.vm.Verify
+
public class AccelerationSensors {
private int deviceNumbers
private List 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))
}
//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() {
}
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) {
package Alarm
import Timer.SimulatedTimer
+//JPF's Verify API
+import gov.nasa.jpf.vm.Verify
+
public class Alarms {
int deviceNumbers
List 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))
}
//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() {
}
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) {
--- /dev/null
+//
+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"}'])
--- /dev/null
+//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
+ }
+}
package Battery
import Timer.SimulatedTimer
+//JPF's Verify API
+import gov.nasa.jpf.vm.Verify
+
public class Batteries {
private int deviceNumbers
private List 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) {
this.deviceNumbers = deviceNumbers
this.batteries = []
+ def init = Verify.getIntFromList(30, 50, 70)
+ this.battery = init
+
batteries.add(new Battery(id, label, displayName, this.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
package BeaconSensor
import Timer.SimulatedTimer
+//JPF's Verify API
+import gov.nasa.jpf.vm.Verify
+
public class BeaconSensors {
private int deviceNumbers
private List 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))
}
package CarbonMonoxideDetector
import Timer.SimulatedTimer
+//JPF's Verify API
+import gov.nasa.jpf.vm.Verify
+
public class CarbonMonoxideDetectors {
private int deviceNumbers
private List 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))
}
//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!")
}
//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) {
package ColorControl
import Timer.SimulatedTimer
+//JPF's Verify API
+import gov.nasa.jpf.vm.Verify
public class ColorControls {
private int deviceNumbers
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))
}
//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) {
package ContactSensor
import Timer.SimulatedTimer
+//JPF's Verify API
+import gov.nasa.jpf.vm.Verify
+
public class ContactSensors {
private int deviceNumbers
private List contacts
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))
}
//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"}'])
+ }
}
}
package DoorControl
import Timer.SimulatedTimer
+//JPF's Verify API
+import gov.nasa.jpf.vm.Verify
+
public class DoorControls {
int deviceNumbers
List 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))
}
//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()
+ }
}
}
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
//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) {
package EnergyMeter
import Timer.SimulatedTimer
+//JPF's Verify API
+import gov.nasa.jpf.vm.Verify
+
public class EnergyMeters {
private int deviceNumbers
private List energyMeters
private String label = "energyMeter0"
private String displayName = "energyMeter0"
private int energy = 50
+ private int currentEnergy = 50
EnergyMeters(Closure sendEvent, int deviceNumbers) {
this.deviceNumbers = deviceNumbers
this.energyMeters = []
+ def init = Verify.getIntFromList(30, 50, 70)
+ this.energy = init
+
energyMeters.add(new EnergyMeter(id, label, displayName, this.energy))
}
if (eventDataMap["value"] != energyMeters[0].energy) {
energyMeters[0].setValue(eventDataMap["value"])
this.energy = energyMeters[0].energy
+ this.currentEnergy = energyMeters[0].currentEnergy
sendEvent(eventDataMap)
}
}
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
/**
- * 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
+ }*/
+ }
+
+}
+
//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
-//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
-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]
/**
- * 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)
}
}
+
//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.¬ifyUnlocked
+//Global Object for functions in subscribe method!
+def sendMessage = this.&sendMessage
-//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"
-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]
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
+//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!
@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
}
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) {
}
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) {
}
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) {
}
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) {
}
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) {
}
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) {
}
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) {
}
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) {
}
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) {
def href(LinkedHashMap metaData) {
println("//IGNORE--some data//")
}
+
+def href(LinkedHashMap metaData, String name) {
+ println("//IGNORE--some data//")
+}
/////Input Methods/////
def section(LinkedHashMap metaData, Closure inputData) {
find(inputData) //Run the closure to extract inputMethods
}
+
+def mappings(Closure inputData) {
+ println("//IGNORE--some data//")
+}
/////MethodsForExtraction/////
import os
readyToReturn = 0
ToReturn = ""
-eventMap = []
+eventList = []
+eventVarMap = {}
+capabilityMap = {}
app1Capabilities = []
app2Capabilities = []
+app1Subscribe = False
+app2Subscribe = False
def GetToken(f):
global readyToReturn
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)
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)
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
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
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")
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")
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")
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")
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")
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")
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")
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")
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+")
#Prepare eventSimulator file while parsing the App1 and App2 files
extractedEvents = open("eventSimulator/eventSimulator.groovy", "w+")
+CheckIfOnlyTouchEvents()
ExtractEvents(extractedEvents)
extractedEvents.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
extractorFile.close()
Extractor.close()
F2.close()
-os.system("groovy Extractor/extractorFile.groovy")
-
-
+os.system("groovy -classpath lib/jpf.jar Extractor/extractorFile.groovy")
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
+//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
@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
@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
}
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) {
}
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) {
}
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) {
}
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) {
}
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) {
}
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) {
}
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) {
}
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) {
}
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) {
}
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) {
def href(LinkedHashMap metaData) {
println("//IGNORE--some data//")
}
+
+def href(LinkedHashMap metaData, String name) {
+ println("//IGNORE--some data//")
+}
/////Input Methods/////
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:
* 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
//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)
--- /dev/null
+//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
+ }
+ }
+
+}
--- /dev/null
+//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]
+ }
+}
}
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() {
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"
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))
}
}
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() {
class LocationVar {
private int contactBookEnabled
private def modes
+ private def timeZone
private String mode
private List contacts
private List phoneNumbers
this.contacts = ['AJ']
this.phoneNumbers = [9495379373]
this.sendEvent = sendEvent
+ this.timeZone = TimeZone.getTimeZone("America/New_York")
}
//By Model Checker
//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"}'])
+ }
}
}
package Lock
import Timer.SimulatedTimer
+//JPF's Verify API
+import gov.nasa.jpf.vm.Verify
+
public class Locks{
int deviceNumbers
List 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"
}
}
- 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"
}
}
+
+ 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)
--- /dev/null
+/////////////////////////////////////////////////////////////////////
+def canSchedule() {
+ return true
+}
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)
}
}
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)
}
}
/////////////////////////////////////////////////////////////////////
def getTemperatureScale() {
- return 'C' //Celsius for now
+ return 'F' //Celsius for now
}
--- /dev/null
+/////////////////////////////////////////////////////////////////////
+def httpPostJson(LinkedHashMap metaData, Closure inputData) {
+ inputData(metaData)
+}
--- /dev/null
+/////////////////////////////////////////////////////////////////////
+def runEvery15Minutes(Closure inputData) {
+ inputData()
+}
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)
}
}
--- /dev/null
+/////////////////////////////////////////////////////////////////////
+def sendNotification(String text, LinkedHashMap metaData) {
+ println("Sending \""+text+"\" to "+metaData.phone.toString())
+}
--- /dev/null
+/////////////////////////////////////////////////////////////////////
+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
+}
--- /dev/null
+//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
+ }
+}
--- /dev/null
+//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]
+ }
+}
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
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 = []
# 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]
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")
# 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()
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
package MotionSensor
import Timer.SimulatedTimer
+//JPF's Verify API
+import gov.nasa.jpf.vm.Verify
+
public class MotionSensors {
private int deviceNumbers
private List 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))
}
//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!")
}
//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)
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) {
package MusicPlayer
import Timer.SimulatedTimer
+//JPF's Verify API
+import gov.nasa.jpf.vm.Verify
public class MusicPlayers {
private int deviceNumbers
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"
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))
}
//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) {
}
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) {
--- /dev/null
+//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
+ }
+ }
+
+}
--- /dev/null
+//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]
+ }
+}
package PresenceSensor
import Timer.SimulatedTimer
+//JPF's Verify API
+import gov.nasa.jpf.vm.Verify
+
public class PresenceSensors {
private int deviceNumbers
private List 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))
}
--- /dev/null
+//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
+ }
+ }
+
+}
--- /dev/null
+//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]
+ }
+}
--- /dev/null
+//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
+ }
+ }
+}
--- /dev/null
+//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]
+ }
+}
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")
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")
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")
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:
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")
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:
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")
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:
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")
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:
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()
--- /dev/null
+//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
+ }
+}
--- /dev/null
+//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]
+ }
+}
package SmokeDetector
import Timer.SimulatedTimer
+//JPF's Verify API
+import gov.nasa.jpf.vm.Verify
+
public class SmokeDetectors {
private int deviceNumbers
private List 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))
}
}
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) {
package SpeechSynthesis
import Timer.SimulatedTimer
+//JPF's Verify API
+import gov.nasa.jpf.vm.Verify
+
public class SpeechSynthesises {
private int deviceNumbers
private List 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))
}
}
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) {
--- /dev/null
+//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()
+ }
+ }
+}
--- /dev/null
+//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]
+ }
+}
}
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([name: "switch", value: "on", deviceId: this.id, descriptionText: "",
- displayed: true, linkText: "", isStateChange: false, unit: "", data: [value: "on"]])
+ displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
}
}
- def off() {
- println("the 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: [value: "off"]])
+ def on(LinkedHashMap metaData) {
+ if (this.switchState != "on") {
+ def task = timers.runAfter(metaData["delay"]) {
+ 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: '{"info": "info"}'])
+ }
+ }
}
- def off(LinkedHashMap metaData) {
- def task = timers.runAfter(metaData["delay"]) {
+ def off() {
+ if (this.switchState != "off") {
println("the 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: [value: "off"]])
+ displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
+ }
+ }
+
+ def off(LinkedHashMap metaData) {
+ if (this.switchState != "off") {
+ def task = timers.runAfter(metaData["delay"]) {
+ println("the 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"}'])
+ }
}
}
package Switch
import Timer.SimulatedTimer
+//JPF's Verify API
+import gov.nasa.jpf.vm.Verify
+
public class Switches {
int deviceNumbers
List switches
this.deviceNumbers = deviceNumbers
this.switches = []
+ def initLevel = Verify.getIntFromList(30, 50, 70)
+ this.currentLevel = initLevel
+ def init = Verify.getBoolean()
+ if (init) {
+ this.switchState = "off"
+ this.currentSwitch = "off"
+ this.switchLatestValue = "off"
+ } else {
+ this.switchState = "on"
+ this.currentSwitch = "on"
+ this.switchLatestValue = "on"
+ }
+
switches.add(new Switch(sendEvent, id, label, displayName, this.switchState, this.currentSwitch, this.currentLevel, this.switchLatestValue))
}
--- /dev/null
+//Create a class for switch level
+package SwitchLevel
+import Timer.SimulatedTimer
+
+public class SwitchLevel {
+ private String id
+ private String label
+ private String displayName
+ private int level
+ private int rate
+ def sendEvent
+ def timers
+
+
+ SwitchLevel(Closure sendEvent, String id, String label, String displayName, int level) {
+ this.sendEvent = sendEvent
+ this.timers = new SimulatedTimer()
+ this.id = id
+ this.label = label
+ this.displayName = displayName
+ this.level = level
+ this.rate = level
+ }
+
+ //By Apps
+ def setLevel(int level) {
+ if (this.level != level) {
+ println("the switch with id:$id is setted to level $level!")
+ this.level = level
+ this.rate = level
+ sendEvent([name: "level", value: "50", deviceId: this.id, descriptionText: "",
+ displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
+ }
+ }
+
+ //By Model Checker
+ def setValue(String value) {
+ println("the switch with id:$id is setted to level $value!")
+ this.level = value.toInteger()
+ this.rate = value.toInteger()
+ }
+}
--- /dev/null
+//Create a class for switch level
+package SwitchLevel
+import Timer.SimulatedTimer
+
+public class SwitchLevels {
+ int deviceNumbers
+ List switchLevels
+ def timers
+ def sendEvent
+
+ //If we have only one device
+ private String id = "switchLevelID0"
+ private String label = "switchLevel0"
+ private String displayName = "switchLevel0"
+ private int level = 50
+ private int rate = 50
+
+ SwitchLevels(Closure sendEvent, int deviceNumbers) {
+ this.sendEvent = sendEvent
+ this.timers = new SimulatedTimer()
+ this.deviceNumbers = deviceNumbers
+ this.switchLevels = []
+
+ switchLevels.add(new SwitchLevel(sendEvent, id, label, displayName, this.level))
+ }
+
+ //Methods for closures
+ def count(Closure Input) {
+ switchLevels.count(Input)
+ }
+ def size() {
+ switchLevels.size()
+ }
+ def each(Closure Input) {
+ switchLevels.each(Input)
+ }
+ def find(Closure Input) {
+ switchLevels.find(Input)
+ }
+ def collect(Closure Input) {
+ switchLevels.collect(Input)
+ }
+
+ //By Apps
+ def setLevel(int level) {
+ if (this.level != level) {
+ switchLevels[0].setLevel(level)
+ this.level = level
+ this.rate = level
+ }
+ }
+
+ //By Model Checker
+ def setValue(LinkedHashMap eventDataMap) {
+ if (eventDataMap["value"] != switchLevels[0].level) {
+ switchLevels[0].setValue(eventDataMap["value"])
+ this.level = switchLevels[0].level
+ this.rate = switchLevels[0].level
+ sendEvent(eventDataMap)
+ }
+ }
+
+ def getAt(int ix) {
+ switchLevels[ix]
+ }
+}
--- /dev/null
+//Create a class for temperature measurement
+package TemperatureMeasurement
+import Timer.SimulatedTimer
+
+public class TemperatureMeasurement {
+ private String id
+ private String label
+ private String displayName
+ private int temperature
+
+ TemperatureMeasurement(String id, String label, String displayName, int temperature) {
+ this.id = id
+ this.label = label
+ this.displayName = displayName
+ this.temperature = temperature
+ }
+
+ //By Model Checker
+ def setValue(String value) {
+ println("the temperature is changed to $value!")
+ this.temperature = value.toInteger()
+ }
+
+}
--- /dev/null
+//Create a class for temperature measurement
+package TemperatureMeasurement
+import Timer.SimulatedTimer
+
+public class TemperatureMeasurements {
+ private int deviceNumbers
+ private List temperatureMeasurements
+ def sendEvent
+
+ //For one device(We cannot have obj.id)-> We should have obj[0].id
+ private String id = "temperatureMeasurementID0"
+ private String label = "temperatureMeasurement0"
+ private String displayName = "temperatureMeasurement0"
+ private int temperature = 50
+
+
+
+
+ TemperatureMeasurements(Closure sendEvent, int deviceNumbers) {
+ this.sendEvent = sendEvent
+ this.deviceNumbers = deviceNumbers
+ this.temperatureMeasurements = []
+
+ temperatureMeasurements.add(new TemperatureMeasurement(id, label, displayName, this.temperature))
+ }
+
+ //By Model Checker
+ def setValue(LinkedHashMap eventDataMap) {
+ if (eventDataMap["value"] != temperatureMeasurements[0].temperature) {
+ temperatureMeasurements[0].setValue(eventDataMap["value"])
+ this.temperature = temperatureMeasurements[0].temperature
+ sendEvent(eventDataMap)
+ }
+ }
+
+ //Methods for closures
+ def count(Closure Input) {
+ temperatureMeasurements.count(Input)
+ }
+ def size() {
+ temperatureMeasurements.size()
+ }
+ def each(Closure Input) {
+ temperatureMeasurements.each(Input)
+ }
+ def find(Closure Input) {
+ temperatureMeasurements.find(Input)
+ }
+ def collect(Closure Input) {
+ temperatureMeasurements.collect(Input)
+ }
+
+ def getAt(int ix) {
+ temperatureMeasurements[ix]
+ }
+}
//By Apps
def setCoolingSetpoint(int coolingSetpoint) {
- this.coolingSetpoint = coolingSetpoint
- this.currentCoolingSetpoint = currentCoolingSetpoint
- println("Cooling set point for the thermostat with id:$id is changed to $coolingSetpoint!")
- sendEvent([name: "coolingSetpoint", value: "$coolingSetpoint", deviceId: this.id, descriptionText: "",
- displayed: true, linkText: "", isStateChange: false, unit: "", data: [value: "$coolingSetpoint"]])
+ if (this.coolingSetpoint != coolingSetpoint) {
+ this.coolingSetpoint = coolingSetpoint
+ this.currentCoolingSetpoint = currentCoolingSetpoint
+ println("Cooling set point for the thermostat with id:$id is changed to $coolingSetpoint!")
+ sendEvent([name: "coolingSetpoint", value: "$coolingSetpoint", deviceId: this.id, descriptionText: "",
+ displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
+ }
}
def setHeatingSetpoint(int heatingSetpoint) {
- this.heatingSetpoint = heatingSetpoint
- this.currentHeatingSetpoint = currentHeatingSetpoint
- println("Heating set point for the thermostat with id:$id is changed to $heatingSetpoint!")
- sendEvent([name: "heatingSetpoint", value: "$heatingSetpoint", deviceId: this.id, descriptionText: "",
- displayed: true, linkText: "", isStateChange: false, unit: "", data: [value: "$heatingSetpoint"]])
+ if (this.heatingSetpoint != heatingSetpoint) {
+ this.heatingSetpoint = heatingSetpoint
+ this.currentHeatingSetpoint = currentHeatingSetpoint
+ println("Heating set point for the thermostat with id:$id is changed to $heatingSetpoint!")
+ sendEvent([name: "heatingSetpoint", value: "$heatingSetpoint", deviceId: this.id, descriptionText: "",
+ displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
+ }
}
def setSchedule() {
}
def setThermostatFanMode(String thermostatFanMode) {
- this.thermostatFanMode = thermostatFanMode
- println("Fan mode of the thermostat with id:$id is changed to $thermostatFanMode!")
- sendEvent([name: "thermostatFanMode", value: "$thermostatFanMode", deviceId: this.id, descriptionText: "",
- displayed: true, linkText: "", isStateChange: false, unit: "", data: [value: "$thermostatFanMode"]])
+ if (this.thermostatFanMode != thermostatFanMode) {
+ this.thermostatFanMode = thermostatFanMode
+ println("Fan mode of the thermostat with id:$id is changed to $thermostatFanMode!")
+ sendEvent([name: "thermostatFanMode", value: "$thermostatFanMode", deviceId: this.id, descriptionText: "",
+ displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
+ }
}
def setThermostatMode(String thermostatMode) {
- this.thermostatMode = thermostatMode
- this.currentThermostatMode = currentThermostatMode
- println("Mode of the thermostat with id:$id is changed to $thermostatMode!")
- sendEvent([name: "thermostatMode", value: "$thermostatMode", deviceId: this.id, descriptionText: "",
- displayed: true, linkText: "", isStateChange: false, unit: "", data: [value: "$thermostatMode"]])
+ if (this.thermostatMode != thermostatMode) {
+ this.thermostatMode = thermostatMode
+ this.currentThermostatMode = currentThermostatMode
+ println("Mode of the thermostat with id:$id is changed to $thermostatMode!")
+ sendEvent([name: "thermostatMode", value: "$thermostatMode", deviceId: this.id, descriptionText: "",
+ displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
+ }
}
def cool() {
- this.thermostatMode = "cool"
- this.currentThermostatMode = "cool"
- println("Mode of the thermostat with id:$id is changed to cool!")
- sendEvent([name: "cool", value: "cool", deviceId: this.id, descriptionText: "",
- displayed: true, linkText: "", isStateChange: false, unit: "", data: [value: "cool"]])
+ if (this.thermostatMode != "cool") {
+ this.thermostatMode = "cool"
+ this.currentThermostatMode = "cool"
+ println("Mode of the thermostat with id:$id is changed to cool!")
+ sendEvent([name: "cool", value: "cool", deviceId: this.id, descriptionText: "",
+ displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
+ }
}
def heat() {
- this.thermostatMode = "heat"
- this.currentThermostatMode = "heat"
- println("Mode of the thermostat with id:$id is changed to heat!")
- sendEvent([name: "heat", value: "heat", deviceId: this.id, descriptionText: "",
- displayed: true, linkText: "", isStateChange: false, unit: "", data: [value: "heat"]])
+ if (this.thermostatMode != "heat") {
+ this.thermostatMode = "heat"
+ this.currentThermostatMode = "heat"
+ println("Mode of the thermostat with id:$id is changed to heat!")
+ sendEvent([name: "heat", value: "heat", deviceId: this.id, descriptionText: "",
+ displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
+ }
}
def auto() {
- this.thermostatMode = "auto"
- this.currentThermostatMode = "auto"
- println("Mode of the thermostat with id:$id is changed to auto!")
- sendEvent([name: "auto", value: "auto", deviceId: this.id, descriptionText: "",
- displayed: true, linkText: "", isStateChange: false, unit: "", data: [value: "auto"]])
+ if (this.thermostatMode != "auto") {
+ this.thermostatMode = "auto"
+ this.currentThermostatMode = "auto"
+ println("Mode of the thermostat with id:$id is changed to auto!")
+ sendEvent([name: "auto", value: "auto", deviceId: this.id, descriptionText: "",
+ displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
+ }
}
def off() {
- this.thermostatMode = "off"
- this.currentThermostatMode = "off"
- println("Mode of the thermostat with id:$id is changed to off!")
- sendEvent([name: "off", value: "off", deviceId: this.id, descriptionText: "",
- displayed: true, linkText: "", isStateChange: false, unit: "", data: [value: "off"]])
+ if (this.thermostatMode != "off") {
+ this.thermostatMode = "off"
+ this.currentThermostatMode = "off"
+ println("Mode of the thermostat with id:$id is changed to off!")
+ sendEvent([name: "off", value: "off", deviceId: this.id, descriptionText: "",
+ displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
+ }
}
def setClimate(String info, String givenClimateName) {
- this.climateName = givenClimateName
- println("Climate name of the thermostat with id:$id is changed to $givenClimateName!")
+ if (this.climateName != givenClimateName) {
+ this.climateName = givenClimateName
+ println("Climate name of the thermostat with id:$id is changed to $givenClimateName!")
+ }
}
def setHold(String info1, int coolingSetpoint, int heatingSetpoint, String info2, String info3) {
- this.coolingSetpoint = coolingSetpoint
- this.currentCoolingSetpoint = currentCoolingSetpoint
- println("Cooling set point for the thermostat with id:$id is changed to $coolingSetpoint!")
- this.heatingSetpoint = heatingSetpoint
- this.currentHeatingSetpoint = currentHeatingSetpoint
- println("Heating set point for the thermostat with id:$id is changed to $heatingSetpoint!")
+ if ((this.heatingSetpoint != heatingSetpoint) || (this.coolingSetpoint != coolingSetpoint)) {
+ this.coolingSetpoint = coolingSetpoint
+ this.currentCoolingSetpoint = currentCoolingSetpoint
+ println("Cooling set point for the thermostat with id:$id is changed to $coolingSetpoint!")
+ this.heatingSetpoint = heatingSetpoint
+ this.currentHeatingSetpoint = currentHeatingSetpoint
+ println("Heating set point for the thermostat with id:$id is changed to $heatingSetpoint!")
+ }
}
//By Model Checker
def setValue(String value, String name) {
- if (name == "temperature") {
+ if ((name == "temperature") && (value != this.temperature)) {
println("the temperature is $value!")
- this.temperature = value
- } else if (name == "heatingSetpoint") {
+ this.temperature = value.toInteger()
+ } else if ((name == "heatingSetpoint") && (value != this.heatingSetpoint)) {
println("the heating set point of the thermostat with id:$id is $value!")
- this.heatingSetpoint = value
- } else if (name == "coolingSetpoint") {
+ this.heatingSetpoint = value.toInteger()
+ } else if ((name == "coolingSetpoint") && (value != this.coolingSetpoint)) {
println("the cooling set point of the thermostat with id:$id is $value!")
- this.coolingSetpoint = value
- } else if (name == "thermostatSetpoint") {
+ this.coolingSetpoint = value.toInteger()
+ } else if ((name == "thermostatSetpoint") && (value != this.thermostatSetpoint)) {
println("the set point of the thermostat with id:$id is $value!")
- this.thermostatSetpoint = value
- } else if (name == "thermostatMode") {
+ this.thermostatSetpoint = value.toInteger()
+ } else if ((name == "thermostatMode") && (value != this.thermostatMode)) {
println("the mode of the thermostat with id:$id is $value!")
this.thermostatMode = value
- } else if (name == "thermostatFanMode") {
+ } else if ((name == "thermostatFanMode") && (value != this.thermostatFanMode)) {
println("the fan mode of the thermostat with id:$id is $value!")
this.thermostatFanMode = value
- } else if (name == "thermostatOperatingState") {
+ } else if ((name == "thermostatOperatingState") && (value != this.thermostatOperatingState)) {
println("the operating state of the thermostat with id:$id is $value!")
this.thermostatOperatingState = value
}
package Thermostat
import Timer.SimulatedTimer
+//JPF's Verify API
+import gov.nasa.jpf.vm.Verify
+
public class Thermostats{
int deviceNumbers
List thermostats
this.deviceNumbers = deviceNumbers
this.thermostats = []
+ def initTemperature = Verify.getIntFromList(60, 66, 70)
+ this.temperature = initTemperature
+
+ def initCoolingSetpoint = Verify.getIntFromList(70, 80, 90)
+ this.currentCoolingSetpoint = initCoolingSetpoint
+ this.coolingSetpoint = initCoolingSetpoint
+
+ def initHeatingSetpoint = Verify.getIntFromList(20, 35, 50)
+ this.currentHeatingSetpoint = initHeatingSetpoint
+ this.heatingSetpoint = initHeatingSetpoint
+
+ def initThermostatSetpoint = Verify.getIntFromList(50, 60, 70)
+ this.thermostatSetpoint = initThermostatSetpoint
+
+ def initFanMode = Verify.getInt(0,4)
+ if (initFanMode == 0) {
+ this.thermostatFanMode = "auto"
+ } else if (initFanMode == 1) {
+ this.thermostatFanMode = "fanCirculate"
+ } else if (initFanMode == 2) {
+ this.thermostatFanMode = "circulate"
+ } else if (initFanMode == 3) {
+ this.thermostatFanMode = "fanOn"
+ } else {
+ this.thermostatFanMode = "on"
+ }
+
+ def initMode = Verify.getInt(0,4)
+ if (initMode == 0) {
+ this.thermostatMode = "auto"
+ this.currentThermostatMode = "auto"
+ } else if (initMode == 1) {
+ this.thermostatMode = "cool"
+ this.currentThermostatMode = "cool"
+ } else if (initMode == 2) {
+ this.thermostatMode = "emergencyHeat"
+ this.currentThermostatMode = "emergencyHeat"
+ } else if (initMode == 3) {
+ this.thermostatMode = "heat"
+ this.currentThermostatMode = "heat"
+ } else {
+ this.thermostatMode = "off"
+ this.currentThermostatMode = "off"
+ }
+
thermostats.add(new Thermostat(sendEvent, id, label, displayName, this.temperature, this.currentCoolingSetpoint,
this.currentHeatingSetpoint, this.coolingSetpoint, this.thermostatSetpoint, this.heatingSetpoint, this.coolingSetpointRange,
this.thermostatSetpointRange, this.heatingSetpointRange, this.supportedThermostatFanModes, this.supportedThermostatModes,
//By Apps
def setCoolingSetpoint(int coolingSetpoint) {
- thermostats[0].setCoolingSetpoint(coolingSetpoint)
- this.currentCoolingSetpoint = coolingSetpoint
- this.coolingSetpoint = coolingSetpoint
+ if (coolingSetpoint != this.coolingSetpoint) {
+ thermostats[0].setCoolingSetpoint(coolingSetpoint)
+ this.currentCoolingSetpoint = coolingSetpoint
+ this.coolingSetpoint = coolingSetpoint
+ }
}
def setHeatingSetpoint(int heatingSetpoint) {
- thermostats[0].setHeatingSetpoint(heatingSetpoint)
- this.currentHeatingSetpoint = heatingSetpoint
- this.heatingSetpoint = heatingSetpoint
+ if (heatingSetpoint != this.heatingSetpoint) {
+ thermostats[0].setHeatingSetpoint(heatingSetpoint)
+ this.currentHeatingSetpoint = heatingSetpoint
+ this.heatingSetpoint = heatingSetpoint
+ }
}
def setSchedule() {
}
def setThermostatFanMode(String thermostatFanMode) {
- thermostats[0].setThermostatFanMode(thermostatFanMode)
- this.thermostatFanMode = thermostatFanMode
+ if (thermostatFanMode != this.thermostatFanMode) {
+ thermostats[0].setThermostatFanMode(thermostatFanMode)
+ this.thermostatFanMode = thermostatFanMode
+ }
}
def setThermostatMode(String thermostatMode) {
- thermostats[0].setThermostatMode(thermostatMode)
- this.thermostatMode = thermostatMode
- this.currentThermostatMode = currentThermostatMode
+ if (thermostatMode != this.thermostatMode) {
+ thermostats[0].setThermostatMode(thermostatMode)
+ this.thermostatMode = thermostatMode
+ this.currentThermostatMode = currentThermostatMode
+ }
}
def cool() {
- thermostats[0].cool()
- this.thermostatMode = "cool"
- this.currentThermostatMode = "cool"
+ if (thermostatMode != "cool") {
+ thermostats[0].cool()
+ this.thermostatMode = "cool"
+ this.currentThermostatMode = "cool"
+ }
}
def heat() {
- thermostats[0].heat()
- this.thermostatMode = "heat"
- this.currentThermostatMode = "heat"
+ if (thermostatMode != "heat") {
+ thermostats[0].heat()
+ this.thermostatMode = "heat"
+ this.currentThermostatMode = "heat"
+ }
}
def auto() {
- thermostats[0].auto()
- this.thermostatMode = "auto"
- this.currentThermostatMode = "auto"
+ if (thermostatMode != "auto") {
+ thermostats[0].auto()
+ this.thermostatMode = "auto"
+ this.currentThermostatMode = "auto"
+ }
}
def off() {
- thermostats[0].off()
- this.thermostatMode = "off"
- this.currentThermostatMode = "off"
+ if (thermostatMode != "off") {
+ thermostats[0].off()
+ this.thermostatMode = "off"
+ this.currentThermostatMode = "off"
+ }
}
def setClimate(String info, String givenClimateName) {
- thermostats[0].setClimate(info, givenClimateName)
- this.climateName = givenClimateName
+ if (givenClimateName != climateName) {
+ thermostats[0].setClimate(info, givenClimateName)
+ this.climateName = givenClimateName
+ }
}
def setHold(String info1, int coolingSetpoint, int heatingSetpoint, String info2, String info3) {
- thermostats[0].setHold(info1, coolingSetpoint, heatingSetpoint, info2, info3)
- this.currentCoolingSetpoint = coolingSetpoint
- this.coolingSetpoint = coolingSetpoint
- this.currentHeatingSetpoint = heatingSetpoint
- this.heatingSetpoint = heatingSetpoint
+ if ((coolingSetpoint != this.coolingSetpoint) || (heatingSetpoint != this.heatingSetpoint)) {
+ thermostats[0].setHold(info1, coolingSetpoint, heatingSetpoint, info2, info3)
+ this.currentCoolingSetpoint = coolingSetpoint
+ this.coolingSetpoint = coolingSetpoint
+ this.currentHeatingSetpoint = heatingSetpoint
+ this.heatingSetpoint = heatingSetpoint
+ }
}
//By Model Checker
--- /dev/null
+//Create a class for valve
+package Valve
+import Timer.SimulatedTimer
+
+public class Valve {
+ private String id
+ private String label
+ private String displayName
+ private String valve
+ private String valveLatestValue
+ def sendEvent
+ def timers
+
+
+ Valve(Closure sendEvent, String id, String label, String displayName, String valve, String valveLatestValue) {
+ this.sendEvent = sendEvent
+ this.timers = new SimulatedTimer()
+ this.id = id
+ this.label = label
+ this.displayName = displayName
+ this.valve = valve
+ this.valveLatestValue = valveLatestValue
+ }
+
+ //By Apps
+ def open() {
+ if (valve != "open") {
+ println("the valve with id:$id is open!")
+ this.valveLatestValue = this.valve
+ this.valve = "open"
+ sendEvent([name: "contact", value: "open", deviceId: this.id, descriptionText: "",
+ displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
+ }
+ }
+
+ def open(LinkedHashMap metaData) {
+ if (valve != "open") {
+ def task = timers.runAfter(metaData["delay"]) {
+ println("the valve with id:$id is open!")
+ this.valveLatestValue = this.valve
+ this.valve = "open"
+ sendEvent([name: "contact", value: "open", deviceId: this.id, descriptionText: "",
+ displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
+ }
+ }
+ }
+
+ def close() {
+ if (valve != "closed") {
+ println("the valve with id:$id is closed!")
+ this.valveLatestValue = this.valve
+ this.valve = "closed"
+ sendEvent([name: "contact", value: "closed", deviceId: this.id, descriptionText: "",
+ displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
+ }
+ }
+
+ def close(LinkedHashMap metaData) {
+ if (valve != "closed") {
+ def task = timers.runAfter(metaData["delay"]) {
+ println("the valve with id:$id is closed!")
+ this.valveLatestValue = this.valve
+ this.valve = "closed"
+ sendEvent([name: "contact", value: "closed", deviceId: this.id, descriptionText: "",
+ displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
+ }
+ }
+ }
+
+ //By Model Checker
+ def setValue(String value) {
+ println("the valve with id:$id is $value!")
+ this.valveLatestValue = this.valve
+ this.valve = value
+ }
+
+ def currentValue(String deviceFeature) {
+ if (deviceFeature == "valve") {
+ return valve
+ }
+ }
+
+ def latestValue(String deviceFeature) {
+ if (deviceFeature == "valve") {
+ return valveLatestValue
+ }
+ }
+}
--- /dev/null
+//Create a class for valve
+package Valve
+import Timer.SimulatedTimer
+
+public class Valves {
+ int deviceNumbers
+ List valves
+ def timers
+ def sendEvent
+
+ //If we have only one device
+ private String id = "ValveID0"
+ private String label = "Valve0"
+ private String displayName = "Valve0"
+ private String valve = "closed"
+ private String valveLatestValue = "closed"
+
+ Valves(Closure sendEvent, int deviceNumbers) {
+ this.sendEvent = sendEvent
+ this.timers = new SimulatedTimer()
+ this.deviceNumbers = deviceNumbers
+ this.valves = []
+
+ valves.add(new Valve(sendEvent, id, label, displayName, this.valve, this.valveLatestValue))
+ }
+
+ //Methods for closures
+ def count(Closure Input) {
+ valves.count(Input)
+ }
+ def size() {
+ valves.size()
+ }
+ def each(Closure Input) {
+ valves.each(Input)
+ }
+ def find(Closure Input) {
+ valves.find(Input)
+ }
+ def collect(Closure Input) {
+ valves.collect(Input)
+ }
+
+ //By Apps
+ def open() {
+ if (valve != "open")
+ valves[0].open()
+ }
+
+ def open(LinkedHashMap metaData) {
+ if (valve != "open") {
+ def task = timers.runAfter(metaData["delay"]) {
+ valves[0].open()
+ }
+ }
+ }
+
+ def close() {
+ if (valve != "closed")
+ valves[0].close()
+ }
+
+ def close(LinkedHashMap metaData) {
+ if (valve != "closed") {
+ def task = timers.runAfter(metaData["delay"]) {
+ valves[0].close()
+ }
+ }
+ }
+
+ //By Model Checker
+ def setValue(LinkedHashMap eventDataMap) {
+ if (eventDataMap["value"] != valves[0].valve) {
+ valves[0].setValue(eventDataMap["value"])
+ this.valve = valves[0].valve
+ }
+ }
+
+
+ def currentValue(String deviceFeature) {
+ valves[0].currentValue(deviceFeature)
+ }
+
+ def latestValue(String deviceFeature) {
+ valves[0].latestValue(deviceFeature)
+ }
+
+ def getAt(int ix) {
+ valves[ix]
+ }
+}
//For Alarms:
String currentAlarm or String alarm
/*events*/
-//No events based on this device
+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"]])
/*events*/
//
-------------------------------------------------------------------------------
String currentContact or String contactState
/*events*/
/////
-contact closed event:
contactObject.setValue([name: "contact.closed", value: "closed", deviceId: "contactSensorID0", descriptionText: "",
displayed: true, linkText: "", isStateChange: false, unit: "", data: [info: "info"]])
-/////
-contact open event:
contactObject.setValue([name: "contact.open", value: "open", deviceId: "contactSensorID0", descriptionText: "",
displayed: true, linkText: "", isStateChange: false, unit: "", data: [info: "info"]])
/////
//For DoorControl:
String doorState
/*events*/
-door closed event using doorControl:
doorControlObject.setValue([name: "doorState", value: "closed", deviceId: "doorControlID0", descriptionText: "",
displayed: true, linkText: "", isStateChange: false, unit: "", data: [info: "info"]])
-/////
-door open event using doorControl:
doorControlObject.setValue([name: "doorState", value: "open", deviceId: "doorControlID0", descriptionText: "",
displayed: true, linkText: "", isStateChange: false, unit: "", data: [info: "info"]])
/////
//For Location:
String location.mode
/*events*/
-location changes event:
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: "",
//For Locks:
String currentLock or String lockState
/*events*/
-lock event:
lockObject.setValue([name: "lock", value: "locked", deviceId: "lockID0", descriptionText: "",
displayed: true, linkText: "", isStateChange: false, unit: "", data: [info: "info"]])
-/////
-unlock event:
lockObject.setValue([name: "unlock", value: "unlocked ", deviceId: "lockID0", descriptionText: "",
displayed: true, linkText: "", isStateChange: false, unit: "", data: [info: "info"]])
/////
//For MotionSensors:
String currentMotion or String motion
/*events*/
-Motion sensor event: motion detected:
motionSensorObject.setValue([name: "motion", value: "active", deviceId: "motionSensorID0", descriptionText: "",
displayed: true, linkText: "", isStateChange: false, unit: "", data: [info: "info"]])
-/////
-Motion sensor event: motion not detected:
motionSensorObject.setValue([name: "motion", value: "inactive", deviceId: "motionSensorID0", descriptionText: "",
displayed: true, linkText: "", isStateChange: false, unit: "", data: [info: "info"]])
/////
//For MusicPlayer:
String status
+int level
+String trackDescription
+String trackData
+String mute
/*events*/
-//No events based on this device
+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"]])
/*events*/
//
-------------------------------------------------------------------------------
//For PresenceSensor:
String currentPresence or String presenceState
/*events*/
-presence sensor, present event:
presenceSensorObject.setValue([name: "presence", value: "present", deviceId: "presenceSensorID0", descriptionText: "",
displayed: true, linkText: "", isStateChange: false, unit: "", data: [info: "info"]])
-/////
-presence sensor, left event:
presenceSensorObject.setValue([name: "presence", value: "not present", deviceId: "presenceSensorID0", descriptionText: "",
displayed: true, linkText: "", isStateChange: false, unit: "", data: [info: "info"]])
/////
//For SmokeDetector:
String currentSmokeValue or String smoke
/*events*/
-smoke is clear event:
smokeDetectorObject.setValue([name: "smoke", value: "clear", deviceId: "smokeDetectorID0", descriptionText: "",
displayed: true, linkText: "", isStateChange: false, unit: "", data: [info: "info"]])
-/////
-smoke is detected event:
smokeDetectorObject.setValue([name: "smoke", value: "detected", deviceId: "smokeDetectorID0", descriptionText: "",
displayed: true, linkText: "", isStateChange: false, unit: "", data: [info: "info"]])
-/////
-smoke is tested event:
smokeDetectorObject.setValue([name: "smoke", value: "tested", deviceId: "smokeDetectorID0", descriptionText: "",
displayed: true, linkText: "", isStateChange: false, unit: "", data: [info: "info"]])
-/////
-carbonMonoxide is clear event:
smokeDetectorObject.setValue([name: "carbonMonoxide", value: "clear", deviceId: "smokeDetectorID0", descriptionText: "",
displayed: true, linkText: "", isStateChange: false, unit: "", data: [info: "info"]])
-/////
-carbonMonoxide is detected event:
smokeDetectorObject.setValue([name: "carbonMonoxide", value: "detected", deviceId: "smokeDetectorID0", descriptionText: "",
displayed: true, linkText: "", isStateChange: false, unit: "", data: [info: "info"]])
-/////
-carbonMonoxide is tested event:
smokeDetectorObject.setValue([name: "carbonMonoxide", value: "tested", deviceId: "smokeDetectorID0", descriptionText: "",
displayed: true, linkText: "", isStateChange: false, unit: "", data: [info: "info"]])
-/////
-battery charge value event:
-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"]])
-/////
-battery charge value event:
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"]])
/////
//For Thermostats:(we have different features in each line)
-String heatingSetpoint or currentHeatingSetpoint //heating set point
-String thermostatSetpoint //normal set point
-String coolingSetpoint or currentCoolingSetpoint //cooling set point
+int heatingSetpoint or currentHeatingSetpoint //heating set point
+int thermostatSetpoint //normal set point
+int coolingSetpoint or currentCoolingSetpoint //cooling set point
String thermostatOperatingState //operating state
String thermostatFanMode //fan mode
String thermostatMode or currentThermostatMode //mode
/*events*/
-thermostad mode change event: to auto
thermostatObject.setValue([name: "thermostatMode", value: "auto", deviceId: "thermostatID0", descriptionText: "",
displayed: true, linkText: "", isStateChange: false, unit: "", data: [info: "info"]])
-/////
-thermostad mode change event: to cool
thermostatObject.setValue([name: "thermostatMode", value: "cool", deviceId: "thermostatID0", descriptionText: "",
displayed: true, linkText: "", isStateChange: false, unit: "", data: [info: "info"]])
-/////
-thermostad mode change event: to emergencyHeat
thermostatObject.setValue([name: "thermostatMode", value: "emergencyHeat", deviceId: "thermostatID0", descriptionText: "",
displayed: true, linkText: "", isStateChange: false, unit: "", data: [info: "info"]])
-/////
-thermostad mode change event: to heat
thermostatObject.setValue([name: "thermostatMode", value: "heat", deviceId: "thermostatID0", descriptionText: "",
displayed: true, linkText: "", isStateChange: false, unit: "", data: [info: "info"]])
-/////
-thermostad mode change event: to off
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"]])
/////
/*events*/
//
//For Switches:
String currentSwitch or switchState
/*events*/
-switch changes to off:
switchObject.setValue([name: "switch", value: "off", deviceId: "switchID0", descriptionText: "",
displayed: true, linkText: "", isStateChange: false, unit: "", data: [info: "info"]])
-/////
-switch changes to on:
switchObject.setValue([name: "switch", value: "on", deviceId: "switchID0", descriptionText: "",
displayed: true, linkText: "", isStateChange: false, unit: "", data: [info: "info"]])
/////
//For nfcTouch:
/*events*/
-Nfc touched event:
-appObject.setValue([name: "nfcTouch", value: "touched", deviceId: "nfcSensorID0", descriptionText: "",
+touchSensorObject.setValue([name: "nfcTouch", value: "touched", deviceId: "nfcSensorID0", descriptionText: "",
displayed: true, linkText: "", isStateChange: false, unit: "", data: [info: "info"]])
/////
/*events*/
//For aeonKeyFob push button:
/*events*/
-button pushed event:
aeonKeyFobObject.setValue([name: "button", value: "pushed", deviceId: "aeonKeyFobID0", descriptionText: "",
displayed: true, linkText: "", isStateChange: false, unit: "", data: [info: "info"]])
-/////
-button held event:
aeonKeyFobObject.setValue([name: "button", value: "held", deviceId: "aeonKeyFobID0", descriptionText: "",
displayed: true, linkText: "", isStateChange: false, unit: "", data: [info: "info"]])
/////
//For acceleration sensor:
String currentAcceleration or String acceleration
/*events*/
-Acceleration sensor event: acceleration detected:
accelerationSensorObject.setValue([name: "acceleration", value: "active", deviceId: "accelerationSensorID0", descriptionText: "",
displayed: true, linkText: "", isStateChange: false, unit: "", data: [info: "info"]])
-/////
-Acceleration sensor event: acceleration not detected:
accelerationSensorObject.setValue([name: "acceleration", value: "inactive", deviceId: "accelerationSensorID0", descriptionText: "",
displayed: true, linkText: "", isStateChange: false, unit: "", data: [info: "info"]])
/////
//For battery:
-String currentBattery or String battery
+int currentBattery or int battery
/*events*/
-//No events based on this device
+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"]])
/*events*/
//
-------------------------------------------------------------------------------
//For beacon sensor:
String currentPresence or String presence
/*events*/
-beacon sensor, present event:
beaconSensorObject.setValue([name: "beacon", value: "present", deviceId: "beaconeSensorID0", descriptionText: "",
displayed: true, linkText: "", isStateChange: false, unit: "", data: [info: "info"]])
-/////
-beacon sensor, left event:
beaconSensorObject.setValue([name: "beacon", value: "not present", deviceId: "beaconSensorID0", descriptionText: "",
displayed: true, linkText: "", isStateChange: false, unit: "", data: [info: "info"]])
/////
//For carbon monoxide:
String currentCarbonMonoxideValue or String carbonMonoxide
/*events*/
-carbonMonoxide is clear event:
carbonMonoxideDetectorObject.setValue([name: "carbonMonoxide", value: "clear", deviceId: "carbonMonoxideDetectorID0", descriptionText: "",
displayed: true, linkText: "", isStateChange: false, unit: "", data: [info: "info"]])
-/////
-carbonMonoxide is detected event:
carbonMonoxideDetectorObject.setValue([name: "carbonMonoxide", value: "detected", deviceId: "carbonMonoxideDetectorID0", descriptionText: "",
displayed: true, linkText: "", isStateChange: false, unit: "", data: [info: "info"]])
-/////
-carbonMonoxide is tested event:
carbonMonoxideDetectorObject.setValue([name: "carbonMonoxide", value: "tested", deviceId: "carbonMonoxideDetectorID0", descriptionText: "",
displayed: true, linkText: "", isStateChange: false, unit: "", data: [info: "info"]])
/*events*/
//For color control:
String color
-String hue
-String saturation
+int hue
+int saturation
/*events*/
-color changed:
colorControlObject.setValue([name: "color", value: "red", deviceId: "colorControlID0", descriptionText: "",
displayed: true, linkText: "", isStateChange: false, unit: "", data: [info: "info"]])
-/////
-hue changed:
colorControlObject.setValue([name: "hue", value: "50", deviceId: "colorControlID0", descriptionText: "",
displayed: true, linkText: "", isStateChange: false, unit: "", data: [info: "info"]])
-/////
-saturation changed:
colorControlObject.setValue([name: "saturation", value: "50", deviceId: "colorControlID0", descriptionText: "",
displayed: true, linkText: "", isStateChange: false, unit: "", data: [info: "info"]])
/*events*/
//
+-------------------------------------------------------------------------------
+
+
+//For energy meter:
+int energy or int currentEnergy
+/*events*/
+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"]])
+/*events*/
+//
+-------------------------------------------------------------------------------
+
+
+//For illuminance measurement:
+int illuminance or int currentIlluminance
+/*events*/
+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"]])
+/*events*/
+//
+-------------------------------------------------------------------------------
+
+
+//For power meter:
+int power or int currentPower
+/*events*/
+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"]])
+/*events*/
+//
+-------------------------------------------------------------------------------
+
+
+//For relative humidity measurement:
+int humidity or int currentHumidity
+/*events*/
+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"]])
+/*events*/
+//
+-------------------------------------------------------------------------------
+
+
+//For relay switches:
+String currentSwitch or switchState
+/*events*/
+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"]])
+/////
+/*events*/
+//
+-------------------------------------------------------------------------------
+
+
+//For sleep sensor:
+String sleeping
+/*events*/
+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"]])
+/////
+/*events*/
+//
+-------------------------------------------------------------------------------
+
+
+//For step sensor:
+int goal
+int steps
+/*events*/
+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"]])
+/////
+/*events*/
+//
+-------------------------------------------------------------------------------
+
+
+//For switch levels:
+int level or int rate
+/*events*/
+switchLevelObject.setValue([name: "level", value: "45"/*A number between 0 to 100*/, deviceId: "switchLevelID0", descriptionText: "",
+displayed: true, linkText: "", isStateChange: false, unit: "", data: [info: "info"]])
+/////
+/*events*/
+//
+-------------------------------------------------------------------------------
+
+
+//For temperature measurement:
+int temperature
+/*events*/
+temperatureMeasurementObject.setValue([name: "temperature", value: "45"/*A number between 0 to 100*/, deviceId: "temperatureMeasurementID0", descriptionText: "",
+displayed: true, linkText: "", isStateChange: false, unit: "", data: [info: "info"]])
+/////
+/*events*/
+//
+-------------------------------------------------------------------------------
+
+
+//For valve:
+String valve
+/*events*/
+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"]])
+/////
+/*events*/
+//
+-------------------------------------------------------------------------------
+
+
+//For water sensor:
+String water
+/*events*/
+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"]])
+/////
+/*events*/
+//
--- /dev/null
+//Create a class for water sensor
+package WaterSensor
+import Timer.SimulatedTimer
+
+public class WaterSensor {
+ private String id
+ private String label
+ private String displayName
+ private String water
+
+ WaterSensor(String id, String label, String displayName, String water) {
+ this.id = id
+ this.label = label
+ this.displayName = displayName
+ this.water = water
+ }
+
+ //By Model Checker
+ def setValue(String value) {
+ println("the water state is changed to $value!")
+ this.water = value
+ }
+}
--- /dev/null
+//Create a class for water sensor
+package WaterSensor
+import Timer.SimulatedTimer
+
+public class WaterSensors {
+ private int deviceNumbers
+ private List waterSensors
+ def sendEvent
+
+ //For one device(We cannot have obj.id)-> We should have obj[0].id
+ private String id = "waterSensorID0"
+ private String label = "waterSensor0"
+ private String displayName = "waterSensor0"
+ private String water = "dry"
+
+
+ WaterSensors(Closure sendEvent, int deviceNumbers) {
+ this.sendEvent = sendEvent
+ this.deviceNumbers = deviceNumbers
+ this.waterSensors = []
+
+ waterSensors.add(new WaterSensor(id, label, displayName, this.water))
+ }
+
+ //By Model Checker
+ def setValue(LinkedHashMap eventDataMap) {
+ if (eventDataMap["value"] != waterSensors[0].water) {
+ waterSensors[0].setValue(eventDataMap["value"])
+ this.water = waterSensors[0].water
+ sendEvent(eventDataMap)
+ }
+ }
+
+ //Methods for closures
+ def count(Closure Input) {
+ waterSensors.count(Input)
+ }
+ def size() {
+ waterSensors.size()
+ }
+ def each(Closure Input) {
+ waterSensors.each(Input)
+ }
+ def find(Closure Input) {
+ waterSensors.find(Input)
+ }
+ def collect(Closure Input) {
+ waterSensors.collect(Input)
+ }
+
+ def getAt(int ix) {
+ waterSensors[ix]
+ }
+}
public class Touched{
def sendEvent
private int isTouched
+ private String label
Touched(Closure sendEvent, int isTouched) {
this.sendEvent = sendEvent
this.isTouched = isTouched
+ this.label = "App"
}
//By Model Checker
--- /dev/null
+ accelerationSensorObject.setValue([name: "acceleration", value: "active", deviceId: "accelerationSensorID0", descriptionText: "",
+ displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
--- /dev/null
+ accelerationSensorObject.setValue([name: "acceleration", value: "inactive", deviceId: "accelerationSensorID0", 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"]])
+ 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"]])
+ smokeDetectorObject.setValue([name: "battery", value: "5", deviceId: "smokeDetectorID0", descriptionText: "",
+ displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
--- /dev/null
+ beaconSensorObject.setValue([name: "presence", value: "not present", deviceId: "beaconSensorID0", descriptionText: "",
+ displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"presence":"0","dni":"mobile0"}'])
--- /dev/null
+ beaconSensorObject.setValue([name: "presence", value: "present", deviceId: "beaconeSensorID0", descriptionText: "",
+ displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"presence":"1","dni":"mobile0"}'])
aeonKeyFobObject.setValue([name: "button", value: "held", deviceId: "aeonKeyFobID0", descriptionText: "",
- displayed: true, linkText: "", isStateChange: false, unit: "", data: [info: "info"]])
+ 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"]])
+ 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"]])
+ carbonMonoxideDetectorObject.setValue([name: "carbonMonoxide", value: "clear", deviceId: "carbonMonoxideDetectorID0", 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"]])
+ carbonMonoxideDetectorObject.setValue([name: "carbonMonoxide", value: "tested", deviceId: "carbonMonoxideDetectorID0", 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"]])
+ carbonMonoxideDetectorObject.setValue([name: "carbonMonoxide", value: "tested", deviceId: "carbonMonoxideDetectorID0", descriptionText: "",
+ displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
--- /dev/null
+ colorControlObject.setValue([name: "color", value: "red", deviceId: "colorControlID0", 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"]])
+ 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"]])
+ 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"]])
+ 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"]])
+ displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
-Random random = new Random(42)
-counter = 1000
-while(counter > 0) {
- def eventNumber = random.nextInt(1)
+while(true) {
+ def eventNumber = Verify.getInt(0,53)
switch(eventNumber) {
case 0:
- appObject.setValue([name: "nfcTouch", value: "Touched", deviceId: 0, descriptionText: "",
- displayed: true, linkText: "", isStateChange: false, unit: "", data: [value: "Touched"]])
-
break
case 1:
- appObject.setValue([name: "Touched", value: "Touched", deviceId: 0, descriptionText: "",
- displayed: true, linkText: "", isStateChange: false, unit: "", data: []])
-
+ break
+ case 2:
+ break
+ case 3:
+ def event = Verify.getInt(0,2)
+ if (event == 0) {
+ smokeDetectorObject.setValue([name: "smoke", value: "clear", deviceId: "smokeDetectorID0", descriptionText: "",
+ displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
+ } else if (event == 1) {
+ smokeDetectorObject.setValue([name: "smoke", value: "detected", deviceId: "smokeDetectorID0", descriptionText: "",
+ displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
+ } else {
+ smokeDetectorObject.setValue([name: "smoke", value: "tested", deviceId: "smokeDetectorID0", descriptionText: "",
+ displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
+ }
+ break
+ case 4:
+ def event = Verify.getInt(0,2)
+ if (event == 0) {
+ smokeDetectorObject.setValue([name: "carbonMonoxide", value: "clear", deviceId: "smokeDetectorID0", descriptionText: "",
+ displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
+ } else if (event == 1) {
+ smokeDetectorObject.setValue([name: "carbonMonoxide", value: "detected", deviceId: "smokeDetectorID0", descriptionText: "",
+ displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
+ } else {
+ smokeDetectorObject.setValue([name: "carbonMonoxide", value: "tested", deviceId: "smokeDetectorID0", descriptionText: "",
+ displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
+ }
+ break
+ case 5:
+ break
+ case 6:
+ break
+ case 7:
+ lockObject.setValue([name: "lock", value: "locked", deviceId: "lockID0", descriptionText: "",
+ displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
+ break
+ case 8:
+ def event = Verify.getInt(0,1)
+ if (event == 0) {
+ accelerationSensorObject.setValue([name: "acceleration", value: "active", deviceId: "accelerationSensorID0", descriptionText: "",
+ displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
+ } else {
+ accelerationSensorObject.setValue([name: "acceleration", value: "inactive", deviceId: "accelerationSensorID0", descriptionText: "",
+ displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
+ }
+ break
+ case 9:
+ def event = Verify.getInt(0,1)
+ if (event == 0) {
+ motionSensorObject.setValue([name: "motion", value: "active", deviceId: "motionSensorID0", descriptionText: "",
+ displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
+ } else {
+ motionSensorObject.setValue([name: "motion", value: "inactive", deviceId: "motionSensorID0", descriptionText: "",
+ displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
+ }
+ break
+ case 10:
+ def event = Verify.getInt(0,1)
+ if (event == 0) {
+ presenceSensorObject.setValue([name: "presence", value: "present", deviceId: "presenceSensorID0", descriptionText: "",
+ displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"presence":"1","dni":"mobile0"}'])
+ } else {
+ presenceSensorObject.setValue([name: "presence", value: "not present", deviceId: "presenceSensorID0", descriptionText: "",
+ displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"presence":"0","dni":"mobile0"}'])
+ }
+ break
+ case 11:
+ def event = Verify.getInt(0,1)
+ if (event == 0) {
+ switchObject.setValue([name: "switch", value: "on", deviceId: "switchID0", descriptionText: "",
+ displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
+ } else {
+ switchObject.setValue([name: "switch", value: "off", deviceId: "switchID0", descriptionText: "",
+ displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
+ }
+ break
+ case 12:
+ break
+ case 13:
+ smokeDetectorObject.setValue([name: "battery", value: "5", deviceId: "smokeDetectorID0", descriptionText: "",
+ displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
+ break
+ case 14:
+ break
+ case 15:
+ break
+ case 16:
+ break
+ case 17:
+ break
+ case 18:
+ break
+ case 19:
+ def event = Verify.getInt(0,4)
+ if (event == 0) {
+ thermostatObject.setValue([name: "thermostatMode", value: "auto", deviceId: "thermostatID0", descriptionText: "",
+ displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
+ } else if (event == 1) {
+ thermostatObject.setValue([name: "thermostatMode", value: "cool", deviceId: "thermostatID0", descriptionText: "",
+ displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
+ } else if (event == 2) {
+ thermostatObject.setValue([name: "thermostatMode", value: "emergencyHeat", deviceId: "thermostatID0", descriptionText: "",
+ displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
+ } else if (event == 3) {
+ thermostatObject.setValue([name: "thermostatMode", value: "heat", deviceId: "thermostatID0", descriptionText: "",
+ displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
+ } else {
+ thermostatObject.setValue([name: "thermostatMode", value: "off", deviceId: "thermostatID0", descriptionText: "",
+ displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
+ }
+ break
+ case 20:
+ break
+ case 21:
+ break
+ case 22:
+ break
+ case 23:
+ break
+ case 24:
+ break
+ case 25:
+ break
+ case 26:
+ break
+ case 27:
+ break
+ case 28:
+ break
+ case 29:
+ break
+ case 30:
+ break
+ case 31:
+ break
+ case 32:
+ break
+ case 33:
+ break
+ case 34:
+ break
+ case 35:
+ break
+ case 36:
+ break
+ case 37:
+ break
+ case 38:
+ break
+ case 39:
+ break
+ case 40:
+ break
+ case 41:
+ break
+ case 42:
+ break
+ case 43:
+ break
+ case 44:
+ break
+ case 45:
+ break
+ case 46:
+ break
+ case 47:
+ break
+ case 48:
+ break
+ case 49:
+ break
+ case 50:
+ break
+ case 51:
+ break
+ case 52:
+ def event = Verify.getInt(0,2)
+ if (event == 0) {
+ locationObject.setValue([name: "Location", value: "home", deviceId: "locationID0", descriptionText: "",
+ displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
+ } else if (event == 1) {
+ locationObject.setValue([name: "Location", value: "away", deviceId: "locationID0", descriptionText: "",
+ displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
+ } else {
+ locationObject.setValue([name: "Location", value: "night", deviceId: "locationID0", descriptionText: "",
+ displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
+ }
+ break
+ case 53:
+ appObject.setValue([name: "Touched", value: "touched", deviceId: "touchedSensorID0", descriptionText: "",
+ displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
break
}
- counter--
}
switchObject.setValue([name: "switch.off", value: "off", deviceId: 0, descriptionText: "",
- displayed: true, linkText: "", isStateChange: false, unit: "", data: [value: "off"]])
+ displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
switchObject.setValue([name: "switch.on", value: "on", deviceId: 0, descriptionText: "",
- displayed: true, linkText: "", isStateChange: false, unit: "", data: [value: "on"]])
+ displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
--- /dev/null
+ colorControlObject.setValue([name: "hue", value: "50", deviceId: "colorControlID0", 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"]])
+ 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"]])
+ 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"]])
+ 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"]])
+ 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"]])
+ 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"]])
+ displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
- appObject.setValue([name: "nfcTouch", value: "touched", deviceId: "nfcSensorID0", 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"}'])
presenceSensorObject.setValue([name: "presence", value: "not present", deviceId: "presenceSensorID0", descriptionText: "",
- displayed: true, linkText: "", isStateChange: false, unit: "", data: [info: "info"]])
+ displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"presence":"0","dni":"mobile0"}'])
presenceSensorObject.setValue([name: "presence", value: "present", deviceId: "presenceSensorID0", descriptionText: "",
- displayed: true, linkText: "", isStateChange: false, unit: "", data: [info: "info"]])
+ displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"presence":"1","dni":"mobile0"}'])
--- /dev/null
+ colorControlObject.setValue([name: "saturation", value: "50", deviceId: "colorControlID0", descriptionText: "",
+ displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
--- /dev/null
+ smokeDetectorObject.setValue([name: "carbonMonoxide", value: "clear", deviceId: "smokeDetectorID0", descriptionText: "",
+ displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
--- /dev/null
+ smokeDetectorObject.setValue([name: "carbonMonoxide", value: "detected", deviceId: "smokeDetectorID0", descriptionText: "",
+ displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
--- /dev/null
+ smokeDetectorObject.setValue([name: "carbonMonoxide", value: "tested", deviceId: "smokeDetectorID0", descriptionText: "",
+ displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
smokeDetectorObject.setValue([name: "smoke", value: "clear", deviceId: "smokeDetectorID0", descriptionText: "",
- displayed: true, linkText: "", isStateChange: false, unit: "", data: [info: "info"]])
+ 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"]])
+ 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"]])
+ 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"]])
+ 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"]])
+ 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"]])
+ 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"]])
+ 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"]])
+ 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"]])
+ 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"]])
+ 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"]])
+ displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
//Infrastructure for SmartThings Application
//Importing Libraries
import groovy.transform.Field
+import groovy.json.JsonSlurper
//Importing Classes
import ContactSensor.ContactSensor
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 Event.Event
+import AtomicState.AtomicState
import Timer.SimulatedTimer
+//JPF's Verify API
+import gov.nasa.jpf.vm.Verify
+
//Global eventHandler
/////////////////////////////////////////////////////////////////////
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)
}
}
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)
}
}
//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 alarmObject = new Alarms(sendEvent, 1)
//Global Object for class speech synthesis!
@Field def speechSynthesisObject = new SpeechSynthesises(sendEvent, 1)
+//Global Object for class acceleration sensor!
+@Field def accelerationSensorObject = new AccelerationSensors(sendEvent, 1)
+//Global Object for class Battery!
+@Field def batteryObject = new Batteries(sendEvent, 1)
+//Global Object for class beacon sensor!
+@Field def beaconSensorObject = new BeaconSensors(sendEvent, 1)
+//Global Object for class carbon monoxide!
+@Field def carbonMonoxideDetectorObject = new CarbonMonoxideDetectors(sendEvent, 1)
+//Global Object for class color control!
+@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)
//Application #1
class App1 {
def reference
def location
def app
+ def atomicState
//Extracted objects for App1
- //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
//Extracted objects for functions for App1
//Global Object for functions in subscribe method!
//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 appTouch = this.&appTouch
+ //Global Object for functions in subscribe method!
+ 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 doorOpenCheck = this.&doorOpenCheck
+ def handleAccelerationEvent = this.&handleAccelerationEvent
//Global Object for functions in subscribe method!
- def lockMessage = this.&lockMessage
+ 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
App1(Object obj) {
reference = obj
location = obj.locationObject
app = obj.appObject
- lock = obj.lockObject
- contact = obj.contactObject
+ atomicState = obj.atomicState
+ 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]
}
//Global variables for each app
//Global variable for state[mode]
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)
}
}
/////////////////////////////////////////////////////////////////////
}
/////////////////////////////////////////////////////////////////////
def getTemperatureScale() {
- return 'C' //Celsius for now
+ return 'F' //Celsius for now
}
/////////////////////////////////////////////////////////////////////
def sunRiseSetInfo = [sunrise:[time:1563800160000],sunset:[time:1563850740000]]
return sunRiseSetInfo
}
+ /////////////////////////////////////////////////////////////////////
+ def httpPostJson(LinkedHashMap metaData, Closure inputData) {
+ inputData(metaData)
+ }
+ /////////////////////////////////////////////////////////////////////
+ def runEvery15Minutes(Closure inputData) {
+ inputData()
+ }
+ /////////////////////////////////////////////////////////////////////
+ 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
+ }
+ /////////////////////////////////////////////////////////////////////
+ def sendNotification(String text, LinkedHashMap metaData) {
+ println("Sending \""+text+"\" to "+metaData.phone.toString())
+ }
+ /////////////////////////////////////////////////////////////////////
+ def canSchedule() {
+ return true
+ }
def installed() {
- schedule(time, "setTimeCallback")
+ 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 updated(settings) {
- unschedule()
- schedule(time, "setTimeCallback")
+ def appTouch(evt) {
+ rescheduleIfNeeded(evt)
+ processQueue()
+ def queue = []
+ atomicState.queue=queue
}
- def setTimeCallback() {
- if (contact) {
- doorOpenCheck()
- } else {
- lockMessage()
- lock.lock()
- }
+
+ 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 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
- }
+
+ 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
+ }*/
+ }
+
+ }
+
}
def reference
def location
def app
+ def atomicState
//Extracted objects for App2
- //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"
//Extracted objects for functions for App2
//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.¬ifyUnlocked
+ //Global Object for functions in subscribe method!
+ def sendMessage = this.&sendMessage
App2(Object obj) {
reference = obj
location = obj.locationObject
app = obj.appObject
- tag = obj.touchSensorObject
- switch1 = obj.switchObject
- lock = obj.lockObject
- garageDoor = obj.doorControlObject
+ atomicState = obj.atomicState
+ 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]
}
//Global variables for each app
//Global variable for state[mode]
println("Sending \""+text+"\" to "+phoneNumber.toString())
}
/////////////////////////////////////////////////////////////////////
+ ////sendPush(text)
+ def sendPush(String text) {
+ println(text)
+ }
+ /////////////////////////////////////////////////////////////////////
////schedule(time, nameOfFunction as String)
def schedule(String time, String nameOfFunction) {
def _inputTime = time.split(':')
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)
}
}
/////////////////////////////////////////////////////////////////////
}
/////////////////////////////////////////////////////////////////////
def getTemperatureScale() {
- return 'C' //Celsius for now
+ return 'F' //Celsius for now
}
/////////////////////////////////////////////////////////////////////
def sunRiseSetInfo = [sunrise:[time:1563800160000],sunset:[time:1563850740000]]
return sunRiseSetInfo
}
-
- 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
- }
- }
+ /////////////////////////////////////////////////////////////////////
+ def httpPostJson(LinkedHashMap metaData, Closure inputData) {
+ inputData(metaData)
}
-
- def installed() {
- log.debug "Installed with settings: ${settings}"
-
- initialize()
+ /////////////////////////////////////////////////////////////////////
+ def runEvery15Minutes(Closure inputData) {
+ inputData()
+ }
+ /////////////////////////////////////////////////////////////////////
+ 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
+ }
+ /////////////////////////////////////////////////////////////////////
+ def sendNotification(String text, LinkedHashMap metaData) {
+ println("Sending \""+text+"\" to "+metaData.phone.toString())
+ }
+ /////////////////////////////////////////////////////////////////////
+ def canSchedule() {
+ return true
+ }
+
+ 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)
}
}
+
+}
+
+@Field def app1
+@Field def app2
+def initOrder = Verify.getBoolean()
+if (initOrder) {
+ app1 = new App1(this)
+ app2 = new App2(this)
+} else {
+ app2 = new App2(this)
+ app1 = new App1(this)
}
-@Field def app1 = new App1(this)
-@Field def app2 = new App2(this)
-app1.installed()
-app2.installed()
+def installOrder = Verify.getBoolean()
+if (installOrder) {
+ app1.installed()
+ app2.installed()
+} else {
+ app2.installed()
+ app1.installed()
+}
+while(true) {
+ def eventNumber = Verify.getInt(0,53)
+ switch(eventNumber) {
+ case 0:
+ break
+ case 1:
+ break
+ case 2:
+ break
+ case 3:
+ def event = Verify.getInt(0,2)
+ if (event == 0) {
+ smokeDetectorObject.setValue([name: "smoke", value: "clear", deviceId: "smokeDetectorID0", descriptionText: "",
+ displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
+ } else if (event == 1) {
+ smokeDetectorObject.setValue([name: "smoke", value: "detected", deviceId: "smokeDetectorID0", descriptionText: "",
+ displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
+ } else {
+ smokeDetectorObject.setValue([name: "smoke", value: "tested", deviceId: "smokeDetectorID0", descriptionText: "",
+ displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
+ }
+ break
+ case 4:
+ def event = Verify.getInt(0,2)
+ if (event == 0) {
+ smokeDetectorObject.setValue([name: "carbonMonoxide", value: "clear", deviceId: "smokeDetectorID0", descriptionText: "",
+ displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
+ } else if (event == 1) {
+ smokeDetectorObject.setValue([name: "carbonMonoxide", value: "detected", deviceId: "smokeDetectorID0", descriptionText: "",
+ displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
+ } else {
+ smokeDetectorObject.setValue([name: "carbonMonoxide", value: "tested", deviceId: "smokeDetectorID0", descriptionText: "",
+ displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
+ }
+ break
+ case 5:
+ break
+ case 6:
+ break
+ case 7:
+ lockObject.setValue([name: "lock", value: "locked", deviceId: "lockID0", descriptionText: "",
+ displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
+ break
+ case 8:
+ def event = Verify.getInt(0,1)
+ if (event == 0) {
+ accelerationSensorObject.setValue([name: "acceleration", value: "active", deviceId: "accelerationSensorID0", descriptionText: "",
+ displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
+ } else {
+ accelerationSensorObject.setValue([name: "acceleration", value: "inactive", deviceId: "accelerationSensorID0", descriptionText: "",
+ displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
+ }
+ break
+ case 9:
+ def event = Verify.getInt(0,1)
+ if (event == 0) {
+ motionSensorObject.setValue([name: "motion", value: "active", deviceId: "motionSensorID0", descriptionText: "",
+ displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
+ } else {
+ motionSensorObject.setValue([name: "motion", value: "inactive", deviceId: "motionSensorID0", descriptionText: "",
+ displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
+ }
+ break
+ case 10:
+ def event = Verify.getInt(0,1)
+ if (event == 0) {
+ presenceSensorObject.setValue([name: "presence", value: "present", deviceId: "presenceSensorID0", descriptionText: "",
+ displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"presence":"1","dni":"mobile0"}'])
+ } else {
+ presenceSensorObject.setValue([name: "presence", value: "not present", deviceId: "presenceSensorID0", descriptionText: "",
+ displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"presence":"0","dni":"mobile0"}'])
+ }
+ break
+ case 11:
+ def event = Verify.getInt(0,1)
+ if (event == 0) {
+ switchObject.setValue([name: "switch", value: "on", deviceId: "switchID0", descriptionText: "",
+ displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
+ } else {
+ switchObject.setValue([name: "switch", value: "off", deviceId: "switchID0", descriptionText: "",
+ displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
+ }
+ break
+ case 12:
+ break
+ case 13:
+ smokeDetectorObject.setValue([name: "battery", value: "5", deviceId: "smokeDetectorID0", descriptionText: "",
+ displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
+ break
+ case 14:
+ break
+ case 15:
+ break
+ case 16:
+ break
+ case 17:
+ break
+ case 18:
+ break
+ case 19:
+ def event = Verify.getInt(0,4)
+ if (event == 0) {
+ thermostatObject.setValue([name: "thermostatMode", value: "auto", deviceId: "thermostatID0", descriptionText: "",
+ displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
+ } else if (event == 1) {
+ thermostatObject.setValue([name: "thermostatMode", value: "cool", deviceId: "thermostatID0", descriptionText: "",
+ displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
+ } else if (event == 2) {
+ thermostatObject.setValue([name: "thermostatMode", value: "emergencyHeat", deviceId: "thermostatID0", descriptionText: "",
+ displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
+ } else if (event == 3) {
+ thermostatObject.setValue([name: "thermostatMode", value: "heat", deviceId: "thermostatID0", descriptionText: "",
+ displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
+ } else {
+ thermostatObject.setValue([name: "thermostatMode", value: "off", deviceId: "thermostatID0", descriptionText: "",
+ displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
+ }
+ break
+ case 20:
+ break
+ case 21:
+ break
+ case 22:
+ break
+ case 23:
+ break
+ case 24:
+ break
+ case 25:
+ break
+ case 26:
+ break
+ case 27:
+ break
+ case 28:
+ break
+ case 29:
+ break
+ case 30:
+ break
+ case 31:
+ break
+ case 32:
+ break
+ case 33:
+ break
+ case 34:
+ break
+ case 35:
+ break
+ case 36:
+ break
+ case 37:
+ break
+ case 38:
+ break
+ case 39:
+ break
+ case 40:
+ break
+ case 41:
+ break
+ case 42:
+ break
+ case 43:
+ break
+ case 44:
+ break
+ case 45:
+ break
+ case 46:
+ break
+ case 47:
+ break
+ case 48:
+ break
+ case 49:
+ break
+ case 50:
+ break
+ case 51:
+ break
+ case 52:
+ def event = Verify.getInt(0,2)
+ if (event == 0) {
+ locationObject.setValue([name: "Location", value: "home", deviceId: "locationID0", descriptionText: "",
+ displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
+ } else if (event == 1) {
+ locationObject.setValue([name: "Location", value: "away", deviceId: "locationID0", descriptionText: "",
+ displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
+ } else {
+ locationObject.setValue([name: "Location", value: "night", deviceId: "locationID0", descriptionText: "",
+ displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
+ }
+ break
+ case 53:
+ appObject.setValue([name: "Touched", value: "touched", deviceId: "touchedSensorID0", descriptionText: "",
+ displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
+ break
+ }
+}
+++ /dev/null
-/////////////
- input "illuminances", "capability.illuminanceMeasurement", title: "Illuminance Meters", multiple: true, required: false
- input "powerMeters", "capability.powerMeter", title: "Power Meters", multiple: true, required: false
- input "humidities", "capability.relativeHumidityMeasurement", title: "Humidity Meters", multiple: true, required: false
- input "relaySwitches", "capability.relaySwitch", title: "Relay Switches", multiple: true, required: false
- input "sleepSensors", "capability.sleepSensor", title: "Sleep Sensors", multiple: true, required: false
- input "peds", "capability.stepSensor", title: "Pedometers", multiple: true, required: false
- input "switchLevels", "capability.switchLevel", title: "Switch Levels", multiple: true, required: false
- input "temperatures", "capability.temperatureMeasurement", title: "Temperature Sensors", multiple: true, required: false
- input "valves", "capability.valve", title: "Valves", multiple: true, required: false
- input "waterSensors", "capability.waterSensor", title: "Water Sensors", multiple: true, required: false
+++ /dev/null
-////
-import groovy.json.JsonSlurper
-import groovy.transform.Field
-
-class Logger {
- private boolean printToConsole = true
-
- def methodMissing(String name, args) {
- def messsage = args[0]
- if (printToConsole) {
- println messsage
- }
- }
-}
-
-///////////////////////////////////////////////////
-class RequestBuckets {
- def jsonSlurper = new JsonSlurper()
- def JSON = jsonSlurper.parseText '''
- {
- "version": 1.06,
- "accessKey": 100,
- "bucketKey": 50,
- "bucketName": "TEST",
- "isBucketCreated": true,
- "grokerSubdomain": "DOMAIN"
- }'''
-}
-///////////////////////////////////////////////////
-
-
-///////////////////////////////////////////////////
-class Atomic {
- def version
- def accessKey
- def bucketKey
- def bucketName
- def isBucketCreated
- def grokerSubdomain
-}
-///////////////////////////////////////////////////
-
-@Field def log = new Logger()
-///////////////////////////////////////////////////
-@Field def atomicState = new Atomic()
-@Field def request = new RequestBuckets()
-///////////////////////////////////////////////////
-
-
-getAccessKey()
-getBucketKey()
-setBucketKey()
-setAccessKey()
-tryCreateBucket()
-
-///////////////////////////////////////////////////
-def httpError(int errorNumber, String errorReport) {
- println("---Just IGNORE---For http connection in a streamer app")
-}
-def httpPostJson(LinkedHashMap metaData, Closure Input) {
- Input(metaData)
-}
-///////////////////////////////////////////////////
-
-
-
-def getAccessKey() {
- log.trace "get access key"
- if (atomicState.accessKey == null) {
- httpError(404, "Access Key Not Found")
- } else {
- [
- accessKey: atomicState.accessKey
- ]
- }
-}
-
-def getBucketKey() {
- log.trace "get bucket key"
- if (atomicState.bucketKey == null) {
- httpError(404, "Bucket key Not Found")
- } else {
- [
- bucketKey: atomicState.bucketKey,
- bucketName: atomicState.bucketName
- ]
- }
-}
-
-def setBucketKey() {
- log.trace "set bucket key"
- def newBucketKey = request.JSON?.bucketKey
- def newBucketName = request.JSON?.bucketName
-
- log.debug "bucket name: $newBucketName"
- log.debug "bucket key: $newBucketKey"
-
- if (newBucketKey && (newBucketKey != atomicState.bucketKey || newBucketName != atomicState.bucketName)) {
- atomicState.bucketKey = "$newBucketKey"
- atomicState.bucketName = "$newBucketName"
- atomicState.isBucketCreated = false
- }
-
- tryCreateBucket()
-}
-
-def setAccessKey() {
- log.trace "set access key"
- def newAccessKey = request.JSON?.accessKey
- def newGrokerSubdomain = request.JSON?.grokerSubdomain
-
- if (newGrokerSubdomain && newGrokerSubdomain != "" && newGrokerSubdomain != atomicState.grokerSubdomain) {
- atomicState.grokerSubdomain = "$newGrokerSubdomain"
- atomicState.isBucketCreated = false
- }
-
- if (newAccessKey && newAccessKey != atomicState.accessKey) {
- atomicState.accessKey = "$newAccessKey"
- atomicState.isBucketCreated = false
- }
-}
-
-
-
-def tryCreateBucket() {
-
- // can't ship events if there is no grokerSubdomain
- if (atomicState.grokerSubdomain == null || atomicState.grokerSubdomain == "") {
- log.error "streaming url is currently null"
- return
- }
-
- // if the bucket has already been created, no need to continue
- if (atomicState.isBucketCreated) {
- return
- }
-
- if (!atomicState.bucketName) {
- atomicState.bucketName = atomicState.bucketKey
- }
- if (!atomicState.accessKey) {
- return
- }
- def bucketName = "${atomicState.bucketName}"
- def bucketKey = "${atomicState.bucketKey}"
- def accessKey = "${atomicState.accessKey}"
-
- def bucketCreateBody = new JsonSlurper().parseText("{\"bucketKey\": \"$bucketKey\", \"bucketName\": \"$bucketName\"}")
-
- def bucketCreatePost = [
- uri: "https://${atomicState.grokerSubdomain}.initialstate.com/api/buckets",
- headers: [
- "Content-Type": "application/json",
- "X-IS-AccessKey": accessKey
- ],
- body: bucketCreateBody
- ]
-
- log.debug bucketCreatePost
-
- try {
- // Create a bucket on Initial State so the data has a logical grouping
- httpPostJson(bucketCreatePost) { resp ->
- log.debug "bucket posted"
- if (resp.status >= 400) {
- log.error "bucket not created successfully"
- } else {
- atomicState.isBucketCreated = true
- }
- }
- } catch (e) {
- log.error "bucket creation error: $e"
- }
-
-}
-
-