-
Notifications
You must be signed in to change notification settings - Fork 1
/
jvm.AnyZWaveUniversalParentDriverv1.6.1.groovy
270 lines (220 loc) · 11.3 KB
/
jvm.AnyZWaveUniversalParentDriverv1.6.1.groovy
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
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
import java.util.concurrent.* // Available (allow-listed) concurrency classes: ConcurrentHashMap, ConcurrentLinkedQueue, Semaphore, SynchronousQueue
import groovy.transform.Field
//////////////
#include zwaveTools.sendReceiveTools
Integer getS2MaxRetries() { return 5 }
///////////
#include zwaveTools.globalDataTools
#include zwaveTools.endpointTools
#include zwaveTools.batteryTools
#include zwaveTools.versionInfoTools
#include zwaveTools.zwaveDeviceDatabase
#include zwaveTools.notificationTools
#include zwaveTools.meterTools
#include zwaveTools.sensorTools
#include zwaveTools.binaryAndMultilevelDeviceTools
#include zwaveTools.centralSceneTools
#include zwaveTools.openSmarthouseTools
#include zwaveTools.childDeviceTools
#include zwaveTools.parameterManagementTools
/////////////////
metadata {
definition (name: "Any Z-Wave Universal Parent Driver v1.6.1",namespace: "jvm", author: "jvm", singleThreaded:false) {
capability "Initialize"
capability "Refresh"
// Uncomment capabilities that you want to expose in the parent.
// Otherwise, all capabilities / attributes are by adding child devices.
// capability "Actuator"
// capability "Switch"
// capability "SwitchLevel"
capability "PushableButton"
capability "HoldableButton"
capability "ReleasableButton"
capability "DoubleTapableButton"
attribute "multiTapButton", "number"
// capability "Sensor"
// capability "MotionSensor"
// capability "TamperAlert"
// capability "WaterSensor"
// capability "ContactSensor"
// capability "ShockSensor" // Use this for glass breakage!
// capability "IllumanceMeasurement"
// capability "LiquidFlowRate"
// attribute "carbonDioxideDetected"
// capability "Battery"
// capability "Consumable" // For smoke, CO, CO2 alarms that report their end-of-life
// capability "FilterStatus" // For water filters that report status of filter
command "identify" // implements the Z-Wave Plus identify function which can flash device indicators.
command "resetDriver" // deletes the stored state information
command "addNewChildDevice", [[name:"Device Name*", type:"STRING"],
[name:"componentDriverName*",type:"ENUM", constraints:(getDriverChoices()) ],
[name:"Endpoint",type:"NUMBER", description:"Endpoint Number, blank or 0 = root" ] ]
command "multiTap", [[name:"button",type:"NUMBER", description:"Button Number", constraints:["NUMBER"]],
[name:"taps",type:"NUMBER", description:"Tap count", constraints:["NUMBER"]]]
command "setParameter",[[name:"parameterNumber",type:"NUMBER", description:"Parameter Number", constraints:["NUMBER"]],
[name:"value",type:"NUMBER", description:"Parameter Value", constraints:["NUMBER"]]
]
command "refreshManufacturerSpecificInfo"
// Following Command is to help create a new data record to be added to deviceDatabase
// command "logDataRecord"
}
preferences
{
input name: "showParameterInputs", type: "bool", title: "Show Parameter Value Input Controls", defaultValue: false
input name: "logEnable", type: "bool", title: "Enable debug logging", defaultValue: false
input name: "txtEnable", type: "bool", title: "Enable text logging", defaultValue: true
if (showParameterInputs) {
getParameterValuesFromDevice()
deviceInputs?.each{key, value -> input value}
}
}
}
/////////////////////////////////////////////////////////////////////////
////// Create and Manage Child Devices for Endpoints ///////
/////////////////////////////////////////////////////////////////////////
void logDataRecord() {
log.debug dataRecordByProductType
}
/////////////////////////////////////////////////////////////////
void identify() {
log.warn "Device ${device.displayName}: The 'identify' function is experimental and only works for Zwave Plus Version 2 or greater devices!"
// Identify function supported by Zwave Plus Version 2 and greater devices!
List<Map<String, Short>> indicators = [
[indicatorId:0x50, propertyId:0x03, value:0x08],
[indicatorId:0x50, propertyId:0x04, value:0x03],
[indicatorId:0x50, propertyId:0x05, value:0x06]
]
advancedZwaveSend(zwave.indicatorV3.indicatorSet(indicatorCount:3 , value:0, indicatorValues: indicators ))
}
void resetDriver() {
state.clear()
}
void clearLeftoverStates() {
List<String> allowed = ["deviceRecord"]
// Can't modify state from within state.each{}, so first collect what is unwanted, then remove in a separate unwanted.each
List<String> unwanted = state.collect{
if (allowed.contains( it.key as String)) return
return it.key
}.each{state.remove( it ) }
}
void removeAllSettings() {
if (logEnable) log.debug "settings before clearing: " + settings
// Copy keys set first to avoid any chance of concurrent modification
def keys = new HashSet(settings.keySet())
keys.each{ key -> device.removeSetting(key) }
if (logEnable) log.debug "settings after clearing: " + settings
}
void initialize()
{
// removeAllSettings()
// By default, hide the parameter settings inputs since displaying them forces a refresh of all values the first time they are shown and is time consuming!
device.updateSetting("showParameterInputs",[value:"false",type:"bool"])
clearLeftoverStates()
log.info "Device ${device.displayName}: Initializing."
/////////////////////////////////////////////////////////////////////////////////////
/// Don't Alter this code block code! ///
/// This code manages the different ways in which the device record may be stored ///
/// - i.e., locally or from the openSmartHouse database ///
/////////////////////////////////////////////////////////////////////////////////////
// If the format of the device record has changed, delete any locally stored data and recreate
if ((state.deviceRecord?.formatVersion as Integer) != dataRecordFormatVersion) state.remove("deviceRecord")
Map localDataRecord = getThisDeviceDatabaseRecord()
if (localDataRecord && (localDataRecord.formatVersion != dataRecordFormatVersion)) {
log.warn "Device ${device.displayName}: Locally stored data record has wrong version number and will be ignored. Obtaining data from openSmartHouse instead. Locally stored record is: ${localDataRecord.inspect()}."
}
if (localDataRecord && (localDataRecord.formatVersion == dataRecordFormatVersion)){
state.remove("deviceRecord") // If a device data record from openSmartHouse was added to the state, delete it as it is now in the local database.
dataRecordByProductType.putAll(reparseDeviceData(localDataRecord)) // Store in the Global ConcurrentHashMap
} else if ( state.deviceRecord && getDataRecordByProductType().deviceRecord.is( null ) ) {
// Put in the Global ConcurrentHashMap if it exists in state.
dataRecordByProductType.putAll(reparseDeviceData(state.deviceRecord)) // Store in the Global ConcurrentHashMap
} else if ( state.deviceRecord.is( null ) && getDataRecordByProductType().deviceRecord ) {
// Data record doesn't exist in state, but it is in the concurrentHashMap - So store in state rather than re-retrieve
state.deviceRecord = dataRecordByProductType.deviceRecord
updateDataValue("deviceModel", state.deviceRecord?.fingerprints?.name)
} else if ( state.deviceRecord.is( null )) {
// Data record doesn't exist - get it and store in the global data record
Map createdRecord = openSmarthouseCreateDeviceDataRecord()
if (createdRecord) {
state.deviceRecord = createdRecord
updateDataValue("deviceModel", createdRecord?.fingerprints?.name)
dataRecordByProductType.putAll(reparseDeviceData(createdRecord))
}
}
///////////////////////////////////////////////////////////////////////////////////
////////// Done with Device Data Record Management //////////////////
///////////////////////////////////////////////////////////////////////////////////
List<Integer> supportedClasses = getThisEndpointClasses(ep)
// Create child devices if this is a multi-channel device.
if (getDataRecordByProductType().classVersions?.containsKey(0x60)) {
deleteUnwantedChildDevices()
createChildDevices()
}
if (getDataRecordByProductType().classVersions?.containsKey(0x5B)) advancedZwaveSend(zwave.centralSceneV3.centralSceneSupportedGet())
if (getDataRecordByProductType().classVersions?.containsKey(0x6C)) sendInitialCommand()
if (txtEnable) log.info "Device ${device.displayName}: Refreshing device data."
refresh()
runIn(5, versionInfoTools_refreshVersionInfo)
if (txtEnable) log.info "Device ${device.displayName}: Done Initializing."
// schedule('0 */10 * ? * * *', refresh)
}
//////////// Get Inputs //////////////
Map getDeviceInputs() {
Map returnMe = getDataRecordByProductType()?.deviceInputs?.sort({it.key})
if (logEnable && returnMe.is( null ) ) log.warn "Device ${device.displayName}: Device has no inputs. Check if device was initialized. returnMe is ${returnMe}."
return returnMe
}
Map filteredDeviceInputs() {
if (advancedEnable) {
return getDeviceInputs()?.sort()
} else { // Just show the basic items
return getDeviceInputs()?.findAll { it.value.category != "advanced" }?.sort()
}
}
///////////////////////////////////////////////////////////////////////////////////////
/////// Handle Refreshes ////////
///////////////////////////////////////////////////////////////////////////////////////
void componentRefresh(com.hubitat.app.DeviceWrapper cd){
refreshEndpoint(cd:cd)
}
void refreshEndpoint(Map params = [cd: null, ep: null ])
{
// com.hubitat.app.DeviceWrapper targetDevice = device
Integer ep = null
if (params.cd) {
ep = (params.cd.deviceNetworkId.split("-ep")[-1]) as Integer
} else if (! params.ep.is( null )) {
ep = params.ep as Integer
}
if (ep.is( null )) return
Map record = getThisEndpointData(ep)
if (logEnable) log.debug "Device ${device.displayName}: Refreshing endpoint: ${ep ?: 0} with record ${record}"
if (txtEnable) log.info "Device ${device.displayName}: refreshing values for endpoint ${ep}."
List<Integer> supportedClasses = getThisEndpointClasses(ep)
if (supportedClasses.contains(0x25)) advancedZwaveSend(zwave.switchBinaryV1.switchBinaryGet(), ep)
if (supportedClasses.contains(0x26)) advancedZwaveSend(zwave.switchMultilevelV4.switchMultilevelGet(), ep)
if (supportedClasses.contains(0x32) && meterTools_refresh) meterTools_refresh(ep)
if (supportedClasses.contains(0x71) && notificationTools_refresh ) notificationTools_refresh(ep)
// if (record.classes.contains(0x62)) refreshLock(ep)
if (supportedClasses.contains(0x80)) batteryTools_refreshBattery()
}
void refresh()
{
getFullEndpointRecord().each{thisEp, v ->
refreshEndpoint(ep:thisEp)
}
}
void refreshLock(ep = null ) {
log.error "Device ${device.displayName} Function refreshLock is not fully implemented."
}
//////////////////////////////////////////////////////////////////////
////// Z-Wave Helper Functions ///////
////// Format messages, Send to Device, secure Messages ///////
//////////////////////////////////////////////////////////////////////
void logsOff() {
device.updateSetting("logEnable",[value:"false",type:"bool"])
}
//// Hail ////
void zwaveEvent(hubitat.zwave.commands.hailv1.Hail cmd) {
refresh()
}