Adding missing methods etc.
authorrtrimana <rtrimana@uci.edu>
Wed, 7 Aug 2019 18:44:56 +0000 (11:44 -0700)
committerrtrimana <rtrimana@uci.edu>
Wed, 7 Aug 2019 18:44:56 +0000 (11:44 -0700)
ColorControl/ColorControl.groovy
ColorControl/ColorControls.groovy
Extractor/ExtractorScript.py
MusicPlayer/MusicPlayers.groovy
StepSensor/StepSensors.groovy
eventSimulator/stepGoalEvent.groovy [deleted file]
eventSimulator/stepGoalHighEvent.groovy [new file with mode: 0644]
eventSimulator/stepGoalLowEvent.groovy [new file with mode: 0644]
eventSimulator/stepStepsEvent.groovy [deleted file]
eventSimulator/stepStepsHighEvent.groovy [new file with mode: 0644]
eventSimulator/stepStepsLowEvent.groovy [new file with mode: 0644]

index 0e9ced0f3d70afae552600d363ac1ccdd2175ee9..4878c48b9f82c55e43a105068269d29e1b6f02dc 100644 (file)
@@ -66,37 +66,38 @@ public class ColorControl {
        //methods
        def setColor(LinkedHashMap metaData) {
                def hexColor = metaData.hex
        //methods
        def setColor(LinkedHashMap metaData) {
                def hexColor = metaData.hex
+               def newColor
                switch (hexColor) {
                        case "#0000FF":
                switch (hexColor) {
                        case "#0000FF":
-                               color = "Blue"
+                               newColor = "Blue"
                                break;
                        case "#00FF00":
                                break;
                        case "#00FF00":
-                               color = "Green"
+                               newColor = "Green"
                                break;
                        case "#FFFF00":
                                break;
                        case "#FFFF00":
-                               color = "Yellow"
+                               newColor = "Yellow"
                                break;
                        case "#FF6000":
                                break;
                        case "#FF6000":
-                               color = "Orange"
+                               newColor = "Orange"
                                break;
                        case "#BF7FBF":
                                break;
                        case "#BF7FBF":
-                               color = "Purple"
+                               newColor = "Purple"
                                break;
                        case "#FF5F5F":
                                break;
                        case "#FF5F5F":
-                               color = "Pink"
+                               newColor = "Pink"
                                break;
                        case "#FF0000":
                                break;
                        case "#FF0000":
-                               color = "Red"
+                               newColor = "Red"
                                break;
                        default:
                                break;
                        default:
-                               color = "Blue"
+                               newColor = "Blue"
                                break;
                }
                                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: "",
+               if (newColor != this.color) {
+                       this.currentColor = newColor
+                       this.color = newColor
+                       println("The color of the light is changed to $newColor!")
+                       sendEvent([name: "color", value: "$newColor", deviceId: this.id, descriptionText: "",
                                   displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
                }
        }
                                   displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
                }
        }
index 6fc62aa14461788cf41218f7f2828ffaa9edd9b6..0ff9cfdf1ae825fca522d4d303fb96319a262fe4 100644 (file)
@@ -11,8 +11,8 @@ public class ColorControls {
        private String id = "colorControlID0"
        private String label = "colorControl0"
        private String displayName = "colorControl0"
        private String id = "colorControlID0"
        private String label = "colorControl0"
        private String displayName = "colorControl0"
-       private String color = "red"
-       private String currentColor = "red"
+       private String color = "Red"
+       private String currentColor = "Red"
        private String currentSwitch = "on"
        private int level = 50
        private int currentLevel = 50
        private String currentSwitch = "on"
        private int level = 50
        private int currentLevel = 50
@@ -21,6 +21,7 @@ public class ColorControls {
        private int saturation = 50
        private int currentSaturation = 50
        private int colorTemperature = 15000
        private int saturation = 50
        private int currentSaturation = 50
        private int colorTemperature = 15000
+       private boolean colorChanged = false
        
 
        ColorControls(Closure sendEvent, int deviceNumbers, boolean init) {
        
 
        ColorControls(Closure sendEvent, int deviceNumbers, boolean init) {
@@ -29,17 +30,26 @@ public class ColorControls {
                this.colorControls = []
 
                if (init) {
                this.colorControls = []
 
                if (init) {
+                       this.level = 20
+                       this.currentLevel = 20
                        this.hue = 30
                        this.hue = 30
+                       this.currentHue = 30
                        this.saturation = 40
                        this.saturation = 40
-                       this.color = "red"
+                       this.currentSaturation = 40
+                       this.colorTemperature = 10000
+                       this.color = "Red"
                        this.currentSwitch = "off"
                } else {
                        this.currentSwitch = "off"
                } else {
+                       this.level = 50
+                       this.currentLevel = 50
                        this.hue = 50
                        this.hue = 50
+                       this.currentHue = 50
                        this.saturation = 50
                        this.saturation = 50
-                       this.color = "blue"
+                       this.currentSaturation = 50
+                       this.colorTemperature = 15000
+                       this.color = "Blue"
                        this.currentSwitch = "on"
                }
                        this.currentSwitch = "on"
                }
-
                colorControls.add(new ColorControl(sendEvent, id, label, displayName, this.color, this.hue, this.saturation, this.level, this.currentSwitch, this.colorTemperature))
        }
 
                colorControls.add(new ColorControl(sendEvent, id, label, displayName, this.color, this.hue, this.saturation, this.level, this.currentSwitch, this.colorTemperature))
        }
 
@@ -112,36 +122,54 @@ public class ColorControls {
        //methods
        def setColor(LinkedHashMap metaData) {
                def hexColor = metaData.hex
        //methods
        def setColor(LinkedHashMap metaData) {
                def hexColor = metaData.hex
+               def newColor
                switch (hexColor) {
                        case "#0000FF":
                switch (hexColor) {
                        case "#0000FF":
-                               color = "Blue"
+                               newColor = "Blue"
                                break;
                        case "#00FF00":
                                break;
                        case "#00FF00":
-                               color = "Green"
+                               newColor = "Green"
                                break;
                        case "#FFFF00":
                                break;
                        case "#FFFF00":
-                               color = "Yellow"
+                               newColor = "Yellow"
                                break;
                        case "#FF6000":
                                break;
                        case "#FF6000":
-                               color = "Orange"
+                               newColor = "Orange"
                                break;
                        case "#BF7FBF":
                                break;
                        case "#BF7FBF":
-                               color = "Purple"
+                               newColor = "Purple"
                                break;
                        case "#FF5F5F":
                                break;
                        case "#FF5F5F":
-                               color = "Pink"
+                               newColor = "Pink"
                                break;
                        case "#FF0000":
                                break;
                        case "#FF0000":
-                               color = "Red"
+                               newColor = "Red"
                                break;
                        default:
                                break;
                        default:
-                               color = "Blue"
+                               newColor = "Blue"
                                break;
                }
                                break;
                }
-               if (color != this.color) {
-                       this.currentColor = color
-                       this.color = color
-                       colorControls[0].setColor(color)                        
+               if (newColor != this.color) {
+                       this.currentColor = newColor
+                       this.color = newColor
+                       colorControls[0].setColor(newColor)
+                       if (this.colorChanged) {
+                               this.colorChanged = false
+                       } else {
+                               this.colorChanged = true
+                       }
+               }
+               def newLevel = metaData.level
+               def newHue = metaData.hue
+               def newSaturation = metaData.saturation
+               if (newLevel != null) {
+                       setLevel(newLevel)
+               }
+               if (newHue != null) {
+                       setHue(newHue)
+               }
+               if (newSaturation != null) {
+                       setSaturation(newSaturation)
                }
        }
 
                }
        }
 
index 9437601d412579ff8abcf726dcf52128248f5233..3a87c2389d32699e6d6eba606e052981bf8211bd 100644 (file)
@@ -39,14 +39,14 @@ eventTypeCounterMap =  {'lock': 2,
                                                'sunriseTime' : 1,
                                                'acceleration' : 2,
                                                'sleeping' : 2,
                                                'sunriseTime' : 1,
                                                'acceleration' : 2,
                                                'sleeping' : 2,
-                                               'goal' : 1,
-                                               'steps' : 1,
+                                               'goal' : 2,
+                                               'steps' : 2,
                                                'color' : 1,
                                                'colorTemperature' : 1,
                                                'hue' : 1,
                                                'saturation' : 1,
                                                'energy' : 1,
                                                'color' : 1,
                                                'colorTemperature' : 1,
                                                'hue' : 1,
                                                'saturation' : 1,
                                                'energy' : 1,
-                                               'power' : 1,
+                                               'power' : 2,
                                                'illuminance' : 1,
                                                'humidity' : 1,
                                                'alarm' : 4,
                                                'illuminance' : 1,
                                                'humidity' : 1,
                                                'alarm' : 4,
@@ -761,12 +761,28 @@ def ExtractEvents(extractedEvents):
                                extractedEvents.write(line)
                        event.close()
                elif eventList[i] == "goal":
                                extractedEvents.write(line)
                        event.close()
                elif eventList[i] == "goal":
-                       event = open("eventSimulator/stepGoalEvent.groovy", "r")
+                       #Write two events subsequently
+                       event = open("eventSimulator/stepGoalHighEvent.groovy", "r")
+                       for line in event:
+                               extractedEvents.write(line)
+                       event.close()
+                       extractedEvents.write("\n\t\t\tbreak\n")
+                       counter = counter + 1
+                       extractedEvents.write("\t\tcase %d:\n" % counter)
+                       event = open("eventSimulator/stepGoalLowEvent.groovy", "r")
                        for line in event:
                                extractedEvents.write(line)
                        event.close()
                elif eventList[i] == "steps":
                        for line in event:
                                extractedEvents.write(line)
                        event.close()
                elif eventList[i] == "steps":
-                       event = open("eventSimulator/stepStepsEvent.groovy", "r")
+                       #Write two events subsequently
+                       event = open("eventSimulator/stepStepsHighEvent.groovy", "r")
+                       for line in event:
+                               extractedEvents.write(line)
+                       event.close()
+                       extractedEvents.write("\n\t\t\tbreak\n")
+                       counter = counter + 1
+                       extractedEvents.write("\t\tcase %d:\n" % counter)
+                       event = open("eventSimulator/stepStepsLowEvent.groovy", "r")
                        for line in event:
                                extractedEvents.write(line)
                        event.close()
                        for line in event:
                                extractedEvents.write(line)
                        event.close()
index 1906b01edd105090c11ff383c6ea0e254dac713a..5a8aed073d13e4cd3fac2b96b5c88f395f70caca 100644 (file)
@@ -12,6 +12,7 @@ public class MusicPlayers {
        private String label = "musicPlayer0"
        private String displayName = "musicPlayer0"
        private int level = 20
        private String label = "musicPlayer0"
        private String displayName = "musicPlayer0"
        private int level = 20
+       private int duration = 10
        private String mute = "unmuted"
        private String status = "pause"
        private int trackNumber = 1
        private String mute = "unmuted"
        private String status = "pause"
        private int trackNumber = 1
@@ -27,6 +28,7 @@ public class MusicPlayers {
                
                if (init) {
                        this.level = 20
                
                if (init) {
                        this.level = 20
+                       this.duration = 10
                        this.mute = "unmuted"
                        this.status = "paused"
                        this.trackNumber = 1
                        this.mute = "unmuted"
                        this.status = "paused"
                        this.trackNumber = 1
@@ -34,6 +36,7 @@ public class MusicPlayers {
                        this.trackDescription = "someDescriptions"
                } else {
                        this.level = 30
                        this.trackDescription = "someDescriptions"
                } else {
                        this.level = 30
+                       this.duration = 20
                        this.mute = "muted"
                        this.status = "playing"
                        this.trackNumber = 2
                        this.mute = "muted"
                        this.status = "playing"
                        this.trackNumber = 2
@@ -155,7 +158,25 @@ public class MusicPlayers {
                }
        }
        def playTrack(LinkedHashMap metaData) {
                }
        }
        def playTrack(LinkedHashMap metaData) {
-               playTrack()
+               playTrack("someTrack")
+       }
+       def playTrackAndResume(String trackData, int duration) {
+               playTrack(trackData)
+               if (duration != this.duration) {
+                       this.duration = duration
+               }
+       }
+       def playTrackAndResume(String trackData, int duration, int level) {
+               playTrackAndResume(trackData, duration)
+               if (level != this.level) {
+                       this.level = level
+               }
+       }
+       def playTrackAtVolume(String trackData, int level) {
+               playTrack(trackData)
+               if (level != this.level) {
+                       this.level = level
+               }
        }
        def playTrack(String trackToPlay) {
                if (status != "play") {
        }
        def playTrack(String trackToPlay) {
                if (status != "play") {
index d3edb7b4f6f9fc035374e54317c3fb5788dbac27..d9200c6a24e258144af1c4ca66576836e6a407d6 100644 (file)
@@ -22,10 +22,10 @@ public class StepSensors {
 
                if (init) {
                        this.goal = 50
 
                if (init) {
                        this.goal = 50
-                       this.steps = 0
+                       this.steps = 35
                } else {
                } else {
-                       this.goal = 60
-                       this.steps = 1
+                       this.goal = 40
+                       this.steps = 60
                }
                stepSensors.add(new StepSensor(id, label, displayName, this.steps, this.goal))
        }
                }
                stepSensors.add(new StepSensor(id, label, displayName, this.steps, this.goal))
        }
diff --git a/eventSimulator/stepGoalEvent.groovy b/eventSimulator/stepGoalEvent.groovy
deleted file mode 100644 (file)
index de1ee84..0000000
+++ /dev/null
@@ -1,2 +0,0 @@
-                       stepSensorObject.setValue([name: "goal", value: "100"/*A number*/, deviceId: "stepSensorID0", descriptionText: "",
-                                       displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
diff --git a/eventSimulator/stepGoalHighEvent.groovy b/eventSimulator/stepGoalHighEvent.groovy
new file mode 100644 (file)
index 0000000..de1ee84
--- /dev/null
@@ -0,0 +1,2 @@
+                       stepSensorObject.setValue([name: "goal", value: "100"/*A number*/, deviceId: "stepSensorID0", descriptionText: "",
+                                       displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
diff --git a/eventSimulator/stepGoalLowEvent.groovy b/eventSimulator/stepGoalLowEvent.groovy
new file mode 100644 (file)
index 0000000..6443e66
--- /dev/null
@@ -0,0 +1,2 @@
+                       stepSensorObject.setValue([name: "goal", value: "20"/*A number*/, deviceId: "stepSensorID0", descriptionText: "",
+                                       displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
diff --git a/eventSimulator/stepStepsEvent.groovy b/eventSimulator/stepStepsEvent.groovy
deleted file mode 100644 (file)
index bd9a683..0000000
+++ /dev/null
@@ -1,2 +0,0 @@
-                       stepSensorObject.setValue([name: "steps", value: "46"/*A number*/, deviceId: "stepSensorID0", descriptionText: "",
-                                       displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
diff --git a/eventSimulator/stepStepsHighEvent.groovy b/eventSimulator/stepStepsHighEvent.groovy
new file mode 100644 (file)
index 0000000..4113fe4
--- /dev/null
@@ -0,0 +1,2 @@
+                       stepSensorObject.setValue([name: "steps", value: "70"/*A number*/, deviceId: "stepSensorID0", descriptionText: "",
+                                       displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
diff --git a/eventSimulator/stepStepsLowEvent.groovy b/eventSimulator/stepStepsLowEvent.groovy
new file mode 100644 (file)
index 0000000..3dc916f
--- /dev/null
@@ -0,0 +1,2 @@
+                       stepSensorObject.setValue([name: "steps", value: "30"/*A number*/, deviceId: "stepSensorID0", descriptionText: "",
+                                       displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])