+++ /dev/null
-//Create a class for switch device
-package Switch
-import Timer.SimulatedTimer
-
-public class Switching{
- int deviceNumbers
- List switches
- def timers
- def sendEvent
-
- //If we have only one device
- private int id = 0
- private String displayName = "switch0"
- private String switchState = "off"
- private String switchLatestValue = "off"
-
- Switching(Closure sendEvent, int deviceNumbers) {
- this.sendEvent = sendEvent
- this.timers = new SimulatedTimer()
- this.deviceNumbers = deviceNumbers
- this.switches = []
- if (deviceNumbers == 1) {
- switches = [new Switches(sendEvent, this.id, this.displayName, this.switchState, this.switchLatestValue)]
- } else if (deviceNumbers == 2) {
- switches = [new Switches(sendEvent, 0, "switch0", "off", "off"), new Switches(sendEvent, 1, "switch1", "off", "off")]
- } else if (deviceNumbers == 3) {
- switches = [new Switches(sendEvent, 0, "switch0", "off", "off"), new Switches(sendEvent, 1, "switch1", "off", "off")
- ,new Switches(sendEvent, 2, "switch2", "off", "off")]
- }
- }
-
- //By Apps
- def on() {
- switches*.on()
- }
-
- def on(LinkedHashMap metaData) {
- def task = timers.runAfter(metaData["delay"]) {
- switches*.on()
- }
- }
-
- def off() {
- switches*.off()
- }
-
- def off(LinkedHashMap metaData) {
- def task = timers.runAfter(metaData["delay"]) {
- switches*.off()
- }
- }
-
- //By Model Checker
- def setValue(LinkedHashMap eventDataMap) {
- switches[eventDataMap["deviceId"]].setValue(eventDataMap["value"])
- if (deviceNumbers == 1)
- this.switchState = switches[eventDataMap["deviceId"]].switchState
- this.switchLatestValue = switches[eventDataMap["deviceId"]].switchLatestValue
- sendEvent(eventDataMap)
- }
-
-
- def currentValue(String deviceFeature) {
- if (deviceNumbers == 1)
- switches[0].currentValue(deviceFeature)
- else
- switches*.currentValue(deviceFeature)
- }
-
- def latestValue(String deviceFeature) {
- if (deviceNumbers == 1)
- switches[0].latestValue(deviceFeature)
- else
- switches*.latestValue(deviceFeature)
- }
-
- def getAt(int ix) {
- switches[ix]
- }
-}