From: rtrimana Date: Wed, 7 Aug 2019 18:44:56 +0000 (-0700) Subject: Adding missing methods etc. X-Git-Url: http://plrg.eecs.uci.edu/git/?p=smartthings-infrastructure.git;a=commitdiff_plain;h=752df0b3baa7349d6a0f5bdefb7d644a552bea2e Adding missing methods etc. --- diff --git a/ColorControl/ColorControl.groovy b/ColorControl/ColorControl.groovy index 0e9ced0..4878c48 100644 --- a/ColorControl/ColorControl.groovy +++ b/ColorControl/ColorControl.groovy @@ -66,37 +66,38 @@ public class ColorControl { //methods def setColor(LinkedHashMap metaData) { def hexColor = metaData.hex + def newColor switch (hexColor) { case "#0000FF": - color = "Blue" + newColor = "Blue" break; case "#00FF00": - color = "Green" + newColor = "Green" break; case "#FFFF00": - color = "Yellow" + newColor = "Yellow" break; case "#FF6000": - color = "Orange" + newColor = "Orange" break; case "#BF7FBF": - color = "Purple" + newColor = "Purple" break; case "#FF5F5F": - color = "Pink" + newColor = "Pink" break; case "#FF0000": - color = "Red" + newColor = "Red" break; default: - color = "Blue" + newColor = "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: "", + 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"}']) } } diff --git a/ColorControl/ColorControls.groovy b/ColorControl/ColorControls.groovy index 6fc62aa..0ff9cfd 100644 --- a/ColorControl/ColorControls.groovy +++ b/ColorControl/ColorControls.groovy @@ -11,8 +11,8 @@ public class ColorControls { 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 @@ -21,6 +21,7 @@ public class ColorControls { private int saturation = 50 private int currentSaturation = 50 private int colorTemperature = 15000 + private boolean colorChanged = false ColorControls(Closure sendEvent, int deviceNumbers, boolean init) { @@ -29,17 +30,26 @@ public class ColorControls { this.colorControls = [] if (init) { + this.level = 20 + this.currentLevel = 20 this.hue = 30 + this.currentHue = 30 this.saturation = 40 - this.color = "red" + this.currentSaturation = 40 + this.colorTemperature = 10000 + this.color = "Red" this.currentSwitch = "off" } else { + this.level = 50 + this.currentLevel = 50 this.hue = 50 + this.currentHue = 50 this.saturation = 50 - this.color = "blue" + this.currentSaturation = 50 + this.colorTemperature = 15000 + this.color = "Blue" this.currentSwitch = "on" } - 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 + def newColor switch (hexColor) { case "#0000FF": - color = "Blue" + newColor = "Blue" break; case "#00FF00": - color = "Green" + newColor = "Green" break; case "#FFFF00": - color = "Yellow" + newColor = "Yellow" break; case "#FF6000": - color = "Orange" + newColor = "Orange" break; case "#BF7FBF": - color = "Purple" + newColor = "Purple" break; case "#FF5F5F": - color = "Pink" + newColor = "Pink" break; case "#FF0000": - color = "Red" + newColor = "Red" break; default: - color = "Blue" + newColor = "Blue" 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) } } diff --git a/Extractor/ExtractorScript.py b/Extractor/ExtractorScript.py index 9437601..3a87c23 100644 --- a/Extractor/ExtractorScript.py +++ b/Extractor/ExtractorScript.py @@ -39,14 +39,14 @@ eventTypeCounterMap = {'lock': 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, - 'power' : 1, + 'power' : 2, 'illuminance' : 1, 'humidity' : 1, 'alarm' : 4, @@ -761,12 +761,28 @@ def ExtractEvents(extractedEvents): 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": - 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() diff --git a/MusicPlayer/MusicPlayers.groovy b/MusicPlayer/MusicPlayers.groovy index 1906b01..5a8aed0 100644 --- a/MusicPlayer/MusicPlayers.groovy +++ b/MusicPlayer/MusicPlayers.groovy @@ -12,6 +12,7 @@ public class MusicPlayers { 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 @@ -27,6 +28,7 @@ public class MusicPlayers { if (init) { this.level = 20 + this.duration = 10 this.mute = "unmuted" this.status = "paused" this.trackNumber = 1 @@ -34,6 +36,7 @@ public class MusicPlayers { this.trackDescription = "someDescriptions" } else { this.level = 30 + this.duration = 20 this.mute = "muted" this.status = "playing" this.trackNumber = 2 @@ -155,7 +158,25 @@ public class MusicPlayers { } } 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") { diff --git a/StepSensor/StepSensors.groovy b/StepSensor/StepSensors.groovy index d3edb7b..d9200c6 100644 --- a/StepSensor/StepSensors.groovy +++ b/StepSensor/StepSensors.groovy @@ -22,10 +22,10 @@ public class StepSensors { if (init) { this.goal = 50 - this.steps = 0 + this.steps = 35 } else { - this.goal = 60 - this.steps = 1 + this.goal = 40 + this.steps = 60 } 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 index de1ee84..0000000 --- a/eventSimulator/stepGoalEvent.groovy +++ /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 index 0000000..de1ee84 --- /dev/null +++ b/eventSimulator/stepGoalHighEvent.groovy @@ -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 index 0000000..6443e66 --- /dev/null +++ b/eventSimulator/stepGoalLowEvent.groovy @@ -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 index bd9a683..0000000 --- a/eventSimulator/stepStepsEvent.groovy +++ /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 index 0000000..4113fe4 --- /dev/null +++ b/eventSimulator/stepStepsHighEvent.groovy @@ -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 index 0000000..3dc916f --- /dev/null +++ b/eventSimulator/stepStepsLowEvent.groovy @@ -0,0 +1,2 @@ + stepSensorObject.setValue([name: "steps", value: "30"/*A number*/, deviceId: "stepSensorID0", descriptionText: "", + displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])