forked from joelwetzel/Hubitat-Reliable-Locks
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathReliableLockVirtualDevice.groovy
More file actions
121 lines (90 loc) · 2.74 KB
/
Copy pathReliableLockVirtualDevice.groovy
File metadata and controls
121 lines (90 loc) · 2.74 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
/**
* Reliable Lock Virtual Device v1.4 (Do not use outside of the Reliable Locks app!!!)
*
* Copyright 2019 Joel Wetzel
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
* in compliance with the License. You may obtain a copy of the License at:
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed
* on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License
* for the specific language governing permissions and limitations under the License.
*
*/
metadata {
definition (name: "Reliable Lock Virtual Device", namespace: "joelwetzel", author: "Joel Wetzel") {
capability "Refresh"
capability "Sensor"
capability "Actuator"
capability "Lock"
capability "Battery"
command "markAsLocked"
command "markAsUnlocked"
command "setBattery"
}
preferences {
section {
}
}
}
def log (msg) {
if (getParent().enableDebugLogging) {
log.debug msg
}
}
def installed () {
log.info "${device.displayName}.installed()"
updated()
}
def updated () {
log.info "${device.displayName}.updated()"
}
// Tell the parent app to reliably refresh the physical lock
def refresh() {
log "${device.displayName}.refresh()"
def parent = getParent()
if (parent == null) {
return
}
parent.refreshWrappedLock()
}
// Tell the parent app to reliably lock the physical lock
def lock() {
log "${device.displayName}.lock()"
def parent = getParent()
if (parent == null) {
return
}
parent.lockWrappedLock()
}
// Tell the parent app to reliably unlock the physical lock
def unlock() {
log "${device.displayName}.unlock()"
def parent = getParent()
if (parent == null) {
return
}
parent.unlockWrappedLock()
}
// Mark as locked without sending the event back to the parent app. Called when the physical lock has locked, to prevent cyclical firings.
def markAsLocked() {
log "${device.displayName}.markAsLocked()"
sendEvent(name: "lock", value: "locked")
}
// Mark as unlocked without sending the event back to the parent app. Called when the physical lock has unlocked, to prevent cyclical firings.
def markAsUnlocked() {
log "${device.displayName}.markAsUnlocked()"
sendEvent(name: "lock", value: "unlocked")
}
// Mark as unknown without sending the event back to the parent app. Called when the physical lock has jammed or is dead, to prevent cyclical firings.
def markAsUnknown(state) {
log "${device.displayName}.markAsUnknown(${state})"
sendEvent(name: "lock", value: state)
}
def setBattery(val) {
if (val != null) {
sendEvent(name: "battery", value: val)
}
}