From: amiraj Date: Mon, 5 Aug 2019 02:57:28 +0000 (-0700) Subject: Infrastructure works for lights' group now! X-Git-Url: http://plrg.eecs.uci.edu/git/?p=smartthings-infrastructure.git;a=commitdiff_plain;h=eaa326d5f41665f412a4731e093ebe8695a1c6d7 Infrastructure works for lights' group now! --- diff --git a/ColorControl/ColorControl.groovy b/ColorControl/ColorControl.groovy index cd33e8e..c60afb1 100644 --- a/ColorControl/ColorControl.groovy +++ b/ColorControl/ColorControl.groovy @@ -64,6 +64,43 @@ public class ColorControl { } //methods + def setColor(LinkedHashMap metaData) { + def hexColor = metaData.hex + switch (hexColor) { + case "#0000FF": + color = "Blue" + break; + case "#00FF00": + color = "Green" + break; + case "#FFFF00": + color = "Yellow" + break; + case "#FF6000": + color = "Orange" + break; + case "#BF7FBF": + color = "Purple" + break; + case "#FF5F5F": + color = "Pink" + break; + case "#FF0000": + color = "Red" + break; + default: + color = "Blue" + break; + } + if (color != this.color) { + this.currentColor = 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 setColor(String color) { if (color != this.color) { this.currentColor = color diff --git a/ColorControl/ColorControls.groovy b/ColorControl/ColorControls.groovy index 5122f6b..306ba87 100644 --- a/ColorControl/ColorControls.groovy +++ b/ColorControl/ColorControls.groovy @@ -114,6 +114,41 @@ public class ColorControls { //methods + def setColor(LinkedHashMap metaData) { + def hexColor = metaData.hex + switch (hexColor) { + case "#0000FF": + color = "Blue" + break; + case "#00FF00": + color = "Green" + break; + case "#FFFF00": + color = "Yellow" + break; + case "#FF6000": + color = "Orange" + break; + case "#BF7FBF": + color = "Purple" + break; + case "#FF5F5F": + color = "Pink" + break; + case "#FF0000": + color = "Red" + break; + default: + color = "Blue" + break; + } + if (color != this.color) { + this.currentColor = color + this.color = color + colorControls[0].setColor(color) + } + } + def setColor(String color) { if (color != this.color) { this.currentColor = color diff --git a/Event/Event.groovy b/Event/Event.groovy index 60d7276..eecbc7b 100644 --- a/Event/Event.groovy +++ b/Event/Event.groovy @@ -1,5 +1,6 @@ //Create a class for Events package Event +import groovy.json.JsonSlurper public class Event { private String deviceId @@ -12,6 +13,7 @@ public class Event { private boolean isStateChange private String unit private String data + private jsonData private int integerValue private double doubleValue private List integerValues = ["battery", "hue", "saturation", "energy", "level", "temperature", @@ -27,6 +29,7 @@ public class Event { this.isStateChange = isStateChange this.unit = unit this.data = data + this.jsonData = new groovy.json.JsonSlurper().parseText(data) this.displayed = displayed if (integerValues.contains(name)) { this.integerValue = value.toInteger() diff --git a/Methods/httpPostJson.groovy b/Methods/httpPostJson.groovy index e53be72..d856bed 100644 --- a/Methods/httpPostJson.groovy +++ b/Methods/httpPostJson.groovy @@ -2,3 +2,7 @@ def httpPostJson(LinkedHashMap metaData, Closure inputData) { inputData(metaData) } + +def httpPostJson(LinkedHashMap metaData) { + +} diff --git a/PresenceSensor/PresenceSensor.groovy b/PresenceSensor/PresenceSensor.groovy index c1553fb..b370736 100644 --- a/PresenceSensor/PresenceSensor.groovy +++ b/PresenceSensor/PresenceSensor.groovy @@ -26,6 +26,9 @@ public class PresenceSensor { this.currentPresence = value } + def currentState(String deviceFeature) { + return [rawDateCreated: [time: System.currentTimeMillis()]] + } def currentValue(String deviceFeature) { if (deviceFeature == "presence") { diff --git a/PresenceSensor/PresenceSensors.groovy b/PresenceSensor/PresenceSensors.groovy index ec24f3b..181be40 100644 --- a/PresenceSensor/PresenceSensors.groovy +++ b/PresenceSensor/PresenceSensors.groovy @@ -66,6 +66,9 @@ public class PresenceSensors { presenceSensors.collect(Input) } + def currentState(String deviceFeature) { + presenceSensors[0].currentState(deviceFeature) + } def currentValue(String deviceFeature) { presenceSensors[0].currentValue(deviceFeature)//It is called if we have only one device diff --git a/StepSensor/StepSensor.groovy b/StepSensor/StepSensor.groovy index 4a408ad..6ec578f 100644 --- a/StepSensor/StepSensor.groovy +++ b/StepSensor/StepSensor.groovy @@ -27,4 +27,18 @@ public class StepSensor { this.goal = value.toInteger() } } + + def currentValue(String deviceFeature) { + if (deviceFeature == "steps") + return steps + else if (deviceFeature == "goal") + return goal + } + + def latestValue(String deviceFeature) { + if (deviceFeature == "steps") + return steps + else if (deviceFeature == "goal") + return goal + } } diff --git a/StepSensor/StepSensors.groovy b/StepSensor/StepSensors.groovy index 021db25..fbfe70f 100644 --- a/StepSensor/StepSensors.groovy +++ b/StepSensor/StepSensors.groovy @@ -73,6 +73,10 @@ public class StepSensors { stepSensors[0].currentValue(deviceFeature)//It is called if we have only one device } + def latestValue(String deviceFeature) { + stepSensors[0].currentValue(deviceFeature)//It is called if we have only one device + } + def getAt(int ix) { stepSensors[ix] } diff --git a/Variables and events for each device b/Variables and events for each device index 9594b89..bf5e119 100644 --- a/Variables and events for each device +++ b/Variables and events for each device @@ -139,6 +139,8 @@ presenceSensorObject.setValue([name: "presence", value: "not present", deviceId: displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"presence":"0","dni":"mobile0"}']) presenceSensorObject.setValue([name: "presence.present", value: "present", deviceId: "presenceSensorID0", descriptionText: "", displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"presence":"1","dni":"mobile0"}']) +presenceSensorObject.setValue([name: "presence.not present", value: "present", deviceId: "presenceSensorID0", descriptionText: "", +displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"presence":"1","dni":"mobile0"}']) ///// /*events*/ // @@ -259,7 +261,7 @@ displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": " //For appTouch: /*events*/ -appObject.setValue([name: "Touched", value: "touched", deviceId: "appID0", descriptionText: "", +appObject.setValue([name: "Touched", value: "touched", deviceId: "appTouchID0", descriptionText: "", displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}']) ///// /*events*/ diff --git a/appTouch/Touched.groovy b/appTouch/Touched.groovy index 1d9e57f..89d575e 100644 --- a/appTouch/Touched.groovy +++ b/appTouch/Touched.groovy @@ -6,12 +6,15 @@ public class Touched{ private String id private int isTouched private String label + private String name + Touched(Closure sendEvent, int isTouched) { this.sendEvent = sendEvent this.isTouched = isTouched this.label = "app0" this.id = "appID0" + this.name = "app0" } //By Model Checker