X-Git-Url: http://demsky.eecs.uci.edu/git/?a=blobdiff_plain;f=BeaconSensor%2FBeaconSensor.groovy;h=be77c046b78c1ee08be3c0c5ec52774ab1810d11;hb=d0b538d93e64c63d2673796db08570953b57f947;hp=1aafbb4a11731007655f1639f032cb06fcbc1778;hpb=2932def9bb947d617975235763f7338360f0e5a4;p=smartthings-infrastructure.git diff --git a/BeaconSensor/BeaconSensor.groovy b/BeaconSensor/BeaconSensor.groovy index 1aafbb4..be77c04 100644 --- a/BeaconSensor/BeaconSensor.groovy +++ b/BeaconSensor/BeaconSensor.groovy @@ -1,41 +1,35 @@ //Create a class for beacon sensor package BeaconSensor -import Timer.SimulatedTimer +import SmartThing.SmartThing -public class BeaconSensor { - private String id - private String label - private String displayName - private String presence - private String currentPresence - private String presenceLatestValue +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() + // Maps from features to values + HashMap deviceValuesMap = new HashMap() - BeaconSensor(String id, String label, String displayName, String presence, String presenceLatestValue) { + BeaconSensor(Closure sendEvent, StringBuilder id, StringBuilder label, StringBuilder displayName, StringBuilder currentPresence) { + deviceValuesMap = deviceValueSmartThing + idSmartThing = id + labelSmartThing = label + displayNameSmartThing = displayName + sendEventSmartThings = sendEvent + + // Initialization this.id = id this.label = label this.displayName = displayName - this.presence = presence - this.currentPresence = presence - this.presenceLatestValue = presenceLatestValue - } - - def setValue(String value) { - println("the beacon sensor with id:$id is triggered to $value!") - this.presenceLatestValue = value - this.presence = value - this.currentPresence = value - } - - - def currentValue(String deviceFeature) { - if (deviceFeature == "beacon") { - return presence - } + this.currentPresence = currentPresence + + deviceValuesMap.put("beacon", currentPresence) } - def latestValue(String deviceFeature) { - if (deviceFeature == "beacon") { - return presenceLatestValue - } + // Methods to return values + def getCurrentPresence() { + return currentPresence.toString() } }