Infrastructure works for lights' group now!
authoramiraj <amiraj.95@uci.edu>
Mon, 5 Aug 2019 02:57:28 +0000 (19:57 -0700)
committeramiraj <amiraj.95@uci.edu>
Mon, 5 Aug 2019 02:57:28 +0000 (19:57 -0700)
ColorControl/ColorControl.groovy
ColorControl/ColorControls.groovy
Event/Event.groovy
Methods/httpPostJson.groovy
PresenceSensor/PresenceSensor.groovy
PresenceSensor/PresenceSensors.groovy
StepSensor/StepSensor.groovy
StepSensor/StepSensors.groovy
Variables and events for each device
appTouch/Touched.groovy

index cd33e8e..c60afb1 100644 (file)
@@ -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
index 5122f6b..306ba87 100644 (file)
@@ -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
index 60d7276..eecbc7b 100644 (file)
@@ -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()
index e53be72..d856bed 100644 (file)
@@ -2,3 +2,7 @@
 def httpPostJson(LinkedHashMap metaData, Closure inputData) {
        inputData(metaData)
 }
+
+def httpPostJson(LinkedHashMap metaData) {
+
+}
index c1553fb..b370736 100644 (file)
@@ -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") {
index ec24f3b..181be40 100644 (file)
@@ -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
index 4a408ad..6ec578f 100644 (file)
@@ -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
+       }
 }
index 021db25..fbfe70f 100644 (file)
@@ -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]
        }
index 9594b89..bf5e119 100644 (file)
@@ -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*/
index 1d9e57f..89d575e 100644 (file)
@@ -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