public class AccelerationSensor extends SmartThing {
// id, label, and display name of the device
- StringBuilder id = new StringBuilder()
- StringBuilder label = new StringBuilder()
- StringBuilder displayName = new StringBuilder()
- // Features with string values
- StringBuilder currentAcceleration = new StringBuilder()
+ String id
+ String label
+ String displayName
// Maps from features to values
- HashMap<String, StringBuilder> deviceValuesMap = new HashMap<String, StringBuilder>()
+ HashMap<String, String> deviceValuesMap = new HashMap<String, String>()
// Possible values for eventsSince method
- List<StringBuilder> possibleValues = new ArrayList<StringBuilder>();
+ List<String> possibleValues = new ArrayList<String>();
- AccelerationSensor(Closure sendEvent, StringBuilder id, StringBuilder label, StringBuilder displayName, StringBuilder currentAcceleration) {
- deviceValuesMap = deviceValueSmartThing
- deviceIntValuesMap = deviceIntValueSmartThing
+ AccelerationSensor(Closure sendEvent, String id, String label, String displayName, String currentAcceleration) {
+ deviceValueSmartThing = deviceValuesMap
idSmartThing = id
labelSmartThing = label
displayNameSmartThing = displayName
- sendEventSmartThings = sendEvent
possibleValuesSmartThings = possibleValues
+ sendEventSmartThings = sendEvent
// Initialization
this.id = id
this.label = label
this.displayName = displayName
- this.currentAcceleration = currentAcceleration
possibleValues.add("active")
possibleValues.add("inactive")
deviceValuesMap.put("acceleration", currentAcceleration)
}
-
- // Methods to return values
- def getCurrentAcceleration() {
- return currentAcceleration.toString()
- }
}
accelerationSensors = smartThings
// Initialize
- StringBuilder id = new StringBuilder("accelerationID0")
- StringBuilder label = new StringBuilder("acceleration")
- StringBuilder displayName = new StringBuilder("acceleration0")
- StringBuilder acceleration = new StringBuilder()
+ String id = "accelerationID0"
+ String label = "acceleration"
+ String displayName = "accelerationSensor"
+ String acceleration
// Initialization
if (init)
- acceleration.append("inactive")
+ acceleration = "inactive"
else
- acceleration.append("active")
+ acceleration = "active"
accelerationSensors.add(new AccelerationSensor(sendEvent, id, label, displayName, acceleration))
}
-
- // Methods to return values
- def getCurrentAcceleration() {
- List tmpValues = new ArrayList()
- tmpValues.add(accelerationSensors[0].getCurrentAcceleration())
- return tmpValues
- }
}
public class AeonKeyFob extends SmartThing {
// id, label, and display name of the device
- StringBuilder id = new StringBuilder()
- StringBuilder label = new StringBuilder()
- StringBuilder displayName = new StringBuilder()
+ String id
+ String label
+ String displayName
// Possible values for eventsSince method
- List<StringBuilder> possibleValues = new ArrayList<StringBuilder>();
+ List<String> possibleValues = new ArrayList<String>()
- AeonKeyFob(Closure sendEvent, StringBuilder id, StringBuilder label, StringBuilder displayName) {
+ AeonKeyFob(Closure sendEvent, String id, String label, String displayName) {
idSmartThing = id
labelSmartThing = label
displayNameSmartThing = displayName
- sendEventSmartThings = sendEvent
possibleValuesSmartThings = possibleValues
+ sendEventSmartThings = sendEvent
// Initialization
this.id = id
aeonKeyFobs = smartThings
// Initialization
- StringBuilder id = new StringBuilder("aeonKeyFobID0")
- StringBuilder label = new StringBuilder("button")
- StringBuilder displayName = new StringBuilder("aeonKeyFob0")
+ String id = "aeonKeyFobID0"
+ String label = "button"
+ String displayName = "aeonKeyFob"
aeonKeyFobs.add(new AeonKeyFob(sendEvent, id, label, displayName))
}
public class Alarm extends SmartThing {
// id, label, and display name of the device
- StringBuilder id = new StringBuilder()
- StringBuilder label = new StringBuilder()
- StringBuilder displayName = new StringBuilder()
- // Features with string values
- StringBuilder currentAlarm = new StringBuilder()
+ String id
+ String label
+ String displayName
// Maps from features to values
- HashMap<String, StringBuilder> deviceValuesMap = new HashMap<String, StringBuilder>()
+ HashMap<String, String> deviceValuesMap = new HashMap<String, String>()
- Alarm(Closure sendEvent, StringBuilder id, StringBuilder label, StringBuilder displayName, StringBuilder currentAlarm) {
- deviceValuesMap = deviceValueSmartThing
+ Alarm(Closure sendEvent, String id, String label, String displayName, String currentAlarm) {
+ deviceValueSmartThing = deviceValuesMap
idSmartThing = id
labelSmartThing = label
displayNameSmartThing = displayName
this.id = id
this.label = label
this.displayName = displayName
- this.currentAlarm = currentAlarm
deviceValuesMap.put("alarm", currentAlarm)
}
// Methods to set values
def both() {
- action("both")
+ action("both", "alarm")
}
def on() {
- action("both")
+ action("both", "alarm")
}
def off() {
- action("off")
+ action("off", "alarm")
}
def siren() {
- action("siren")
+ action("siren", "alarm")
}
def strobe() {
- action("strobe")
- }
-
- def action(String newValue) {
- if (!currentAlarm.equals(newValue)) {
- String tmpID = id.toString()
- currentAlarm.replace(0, currentAlarm.length(), newValue)
- println("the alarm with id:$tmpID is changed to $newValue!")
- sendEvent([name: "alarm", value: newValue, deviceId: tmpID, descriptionText: "",
- displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
- }
- }
-
- // Methods to return values
- def getCurrentAlarm() {
- return currentAlarm.toString()
+ action("strobe", "alarm")
}
}
alarms = smartThings
// Initialization
- StringBuilder id = new StringBuilder("alarmID0")
- StringBuilder label = new StringBuilder("alarm")
- StringBuilder displayName = new StringBuilder("alarm0")
- StringBuilder alarm = new StringBuilder()
+ String id = "alarmID0"
+ String label = "alarm"
+ String displayName = "alarmSensor"
+ String alarm
if (init)
- alarm.append("off")
+ alarm = "off"
else
- alarm.append("on")
+ alarm = "on"
alarms.add(new Alarm(sendEvent, id, label, displayName, alarm))
}
def strobe() {
alarms[0].strobe()
}
-
- // Methods to return values
- def getCurrentAlarm() {
- List tmpValues = new ArrayList()
- tmpValues.add(alarms[0].getCurrentAlarm())
- return tmpValues
- }
}
package Battery
import SmartThing.SmartThings
-//Importing mutable integer class
-import MutableInteger.MutableInteger
-
public class Batteries extends SmartThings {
List batteries = new ArrayList()
Batteries(Closure sendEvent, boolean init) {
batteries = smartThings
- StringBuilder id = new StringBuilder("batteryID0")
- StringBuilder label = new StringBuilder("battery")
- StringBuilder displayName = new StringBuilder("battery0")
- MutableInteger battery = new MutableInteger()
-
// Initialization
+ String id = "batteryID0"
+ String label = "battery"
+ String displayName = "batteryDevice"
+ Integer battery
+
if (init)
- battery.setValue(50)
+ battery = 50
else
- battery.setValue(0)
+ battery = 0
batteries.add(new Battery(sendEvent, id, label, displayName, battery))
}
-
- // Methods to return values
- def getCurrentBattery() {
- List tmpValues = new ArrayList()
- tmpValues.add(batteries[0].getCurrentBattery())
- return tmpValues
- }
}
package Battery
import SmartThing.SmartThing
-//Importing mutable integer class
-import MutableInteger.MutableInteger
-
public class Battery 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 currentBattery = new MutableInteger()
+ String id
+ String label
+ String displayName
// Maps from features to values
- HashMap<String, MutableInteger> deviceIntValuesMap = new HashMap<String, MutableInteger>()
+ HashMap<String, Integer> deviceIntValuesMap = new HashMap<String, Integer>()
- Battery(Closure sendEvent, StringBuilder id, StringBuilder label, StringBuilder displayName, MutableInteger currentBattery) {
- deviceIntValuesMap = deviceIntValueSmartThing
+ Battery(Closure sendEvent, String id, String label, String displayName, Integer currentBattery) {
+ deviceIntValueSmartThing = deviceIntValuesMap
idSmartThing = id
labelSmartThing = label
displayNameSmartThing = displayName
this.id = id
this.label = label
this.displayName = displayName
- this.currentBattery = currentBattery
deviceIntValuesMap.put("battery", currentBattery)
}
-
- // Methods to return values
- def getCurrentBattery() {
- return currentBattery.toString()
- }
}
public class BeaconSensor extends SmartThing {
// id, label, and display name of the device
- StringBuilder id = new StringBuilder()
- StringBuilder label = new StringBuilder()
- StringBuilder displayName = new StringBuilder()
- // Features with string values
- StringBuilder currentPresence = new StringBuilder()
+ String id
+ String label
+ String displayName
// Maps from features to values
- HashMap<String, StringBuilder> deviceValuesMap = new HashMap<String, StringBuilder>()
+ HashMap<String, String> deviceValuesMap = new HashMap<String, String>()
- BeaconSensor(Closure sendEvent, StringBuilder id, StringBuilder label, StringBuilder displayName, StringBuilder currentPresence) {
- deviceValuesMap = deviceValueSmartThing
+ BeaconSensor(Closure sendEvent, String id, String label, String displayName, String currentPresence) {
+ deviceValueSmartThing = deviceValuesMap
idSmartThing = id
labelSmartThing = label
displayNameSmartThing = displayName
this.id = id
this.label = label
this.displayName = displayName
- this.currentPresence = currentPresence
- deviceValuesMap.put("beacon", currentPresence)
- }
-
- // Methods to return values
- def getCurrentPresence() {
- return currentPresence.toString()
+ deviceValuesMap.put("presence", currentPresence)
}
}
beaconSensors = smartThings
// Initialization
- StringBuilder id = new StringBuilder("beaconID0")
- StringBuilder label = new StringBuilder("beacon")
- StringBuilder displayName = new StringBuilder("beacon0")
- StringBuilder presence = new StringBuilder()
+ String id = "beaconID0"
+ String label = "beacon"
+ String displayName = "beaconSensor"
+ String presence
if (init)
- presence.append("not present")
+ presence = "not present"
else
- presence.append("present")
+ presence = "present"
beaconSensors.add(new BeaconSensor(sendEvent, id, label, displayName, presence))
}
-
- // Methods to return values
- def getCurrentPresence() {
- List tmpValues = new ArrayList()
- tmpValues.add(beaconSensors[0].getCurrentPresence())
- return tmpValues
- }
}
public class Button extends SmartThing {
// id, label, and display name of the device
- StringBuilder id = new StringBuilder()
- StringBuilder label = new StringBuilder()
- StringBuilder displayName = new StringBuilder()
+ String id
+ String label
+ String displayName
// Possible values for eventsSince method
- List<StringBuilder> possibleValues = new ArrayList<StringBuilder>();
+ List<String> possibleValues = new ArrayList<String>();
- Button(Closure sendEvent, StringBuilder id, StringBuilder label, StringBuilder displayName) {
+ Button(Closure sendEvent, String id, String label, String displayName) {
idSmartThing = id
labelSmartThing = label
displayNameSmartThing = displayName
buttons = smartThings
// Initialization
- StringBuilder id = new StringBuilder("buttonID0")
- StringBuilder label = new StringBuilder("button")
- StringBuilder displayName = new StringBuilder("button0")
+ String id = "buttonID0"
+ String label = "button"
+ String displayName = "buttonController"
buttons.add(new Button(sendEvent, id, label, displayName))
}
public class CarbonMonoxideDetector extends SmartThing {
// id, label, and display name of the device
- StringBuilder id = new StringBuilder()
- StringBuilder label = new StringBuilder()
- StringBuilder displayName = new StringBuilder()
- // Features with string values
- StringBuilder currentCarbonMonoxideValue = new StringBuilder()
+ String id
+ String label
+ String displayName
// Maps from features to values
- HashMap<String, StringBuilder> deviceValuesMap = new HashMap<String, StringBuilder>()
+ HashMap<String, String> deviceValuesMap = new HashMap<String, String>()
- CarbonMonoxideDetector(Closure sendEvent, StringBuilder id, StringBuilder label, StringBuilder displayName, StringBuilder currentCarbonMonoxideValue) {
- deviceValuesMap = deviceValueSmartThing
+ CarbonMonoxideDetector(Closure sendEvent, String id, String label, String displayName, String currentCarbonMonoxideValue) {
+ deviceValueSmartThing = deviceValuesMap
idSmartThing = id
labelSmartThing = label
displayNameSmartThing = displayName
this.id = id
this.label = label
this.displayName = displayName
- this.currentCarbonMonoxideValue = currentCarbonMonoxideValue
deviceValuesMap.put("carbonMonoxide", currentCarbonMonoxideValue)
}
-
- // Methods to return values
- def getCurrentCarbonMonoxideValue() {
- return currentCarbonMonoxideValue.toString()
- }
}
carbonMonoxideDetectors = smartThings
// Initialization
- StringBuilder id = new StringBuilder("carbonMonoxideID0")
- StringBuilder label = new StringBuilder("carbonMonoxide")
- StringBuilder displayName = new StringBuilder("carbonMonoxide0")
- StringBuilder carbonMonoxide = new StringBuilder()
+ String id = "carbonMonoxideID0"
+ String label = "carbonMonoxide"
+ String displayName = "carbonMonoxideDetector"
+ String carbonMonoxide
if (init)
- carbonMonoxide.append("clear")
+ carbonMonoxide = "clear"
else
- carbonMonoxide.append("detected")
+ carbonMonoxide = "detected"
carbonMonoxideDetectors.add(new CarbonMonoxideDetector(sendEvent, id, label, displayName, carbonMonoxide))
}
-
- // Methods to return values
- def getCurrentCarbonMonoxideValue() {
- List tmpValues = new ArrayList()
- tmpValues.add(carbonMonoxideDetectors[0].getCurrentCarbonMonoxideValue())
- return tmpValues
- }
}
package ColorControl
import SmartThing.SmartThing
-//Importing mutable integer class
-import MutableInteger.MutableInteger
-
public class ColorControl 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 currentHue = new MutableInteger()
- MutableInteger currentSaturation = new MutableInteger()
- // Features with string values
- StringBuilder currentColor = 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>()
- ColorControl(Closure sendEvent, StringBuilder id, StringBuilder label, StringBuilder displayName, StringBuilder currentColor, MutableInteger currentHue, MutableInteger currentSaturation) {
- deviceValuesMap = deviceValueSmartThing
- deviceIntValuesMap = deviceIntValueSmartThing
+ ColorControl(Closure sendEvent, String id, String label, String displayName, String currentColor, Integer currentHue, Integer currentSaturation) {
+ deviceValueSmartThing = deviceValuesMap
+ deviceIntValueSmartThing = deviceIntValuesMap
idSmartThing = id
labelSmartThing = label
displayNameSmartThing = displayName
this.id = id
this.label = label
this.displayName = displayName
- this.currentHue = currentHue
- this.currentSaturation = currentSaturation
- this.currentColor = currentColor
deviceValuesMap.put("color", currentColor)
deviceIntValuesMap.put("hue", currentHue)
// Methods to set values
def setColor(String newValue) {
- action(currentColor, newValue, "color")
+ action(newValue, "color")
}
def setHue(int newValue) {
- action(currentHue, newValue, "hue")
+ action(newValue, "hue")
}
def setHue(double newValue) {
}
def setSaturation(int newValue) {
- action(currentSaturation, newValue, "saturation")
+ action(newValue, "saturation")
}
def setSaturation(double newValue) {
setSaturation((int) newValue)
}
-
- 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 light with id:$id 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 of the light with id:$id is changed to $newValue!")
- sendEvent([name: feature, value: newValue, deviceId: tmpID, descriptionText: "",
- displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
- }
- }
-
- // Methods to return values
- def getCurrentHue() {
- return currentHue.getValue()
- }
-
- def getCurrentSaturation() {
- return currentSaturation.getValue()
- }
-
- def getCurrentColor() {
- return currentColor.toString()
- }
}
colorControls = smartThings
// Initialization
- StringBuilder id = new StringBuilder("colorControlID0")
- StringBuilder label = new StringBuilder("colorControl")
- StringBuilder displayName = new StringBuilder("colorControl0")
- StringBuilder color = new StringBuilder()
- MutableInteger hue = new MutableInteger()
- MutableInteger saturation = new MutableInteger()
+ String id = "colorControlID0"
+ String label = "colorControl"
+ String displayName = "light"
+ String color
+ Integer hue
+ Integer saturation
if (init) {
- color.append("Red")
- hue.setValue(30)
- saturation.setValue(40)
+ color = "Red"
+ hue = 30
+ saturation = 40
} else {
- color.append("Blue")
- hue.setValue(50)
- saturation.setValue(50)
+ color = "Blue"
+ hue = 50
+ saturation = 50
}
colorControls.add(new ColorControl(sendEvent, id, label, displayName, color, hue,
def off() {
colorControls[0].off()
}
-
- // Methods to return values
- def getCurrentHue() {
- List tmpValues = new ArrayList()
- tmpValues.add(colorControls[0].getCurrentHue())
- return tmpValues
- }
-
- def getCurrentSaturation() {
- List tmpValues = new ArrayList()
- tmpValues.add(colorControls[0].getCurrentSaturation())
- return tmpValues
- }
-
- def getCurrentColor() {
- List tmpValues = new ArrayList()
- tmpValues.add(colorControls[0].getCurrentColor())
- return tmpValues
- }
}
package ColorTemperature
import SmartThing.SmartThing
-//Importing mutable integer class
-import MutableInteger.MutableInteger
-
public class ColorTemperature 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 currentColorTemperature = new MutableInteger()
+ String id
+ String label
+ String displayName
// Maps from features to values
- HashMap<String, MutableInteger> deviceIntValuesMap = new HashMap<String, MutableInteger>()
+ HashMap<String, Integer> deviceIntValuesMap = new HashMap<String, Integer>()
- ColorTemperature(Closure sendEvent, StringBuilder id, StringBuilder label, StringBuilder displayName, MutableInteger colorTemperature) {
- deviceIntValuesMap = deviceIntValueSmartThing
+ ColorTemperature(Closure sendEvent, String id, String label, String displayName, Integer colorTemperature) {
+ deviceIntValueSmartThing = deviceIntValuesMap
idSmartThing = id
labelSmartThing = label
displayNameSmartThing = displayName
this.id = id
this.label = label
this.displayName = displayName
- this.currentColorTemperature = currentColorTemperature
deviceIntValuesMap.put("colorTemperature", currentColorTemperature)
}
// Methods to set values
def setColorTemperature(int newValue) {
- if (!currentColorTemperature.getValue().equals(newValue)) {
- String tmpID = id.toString()
- currentColorTemperature.setValue(newValue)
- println("The color temperature of the light with id $tmpID is changed to $newValue!")
- sendEvent([name: "colorTemperature", value: "$newValue", deviceId: tmpID, descriptionText: "",
- displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
- }
- }
-
- // Methods to return values
- def getCurrentColorTemperature() {
- return currentColorTemperature.getValue()
+ action(newValue, "colorTemperature")
}
}
package ColorTemperature
import SmartThing.SmartThings
-//Importing mutable integer class
-import MutableInteger.MutableInteger
-
public class ColorTemperatures extends SmartThings {
List colorTemperatues = new ArrayList()
colorTemperatues = smartThings
// Initialization
- StringBuilder id = new StringBuilder("colorTemperatureID0")
- StringBuilder label = new StringBuilder("colorTemperature")
- StringBuilder displayName = new StringBuilder("colorTemperature0")
- MutableInteger colorTemperatue = new MutableInteger()
+ String id = "colorTemperatureID0"
+ String label = "colorTemperature"
+ String displayName = "light"
+ Integer colorTemperatue
if (init)
colorTemperature = 10000
def setColorTemperature(int newValue) {
colorTemperatues[0].setColorTemperature(newValue)
}
-
- // Methods to return values
- def getCurrentColorTemperature() {
- List tmpValues = new ArrayList()
- tmpValues.add(colorTemperatues[0].getCurrentColorTemperature())
- return tmpValues
- }
}
public class ContactSensor extends SmartThing {
// id, label, and display name of the device
- StringBuilder id = new StringBuilder()
- StringBuilder label = new StringBuilder()
- StringBuilder displayName = new StringBuilder()
- // Features with string values
- StringBuilder currentContact = new StringBuilder()
+ String id
+ String label
+ String displayName
// Maps from features to values
- HashMap<String, StringBuilder> deviceValuesMap = new HashMap<String, StringBuilder>()
+ HashMap<String, String> deviceValuesMap = new HashMap<String, String>()
// Possible values for eventsSince method
- List<StringBuilder> possibleValues = new ArrayList<StringBuilder>();
+ List<String> possibleValues = new ArrayList<String>();
- ContactSensor(Closure sendEvent, StringBuilder id, StringBuilder label, StringBuilder displayName, StringBuilder currentContact) {
- deviceValuesMap = deviceValueSmartThing
+ ContactSensor(Closure sendEvent, String id, String label, String displayName, String currentContact) {
+ deviceValueSmartThing = deviceValuesMap
idSmartThing = id
labelSmartThing = label
displayNameSmartThing = displayName
this.id = id
this.label = label
this.displayName = displayName
- this.currentContact = currentContact
possibleValues.add("closed")
possibleValues.add("open")
deviceValuesMap.put("contact", currentContact)
}
-
- // Methods to return values
- def getCurrentContact() {
- return currentContact.toString()
- }
}
contacts = smartThings
// Initialization
- StringBuilder id = new StringBuilder("contactID0")
- StringBuilder label = new StringBuilder("contact")
- StringBuilder displayName = new StringBuilder("contact0")
- StringBuilder currentContact = new StringBuilder()
+ String id = "contactID0"
+ String label = "contact"
+ String displayName = "contactSensor"
+ String currentContact
if (init)
- currentContact.append("closed")
+ currentContact = "closed"
else
- currentContact.append("open")
+ currentContact = "open"
contacts.add(new ContactSensor(sendEvent, id, label, displayName, currentContact))
}
-
- // Methods to return values
- def getCurrentContact() {
- List tmpValues = new ArrayList()
- tmpValues.add(contacts[0].getCurrentContact())
- return tmpValues
- }
}
public class DoorControl extends SmartThing {
// id, label, and display name of the device
- StringBuilder id = new StringBuilder()
- StringBuilder label = new StringBuilder()
- StringBuilder displayName = new StringBuilder()
- // Features with string values
- StringBuilder currentDoorState = new StringBuilder()
+ String id
+ String label
+ String displayName
// Maps from features to values
- HashMap<String, StringBuilder> deviceValuesMap = new HashMap<String, StringBuilder>()
+ HashMap<String, String> deviceValuesMap = new HashMap<String, String>()
- DoorControl(Closure sendEvent, StringBuilder id, StringBuilder label, StringBuilder displayName, StringBuilder currentDoorState) {
- deviceValuesMap = deviceValueSmartThing
+ DoorControl(Closure sendEvent, String id, String label, String displayName, String currentDoor) {
+ deviceValueSmartThing = deviceValuesMap
idSmartThing = id
labelSmartThing = label
displayNameSmartThing = displayName
this.id = id
this.label = label
this.displayName = displayName
- this.currentDoorState = currentDoorState
- deviceValuesMap.put("status", currentDoorState)
+ deviceValuesMap.put("door", currentDoor)
}
// Methods to set values
def open() {
- action(currentDoorState, "open", "status")
+ action("open", "door")
}
def open(LinkedHashMap metaData) {
}
def close() {
- action(currentDoorState, "closed", "status")
+ action("closed", "door")
}
def close(LinkedHashMap metaData) {
close()
}
-
- 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 door with id:$tmpID is changed to $newValue!")
- sendEvent([name: feature, value: newValue, deviceId: tmpID, descriptionText: "",
- displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
- }
- }
-
- // Methods to return values
- def getCurrentDoorState() {
- return currentDoorState.toString()
- }
}
doorControls = smartThings
// Initialization
- StringBuilder id = new StringBuilder("doorControlID0")
- StringBuilder label = new StringBuilder("doorControl")
- StringBuilder displayName = new StringBuilder("doorControl0")
- StringBuilder doorState = new StringBuilder()
+ String id = "doorControlID0"
+ String label = "doorControl"
+ String displayName = "doorController"
+ String door
if (init)
- doorState.append("open")
+ door = "open"
else
- doorState.append("closed")
+ door = "closed"
- doorControls.add(new DoorControl(sendEvent, id, label, displayName, doorState))
+ doorControls.add(new DoorControl(sendEvent, id, label, displayName, door))
}
// Methods to set values
def close(LinkedHashMap metaData) {
close()
}
-
- // Methods to return values
- def getCurrentDoorState() {
- List tmpValues = new ArrayList()
- tmpValues.add(doorControls[0].getCurrentDoorState())
- return tmpValues
- }
}
package EnergyMeter
import SmartThing.SmartThing
-//Importing mutable integer class
-import MutableInteger.MutableInteger
-
public class EnergyMeter 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 currentEnergy = new MutableInteger()
+ String id
+ String label
+ String displayName
// Maps from features to values
- HashMap<String, MutableInteger> deviceIntValuesMap = new HashMap<String, MutableInteger>()
+ HashMap<String, Integer> deviceIntValuesMap = new HashMap<String, Integer>()
- EnergyMeter(Closure sendEvent, StringBuilder id, StringBuilder label, StringBuilder displayName, MutableInteger currentEnergy) {
- deviceIntValuesMap = deviceIntValueSmartThing
+ EnergyMeter(Closure sendEvent, String id, String label, String displayName, Integer currentEnergy) {
+ deviceIntValueSmartThing = deviceIntValuesMap
idSmartThing = id
labelSmartThing = label
displayNameSmartThing = displayName
this.id = id
this.label = label
this.displayName = displayName
- this.currentEnergy = currentEnergy
deviceIntValuesMap.put("energy", currentEnergy)
}
-
- // Methods to return values
- def getCurrentEnergy() {
- return currentEnergy.getValue()
- }
}
package EnergyMeter
import SmartThing.SmartThings
-//Importing mutable integer class
-import MutableInteger.MutableInteger
-
public class EnergyMeters extends SmartThings {
List energyMeters = new ArrayList()
energyMeters = smartThings
// Initialization
- StringBuilder id = new StringBuilder("energyID0")
- StringBuilder label = new StringBuilder("energy")
- StringBuilder displayName = new StringBuilder("energy0")
- MutableInteger energy = new MutableInteger()
+ String id = "energyID0"
+ String label = "energy"
+ String displayName = "energyMeter"
+ Integer energy
if (init)
- energy.setValue(50)
+ energy = 50
else
- energy.setValue(60)
+ energy = 60
energyMeters.add(new EnergyMeter(sendEvent, id, label, displayName, energy))
}
-
- // Methods to return values
- def getCurrentEnergy() {
- List tmpValues = new ArrayList()
- tmpValues.add(energyMeters[0].getCurrentEnergy())
- return tmpValues
- }
}
package IlluminanceMeasurement
import SmartThing.SmartThing
-//Importing mutable integer class
-import MutableInteger.MutableInteger
-
public class IlluminanceMeasurement 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 currentIlluminance = new MutableInteger()
+ String id
+ String label
+ String displayName
// Maps from features to values
- HashMap<String, MutableInteger> deviceIntValuesMap = new HashMap<String, MutableInteger>()
+ HashMap<String, Integer> deviceIntValuesMap = new HashMap<String, Integer>()
- IlluminanceMeasurement(Closure sendEvent, StringBuilder id, StringBuilder label, StringBuilder displayName, MutableInteger currentIlluminance) {
- deviceIntValuesMap = deviceIntValueSmartThing
+ IlluminanceMeasurement(Closure sendEvent, String id, String label, String displayName, Integer currentIlluminance) {
+ deviceIntValueSmartThing = deviceIntValuesMap
idSmartThing = id
labelSmartThing = label
displayNameSmartThing = displayName
this.id = id
this.label = label
this.displayName = displayName
- this.currentIlluminance = currentIlluminance
deviceIntValuesMap.put("illuminance", currentIlluminance)
}
-
- // Methods to return values
- def getCurrentIlluminance() {
- return currentIlluminance.getValue()
- }
}
package IlluminanceMeasurement
import SmartThing.SmartThings
-//Importing mutable integer class
-import MutableInteger.MutableInteger
-
public class IlluminanceMeasurements extends SmartThings {
List illuminanceMeasurements = new ArrayList()
IlluminanceMeasurements(Closure sendEvent, boolean init) {
- // Only initialize one time since we only have one device for each capability
illuminanceMeasurements = smartThings
// Initialization
- StringBuilder id = new StringBuilder("illuminanceID0")
- StringBuilder label = new StringBuilder("illuminance")
- StringBuilder displayName = new StringBuilder("illuminance0")
- MutableInteger illuminance = new MutableInteger()
+ String id = "illuminanceID0"
+ String label = "illuminance"
+ String displayName = "illuminanceSensor"
+ Integer illuminance
if (init)
- illuminance.setValue(20000)
+ illuminance = 20000
else
- illuminance.setValue(5)
+ illuminance = 5
illuminanceMeasurements.add(new IlluminanceMeasurement(sendEvent, id, label, displayName, illuminance))
}
-
- // Methods to return values
- def getCurrentIlluminance() {
- List tmpValues = new ArrayList()
- tmpValues.add(illuminanceMeasurements[0].getCurrentIlluminance())
- return tmpValues
- }
}
public class ImageCapture extends SmartThing {
// id, label, and display name of the device
- StringBuilder id = new StringBuilder()
- StringBuilder label = new StringBuilder()
- StringBuilder displayName = new StringBuilder()
- // Features with string values
- StringBuilder currentImage = new StringBuilder()
+ String id
+ String label
+ String displayName
// Maps from features to values
- HashMap<String, StringBuilder> deviceValuesMap = new HashMap<String, StringBuilder>()
+ HashMap<String, String> deviceValuesMap = new HashMap<String, String>()
- ImageCapture(Closure sendEvent, StringBuilder id, StringBuilder label, StringBuilder displayName, StringBuilder currentImage) {
- deviceValuesMap = deviceValueSmartThing
+ ImageCapture(Closure sendEvent, String id, String label, String displayName, String currentImage) {
+ deviceValueSmartThing = deviceValuesMap
idSmartThing = id
labelSmartThing = label
displayNameSmartThing = displayName
this.id = id
this.label = label
this.displayName = displayName
- this.currentImage = currentImage
deviceValuesMap.put("image", currentImage)
}
def take() {
- String tmpID = id.toString()
- println("The camera with id:$tmpID is taken a picture!")
+ println("The camera with id:$id is taken a picture!")
}
def take(LinkedHashMap metaData) {
take()
}
-
- // Methods to return values
- def getCurrentImage() {
- return currentImage.toString()
- }
}
imageCaptureSensors = smartThings
// Initialization
- StringBuilder id = new StringBuilder("imageCaptureID0")
- StringBuilder label = new StringBuilder("imageCapture")
- StringBuilder displayName = new StringBuilder("imageCapture0")
- StringBuilder image = new StringBuilder("image0")
+ String id = "imageCaptureID0"
+ String label = "imageCapture"
+ String displayName = "imageCapturer"
+ String image = "image0"
imageCaptureSensors.add(new ImageCapture(sendEvent, id, label, displayName, image))
}
def take(LinkedHashMap metaData) {
take()
}
-
- // Methods to return values
- def getCurrentImage() {
- List tmpValues = new ArrayList()
- tmpValues.add(imageCaptureSensors[0].getCurrentImage())
- return tmpValues
- }
}
package Location
import SmartThing.SmartThing
-//Importing mutable integer class
-import MutableInteger.MutableInteger
-
public class LocationVar extends SmartThing {
- // Features with numberical values
- MutableInteger contactBookEnabled = new MutableInteger()
- // Features with string values
- StringBuilder mode = new StringBuilder()
- StringBuilder locationMode = mode
- StringBuilder name = new StringBuilder()
- StringBuilder temperatureScale = new StringBuilder()
+ // id, label, and display name of the device
+ String id
+ String label
+ String displayName
// Maps from features to values
- HashMap<String, StringBuilder> deviceValuesMap = new HashMap<String, StringBuilder>()
+ HashMap<String, String> deviceValuesMap = new HashMap<String, String>()
+ HashMap<String, Integer> deviceIntValuesMap = new HashMap<String, Integer>()
// Other variables
Phrase helloHome
TimeZone timeZone
List phoneNumbers
LocationVar(Closure sendEvent, boolean init) {
- deviceValuesMap = deviceValueSmartThing
+ deviceValueSmartThing = deviceValuesMap
+ deviceIntValueSmartThing = deviceIntValuesMap
+ idSmartThing = id
+ labelSmartThing = label
+ displayNameSmartThing = displayName
sendEventSmartThings = sendEvent
// Initialization
- StringBuilder sunset = new StringBuilder("sunset")
- StringBuilder sunsetTime = sunset
- StringBuilder sunrise = new StringBuilder("sunrise")
- StringBuilder sunriseTime = sunrise
- hubs = [[id:0, localIP:"128.195.204.105"]]
- modes = [[name: "home"],[name: "away"],[name: "night"]]
helloHome = new Phrase()
- contactBookEnabled.setValue(1)
contacts = ['AJ']
phoneNumbers = [9495379373]
- name.append("hub0")
- temperatureScale.append("F")
+ modes = [[name: "home"],[name: "away"],[name: "night"]]
timeZone = TimeZone.getTimeZone("America/New_York")
-
+ hubs = [[id:0, localIP:"128.195.204.105"]]
if (init)
mode.append("away")
mode.append("home")
deviceValuesMap.put("mode", mode)
- deviceValuesMap.put("Location", mode)
+ deviceValuesMap.put("name", "hub0")
+ deviceValuesMap.put("temperatureScale", "F")
+ deviceValuesMap.put("sunset", "sunset")
+ deviceValuesMap.put("sunrise", "sunrise")
+ deviceValuesMap.put("sunsetTime", "sunsetTime")
+ deviceValuesMap.put("sunriseTime", "sunriseTime")
+ deviceIntValuesMap.put("contactBookEnabled", 1)
}
-
- // Methods to return values
- def getMode() {
- return mode.toString()
- }
-
- def getLocationMode() {
- return locationMode.toString()
- }
-
- def getName() {
- return name.toString()
- }
-
- def getTemperatureScale() {
- return temperatureScale.toString()
- }
-
- def getContactBookEnabled() {
- return contactBookEnabled.getValue()
- }
}
public class Lock extends SmartThing {
// id, label, and display name of the device
- StringBuilder id = new StringBuilder()
- StringBuilder label = new StringBuilder()
- StringBuilder displayName = new StringBuilder()
- // Features with string values
- StringBuilder currentLock = new StringBuilder()
+ String id
+ String label
+ String displayName
// Maps from features to values
- HashMap<String, StringBuilder> deviceValuesMap = new HashMap<String, StringBuilder>()
+ HashMap<String, String> deviceValuesMap = new HashMap<String, String>()
-
- Lock(Closure sendEvent, StringBuilder id, StringBuilder label, StringBuilder displayName, StringBuilder currentLock) {
- deviceValuesMap = deviceValueSmartThing
+ Lock(Closure sendEvent, String id, String label, String displayName, String currentLock) {
+ deviceValueSmartThing = deviceValuesMap
idSmartThing = id
labelSmartThing = label
displayNameSmartThing = displayName
this.id = id
this.label = label
this.displayName = displayName
- this.currentLock = currentLock
deviceValuesMap.put("lock", currentLock)
}
// Methods to set values
def lock() {
- action(currentLock, "locked")
+ action("locked", "lock")
}
def lock(LinkedHashMap metaData) {
}
def unlock() {
- action(currentLock, "unlocked")
+ action("unlocked", "lock")
}
def unlock(LinkedHashMap metaData) {
unlock()
}
-
- def action(StringBuilder variable, String newValue) {
- if (!variable.toString().equals(newValue)) {
- String tmpID = id.toString()
- variable.replace(0, variable.length(), newValue)
- println("Lock with id:$tmpID is changed to $newValue!")
- sendEvent([name: "lock", value: newValue, deviceId: tmpID, descriptionText: "",
- displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
- }
- }
-
- // Methods to return values
- def getCurrentLock() {
- return currentLock.toString()
- }
-
}
locks = smartThings
// Initialization
- StringBuilder id = new StringBuilder("lockID0")
- StringBuilder label = new StringBuilder("lock")
- StringBuilder displayName = new StringBuilder("lock0")
- StringBuilder lock = new StringBuilder()
+ String id = "lockID0"
+ String label = "lock"
+ String displayName = "lock"
+ String lock
if (init)
- lock.append("locked")
+ lock = "locked"
else
- lock.append("unlocked")
+ lock = "unlocked"
- locks.add(new Lock(sendEvent,id, label, displayName, lock))
+ locks.add(new Lock(sendEvent, id, label, displayName, lock))
}
// Methods to set values
def unlock(LinkedHashMap metaData) {
unlock()
}
-
- // Methods to return values
- def getCurrentLock() {
- List tmpValues = new ArrayList()
- tmpValues.add(locks[0].getCurrentLock())
- return tmpValues
- }
}
/////////////////////////////////////////////////////////////////////
def setLocationMode(String mode) {
log.debug "DEBUG: setLocationMode is called. Current mode is: ${location_mode} and new mode is: ${mode}"
- location.setValue([name: "Location", value: "$mode", deviceId: "locationID0", descriptionText: "",
- displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
location.setValue([name: "mode", value: "$mode", deviceId: "locationID0", descriptionText: "",
displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
location_mode = mode
functionList.add(FunctionToCall)
} else if (obj == location) {
objectList.add(obj)
- eventList.add("Location")
+ eventList.add("mode")
valueList.add("")
functionList.add(FunctionToCall)
}
def subscribe(Object obj, String event, Closure FunctionToCall) {
if (event == "tamper.tampered") {
event = "contact" //This really should be its own name
- } else if ((event == "mode")||(event == "mode.away")||(event == "mode.home")||(event == "mode.night")) {
- //This really should be fixed also...
- event = "Location"
- } else if (event == "unlocked") {
- return
}
int dot = event.indexOf('.')
def subscribe(Object obj, String event, String FunctionToCall) {
if (event == "tamper.tampered") {
event = "contact" //This really should be its own name
- } else if ((event == "mode")||(event == "mode.away")||(event == "mode.home")||(event == "mode.night")) {
- event = "Location"
- } else if (event == "unlocked") {
- return
}
int dot = event.indexOf('.')
public class MobilePresence extends SmartThing {
// id, label, and display name of the device
- StringBuilder id = new StringBuilder()
- StringBuilder label = new StringBuilder()
- StringBuilder displayName = new StringBuilder()
- // Features with string values
- StringBuilder deviceNetworkId = new StringBuilder()
+ String id
+ String label
+ String displayName
// Maps from features to values
- HashMap<String, StringBuilder> deviceValuesMap = new HashMap<String, StringBuilder>()
+ HashMap<String, String> deviceValuesMap = new HashMap<String, String>()
-
- MobilePresence(Closure sendEvent, StringBuilder id, StringBuilder label, StringBuilder displayName, StringBuilder deviceNetworkId) {
+ MobilePresence(Closure sendEvent, String id, String label, String displayName, String deviceNetworkId) {
deviceValuesMap = deviceValueSmartThing
idSmartThing = id
labelSmartThing = label
this.id = id
this.label = label
this.displayName = displayName
- this.deviceNetworkId = deviceNetworkId
deviceValuesMap.put("deviceNetworkId", deviceNetworkId)
}
-
- // Methods to return values
- def getDeviceNetworkId() {
- return deviceNetworkId.toString()
- }
}
mobilePresences = smartThings
// Initialization
- StringBuilder id = new StringBuilder("mobileDeviceID0")
- StringBuilder label = new StringBuilder("mobileDevice")
- StringBuilder displayName = new StringBuilder("mobileDevice0")
- StringBuilder deviceNetworkId = new StringBuilder("mobile0")
+ String id = "mobileDeviceID0"
+ String label = "mobileDevice"
+ String displayName = "mobileDevice"
+ String deviceNetworkId
mobilePresences.add(new MobilePresence(sendEvent, id, label, displayName, deviceNetworkId))
}
-
- // Methods to return values
- def getDeviceNetworkId() {
- List tmpValues = new ArrayList()
- tmpValues.add(mobilePresences[0].getDeviceNetworkId())
- return tmpValues
- }
}
momentaries = smartThings
// Initialization
- StringBuilder id = new StringBuilder("momentaryID0")
- StringBuilder label = new StringBuilder("momentary")
- StringBuilder displayName = new StringBuilder("momentary0")
+ String id = "momentaryID0"
+ String label = "momentary"
+ String displayName = "momentaryDevice"
momentaries.add(new Momentary(sendEvent, id, label, displayName))
}
public class Momentary extends SmartThing {
// id, label, and display name of the device
- StringBuilder id = new StringBuilder()
- StringBuilder label = new StringBuilder()
- StringBuilder displayName = new StringBuilder()
+ String id
+ String label
+ String displayName
- Momentary(Closure sendEvent, StringBuilder id, StringBuilder label, StringBuilder displayName) {
+ Momentary(Closure sendEvent, String id, String label, String displayName) {
idSmartThing = id
labelSmartThing = label
displayNameSmartThing = displayName
// Methods to set values
def push() {
- println("the momentary switch with id:$id is pushed!")
- sendEvent([name: "momentary", value: "pushed", deviceId: id, descriptionText: "",
- displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
+ setValue([name: "momentary", value: "pushed", deviceId: id, descriptionText: "",
+ displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
}
}
public class MotionSensor extends SmartThing {
// id, label, and display name of the device
- StringBuilder id = new StringBuilder()
- StringBuilder label = new StringBuilder()
- StringBuilder displayName = new StringBuilder()
- // Features with string values
- StringBuilder currentMotion = new StringBuilder()
+ String id
+ String label
+ String displayName
// Maps from features to values
- HashMap<String, StringBuilder> deviceValuesMap = new HashMap<String, StringBuilder>()
+ HashMap<String, String> deviceValuesMap = new HashMap<String, String>()
// Possible values for eventsSince method
- List<StringBuilder> possibleValues = new ArrayList<StringBuilder>();
+ List<String> possibleValues = new ArrayList<String>();
- MotionSensor(Closure sendEvent, StringBuilder id, StringBuilder label, StringBuilder displayName, StringBuilder currentMotion) {
- deviceValuesMap = deviceValueSmartThing
+ MotionSensor(Closure sendEvent, String id, String label, String displayName, String currentMotion) {
+ deviceValueSmartThing = deviceValuesMap
idSmartThing = id
labelSmartThing = label
displayNameSmartThing = displayName
this.id = id
this.label = label
this.displayName = displayName
- this.currentMotion = currentMotion
possibleValues.add("active")
possibleValues.add("inactive")
deviceValuesMap.put("motion", currentMotion)
}
-
- // Methods to return values
- def getCurrentMotion() {
- return currentMotion.toString()
- }
}
motionSensors = smartThings
// Initialization
- StringBuilder id = new StringBuilder("motionSensorID0")
- StringBuilder label = new StringBuilder("motion")
- StringBuilder displayName = new StringBuilder("motionSensor0")
- StringBuilder motion = new StringBuilder()
+ String id = "motionSensorID0"
+ String label = "motion"
+ String displayName = "motionSensor"
+ String motion
if (init)
- motion.append("inactive")
+ motion = "inactive"
else
- motion.append("active")
+ motion = "active"
motionSensors.add(new MotionSensor(sendEvent, id, label, displayName, motion))
}
-
- // Methods to return values
- def getCurrentMotion() {
- List tmpValues = new ArrayList()
- tmpValues.add(motionSensors[0].getCurrentMotion())
- return tmpValues
- }
}
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()
- }
}
package MusicPlayer
import SmartThing.SmartThings
-//Importing mutable integer class
-import MutableInteger.MutableInteger
-
public class MusicPlayers extends SmartThings {
List musicPlayers = new ArrayList()
musicPlayers = smartThings
// Initialization
- StringBuilder id = new StringBuilder("musicPlayerID0")
- StringBuilder label = new StringBuilder("status")
- StringBuilder displayName = new StringBuilder("musicPlayer0")
- StringBuilder mute = new StringBuilder()
- StringBuilder status = new StringBuilder()
- StringBuilder trackData = new StringBuilder()
- StringBuilder trackDescription = new StringBuilder()
- MutableInteger level = new MutableInteger()
+ String id = "musicPlayerID0"
+ String label = "status"
+ String displayName = "musicPlayer"
+ String mute
+ String status
+ String trackData
+ String trackDescription
+ Integer level
if (init) {
- level.setValue(20)
- mute.append("unmuted")
- status.append("paused")
- trackData.append("someTrack")
- trackDescription.append("someDescriptions")
+ level = 20
+ mute = "unmuted"
+ status = "paused"
+ trackData = "someTrack"
+ trackDescription = "someDescriptions"
} else {
- level.setValue(30)
- mute.append("muted")
- status.append("play")
- trackData.append("someTrack")
- trackDescription.append("someDescriptions")
+ level = 30
+ mute = "muted"
+ status = "play"
+ trackData = "someTrack"
+ trackDescription = "someDescriptions"
}
musicPlayers.add(new MusicPlayer(sendEvent, id, label, displayName, level, mute, status, trackData, trackDescription))
def stop() {
musicPlayers[0].stop()
}
-
- // Methods to return values
- def getCurrentLevel() {
- List tmpValues = new ArrayList()
- tmpValues.add(musicPlayers[0].getCurrentLevel())
- return tmpValues
- }
-
- def getCurrentMute() {
- List tmpValues = new ArrayList()
- tmpValues.add(musicPlayers[0].getCurrentMute())
- return tmpValues
- }
-
- def getCurrentStatus() {
- List tmpValues = new ArrayList()
- tmpValues.add(musicPlayers[0].getCurrentStatus())
- return tmpValues
- }
-
- def getCurrentTrackData() {
- List tmpValues = new ArrayList()
- tmpValues.add(musicPlayers[0].getCurrentTrackData())
- return tmpValues
- }
-
- def getCurrentTrackDescription() {
- List tmpValues = new ArrayList()
- tmpValues.add(musicPlayers[0].getCurrentTrackDescription())
- return tmpValues
- }
}
+++ /dev/null
-// Create a class for mutable integer
-package MutableInteger
-
-public class MutableInteger {
- private int value;
-
- public int getValue() {
- return value;
- }
-
- public void setValue(int value) {
- this.value = value;
- }
-}
public class NfcTouch extends SmartThing {
// id, label, and display name of the device
- StringBuilder id = new StringBuilder()
- StringBuilder label = new StringBuilder()
- StringBuilder displayName = new StringBuilder()
+ String id
+ String label
+ String displayName
NfcTouch(Closure sendEvent) {
idSmartThing = id
sendEventSmartThings = sendEvent
// Initialization
- id.append("nfcSensorID0")
- label.append("nfcSensor")
- displayName.append("nfcSensor0")
+ id = "nfcSensorID0"
+ label = "nfcSensor"
+ displayName = "nfcSensor"
}
}
package PowerMeter
import SmartThing.SmartThing
-//Importing mutable integer class
-import MutableInteger.MutableInteger
-
public class PowerMeter 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 currentPower = new MutableInteger()
+ String id
+ String label
+ String displayName
// Maps from features to values
- HashMap<String, MutableInteger> deviceIntValuesMap = new HashMap<String, MutableInteger>()
+ HashMap<String, Integer> deviceIntValuesMap = new HashMap<String, Integer>()
- PowerMeter(Closure sendEvent, StringBuilder id, StringBuilder label, StringBuilder displayName, MutableInteger currentPower) {
- deviceIntValuesMap = deviceIntValueSmartThing
+ PowerMeter(Closure sendEvent, String id, String label, String displayName, Integer currentPower) {
+ deviceIntValueSmartThing = deviceIntValuesMap
idSmartThing = id
labelSmartThing = label
displayNameSmartThing = displayName
this.id = id
this.label = label
this.displayName = displayName
- this.currentPower = currentPower
deviceIntValuesMap.put("power", currentPower)
}
-
- // Methods to return values
- def getCurrentPower() {
- return currentPower.getValue()
- }
}
package PowerMeter
import SmartThing.SmartThings
-//Importing mutable integer class
-import MutableInteger.MutableInteger
-
public class PowerMeters extends SmartThings {
List powerMeters = new ArrayList()
powerMeters = smartThings
// Initialization
- StringBuilder id = new StringBuilder("powerMeterID0")
- StringBuilder label = new StringBuilder("powerMeter")
- StringBuilder displayName = new StringBuilder("powerMeter0")
- MutableInteger power = new MutableInteger()
+ String id = "powerMeterID0"
+ String label = "powerMeter"
+ String displayName = "powerMeter"
+ Integer power
if (init)
- power.setValue(50)
+ power = 50
else
- power.setValue(60)
+ power = 60
powerMeters.add(new PowerMeter(sendEvent, id, label, displayName, power))
}
-
- // Methods to return values
- def getCurrentPower() {
- List tmpValues = new ArrayList()
- tmpValues.add(powerMeters[0].getCurrentPower())
- return tmpValues
- }
}
public class PresenceSensor extends SmartThing {
// id, label, and display name of the device
- StringBuilder id = new StringBuilder()
- StringBuilder label = new StringBuilder()
- StringBuilder displayName = new StringBuilder()
- // Features with string values
- StringBuilder currentPresence = new StringBuilder()
+ String id
+ String label
+ String displayName
// Maps from features to values
- HashMap<String, StringBuilder> deviceValuesMap = new HashMap<String, StringBuilder>()
+ HashMap<String, String> deviceValuesMap = new HashMap<String, String>()
// Possible values for eventsSince method
- List<StringBuilder> possibleValues = new ArrayList<StringBuilder>();
+ List<String> possibleValues = new ArrayList<String>();
- PresenceSensor(Closure sendEvent, StringBuilder id, StringBuilder label, StringBuilder displayName, StringBuilder currentPresence) {
+ PresenceSensor(Closure sendEvent, String id, String label, String displayName, String currentPresence) {
deviceValuesMap = deviceValueSmartThing
idSmartThing = id
labelSmartThing = label
this.id = id
this.label = label
this.displayName = displayName
- this.currentPresence = currentPresence
possibleValues.add("present")
possibleValues.add("not present")
deviceValuesMap.put("presence", currentPresence)
}
-
- // Methods to return values
- def getCurrentPresence() {
- return currentPresence.toString()
- }
}
presenceSensors = smartThings
// Initialization
- StringBuilder id = new StringBuilder("presenceSensorID0")
- StringBuilder label = new StringBuilder("presence")
- StringBuilder displayName = new StringBuilder("presenceSensor0")
- StringBuilder presence = new StringBuilder()
+ String id = "presenceSensorID0"
+ String label = "presence"
+ String displayName = "presenceSensor"
+ String presence
if (init)
- presence.append("not present")
+ presence = "not present"
else
- presence.append("present")
+ presence = "present"
presenceSensors.add(new PresenceSensor(sendEvent, id, label, displayName, presence))
}
-
- // Methods to return values
- def getCurrentPresence() {
- List tmpValues = new ArrayList()
- tmpValues.add(presenceSensors[0].getCurrentPresence())
- return tmpValues
- }
}
package RelativeHumidityMeasurement
import SmartThing.SmartThing
-//Importing mutable integer class
-import MutableInteger.MutableInteger
-
public class RelativeHumidityMeasurement 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 currentHumidity = new MutableInteger()
+ String id
+ String label
+ String displayName
// Maps from features to values
- HashMap<String, MutableInteger> deviceIntValuesMap = new HashMap<String, MutableInteger>()
+ HashMap<String, Integer> deviceIntValuesMap = new HashMap<String, Integer>()
- RelativeHumidityMeasurement(Closure sendEvent, StringBuilder id, StringBuilder label, StringBuilder displayName, MutableInteger currentHumidity) {
- deviceIntValuesMap = deviceIntValueSmartThing
+ RelativeHumidityMeasurement(Closure sendEvent, String id, String label, String displayName, Integer currentHumidity) {
+ deviceIntValueSmartThing = deviceIntValuesMap
idSmartThing = id
labelSmartThing = label
displayNameSmartThing = displayName
this.id = id
this.label = label
this.displayName = displayName
- this.currentHumidity = currentHumidity
deviceIntValuesMap.put("humidity", currentHumidity)
}
-
- // Methods to return values
- def getCurrentHumidity() {
- return currentHumidity.getValue()
- }
}
package RelativeHumidityMeasurement
import SmartThing.SmartThings
-//Importing mutable integer class
-import MutableInteger.MutableInteger
-
public class RelativeHumidityMeasurements extends SmartThings {
List humidityMeasurements = new ArrayList()
humidityMeasurements = smartThings
// Initialization
- StringBuilder id = new StringBuilder("humidityID0")
- StringBuilder label = new StringBuilder("humidity")
- StringBuilder displayName = new StringBuilder("humidity0")
- MutableInteger humidity = new MutableInteger()
+ String id = "humidityID0"
+ String label = "humidity"
+ String displayName = "humiditySensor"
+ Integer humidity
if (init)
- humidity.setValue(50)
+ humidity = 50
else
- humidity.setValue(60)
+ humidity = 60
humidityMeasurements.add(new RelativeHumidityMeasurement(sendEvent, id, label, displayName, humidity))
}
-
- // Methods to return values
- def getCurrentHumidity() {
- List tmpValues = new ArrayList()
- tmpValues.add(humidityMeasurements[0].getCurrentHumidity())
- return tmpValues
- }
}
public class RelaySwitch extends SmartThing {
// id, label, and display name of the device
- StringBuilder id = new StringBuilder()
- StringBuilder label = new StringBuilder()
- StringBuilder displayName = new StringBuilder()
- // Features with string values
- StringBuilder currentSwitch = new StringBuilder()
+ String id
+ String label
+ String displayName
// Maps from features to values
- HashMap<String, StringBuilder> deviceValuesMap = new HashMap<String, StringBuilder>()
+ HashMap<String, String> deviceValuesMap = new HashMap<String, String>()
- RelaySwitch(Closure sendEvent, StringBuilder id, StringBuilder label, StringBuilder displayName, StringBuilder currentSwitch) {
- deviceValuesMap = deviceValueSmartThing
+ RelaySwitch(Closure sendEvent, String id, String label, String displayName, String currentSwitch) {
+ deviceValueSmartThing = deviceValuesMap
idSmartThing = id
labelSmartThing = label
displayNameSmartThing = displayName
this.id = id
this.label = label
this.displayName = displayName
- this.currentSwitch = currentSwitch
deviceValuesMap.put("switch", currentSwitch)
}
// Methods to set values
def on() {
- action(currentSwitch, "on", "switch")
+ action("on", "switch")
}
def on(LinkedHashMap metaData) {
}
def off() {
- action(currentSwitch, "off", "switch")
+ action("off", "switch")
}
def off(LinkedHashMap metaData) {
off()
}
-
- 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 relay switch with id:$tmpID is changed to $newValue!")
- sendEvent([name: feature, value: newValue, deviceId: tmpID, descriptionText: "",
- displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
- }
- }
-
- // Methods to return values
- def getCurrentSwitch() {
- return currentSwitch.toString()
- }
}
relaySwitches = smartThings
// Initialization
- StringBuilder id = new StringBuilder("relaySwitchID0")
- StringBuilder label = new StringBuilder("relaySwitch")
- StringBuilder displayName = new StringBuilder("relaySwitch0")
- StringBuilder currentSwitch = new StringBuilder()
+ String id = "relaySwitchID0"
+ String label = "switch"
+ String displayName = "relaySwitch"
+ String currentSwitch
if (init)
- currentSwitch.append("off")
+ currentSwitch = "off"
else
- currentSwitch.append("on")
+ currentSwitch = "on"
relaySwitches.add(new RelaySwitch(sendEvent, id, label, displayName, currentSwitch))
}
def off(LinkedHashMap metaData) {
off()
}
-
- // Methods to return values
- def getCurrentSwitch() {
- List tmpValues = new ArrayList()
- tmpValues.add(relaySwitches[0].getCurrentSwitch())
- return tmpValues
- }
}
public class SleepSensor extends SmartThing {
// id, label, and display name of the device
- StringBuilder id = new StringBuilder()
- StringBuilder label = new StringBuilder()
- StringBuilder displayName = new StringBuilder()
- // Features with string values
- StringBuilder currentSleeping = new StringBuilder()
+ String id
+ String label
+ String displayName
// Maps from features to values
- HashMap<String, StringBuilder> deviceValuesMap = new HashMap<String, StringBuilder>()
+ HashMap<String, String> deviceValuesMap = new HashMap<String, String>()
- SleepSensor(Closure sendEvent, StringBuilder id, StringBuilder label, StringBuilder displayName, StringBuilder currentSleeping) {
- deviceValuesMap = deviceValueSmartThing
+ SleepSensor(Closure sendEvent, String id, String label, String displayName, String currentSleeping) {
+ deviceValueSmartThing = deviceValuesMap
idSmartThing = id
labelSmartThing = label
displayNameSmartThing = displayName
this.id = id
this.label = label
this.displayName = displayName
- this.currentSleeping = currentSleeping
deviceValuesMap.put("sleeping", currentSleeping)
}
-
- // Methods to return values
- def getCurrentSleeping() {
- return currentSleeping.toString()
- }
}
sleepSensors = smartThings
// Initialization
- StringBuilder id = new StringBuilder("sleepSensorID0")
- StringBuilder label = new StringBuilder("sleepSensor")
- StringBuilder displayName = new StringBuilder("sleepSensor0")
- StringBuilder sleeping = new StringBuilder()
+ String id = "sleepSensorID0"
+ String label = "sleeping"
+ String displayName = "sleepSensor"
+ String sleeping
if (init)
- sleeping.append("sleeping")
+ sleeping = "sleeping"
else
- sleeping.append("not sleeping")
+ sleeping = "not sleeping"
sleepSensors.add(new SleepSensor(sendEvent, id, label, displayName, sleeping))
}
-
- // Methods to return values
- def getCurrentSleeping() {
- List tmpValues = new ArrayList()
- tmpValues.add(sleepSensors[0].getCurrentSleeping())
- return tmpValues
- }
}
//JPF's Verify API
import gov.nasa.jpf.vm.Verify
-//Importing mutable integer class
-import MutableInteger.MutableInteger
-
-public class SmartThing {
- List nonStoredDevices = ["aeonKeyFob", "appTouch", "button", "momentary", "nfcTouch"] // Devices with no stored value
- List locationTimeFeatures = ["sunset", "sunrise", "sunriseTime", "sunsetTime"]
+public class SmartThing {
def sendEventSmartThings
-
- StringBuilder idSmartThing = new StringBuilder()
- StringBuilder labelSmartThing = new StringBuilder()
- StringBuilder displayNameSmartThing = new StringBuilder()
- HashMap<String, StringBuilder> deviceValueSmartThing = new HashMap<String, StringBuilder>()
- HashMap<String, MutableInteger> deviceIntValueSmartThing = new HashMap<String, MutableInteger>()
- List<StringBuilder> possibleValuesSmartThings = new ArrayList<StringBuilder>();
+ String idSmartThing
+ String labelSmartThing
+ String displayNameSmartThing
+ HashMap<String, String> deviceValueSmartThing = new HashMap<String, String>()
+ HashMap<String, Integer> deviceIntValueSmartThing = new HashMap<String, Integer>()
+ List<String> possibleValuesSmartThings = new ArrayList<String>()
// Method for handling events
- def setValue(LinkedHashMap eventDataMap) {
- def name = eventDataMap["name"]
- def tmpID = eventDataMap["deviceId"]
- def value = eventDataMap["value"]
+ def setValue(LinkedHashMap eventDataMap) {
+ def name = eventDataMap["name"]
+ def tmpID = eventDataMap["deviceId"]
+ def value = eventDataMap["value"]
- if (deviceValueSmartThing.containsKey(name)) {
- StringBuilder tmpStr = deviceValueSmartThing.get(name)
- if (!value.equals(tmpStr.toString())) {
- tmpStr.replace(0, tmpStr.length(), value)
- println("the $name with id:$tmpID is triggered to $value!")
- sendEventSmartThings(eventDataMap)
- }
- } else if (deviceIntValueSmartThing.containsKey(name)) {
- MutableInteger tmpInt = deviceIntValueSmartThing.get(name)
- if (!value.equals(tmpInt.getValue())) {
- tmpInt.setValue(value)
- println("the $name with id:$tmpID is triggered to $value!")
- sendEventSmartThings(eventDataMap)
- }
- } else if (nonStoredDevices.contains(name)) {
- println("the $name with id:$tmpID is triggered to $value!")
- sendEventSmartThings(eventDataMap)
- } else if (locationTimeFeatures.contains(name)) {
- return System.currentTimeMillis()
- println("This is $name!")
- sendEventSmartThings(eventDataMap)
- }
- }
+ if (deviceValueSmartThing.containsKey(name)) {
+ if (!value.equals(deviceValueSmartThing.get(name))) {
+ deviceValueSmartThing.put(name, value)
+ println("the $name of the $displayNameSmartThing with id:$tmpID is triggered to $value!")
+ sendEventSmartThings(eventDataMap)
+ }
+ } else if (deviceIntValueSmartThing.containsKey(name)) {
+ if (!value.equals(deviceIntValueSmartThing.get(name))) {
+ deviceIntValueSmartThing.put(name, value)
+ println("the $name of the $displayNameSmartThing with id:$tmpID is triggered to $value!")
+ sendEventSmartThings(eventDataMap)
+ }
+ } else {
+ println("the $name of the $displayNameSmartThing with id:$tmpID is triggered to $value!")
+ sendEventSmartThings(eventDataMap)
+ }
+ }
def statesSince() {
eventsSince()
}
def eventsSince() {
- if (labelSmartThing.toString().equals("humidity") || labelSmartThing.toString().equals("temperature")) {
+ if (labelSmartThing.equals("humidity") || labelSmartThing.equals("temperature")) {
sendCurrentValue()
} else {
sendPossibleValues()
}
def sendCurrentValue() {
- def label = labelSmartThing.toString()
- def evtTemp = [[name: label, value: deviceIntValueSmartThing.get(label).getValue(), deviceId: idSmartThing.toString(), descriptionText: "",
+ def evtTemp = [[name: labelSmartThing, value: deviceIntValueSmartThing.get(labelSmartThing), deviceId: idSmartThing, descriptionText: "",
displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}']]
def init = Verify.getInt(0,1)
def evtToSend = []
}
def sendPossibleValues() {
- def evtA = [[name: labelSmartThing.toString(), value: possibleValuesSmartThings[0].toString(), deviceId: idSmartThing.toString(), descriptionText: "",
+ def evtA = [[name: labelSmartThing, value: possibleValuesSmartThings[0], deviceId: idSmartThing, descriptionText: "",
displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}']]
- def evtB = [[name: labelSmartThing.toString(), value: possibleValuesSmartThings[1].toString(), deviceId: idSmartThing.toString(), descriptionText: "",
+ def evtB = [[name: labelSmartThing, value: possibleValuesSmartThings[1], deviceId: idSmartThing, descriptionText: "",
displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}']]
def init = Verify.getInt(0,4)
def evtToSend = []
}
}
+ // Methods to set values
+ def action(String newValue, String feature) {
+ if (!deviceValueSmartThing.get(feature).equals(newValue)) {
+ deviceValueSmartThing.put(feature, newValue)
+ println("$feature of the $displayNameSmartThing with id:$idSmartThing is changed to $newValue!")
+ sendEventSmartThings([name: feature, value: newValue, deviceId: idSmartThing, descriptionText: "",
+ displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
+ }
+ }
+
+ def action(int newValue, String feature) {
+ if (!deviceIntValueSmartThing.get(feature).equals(newValue)) {
+ deviceIntValueSmartThing.put(feature, newValue)
+ println("$feature of the $displayNameSmartThing with id:$idSmartThing is changed to $newValue!")
+ sendEventSmartThings([name: feature, value: newValue, deviceId: idSmartThing, descriptionText: "",
+ displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
+ }
+ }
+
// Methods to return values
+ def getProperty(String currentProperty) {
+ String property = currentProperty
+ if (property.contains("current")) // Check to see if we have currentXXX or xxx
+ property = property.substring(7,8).toLowerCase()+property.substring(8);
+
+ if (deviceValueSmartThing.containsKey(property)) {
+ return deviceValueSmartThing.get(property)
+ } else if (deviceIntValueSmartThing.containsKey(property)) {
+ return deviceIntValueSmartThing.get(property)
+ } else {
+ println("This capability does not support this property!")
+ }
+ }
+
def currentState(String deviceFeature) {
return [rawDateCreated: [time: System.currentTimeMillis()]]
}
def latestValue(String deviceFeature) {
currentValue(deviceFeature)
}
-
- def getId() {
- return idSmartThing.toString()
- }
-
- def getLabel() {
- return labelSmartThing.toString()
- }
-
- def getDisplayName() {
- return displayNameSmartThing.toString()
- }
}
//Create a class for SmartThings
package SmartThing
-//Importing mutable integer class
-import MutableInteger.MutableInteger
-
class SmartThings {
List smartThings = new ArrayList()
}
// Methods to return states of the devices
+ def getProperty(String currentProperty) {
+ List tmpValues = new ArrayList()
+ tmpValues.add(smartThings[0].getProperty(currentProperty))
+ return tmpValues
+ }
+
def currentState(String deviceFeature) {
List tmpValues = new ArrayList()
tmpValues.add(smartThings[0].currentState(deviceFeature))
public class SmokeDetector extends SmartThing {
// id, label, and display name of the device
- StringBuilder id = new StringBuilder()
- StringBuilder label = new StringBuilder()
- StringBuilder displayName = new StringBuilder()
- // Features with string values
- StringBuilder currentSmoke = new StringBuilder()
+ String id
+ String label
+ String displayName
// Maps from features to values
- HashMap<String, StringBuilder> deviceValuesMap = new HashMap<String, StringBuilder>()
+ HashMap<String, String> deviceValuesMap = new HashMap<String, String>()
- SmokeDetector(Closure sendEvent, StringBuilder id, StringBuilder label, StringBuilder displayName, StringBuilder currentSmoke) {
- deviceValuesMap = deviceValueSmartThing
+ SmokeDetector(Closure sendEvent, String id, String label, String displayName, String currentSmoke) {
+ deviceValueSmartThing = deviceValuesMap
idSmartThing = id
labelSmartThing = label
displayNameSmartThing = displayName
this.id = id
this.label = label
this.displayName = displayName
- this.currentSmoke = currentSmoke
deviceValuesMap.put("smoke", currentSmoke)
}
-
- // Methods to return values
- def getCurrentSmoke() {
- return currentSmoke.toString()
- }
}
smokeDetectors = smartThings
// Initialization
- StringBuilder id = new StringBuilder("smokeDetectorID0")
- StringBuilder label = new StringBuilder("smokeDetector")
- StringBuilder displayName = new StringBuilder("smokeDetector0")
- StringBuilder smoke = new StringBuilder()
+ String id = "smokeDetectorID0"
+ String label = "smoke"
+ String displayName = "smokeDetector"
+ String smoke
if (init)
- smoke.append("clear")
+ smoke = "clear"
else
- smoke.append("detected")
+ smoke = "detected"
smokeDetectors.add(new SmokeDetector(sendEvent, id, label, displayName, smoke))
}
-
- // Methods to return values
- def getCurrentSmoke() {
- List tmpValues = new ArrayList()
- tmpValues.add(smokeDetectors[0].getCurrentSmoke())
- return tmpValues
- }
}
package SpeechSynthesis
import SmartThing.SmartThing
-//Importing mutable integer class
-import MutableInteger.MutableInteger
-
public class SpeechSynthesis 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()
+ String id
+ String label
+ String displayName
// Maps from features to values
- HashMap<String, MutableInteger> deviceIntValuesMap = new HashMap<String, MutableInteger>()
+ HashMap<String, Integer> deviceIntValuesMap = new HashMap<String, Integer>()
- SpeechSynthesis(Closure sendEvent, StringBuilder id, StringBuilder label, StringBuilder displayName, MutableInteger currentLevel) {
- deviceIntValuesMap = deviceIntValueSmartThing
+ SpeechSynthesis(Closure sendEvent, String id, String label, String displayName, Integer currentLevel) {
+ deviceIntValueSmartThing = deviceIntValuesMap
idSmartThing = id
labelSmartThing = label
displayNameSmartThing = displayName
this.id = id
this.label = label
this.displayName = displayName
- this.currentLevel = currentLevel
deviceIntValuesMap.put("level", currentLevel)
}
// Methods to set values
def setLevel(int newValue) {
- if (!currentLevel.getValue().equals(newValue)) {
- String tmpID = id.toString()
- currentLevel.setValue(newValue)
- println("The level of speech synthesis with id:$tmpID is changed to $currentLevel")
- }
+ action(newValue, "level")
}
def speak(String message) {
- String tmpID = id.toString()
- println("Speech synthesis with id:$tmpID, SPEAKING:\"$message\"!")
- }
-
- // Methods to return values
- def getCurrentLevel() {
- return currentLevel.getValue()
+ println("Speech synthesis with id:$id, SPEAKING:\"$message\"!")
}
}
package SpeechSynthesis
import SmartThing.SmartThings
-//Importing mutable integer class
-import MutableInteger.MutableInteger
-
public class SpeechSynthesises extends SmartThings {
List speechSynthesises = new ArrayList()
speechSynthesises = smartThings
// Initialization
- StringBuilder id = new StringBuilder("speechSynthesisID0")
- StringBuilder label = new StringBuilder("speechSynthesis")
- StringBuilder displayName = new StringBuilder("speechSynthesis0")
- MutableInteger level = new MutableInteger()
+ String id = "speechSynthesisID0"
+ String label = "level"
+ String displayName = "speechSynthesiser"
+ Integer level
if (init)
- level.setValue(50)
+ level = 50
else
- level.setValue(60)
+ level = 60
speechSynthesises.add(new SpeechSynthesis(sendEvent, id, label, displayName, level))
}
def speak(String message) {
speechSynthesises[0].speak(message)
}
-
- // Methods to return values
- def getCurrentLevel() {
- List tmpValues = new ArrayList()
- tmpValues.add(speechSynthesises[0].getCurrentLevel())
- return tmpValues
- }
-
}
package StepSensor
import SmartThing.SmartThing
-//Importing mutable integer class
-import MutableInteger.MutableInteger
-
public class StepSensor 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 currentGoal = new MutableInteger()
- MutableInteger currentSteps = new MutableInteger()
+ String id
+ String label
+ String displayName
// Maps from features to values
- HashMap<String, MutableInteger> deviceIntValuesMap = new HashMap<String, MutableInteger>()
+ HashMap<String, Integer> deviceIntValuesMap = new HashMap<String, Integer>()
- StepSensor(Closure sendEvent, StringBuilder id, StringBuilder label, StringBuilder displayName, MutableInteger currentSteps, MutableInteger currentGoal) {
- deviceIntValuesMap = deviceIntValueSmartThing
+ StepSensor(Closure sendEvent, String id, String label, String displayName, Integer currentSteps, Integer currentGoal) {
+ deviceIntValueSmartThing = deviceIntValuesMap
idSmartThing = id
labelSmartThing = label
displayNameSmartThing = displayName
this.id = id
this.label = label
this.displayName = displayName
- this.currentSteps = currentSteps
- this.currentGoal = currentGoal
deviceIntValuesMap.put("steps", currentSteps)
deviceIntValuesMap.put("goal", currentGoal)
}
-
- // Methods to return values
- def getCurrentSteps() {
- return currentSteps.getValue()
- }
-
- def getCurrentGoal() {
- return currentGoal.getValue()
- }
}
package StepSensor
import SmartThing.SmartThings
-//Importing mutable integer class
-import MutableInteger.MutableInteger
-
public class StepSensors extends SmartThings {
List stepSensors = new ArrayList()
stepSensors = smartThings
// Initialization
- StringBuilder id = new StringBuilder("stepSensorID0")
- StringBuilder label = new StringBuilder("stepSensor")
- StringBuilder displayName = new StringBuilder("stepSensor0")
- MutableInteger steps = new MutableInteger()
- MutableInteger goal = new MutableInteger()
+ String id = "stepSensorID0"
+ String label = "steps"
+ String displayName = "stepSensor"
+ Integer steps
+ Integer goal
if (init) {
- goal.setValue(50)
- steps.setValue(35)
+ goal = 50
+ steps = 35
} else {
- goal.setValue(40)
- steps.setValue(60)
+ goal = 40
+ steps = 60
}
stepSensors.add(new StepSensor(sendEvent, id, label, displayName, steps, goal))
}
-
- // Methods to return values
- def getCurrentSteps() {
- List tmpValues = new ArrayList()
- tmpValues.add(stepSensors[0].getCurrentSteps())
- return tmpValues
- }
-
- def getCurrentGoal() {
- List tmpValues = new ArrayList()
- tmpValues.add(stepSensors[0].getCurrentGoal())
- return tmpValues
- }
}
public class Switch extends SmartThing {
// id, label, and display name of the device
- StringBuilder id = new StringBuilder()
- StringBuilder label = new StringBuilder()
- StringBuilder displayName = new StringBuilder()
- // Features with string values
- StringBuilder currentSwitch = new StringBuilder()
+ String id
+ String label
+ String displayName
// Maps from features to values
- HashMap<String, StringBuilder> deviceValuesMap = new HashMap<String, StringBuilder>()
+ HashMap<String, String> deviceValuesMap = new HashMap<String, String>()
// Possible values for eventsSince method
- List<StringBuilder> possibleValues = new ArrayList<StringBuilder>();
+ List<String> possibleValues = new ArrayList<String>();
- Switch(Closure sendEvent, StringBuilder id, StringBuilder label, StringBuilder displayName, StringBuilder currentSwitch) {
- deviceValuesMap = deviceValueSmartThing
+ Switch(Closure sendEvent, String id, String label, String displayName, String currentSwitch) {
+ deviceValueSmartThing = deviceValuesMap
idSmartThing = id
labelSmartThing = label
displayNameSmartThing = displayName
this.id = id
this.label = label
this.displayName = displayName
- this.currentSwitch = currentSwitch
possibleValues.add("on")
possibleValues.add("off")
// Methods to set values
def on() {
- action(currentSwitch, "on", "switch")
+ action("on", "switch")
}
def on(LinkedHashMap metaData) {
}
def off() {
- action(currentSwitch, "off", "switch")
+ action("off", "switch")
}
def off(LinkedHashMap metaData) {
off()
}
-
- 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 light with id:$tmpID is changed to $newValue!")
- sendEvent([name: feature, value: newValue, deviceId: tmpID, descriptionText: "",
- displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
- }
- }
-
- // Methods to return values
- def getCurrentSwitch() {
- return currentSwitch.toString()
- }
}
switches = smartThings
// Initialization
- StringBuilder id = new StringBuilder("switchID0")
- StringBuilder label = new StringBuilder("switch")
- StringBuilder displayName = new StringBuilder("switch0")
- StringBuilder currentSwitch = new StringBuilder()
+ String id = "switchID0"
+ String label = "switch"
+ String displayName = "switch"
+ String currentSwitch
if (init)
- currentSwitch.append("off")
+ currentSwitch = "off"
else
- currentSwitch.append("on")
+ currentSwitch = "on"
switches.add(new Switch(sendEvent, id, label, displayName, currentSwitch))
}
def off(LinkedHashMap metaData) {
off()
}
-
- // Methods to return values
- def getCurrentSwitch() {
- List tmpValues = new ArrayList()
- tmpValues.add(switches[0].getCurrentSwitch())
- return tmpValues
- }
}
package SwitchLevel
import SmartThing.SmartThing
-//Importing mutable integer class
-import MutableInteger.MutableInteger
-
public class SwitchLevel 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()
+ String id
+ String label
+ String displayName
// Maps from features to values
- HashMap<String, MutableInteger> deviceIntValuesMap = new HashMap<String, MutableInteger>()
+ HashMap<String, Integer> deviceIntValuesMap = new HashMap<String, Integer>()
- SwitchLevel(Closure sendEvent, StringBuilder id, StringBuilder label, StringBuilder displayName, MutableInteger currentLevel) {
- deviceIntValuesMap = deviceIntValueSmartThing
+ SwitchLevel(Closure sendEvent, String id, String label, String displayName, Integer currentLevel) {
+ deviceIntValueSmartThing = deviceIntValuesMap
idSmartThing = id
labelSmartThing = label
displayNameSmartThing = displayName
this.id = id
this.label = label
this.displayName = displayName
- this.currentLevel = currentLevel
deviceIntValuesMap.put("level", currentLevel)
}
}
def setLevel(int newValue) {
- if (!currentLevel.getValue().equals(newValue)) {
- String tmpID = id.toString()
- variable.setValue(newValue)
- println("the switch with id:$tmpID is setted to level $level!")
- sendEvent([name: "level", value: newValue, deviceId: tmpID, descriptionText: "",
- displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
- }
- }
-
- // Methods to return values
- def getCurrentLevel() {
- return currentLevel.getValue()
+ action(newValue, "level")
}
}
package SwitchLevel
import SmartThing.SmartThings
-//Importing mutable integer class
-import MutableInteger.MutableInteger
-
public class SwitchLevels extends SmartThings {
List switchLevels = new ArrayList()
switchLevels = smartThings
// Initialization
- StringBuilder id = new StringBuilder("switchLevelID0")
- StringBuilder label = new StringBuilder("switchLevel")
- StringBuilder displayName = new StringBuilder("switchLevel0")
- MutableInteger level = new MutableInteger()
+ String id = "switchLevelID0"
+ String label = "level"
+ String displayName = "switchLevel"
+ Integer level
if (init)
- level.setValue(50)
+ level = 50
else
- level.setValue(60)
+ level = 60
switchLevels.add(new SwitchLevel(sendEvent, id, label, displayName, level))
}
def setLevel(int newValue) {
switchLevels[0].setLevel(newValue)
}
-
- // Methods to return values
- def getCurrentLevel() {
- List tmpValues = new ArrayList()
- tmpValues.add(switchLevels[0].getCurrentLevel())
- return tmpValues
- }
}
package TemperatureMeasurement
import SmartThing.SmartThing
-//Importing mutable integer class
-import MutableInteger.MutableInteger
-
public class TemperatureMeasurement 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 currentTemperature = new MutableInteger()
+ String id
+ String label
+ String displayName
// Maps from features to values
- HashMap<String, MutableInteger> deviceIntValuesMap = new HashMap<String, MutableInteger>()
+ HashMap<String, Integer> deviceIntValuesMap = new HashMap<String, Integer>()
- TemperatureMeasurement(Closure sendEvent, StringBuilder id, StringBuilder label, StringBuilder displayName, MutableInteger currentTemperature) {
- deviceIntValuesMap = deviceIntValueSmartThing
+ TemperatureMeasurement(Closure sendEvent, String id, String label, String displayName, Integer currentTemperature) {
+ deviceIntValueSmartThing = deviceIntValuesMap
idSmartThing = id
labelSmartThing = label
displayNameSmartThing = displayName
this.id = id
this.label = label
this.displayName = displayName
- this.currentTemperature = currentTemperature
deviceIntValuesMap.put("temperature", currentTemperature)
}
-
- // Methods to return values
- def getCurrentTemperature() {
- return currentTemperature.getValue()
- }
-
}
package TemperatureMeasurement
import SmartThing.SmartThings
-//Importing mutable integer class
-import MutableInteger.MutableInteger
-
public class TemperatureMeasurements extends SmartThings {
List temperatureMeasurements = new ArrayList()
temperatureMeasurements = smartThings
// Initialization
- StringBuilder id = new StringBuilder("temperatureMeasurementID0")
- StringBuilder label = new StringBuilder("temperature")
- StringBuilder displayName = new StringBuilder("temperatureMeasurement0")
- MutableInteger temperature = new MutableInteger()
+ String id = "temperatureMeasurementID0"
+ String label = "temperature"
+ String displayName = "temperatureMeasurement"
+ Integer temperature
if (init)
- temperature.setValue(40)
+ temperature = 40
else
- temperature.setValue(60)
+ temperature = 60
temperatureMeasurements.add(new TemperatureMeasurement(sendEvent, id, label, displayName, temperature))
}
-
- // Methods to return values
- def getCurrentTemperature() {
- List tmpValues = new ArrayList()
- tmpValues.add(temperatureMeasurements[0].getCurrentTemperature())
- return tmpValues
- }
}
package Thermostat
import SmartThing.SmartThing
-//Importing mutable integer class
-import MutableInteger.MutableInteger
-
class Thermostat 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 currentTemperature = new MutableInteger()
- MutableInteger currentCoolingSetpoint = new MutableInteger()
- MutableInteger currentHeatingSetpoint = new MutableInteger()
- MutableInteger currentThermostatSetPoint = new MutableInteger()
- // Features with string values
- StringBuilder currentThermostatOperatingState = new StringBuilder()
- StringBuilder currentThermostatFanMode = new StringBuilder()
- StringBuilder currentThermostatMode = new StringBuilder()
- StringBuilder currentClimateName = 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>()
-
- Thermostat(Closure sendEvent, StringBuilder id, StringBuilder label, StringBuilder displayName, MutableInteger currentTemperature, MutableInteger currentCoolingSetpoint,
- MutableInteger currentHeatingSetpoint, MutableInteger currentThermostatSetPoint, StringBuilder currentThermostatOperatingState, StringBuilder currentThermostatFanMode,
- StringBuilder currentThermostatMode, StringBuilder currentClimateName) {
- deviceValuesMap = deviceValueSmartThing
- deviceIntValuesMap = deviceIntValueSmartThing
+ HashMap<String, String> deviceValuesMap = new HashMap<String, String>()
+ HashMap<String, Integer> deviceIntValuesMap = new HashMap<String, Integer>()
+
+ Thermostat(Closure sendEvent, String id, String label, String displayName, Integer currentTemperature, Integer currentCoolingSetpoint,
+ Integer currentHeatingSetpoint, Integer currentThermostatSetPoint, String currentThermostatOperatingState, String currentThermostatFanMode,
+ String currentThermostatMode, String currentClimateName) {
+ deviceValueSmartThing = deviceValuesMap
+ deviceIntValueSmartThing = deviceIntValuesMap
idSmartThing = id
labelSmartThing = label
displayNameSmartThing = displayName
this.id = id
this.label = label
this.displayName = displayName
- this.currentTemperature = currentTemperature
- this.currentCoolingSetpoint = currentCoolingSetpoint
- this.currentHeatingSetpoint = currentHeatingSetpoint
- this.currentThermostatSetPoint = currentThermostatSetPoint
- this.currentThermostatOperatingState = currentThermostatOperatingState
- this.currentThermostatFanMode = currentThermostatFanMode
- this.currentThermostatMode = currentThermostatMode
- this.currentClimateName = currentClimateName
deviceValuesMap.put("temperature", currentTemperature)
deviceValuesMap.put("thermostatOperatingState", currentThermostatOperatingState)
deviceValuesMap.put("thermostatFanMode", currentThermostatFanMode)
deviceValuesMap.put("thermostatMode", currentThermostatMode)
+ deviceValuesMap.put("climateName", currentClimateName)
deviceIntValuesMap.put("coolingSetpoint", currentCoolingSetpoint)
deviceIntValuesMap.put("heatingSetpoint", currentHeatingSetpoint)
deviceIntValuesMap.put("thermostatSetpoint", currentThermostatSetPoint)
}
// Methods to set values
+ def setThermostatSetpoint(int newValue) {
+ action(newValue, "thermostatSetpoint")
+ }
+
def setCoolingSetpoint(int newValue) {
- action(this.currentCoolingSetpoint, newValue, "coolingSetpoint")
+ action(newValue, "coolingSetpoint")
}
def setCoolingSetpoint(String newValue) {
}
def setHeatingSetpoint(int newValue) {
- action(this.currentHeatingSetpoint, newValue, "heatingSetpoint")
+ action(newValue, "heatingSetpoint")
}
def setHeatingSetpoint(String newValue) {
}
def setThermostatFanMode(String newValue) {
- action(this.currentThermostatFanMode, newValue, "thermostatFanMode")
+ action(newValue, "thermostatFanMode")
+ }
+
+ def setThermostatOperatingState(String newValue) {
+ action(newValue, "thermostatOperatingState")
}
def setThermostatMode(String newValue) {
- action(this.currentThermostatMode, newValue, "thermostatMode")
+ action(newValue, "thermostatMode")
}
def cool() {
- action(this.currentThermostatMode, "cool", "thermostatMode")
+ action("cool", "thermostatMode")
}
def heat() {
- action(this.currentThermostatMode, "heat", "thermostatMode")
+ action("heat", "thermostatMode")
}
def auto() {
- action(this.currentThermostatMode, "auto", "thermostatMode")
+ action("auto", "thermostatMode")
}
def emergencyHeat() {
- action(this.currentThermostatMode, "emergencyHeat", "thermostatMode")
+ action("emergencyHeat", "thermostatMode")
}
def off() {
- action(this.currentThermostatMode, "off", "thermostatMode")
+ action("off", "thermostatMode")
}
def setClimate(String info, String newValue) {
- action(currentClimateName, newValue, "climateName")
+ action(newValue, "climateName")
}
def setHold(String info1, int coolingSetpoint, int heatingSetpoint, String info2, String info3) {
setHeatingSetpoint(heatingSetpoint)
setCoolingSetpoint(coolingSetpoint)
}
-
- 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 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"}'])
- }
- }
-
- 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"}'])
- }
- }
-
- // Methods to return values
- def getCurrentTemperature() {
- return currentTemperature.getValue()
- }
-
- def getCurrentCoolingSetpoint() {
- return currentCoolingSetpoint.getValue()
- }
-
- def getCurrentHeatingSetpoint() {
- return currentHeatingSetpoint.getValue()
- }
-
- def getCurrentThermostatSetPoint() {
- return currentThermostatSetPoint.getValue()
- }
-
- def getCurrentThermostatOperatingState() {
- return currentThermostatOperatingState.toString()
- }
-
- def getCurrentThermostatFanMode() {
- return currentThermostatFanMode.toString()
- }
-
- def getCurrentThermostatMode() {
- return currentThermostatMode.toString()
- }
-
- def getCurrentClimateName() {
- return currentClimateName.toString()
- }
}
package Thermostat
import SmartThing.SmartThings
-//Importing mutable integer class
-import MutableInteger.MutableInteger
-
class Thermostats extends SmartThings {
List thermostats = new ArrayList()
thermostats = smartThings
// Initialization
- StringBuilder id = new StringBuilder("thermostatID0")
- StringBuilder label = new StringBuilder("thermostat")
- StringBuilder displayName = new StringBuilder("thermostat0")
- StringBuilder climateName = new StringBuilder("climateName")
- StringBuilder thermostatOperatingState = new StringBuilder()
- StringBuilder thermostatFanMode = new StringBuilder()
- StringBuilder thermostatMode = new StringBuilder()
- MutableInteger temperature = new MutableInteger()
- MutableInteger coolingSetpoint = new MutableInteger()
- MutableInteger heatingSetpoint = new MutableInteger()
- MutableInteger thermostatSetpoint = new MutableInteger()
+ String id = "thermostatID0"
+ String label = "thermostat"
+ String displayName = "thermostat"
+ String climateName "climateName"
+ String thermostatOperatingState
+ String thermostatFanMode
+ String thermostatMode
+ Integer temperature
+ Integer coolingSetpoint
+ Integer heatingSetpoint
+ Integer thermostatSetpoint
if (init) {
- temperature.setValue(60)
- coolingSetpoint.setValue(70)
- heatingSetpoint.setValue(35)
- thermostatSetpoint.setValue(50)
- thermostatOperatingState.append("off")
- thermostatFanMode.append("off")
- thermostatMode.append("off")
+ temperature = 60
+ coolingSetpoint = 70
+ heatingSetpoint = 35
+ thermostatSetpoint = 50
+ thermostatOperatingState = "off"
+ thermostatFanMode = "off"
+ thermostatMode = "off"
} else {
- temperature.setValue(66)
- coolingSetpoint.setValue(80)
- heatingSetpoint.setValue(50)
- thermostatSetpoint.setValue(60)
- thermostatOperatingState.append("heating")
- thermostatFanMode.append("circulate")
- thermostatMode.append("auto")
+ temperature = 66
+ coolingSetpoint = 80
+ heatingSetpoint = 50
+ thermostatSetpoint = 60
+ thermostatOperatingState = "heating"
+ thermostatFanMode = "circulate"
+ thermostatMode = "auto"
}
thermostats.add(new Thermostat(sendEvent, id, label, displayName, temperature, coolingSetpoint,
}
// Methods to set values
+ def setThermostatSetpoint(int thermostatSetpoint) {
+ thermostats[0].setThermostatSetpoint(thermostatSetpoint)
+ }
+
def setCoolingSetpoint(int coolingSetpoint) {
thermostats[0].setCoolingSetpoint(coolingSetpoint)
}
thermostats[0].setThermostatMode(thermostatMode)
}
+ def setThermostatOperatingState(String thermostatOperatingState) {
+ thermostats[0].setThermostatOperatingState(thermostatOperatingState)
+ }
+
def setClimate(String info, String givenClimateName) {
thermostats[0].setClimate(info, givenClimateName)
}
def off() {
thermostats[0].off()
}
-
- // Methods to return values
- def getCurrentTemperature() {
- List tmpValues = new ArrayList()
- tmpValues.add(thermostats[0].getCurrentTemperature())
- return tmpValues
- }
-
- def getCurrentCoolingSetpoint() {
- List tmpValues = new ArrayList()
- tmpValues.add(thermostats[0].getCurrentCoolingSetpoint())
- return tmpValues
- }
-
- def getCurrentHeatingSetpoint() {
- List tmpValues = new ArrayList()
- tmpValues.add(thermostats[0].getCurrentHeatingSetpoint())
- return tmpValues
- }
-
- def getCurrentThermostatSetPoint() {
- List tmpValues = new ArrayList()
- tmpValues.add(thermostats[0].getCurrentThermostatSetPoint())
- return tmpValues
- }
-
- def getCurrentThermostatOperatingState() {
- List tmpValues = new ArrayList()
- tmpValues.add(thermostats[0].getCurrentThermostatOperatingState())
- return tmpValues
- }
-
- def getCurrentThermostatFanMode() {
- List tmpValues = new ArrayList()
- tmpValues.add(thermostats[0].getCurrentThermostatFanMode())
- return tmpValues
- }
-
- def getCurrentThermostatMode() {
- List tmpValues = new ArrayList()
- tmpValues.add(thermostats[0].getCurrentThermostatMode())
- return tmpValues
- }
-
- def getCurrentClimateName() {
- List tmpValues = new ArrayList()
- tmpValues.add(thermostats[0].getCurrentClimateName())
- return tmpValues
- }
}
public class ThreeAxis {
// id, label, and display name of the device
- StringBuilder id = new StringBuilder()
- StringBuilder label = new StringBuilder()
- StringBuilder displayName = new StringBuilder()
+ String id
+ String label
+ String displayName
// Other variables
def sendEvent
LinkedHashMap currentThreeAxis
- ThreeAxis(Closure sendEvent, StringBuilder id, StringBuilder label, StringBuilder displayName, LinkedHashMap currentThreeAxis) {
+ ThreeAxis(Closure sendEvent, String id, String label, String displayName, LinkedHashMap currentThreeAxis) {
// Initialization
this.id = id
this.label = label
// Methods to set values
def setValue(LinkedHashMap eventDataMap) {
- def tmpID = id.toString()
currentThreeAxis = new groovy.json.JsonSlurper().parseText(eventDataMap["value"])
- println("the three axis with id:$tmpID of cube is chagned to $currentThreeAxis!")
+ println("the three axis with id:$id of cube is chagned to $currentThreeAxis!")
sendEvent(eventDataMap)
}
threeAxises = smartThings
// Initialization
- StringBuilder id = new StringBuilder("threeAxisID0")
- StringBuilder label = new StringBuilder("threeAxis")
- StringBuilder displayName = new StringBuilder("threeAxis0")
+ String id = "threeAxisID0"
+ String label = "threeAxis"
+ String displayName = "threeAxis"
LinkedHashMap threeAxis
if (init)
public class Valve extends SmartThing {
// id, label, and display name of the device
- StringBuilder id = new StringBuilder()
- StringBuilder label = new StringBuilder()
- StringBuilder displayName = new StringBuilder()
- // Features with string values
- StringBuilder currentValve = new StringBuilder()
+ String id
+ String label
+ String displayName
// Maps from features to values
- HashMap<String, StringBuilder> deviceValuesMap = new HashMap<String, StringBuilder>()
+ HashMap<String, String> deviceValuesMap = new HashMap<String, String>()
- Valve(Closure sendEvent, StringBuilder id, StringBuilder label, StringBuilder displayName, StringBuilder currentValve) {
- deviceValuesMap = deviceValueSmartThing
+ Valve(Closure sendEvent, String id, String label, String displayName, String currentValve) {
+ deviceValueSmartThing = deviceValuesMap
idSmartThing = id
labelSmartThing = label
displayNameSmartThing = displayName
this.id = id
this.label = label
this.displayName = displayName
- this.currentValve = currentValve
- deviceValuesMap.put("valve", currentValve)
+ deviceValuesMap.put("contact", currentContact)
}
// Methods to set values
def open() {
- action(currentValve, "open", "contact")
+ action("open", "contact")
}
def open(LinkedHashMap metaData) {
}
def close() {
- action(currentValve, "closed", "contact")
+ action("closed", "contact")
}
def close(LinkedHashMap metaData) {
close()
}
-
- 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 valve with id:$tmpID is $newValue!")
- sendEvent([name: feature, value: newValue, deviceId: tmpID, descriptionText: "",
- displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
- }
- }
-
- // Methods to return values
- def getCurrentValve() {
- return currentValve.toString()
- }
}
valves = smartThings
// Initialization
- StringBuilder id = new StringBuilder("valveID0")
- StringBuilder label = new StringBuilder("valve")
- StringBuilder displayName = new StringBuilder("valve0")
- StringBuilder valve = new StringBuilder()
+ String id = "valveID0"
+ String label = "contact"
+ String displayName = "valveSensor"
+ String valve
if (init)
- valve.append("closed")
+ valve = "closed"
else
- valve.append("open")
+ valve = "open"
valves.add(new Valve(sendEvent, id, label, displayName, valve))
}
def close(LinkedHashMap metaData) {
close()
}
-
- // Methods to return values
- def getCurrentValve() {
- List tmpValues = new ArrayList()
- tmpValues.add(valves[0].getCurrentValve())
- return tmpValues
- }
-
}
public class WaterSensor extends SmartThing {
// id, label, and display name of the device
- StringBuilder id = new StringBuilder()
- StringBuilder label = new StringBuilder()
- StringBuilder displayName = new StringBuilder()
- // Features with string values
- StringBuilder currentWater = new StringBuilder()
+ String id
+ String label
+ String displayName
// Maps from features to values
- HashMap<String, StringBuilder> deviceValuesMap = new HashMap<String, StringBuilder>()
+ HashMap<String, String> deviceValuesMap = new HashMap<String, String>()
- WaterSensor(Closure sendEvent, StringBuilder id, StringBuilder label, StringBuilder displayName, StringBuilder currentWater) {
- deviceValuesMap = deviceValueSmartThing
+ WaterSensor(Closure sendEvent, String id, String label, String displayName, String currentWater) {
+ deviceValueSmartThing = deviceValuesMap
idSmartThing = id
labelSmartThing = label
displayNameSmartThing = displayName
this.id = id
this.label = label
this.displayName = displayName
- this.currentWater = currentWater
deviceValuesMap.put("water", currentWater)
}
-
- // Methods to return values
- def getCurrentWater() {
- return currentWater.toString()
- }
}
public class WaterSensors extends SmartThings {
List waterSensors = new ArrayList()
-
+
WaterSensors(Closure sendEvent, boolean init) {
// Only initialize one time since we only have one device for each capability
waterSensors = smartThings
// Initialization
- StringBuilder id = new StringBuilder("waterSensorID0")
- StringBuilder label = new StringBuilder("waterSensor")
- StringBuilder displayName = new StringBuilder("waterSensor0")
- StringBuilder water = new StringBuilder()
+ String id = "waterSensorID0"
+ String label = "water"
+ String displayName = "waterSensor"
+ String water
if (init)
- water.append("dry")
+ water = "dry"
else
- water.append("wet")
+ water = "wet"
waterSensors.add(new WaterSensor(sendEvent, id, label, displayName, water))
}
-
- // Methods to return values
- def getCurrentWater() {
- List tmpValues = new ArrayList()
- tmpValues.add(waterSensors[0].getCurrentWater())
- return tmpValues
- }
}
public class Touched extends SmartThing {
// id, label, and display name of the device
- StringBuilder id = new StringBuilder()
- StringBuilder label = new StringBuilder()
- StringBuilder displayName = new StringBuilder()
+ String id
+ String label
+ String displayName
Touched(Closure sendEvent) {
+ id = "appTouchID0"
+ label = "appTouch"
+ displayName = "appTouchSensor"
+
idSmartThing = id
labelSmartThing = label
displayNameSmartThing = displayName
sendEventSmartThings = sendEvent
-
- // Initialization
- id.append("appTouchID0")
- label.append("appTouch")
- displayName.append("appTouch0")
}
}
- doorControlObject[0].setValue([name: "doorState", value: "closed", deviceId: "doorControlID0", descriptionText: "",
+ doorControlObject[0].setValue([name: "door", value: "closed", deviceId: "doorControlID0", descriptionText: "",
displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
- doorControlObject[0].setValue([name: "doorState", value: "open", deviceId: "doorControlID0", descriptionText: "",
+ doorControlObject[0].setValue([name: "door", value: "open", deviceId: "doorControlID0", descriptionText: "",
displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
- locationObject.setValue([name: "Location", value: "away", deviceId: "locationID0", descriptionText: "",
+ locationObject.setValue([name: "mode", value: "away", deviceId: "locationID0", descriptionText: "",
displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
- locationObject.setValue([name: "Location", value: "home", deviceId: "locationID0", descriptionText: "",
+ locationObject.setValue([name: "mode", value: "home", deviceId: "locationID0", descriptionText: "",
displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
- locationObject.setValue([name: "Location", value: "night", deviceId: "locationID0", descriptionText: "",
+ locationObject.setValue([name: "mode", value: "night", deviceId: "locationID0", descriptionText: "",
displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
locationObject.setValue([name: "mode", value: "home", deviceId: "locationID0", descriptionText: "",
- displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
+ displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
\ No newline at end of file
- motionSensorObjectp[0].setValue([name: "motion", value: "active", deviceId: "motionSensorID0", descriptionText: "",
+ motionSensorObject[0].setValue([name: "motion", value: "active", deviceId: "motionSensorID0", descriptionText: "",
displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
- touchSensorObject.setValue([name: "nfcTouch", value: "touched", deviceId: "nfcSensorID0", descriptionText: "",
+ touchSensorObject[0].setValue([name: "nfcTouch", value: "touched", deviceId: "nfcSensorID0", descriptionText: "",
displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
- lockObject[0].setValue([name: "unlock", value: "unlocked ", deviceId: "lockID0", descriptionText: "",
+ lockObject[0].setValue([name: "lock.unlocked", value: "unlocked", deviceId: "lockID0", descriptionText: "",
displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])