Reimplementing DPOR Phase 1: First trace execution, cycle detection, R/W field access...
[jpf-core.git] / examples / test.groovy
1 // This function runs when the SmartApp is installed
2 def installed() {
3     // This is a standard debug statement in Groovy
4     log.debug "Installed with settings: ${settings}"
5     initialize()
6 }
7
8 // This function runs when the SmartApp has been updated
9 def updated() {
10     log.debug "Updated with settings: ${settings}"
11     // Notice that all event subscriptions are removed when a SmartApp is updated
12     unsubscribe()
13     initialize()
14 }
15
16 // This function is where you initialize callbacks for event listeners
17 def initialize() {
18     // The subscribe function takes a input, a state, and a callback method
19     subscribe(contact, "contact.open", openHandler)
20     subscribe(contact, "contact.closed", closedHandler)
21 }
22
23 // These are our callback methods
24 def openHandler(evt) {
25     log.debug "$evt.name: $evt.value"
26     // Turn the light on
27     light.on()
28 }
29
30 def closedHandler(evt) {
31     log.debug "$evt.name: $evt.value"
32     // Turn the light off and lock the lock
33     light.off()
34 }