6ba69420098bdd23777652ae8d0d70cbc0557fab
[smartthings-infrastructure.git] / main.groovy
1 //Infrastructure for SmartThings Application
2 //Importing Libraries
3 import groovy.transform.Field
4
5 //Importing Classes
6 import ContactSensor.ContactSensor
7 import ContactSensor.ContactSensors
8 import DoorControl.DoorControl
9 import DoorControl.DoorControls
10 import Lock.Lock
11 import Lock.Locks
12 import Thermostat.Thermostat
13 import Thermostat.Thermostats
14 import Switch.Switch
15 import Switch.Switches
16 import PresenceSensor.PresenceSensor
17 import PresenceSensor.PresenceSensors
18 import Logger.Logger
19 import Location.LocationVar
20 import Location.Phrase
21 import appTouch.Touched
22 import NfcTouch.NfcTouch
23 import AeonKeyFob.AeonKeyFob
24 import AeonKeyFob.AeonKeyFobs
25 import MusicPlayer.MusicPlayer
26 import MusicPlayer.MusicPlayers
27 import Event.Event
28 import Timer.SimulatedTimer
29
30 //Global eventHandler
31 /////////////////////////////////////////////////////////////////////
32 def eventHandler(LinkedHashMap eventDataMap) {
33         def value = eventDataMap["value"]
34         def name = eventDataMap["name"]
35         def deviceId = eventDataMap["deviceId"]
36         def descriptionText = eventDataMap["descriptionText"]
37         def displayed = eventDataMap["displayed"]
38         def linkText = eventDataMap["linkText"]
39         def isStateChange = eventDataMap["isStateChange"]
40         def unit = eventDataMap["unit"]
41         def data = eventDataMap["data"]
42
43         for (int i = 0;i < app2.eventList.size();i++) {
44                 if (app2.eventList[i] == name) {
45                         def event = new Event(value, name, deviceId, descriptionText, displayed, linkText, linkText, isStateChange, unit, data)
46                         evt.add(event)
47                         app2.functionList[i](event)
48                 }
49         }
50
51         for (int i = 0;i < app1.eventList.size();i++) {
52                 if (app1.eventList[i] == name) {
53                         def event = new Event(value, name, deviceId, descriptionText, displayed, linkText, linkText, isStateChange, unit, data)
54                         evt.add(event)
55                         app1.functionList[i](event)
56                 }
57         }
58 }
59
60 //GlobalVariables for both Apps
61 //Create a global variable for send event
62 @Field def sendEvent = {eventDataMap -> 
63                         eventHandler(eventDataMap)
64                         }
65 //Object for location
66 @Field def locationObject = new LocationVar()
67 //Object for touch to call function
68 @Field def appObject = new Touched(sendEvent, 0)
69 //Create a global list for events
70 @Field def evt = []
71 //Global Object for class Touch Sensor!
72 @Field def touchSensorObject = new NfcTouch(sendEvent, 1)
73 //Global Object for class switch!
74 @Field def switchObject = new Switches(sendEvent, 1)
75 //Global Object for class lock!
76 @Field def lockObject = new Locks(sendEvent, 1)
77 //Global Object for class door control!
78 @Field def doorControlObject = new DoorControls(sendEvent, 1)
79 //Global Object for class contact sensor!
80 @Field def contactObject = new ContactSensors(sendEvent, 1)
81 //Global Object for class presence sensor!
82 @Field def presenceSensorObject = new PresenceSensors(sendEvent, 1)
83 //Global Object for class thermostat!
84 @Field def thermostatObject = new Thermostats(sendEvent, 1)
85 //Global Object for class aeon key fob!
86 @Field def aeonKeyFobObject = new AeonKeyFobs(sendEvent, 1)
87 //Global Object for class music player!
88 @Field def musicPlayerObject = new MusicPlayers(sendEvent, 1)
89
90 //Application #1
91 class App1 {
92         def reference
93         def location
94         def app
95
96         //Extracted objects for App1
97         //Object for class lock!
98         def lock1
99         //Global variable for number!
100         def minutesLater = 1
101         //Object for class contactSensor!
102         def openSensor
103
104         //Extracted objects for functions for App1
105         //Global Object for functions in subscribe method!
106         def installed = this.&installed
107         //Global Object for functions in subscribe method!
108         def updated = this.&updated
109         //Global Object for functions in subscribe method!
110         def initialize = this.&initialize
111         //Global Object for functions in subscribe method!
112         def lockDoor = this.&lockDoor
113         //Global Object for functions in subscribe method!
114         def doorOpen = this.&doorOpen
115         //Global Object for functions in subscribe method!
116         def doorClosed = this.&doorClosed
117         //Global Object for functions in subscribe method!
118         def doorHandler = this.&doorHandler
119
120         App1(Object obj) {
121                 reference = obj
122                 location = obj.locationObject
123                 app = obj.appObject
124                 lock1 = obj.lockObject
125                 openSensor = obj.contactObject
126                 //Global variable for settings!
127                 settings = [app:app, lock1:lock1, minutesLater:minutesLater, openSensor:openSensor]
128         }
129         //Global variables for each app
130         //Global variable for state[mode]
131         def state = [home:[],away:[],night:[]]
132         //Create a global logger object for methods
133         def log = new Logger()
134         //Create a global variable for Functions in Subscribe method
135         def functionList = []
136         //Create a global variable for Objects in Subscribe method
137         def objectList = []
138         //Create a global variable for Events in Subscribe method
139         def eventList = []
140         //Create a global list for function schedulers
141         def timersFuncList = []
142         //Create a global list for timer schedulers
143         def timersList = []
144         //Create a global variable for settings
145         def settings
146
147         //Methods
148         /////////////////////////////////////////////////////////////////////
149         def setLocationMode(String mode) {
150                 location.mode = mode
151         }
152         
153         /////////////////////////////////////////////////////////////////////
154         ////subscribe(obj, func)
155         def subscribe(Object obj, Closure FunctionToCall) {
156                 if (obj == app) {
157                         objectList.add(obj)
158                         eventList.add("Touched")
159                         functionList.add(FunctionToCall)
160                 } else if (obj == location) {
161                         objectList.add(obj)
162                         eventList.add("Location")
163                         functionList.add(FunctionToCall)
164                 }
165         }
166         ////subscribe(obj, event, func)
167         def subscribe(Object obj, String event, Closure FunctionToCall) {
168                 objectList.add(obj)
169                 eventList.add(event)
170                 functionList.add(FunctionToCall)
171         }
172         ////subscribe(obj, event, func, data)
173         def subscribe(Object obj, String event, Closure FunctionToCall, LinkedHashMap metaData) {
174                 objectList.add(obj)     
175                 eventList.add(event)
176                 functionList.add(FunctionToCall)
177         }
178         /////////////////////////////////////////////////////////////////////
179         ////runIn(time, func)
180         def runIn(int seconds, Closure functionToCall) {
181                 if (timersFuncList.contains(functionToCall)) {
182                         timersList[timersFuncList.indexOf(functionToCall)].cancel()
183                         def task = timersList[timersFuncList.indexOf(functionToCall)].runAfter(1000*seconds, functionToCall)
184                 } else {
185                         timersFuncList.add(functionToCall)
186                         timersList.add(new SimulatedTimer())
187                         def task = timersList[timersFuncList.indexOf(functionToCall)].runAfter(1000*seconds, functionToCall)
188                 }
189         }
190         /////////////////////////////////////////////////////////////////////
191         ////unschedule(func)
192         def unschedule(Closure functionToUnschedule) {
193                 for (int i = 0;i < timersFuncList.size();i++) {
194                         if (timersFuncList[i] == functionToUnschedule) {
195                                 if (timersList != null)
196                                         timersList[i].cancel()
197                         }
198                 }
199         }
200         
201         
202         def unschedule() {
203                 for (int i = 0;i < timersFuncList.size();i++) {
204                         if (timersList != null)
205                                 timersList[i].cancel()
206                 }
207         }
208         /////////////////////////////////////////////////////////////////////
209         ////sendNotificationToContacts(text, recipients)
210         def sendNotificationToContacts(String text, String recipients) {
211                 for (int i = 0;i < recipients.size();i++) {
212                         for (int j = 0;j < location.contacts.size();j++) {
213                                 if (recipients[i] == location.contacts[j]) {
214                                         println("Sending \""+text+"\" to "+location.phoneNumbers[j].toString())
215                                 }
216                         }
217                 }
218         }
219         /////////////////////////////////////////////////////////////////////
220         ////sendSms(phone, text)
221         def sendSms(long phoneNumber, String text) {
222                 println("Sending \""+text+"\" to "+phoneNumber.toString())
223         }
224         /////////////////////////////////////////////////////////////////////
225         ////sendPush(text)
226         def sendPush(String text) {
227                 println(text)
228         }
229         /////////////////////////////////////////////////////////////////////
230         ////schedule(time, nameOfFunction as String)
231         def schedule(String time, String nameOfFunction) {
232                 def _inputTime = time.split(':')
233                 Date date = new Date()  
234                 def _currentTime = date.format("HH:mm:ss").split(':')
235         
236                 //Convert input time and current time to minutes
237                 def inputTime = Integer.parseInt(_inputTime[0])*3600+Integer.parseInt(_inputTime[1])*60
238                 def currentTime = Integer.parseInt(_currentTime[0])*3600+Integer.parseInt(_currentTime[1])*60+Integer.parseInt(_currentTime[2])
239                 def delay
240         
241                 if (inputTime < currentTime) {
242                         delay = 24*60*60-inputTime+currentTime
243                 } else {
244                         delay = inputTime-currentTime
245                 }
246         
247                 timersFuncList.add(nameOfFunction)
248                 timersList.add(new SimulatedTimer())
249                 def task = timersList[timersFuncList.indexOf(nameOfFunction)].runAfter(delay*1000) {
250                         "$nameOfFunction"()
251                 }
252         }
253         ////schedule(time, nameOfFunction as Closure)
254         def schedule(String time, Closure nameOfFunction) {
255                 def _inputTime = time.split(':')
256                 Date date = new Date()  
257                 def _currentTime = date.format("HH:mm:ss").split(':')
258         
259                 //Convert input time and current time to minutes
260                 def inputTime = Integer.parseInt(_inputTime[0])*3600+Integer.parseInt(_inputTime[1])*60
261                 def currentTime = Integer.parseInt(_currentTime[0])*3600+Integer.parseInt(_currentTime[1])*60+Integer.parseInt(_currentTime[2])
262                 def delay
263         
264                 if (inputTime < currentTime) {
265                         delay = 24*60*60-inputTime+currentTime
266                 } else {
267                         delay = inputTime-currentTime
268                 }
269         
270                 if (timersFuncList.contains(nameOfFunction)) {
271                         timersList[timersFuncList.indexOf(nameOfFunction)].cancel()
272                         def task = timersList[timersFuncList.indexOf(nameOfFunction)].runAfter(delay*seconds, nameOfFunction)
273                 } else {
274                         timersFuncList.add(nameOfFunction)
275                         timersList.add(new SimulatedTimer())
276                         def task = timersList[timersFuncList.indexOf(nameOfFunction)].runAfter(delay*seconds, nameOfFunction)
277                 }
278         }
279         /////////////////////////////////////////////////////////////////////
280         def now() {
281                 return System.currentTimeMillis()
282         }
283
284         def installed()
285         {
286             log.debug "Auto Lock Door installed. (URL: http://www.github.com/smartthings-users/smartapp.auto-lock-door)"
287             initialize()
288         }
289         
290         def updated()
291         {
292             unsubscribe()
293             unschedule()
294             log.debug "Auto Lock Door updated."
295             initialize()
296         }
297         
298         def initialize()
299         {
300             log.debug "Settings: ${settings}"
301             subscribe(lock1, "lock", doorHandler)
302             subscribe(openSensor, "contact.closed", doorClosed)
303             subscribe(openSensor, "contact.open", doorOpen)
304         }
305         
306         def lockDoor()
307         {
308             log.debug "Locking Door if Closed"
309             if((openSensor.latestValue("contact") == "closed")){
310                 log.debug "Door Closed"
311                 lock1.lock()
312             } else {
313                 if ((openSensor.latestValue("contact") == "open")) {
314                 def delay = minutesLater * 60
315                 log.debug "Door open will try again in $minutesLater minutes"
316                 runIn( delay, lockDoor )
317                 }
318             }
319         }
320         
321         def doorOpen(evt) {
322             log.debug "Door open reset previous lock task..."
323             unschedule( lockDoor )
324             def delay = minutesLater * 60
325             runIn( delay, lockDoor )
326         }
327         
328         def doorClosed(evt) {
329             log.debug "Door Closed"
330         }
331         
332         def doorHandler(evt)
333         {
334             log.debug "Door ${openSensor.latestValue}"
335             log.debug "Lock ${evt.name} is ${evt.value}."
336         
337             if (evt.value == "locked") {                  // If the human locks the door then...
338                 log.debug "Cancelling previous lock task..."
339                 unschedule( lockDoor )                  // ...we don't need to lock it later.
340             }
341             else {                                      // If the door is unlocked then...
342                 def delay = minutesLater * 60          // runIn uses seconds
343                 log.debug "Re-arming lock in ${minutesLater} minutes (${delay}s)."
344                 runIn( delay, lockDoor )                // ...schedule to lock in x minutes.
345             }
346         }
347 }
348
349
350 //Application #2
351 class App2 {
352         def reference
353         def location
354         def app
355
356         //Extracted objects for App2
357         //Object for class Touch Sensor!
358         def tag
359         //Object for class switch!
360         def switch1
361         //Object for class lock!
362         def lock
363         //Object for class door control!
364         def garageDoor
365         //Global variable for enum!
366         def masterSwitch = "switchID0"
367         //Global variable for enum!
368         def masterLock = "lockID0"
369         //Global variable for enum!
370         def masterDoor = "DoorControlID0"
371
372         //Extracted objects for functions for App2
373         //Global Object for functions in subscribe method!
374         def pageTwo = this.&pageTwo
375         //Global Object for functions in subscribe method!
376         def installed = this.&installed
377         //Global Object for functions in subscribe method!
378         def updated = this.&updated
379         //Global Object for functions in subscribe method!
380         def initialize = this.&initialize
381         //Global Object for functions in subscribe method!
382         def currentStatus = this.&currentStatus
383         //Global Object for functions in subscribe method!
384         def touchHandler = this.&touchHandler
385
386         App2(Object obj) {
387                 reference = obj
388                 location = obj.locationObject
389                 app = obj.appObject
390                 tag = obj.touchSensorObject
391                 switch1 = obj.switchObject
392                 lock = obj.lockObject
393                 garageDoor = obj.doorControlObject
394                 //Global variable for settings!
395                 settings = [app:app, tag:tag, switch1:switch1, lock:lock, garageDoor:garageDoor, masterSwitch:masterSwitch, masterLock:masterLock, masterDoor:masterDoor]
396         }
397         //Global variables for each app
398         //Global variable for state[mode]
399         def state = [home:[],away:[],night:[]]
400         //Create a global logger object for methods
401         def log = new Logger()
402         //Create a global variable for Functions in Subscribe method
403         def functionList = []
404         //Create a global variable for Objects in Subscribe method
405         def objectList = []
406         //Create a global variable for Events in Subscribe method
407         def eventList = []
408         //Create a global list for function schedulers
409         def timersFuncList = []
410         //Create a global list for timer schedulers
411         def timersList = []
412         //Create a global variable for settings
413         def settings
414
415         //Methods
416         /////////////////////////////////////////////////////////////////////
417         def setLocationMode(String mode) {
418                 location.mode = mode
419         }
420         
421         /////////////////////////////////////////////////////////////////////
422         ////subscribe(obj, func)
423         def subscribe(Object obj, Closure FunctionToCall) {
424                 if (obj == app) {
425                         objectList.add(obj)
426                         eventList.add("Touched")
427                         functionList.add(FunctionToCall)
428                 } else if (obj == location) {
429                         objectList.add(obj)
430                         eventList.add("Location")
431                         functionList.add(FunctionToCall)
432                 }
433         }
434         ////subscribe(obj, event, func)
435         def subscribe(Object obj, String event, Closure FunctionToCall) {
436                 objectList.add(obj)
437                 eventList.add(event)
438                 functionList.add(FunctionToCall)
439         }
440         ////subscribe(obj, event, func, data)
441         def subscribe(Object obj, String event, Closure FunctionToCall, LinkedHashMap metaData) {
442                 objectList.add(obj)     
443                 eventList.add(event)
444                 functionList.add(FunctionToCall)
445         }
446         /////////////////////////////////////////////////////////////////////
447         ////runIn(time, func)
448         def runIn(int seconds, Closure functionToCall) {
449                 if (timersFuncList.contains(functionToCall)) {
450                         timersList[timersFuncList.indexOf(functionToCall)].cancel()
451                         def task = timersList[timersFuncList.indexOf(functionToCall)].runAfter(1000*seconds, functionToCall)
452                 } else {
453                         timersFuncList.add(functionToCall)
454                         timersList.add(new SimulatedTimer())
455                         def task = timersList[timersFuncList.indexOf(functionToCall)].runAfter(1000*seconds, functionToCall)
456                 }
457         }
458         /////////////////////////////////////////////////////////////////////
459         ////unschedule(func)
460         def unschedule(Closure functionToUnschedule) {
461                 for (int i = 0;i < timersFuncList.size();i++) {
462                         if (timersFuncList[i] == functionToUnschedule) {
463                                 if (timersList != null)
464                                         timersList[i].cancel()
465                         }
466                 }
467         }
468         
469         
470         def unschedule() {
471                 for (int i = 0;i < timersFuncList.size();i++) {
472                         if (timersList != null)
473                                 timersList[i].cancel()
474                 }
475         }
476         /////////////////////////////////////////////////////////////////////
477         ////sendNotificationToContacts(text, recipients)
478         def sendNotificationToContacts(String text, String recipients) {
479                 for (int i = 0;i < recipients.size();i++) {
480                         for (int j = 0;j < location.contacts.size();j++) {
481                                 if (recipients[i] == location.contacts[j]) {
482                                         println("Sending \""+text+"\" to "+location.phoneNumbers[j].toString())
483                                 }
484                         }
485                 }
486         }
487         /////////////////////////////////////////////////////////////////////
488         ////sendSms(phone, text)
489         def sendSms(long phoneNumber, String text) {
490                 println("Sending \""+text+"\" to "+phoneNumber.toString())
491         }
492         /////////////////////////////////////////////////////////////////////
493         ////schedule(time, nameOfFunction as String)
494         def schedule(String time, String nameOfFunction) {
495                 def _inputTime = time.split(':')
496                 Date date = new Date()  
497                 def _currentTime = date.format("HH:mm:ss").split(':')
498         
499                 //Convert input time and current time to minutes
500                 def inputTime = Integer.parseInt(_inputTime[0])*3600+Integer.parseInt(_inputTime[1])*60
501                 def currentTime = Integer.parseInt(_currentTime[0])*3600+Integer.parseInt(_currentTime[1])*60+Integer.parseInt(_currentTime[2])
502                 def delay
503         
504                 if (inputTime < currentTime) {
505                         delay = 24*60*60-inputTime+currentTime
506                 } else {
507                         delay = inputTime-currentTime
508                 }
509         
510                 timersFuncList.add(nameOfFunction)
511                 timersList.add(new SimulatedTimer())
512                 def task = timersList[timersFuncList.indexOf(nameOfFunction)].runAfter(delay*1000) {
513                         "$nameOfFunction"()
514                 }
515         }
516         ////schedule(time, nameOfFunction as Closure)
517         def schedule(String time, Closure nameOfFunction) {
518                 def _inputTime = time.split(':')
519                 Date date = new Date()  
520                 def _currentTime = date.format("HH:mm:ss").split(':')
521         
522                 //Convert input time and current time to minutes
523                 def inputTime = Integer.parseInt(_inputTime[0])*3600+Integer.parseInt(_inputTime[1])*60
524                 def currentTime = Integer.parseInt(_currentTime[0])*3600+Integer.parseInt(_currentTime[1])*60+Integer.parseInt(_currentTime[2])
525                 def delay
526         
527                 if (inputTime < currentTime) {
528                         delay = 24*60*60-inputTime+currentTime
529                 } else {
530                         delay = inputTime-currentTime
531                 }
532         
533                 if (timersFuncList.contains(nameOfFunction)) {
534                         timersList[timersFuncList.indexOf(nameOfFunction)].cancel()
535                         def task = timersList[timersFuncList.indexOf(nameOfFunction)].runAfter(delay*seconds, nameOfFunction)
536                 } else {
537                         timersFuncList.add(nameOfFunction)
538                         timersList.add(new SimulatedTimer())
539                         def task = timersList[timersFuncList.indexOf(nameOfFunction)].runAfter(delay*seconds, nameOfFunction)
540                 }
541         }
542
543         def pageTwo() {
544                 dynamicPage(name: "pageTwo") {
545                 section("If set, the state of these devices will be toggled each time the tag is touched, " +
546                         "e.g. a light that's on will be turned off and one that's off will be turned on, " +
547                         "other devices of the same type will be set to the same state as their master device. " +
548                         "If no master is designated then the majority of devices of the same type will be used " +
549                         "to determine whether to turn on or off the devices.") {
550         
551                     if (switch1 || masterSwitch) {
552                         input "masterSwitch", "enum", title: "Master switch", options: switch1.collect{[(it.id): it.displayName]}, required: false
553                     }
554                     if (lock || masterLock) {
555                         input "masterLock", "enum", title: "Master lock", options: lock.collect{[(it.id): it.displayName]}, required: false
556                     }
557                     if (garageDoor || masterDoor) {
558                         input "masterDoor", "enum", title: "Master door", options: garageDoor.collect{[(it.id): it.displayName]}, required: false
559                     }
560                         }
561                         section([mobileOnly:true]) {
562                                 label title: "Assign a name", required: false
563                                 mode title: "Set for specific mode(s)", required: false
564                         }
565             }
566         }
567         
568         def installed() {
569                 log.debug "Installed with settings: ${settings}"
570         
571                 initialize()
572         }
573         
574         def updated() {
575                 log.debug "Updated with settings: ${settings}"
576         
577                 unsubscribe()
578                 initialize()
579         }
580         
581         def initialize() {
582                 subscribe tag, "nfcTouch", touchHandler
583             subscribe app, touchHandler
584         }
585         
586         private currentStatus(devices, master, attribute) {
587                 log.trace "currentStatus($devices, $master, $attribute)"
588                 def result = null
589                 if (master) {
590                 result = devices.find{it.id == master}?.currentValue(attribute)
591             }
592             else {
593                 def map = [:]
594                 devices.each {
595                         def value = it.currentValue(attribute)
596                     map[value] = (map[value] ?: 0) + 1
597                     log.trace "$it.displayName: $value"
598                 }
599                 log.trace map
600                 result = map.collect{it}.sort{it.value}[-1].key
601             }
602             log.debug "$attribute = $result"
603             result
604         }
605         
606         def touchHandler(evt) {
607                 log.trace "touchHandler($evt.descriptionText)"
608             if (switch1) {
609                 def status = currentStatus(switch1, masterSwitch, "switch")
610                 switch1.each {
611                     if (status == "on") {
612                         it.off()
613                     }
614                     else {
615                         it.on()
616                     }
617                 }
618             }
619         
620             if (lock) {
621                 def status = currentStatus(lock, masterLock, "lock")
622                 lock.each {
623                     if (status == "locked") {
624                         lock.unlock()
625                     }
626                     else {
627                         lock.lock()
628                     }
629                 }
630             }
631         
632             if (garageDoor) {
633                 def status = currentStatus(garageDoor, masterDoor, "status")
634                 garageDoor.each {
635                         if (status == "open") {
636                         it.close()
637                     }
638                     else {
639                         it.open()
640                     }
641                 }
642             }
643         }
644 }
645
646 @Field def app1 = new App1(this)
647 @Field def app2 = new App2(this)
648 app1.installed()
649 app2.installed()
650
651 def events = [1,2,3,4,5,6,7]
652 def list = events.permutations()
653 int count = Verify.getInt(0,list.size()-1)
654 println "COUNT: " + count
655
656 list[count].each {
657   switch(it) {
658     case 1:
659       appObject.setValue([name: "Touched", value: "Touched", deviceId: 0, descriptionText: "",
660                                            displayed: true, linkText: "", isStateChange: false, unit: "", data: []])
661       println "1"
662       break
663     case 2:
664       lockObject.setValue([name: "lock0", value: "locked", deviceId: 0, descriptionText: "",
665                                            displayed: true, linkText: "", isStateChange: false, unit: "", data: []])
666       println "   2"
667                         break
668     case 3:
669       lockObject.setValue([name: "lock0", value: "unlocked", deviceId: 0, descriptionText: "",
670                                            displayed: true, linkText: "", isStateChange: false, unit: "", data: []])
671       println "      3"
672       break
673     case 4:
674       contactObject.setValue([name: "contact0", value: "open", deviceId: 0, descriptionText: "",
675                                            displayed: true, linkText: "", isStateChange: false, unit: "", data: []])
676       println "         4"
677       break
678     case 5:
679       contactObject.setValue([name: "contact0", value: "closed", deviceId: 0, descriptionText: "",
680                                            displayed: true, linkText: "", isStateChange: false, unit: "", data: []])
681       println "            5"
682       break
683     case 6:
684       switchObject.setValue([name: "switch0", value: "on", deviceId: 0, descriptionText: "",
685                                            displayed: true, linkText: "", isStateChange: false, unit: "", data: []])
686       println "               6"
687       break
688     case 7:
689       switchObject.setValue([name: "switch0", value: "off", deviceId: 0, descriptionText: "",
690                                            displayed: true, linkText: "", isStateChange: false, unit: "", data: []])
691       println "                   7"
692     default:
693       break
694   }
695 }