package MusicPlayer
import SmartThing.SmartThing
-//Importing mutable integer class
-import MutableInteger.MutableInteger
-
public class MusicPlayer extends SmartThing {
// id, label, and display name of the device
- StringBuilder id = new StringBuilder()
- StringBuilder label = new StringBuilder()
- StringBuilder displayName = new StringBuilder()
- // Features with numberical values
- MutableInteger currentLevel = new MutableInteger()
- // Features with string values
- StringBuilder currentMute = new StringBuilder()
- StringBuilder currentStatus = new StringBuilder()
- StringBuilder currentTrackData = new StringBuilder()
- StringBuilder currentTrackDescription = new StringBuilder()
+ String id
+ String label
+ String displayName
// Maps from features to values
- HashMap<String, StringBuilder> deviceValuesMap = new HashMap<String, StringBuilder>()
- HashMap<String, MutableInteger> deviceIntValuesMap = new HashMap<String, MutableInteger>()
+ HashMap<String, String> deviceValuesMap = new HashMap<String, String>()
+ HashMap<String, Integer> deviceIntValuesMap = new HashMap<String, Integer>()
// Possible values for eventsSince method
- List<StringBuilder> possibleValues = new ArrayList<StringBuilder>();
+ List<String> possibleValues = new ArrayList<String>();
- MusicPlayer(Closure sendEvent, StringBuilder id, StringBuilder label, StringBuilder displayName, MutableInteger currentLevel,
- StringBuilder currentMute, StringBuilder currentStatus, StringBuilder currentTrackData, StringBuilder currentTrackDescription) {
- deviceValuesMap = deviceValueSmartThing
- deviceIntValuesMap = deviceIntValueSmartThing
+ MusicPlayer(Closure sendEvent, String id, String label, String displayName, Integer currentLevel,
+ String currentMute, String currentStatus, String currentTrackData, String currentTrackDescription) {
+ deviceValueSmartThing = deviceValuesMap
+ deviceIntValueSmartThing = deviceIntValuesMap
idSmartThing = id
labelSmartThing = label
displayNameSmartThing = displayName
this.id = id
this.label = label
this.currentLevel = currentLevel
- this.currentMute = currentMute
- this.currentStatus = currentStatus
- this.currentTrackData = currentTrackData
- this.currentTrackDescription = currentTrackDescription
possibleValues.add("on")
possibleValues.add("off")
deviceValuesMap.put("status", currentStatus)
- deviceValuesMap.put("playpause", currentStatus)
deviceValuesMap.put("trackDescription", currentTrackDescription)
deviceValuesMap.put("mute", currentMute)
deviceValuesMap.put("trackData", currentTrackData)
}
def on() {
- action(currentStatus, "on", "status")
+ action("on", "status")
}
def off(LinkedHashMap metaData) {
}
def off() {
- action(currentStatus, "off", "status")
+ action("off", "status")
}
def mute(LinkedHashMap metaData) {
}
def mute() {
- action(currentMute, "muted", "mute")
+ action("muted", "mute")
}
def unmute(LinkedHashMap metaData) {
}
def unmute() {
- action(currentMute, "unmuted", "mute")
+ action("unmuted", "mute")
}
def nextTrack(LinkedHashMap metaData) {
}
def pause() {
- action(currentStatus, "pause", "status")
+ action("pause", "status")
}
def play(LinkedHashMap metaData) {
}
def play() {
- action(currentStatus, "play", "status")
+ action("play", "status")
}
def playTrack(LinkedHashMap metaData) {
}
def setLevel(int level) {
- action(currentLevel, level, "level")
+ action(level, "level")
}
def setTrack(LinkedHashMap metaData) {
}
def stop() {
- action(currentStatus, "stop", "status")
- }
-
- def action(StringBuilder variable, String newValue, String feature) {
- if (!variable.toString().equals(newValue)) {
- String tmpID = id.toString()
- variable.replace(0, variable.length(), newValue)
- println("$feature of the music player with id:$tmpID is changed to $newValue!")
- sendEvent([name: feature, value: newValue, deviceId: tmpID, descriptionText: "",
- displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
- }
- }
-
- def action(MutableInteger variable, int newValue, String feature) {
- if (!variable.getValue().equals(newValue)) {
- String tmpID = id.toString()
- variable.setValue(newValue)
- println("$feature for the thermostat with id:$tmpID is changed to $newValue!")
- sendEvent([name: feature, value: newValue, deviceId: tmpID, descriptionText: "",
- displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
- }
+ action("stop", "status")
}
def musicChangeEvents() {
- sendEvent([name: "trackDescription", value: "someDescriptions", deviceId: id.toString(), descriptionText: "",
+ setValue([name: "trackDescription", value: "someDescriptions", deviceId: id.toString(), descriptionText: "",
displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
- sendEvent([name: "trackData", value: "someTrack", deviceId: id.toString(), descriptionText: "",
+ setValue([name: "trackData", value: "someTrack", deviceId: id.toString(), descriptionText: "",
displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
}
-
- // Methods to return values
- def getCurrentLevel() {
- return currentLevel.getValue()
- }
-
- def getCurrentMute() {
- return currentMute.toString()
- }
-
- def getCurrentStatus() {
- return currentStatus.toString()
- }
-
- def getCurrentTrackData() {
- return currentTrackData.toString()
- }
-
- def getCurrentTrackDescription() {
- return currentTrackDescription.toString()
- }
}