Skip to content

Commit c928d70

Browse files
authored
Merge pull request #9 from eriktack/patch-1
Update for non-secure mode and fixed crc16encap zwaveEvent
2 parents 0313ab5 + 952e8c9 commit c928d70

File tree

1 file changed

+50
-53
lines changed

1 file changed

+50
-53
lines changed

Drivers/fibaro-single-switch-2-fgs-213.src/fibaro-single-switch-2-fgs-213.groovy

+50-53
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ tiles(scale: 2){
7979

8080
}
8181
preferences {
82-
input description: "Once you change values on this page, the corner of the \"configuration\" icon will change orange until all configuration parameters are updated.", title: "Settings", displayDuringSetup: false, type: "paragraph", element: "paragraph"
82+
input description: "Once you change values on this page, the corner of the \"configuration\" icon will change orange until all configuration parameters are updated.", title: "Settings", type: "paragraph", element: "paragraph"
8383
generate_preferences(configuration_model())
8484
}
8585
}
@@ -177,15 +177,15 @@ def refresh() {
177177
cmds << zwave.switchBinaryV1.switchBinaryGet()
178178
cmds << zwave.meterV2.meterGet(scale: 0)
179179
cmds << zwave.meterV2.meterGet(scale: 2)
180-
secureSequence(cmds, 1000)
180+
commands(cmds, 1000)
181181
}
182182

183183
def reset() {
184184
def cmds = []
185185
cmds << zwave.meterV2.meterReset()
186186
cmds << zwave.meterV2.meterGet(scale: 0)
187187
cmds << zwave.meterV2.meterGet(scale: 2)
188-
secureSequence(cmds, 1000)
188+
commands(cmds, 1000)
189189
}
190190

191191
def ping() {
@@ -209,7 +209,7 @@ def configure() {
209209

210210
cmds = update_needed_settings()
211211

212-
if (cmds != []) secureSequence(cmds)
212+
if (cmds != []) commands(cmds)
213213
}
214214

215215
def zwaveEvent(hubitat.zwave.commands.centralscenev1.CentralSceneNotification cmd) {
@@ -224,41 +224,53 @@ def zwaveEvent(hubitat.zwave.commands.centralscenev1.CentralSceneNotification cm
224224

225225
def buttonEvent(button, value) {
226226
logging("buttonEvent() Button:$button, Value:$value")
227-
createEvent(name: "button", value: value, data: [buttonNumber: button], descriptionText: "$device.displayName button $button was $value", isStateChange: true)
227+
sendEvent(name: value, value: button, isStateChange:true)
228+
}
229+
230+
def installed() {
231+
def cmds = initialize()
232+
if (cmds != []) commands(cmds)
228233
}
229234

230235
/**
231236
* Triggered when Done button is pushed on Preference Pane
232237
*/
233238
def updated()
234239
{
235-
state.enableDebugging = settings.enableDebugging
236240
logging("updated() is being called")
241+
def cmds = initialize()
242+
sendEvent(name:"needUpdate", value: device.currentValue("needUpdate"), displayed:false, isStateChange: true)
243+
if (cmds != []) commands(cmds)
244+
}
245+
246+
def initialize() {
247+
log.debug "initialize()"
248+
state.enableDebugging = settings.enableDebugging
237249
sendEvent(name: "checkInterval", value: 2 * 30 * 60 + 2 * 60, displayed: false, data: [protocol: "zwave", hubHardwareId: device.hub.hardwareID])
238-
def cmds = update_needed_settings()
239-
240-
sendEvent(name:"needUpdate", value: device.currentValue("needUpdate"), displayed:false, isStateChange: true)
241-
242-
if (cmds != []) response(secureSequence(cmds))
250+
return update_needed_settings()
243251
}
244252

245253
def on() {
246-
secureSequence([
254+
commands([
247255
zwave.basicV1.basicSet(value: 0xFF)
248256
])
249257
}
250258
def off() {
251-
secureSequence([
259+
commands([
252260
zwave.basicV1.basicSet(value: 0x00)
253261
])
254262
}
255263

256-
private secure(hubitat.zwave.Command cmd) {
257-
zwave.securityV1.securityMessageEncapsulation().encapsulate(cmd).format()
264+
private command(hubitat.zwave.Command cmd) {
265+
if (state.sec) {
266+
zwave.securityV1.securityMessageEncapsulation().encapsulate(cmd).format()
267+
} else {
268+
cmd.format()
269+
}
258270
}
259271

260-
private secureSequence(commands, delay=1500) {
261-
delayBetween(commands.collect{ secure(it) }, delay)
272+
private commands(commands, delay=1000) {
273+
delayBetween(commands.collect{ command(it) }, delay)
262274
}
263275

264276
private encap(cmd, endpoint) {
@@ -270,8 +282,11 @@ private encap(cmd, endpoint) {
270282
}
271283

272284
def zwaveEvent(hubitat.zwave.commands.securityv1.SecurityMessageEncapsulation cmd) {
285+
//log.debug cmd
286+
//def encapsulatedCommand = cmd.encapsulatedCommand([0x20: 1, 0x32: 3, 0x25: 1, 0x98: 1, 0x70: 2, 0x85: 2, 0x9B: 1, 0x90: 1, 0x73: 1, 0x30: 1, 0x28: 1, 0x2B: 1, , 0x5B: 1]) // can specify command class versions here like in zwave.parse
273287
def encapsulatedCommand = cmd.encapsulatedCommand([0x20: 1, 0x32: 3, 0x25: 1, 0x98: 1, 0x70: 2, 0x85: 2, 0x9B: 1, 0x90: 1, 0x73: 1, 0x30: 1, 0x28: 1, 0x2B: 1]) // can specify command class versions here like in zwave.parse
274288
if (encapsulatedCommand) {
289+
state.sec = 1
275290
return zwaveEvent(encapsulatedCommand)
276291
} else {
277292
log.warn "Unable to extract encapsulated cmd from $cmd"
@@ -291,30 +306,26 @@ def generate_preferences(configuration_model)
291306
input "${it.@index}", "number",
292307
title:"${it.@label}\n" + "${it.Help}",
293308
range: "${it.@min}..${it.@max}",
294-
defaultValue: "${it.@value}",
295-
displayDuringSetup: "${it.@displayDuringSetup}"
309+
defaultValue: "${it.@value}"
296310
break
297311
case "list":
298312
def items = []
299313
it.Item.each { items << ["${it.@value}":"${it.@label}"] }
300314
input "${it.@index}", "enum",
301315
title:"${it.@label}\n" + "${it.Help}",
302316
defaultValue: "${it.@value}",
303-
displayDuringSetup: "${it.@displayDuringSetup}",
304317
options: items
305318
break
306319
case "decimal":
307320
input "${it.@index}", "decimal",
308321
title:"${it.@label}\n" + "${it.Help}",
309322
range: "${it.@min}..${it.@max}",
310-
defaultValue: "${it.@value}",
311-
displayDuringSetup: "${it.@displayDuringSetup}"
323+
defaultValue: "${it.@value}"
312324
break
313325
case "boolean":
314326
input "${it.@index}", "bool",
315327
title: it.@label != "" ? "${it.@label}\n" + "${it.Help}" : "" + "${it.Help}",
316-
defaultValue: "${it.@value}",
317-
displayDuringSetup: "${it.@displayDuringSetup}"
328+
defaultValue: "${it.@value}"
318329
break
319330
case "paragraph":
320331
input title: "${it.@label}",
@@ -393,16 +404,16 @@ def convertParam(number, value) {
393404
def parValue
394405
switch (number){
395406
case 28:
396-
parValue = (value == "true" ? 1 : 0)
397-
parValue += (settings."fc_2" == "true" ? 2 : 0)
398-
parValue += (settings."fc_3" == "true" ? 4 : 0)
399-
parValue += (settings."fc_4" == "true" ? 8 : 0)
407+
parValue = (value == true ? 1 : 0)
408+
parValue += (settings."fc_2" == true ? 2 : 0)
409+
parValue += (settings."fc_3" == true ? 4 : 0)
410+
parValue += (settings."fc_4" == true ? 8 : 0)
400411
break
401412
case 29:
402-
parValue = (value == "true" ? 1 : 0)
403-
parValue += (settings."sc_2" == "true" ? 2 : 0)
404-
parValue += (settings."sc_3" == "true" ? 4 : 0)
405-
parValue += (settings."sc_4" == "true" ? 8 : 0)
413+
parValue = (value == true ? 1 : 0)
414+
parValue += (settings."sc_2" == true ? 2 : 0)
415+
parValue += (settings."sc_3" == true ? 4 : 0)
416+
parValue += (settings."sc_4" == true ? 8 : 0)
406417
break
407418
default:
408419
parValue = value
@@ -462,27 +473,13 @@ def integer2Cmd(value, size) {
462473
}
463474
}
464475

465-
private command(hubitat.zwave.Command cmd) {
466-
467-
if (state.sec && cmd.toString() != "WakeUpIntervalGet()") {
468-
zwave.securityV1.securityMessageEncapsulation().encapsulate(cmd).format()
469-
} else {
470-
cmd.format()
471-
}
472-
}
473-
474-
private commands(commands, delay=1000) {
475-
delayBetween(commands.collect{ command(it) }, delay)
476-
}
477-
478476
def zwaveEvent(hubitat.zwave.commands.crc16encapv1.Crc16Encap cmd) {
479-
def versions = [0x31: 5, 0x30: 1, 0x9C: 1, 0x70: 2, 0x85: 2]
480-
def version = versions[cmd.commandClass as Integer]
481-
def ccObj = version ? zwave.commandClass(cmd.commandClass, version) : zwave.commandClass(cmd.commandClass)
482-
def encapsulatedCommand = ccObj?.command(cmd.command)?.parse(cmd.data)
483-
if (encapsulatedCommand) {
484-
zwaveEvent(encapsulatedCommand)
485-
}
477+
def encapsulatedCommand = zwave.getCommand(cmd.commandClass, cmd.command, cmd.data, 1)
478+
if (encapsulatedCommand) {
479+
zwaveEvent(encapsulatedCommand)
480+
} else {
481+
log.warn "Unable to extract CRC16 command from ${cmd}"
482+
}
486483
}
487484

488485
def configuration_model()
@@ -704,4 +701,4 @@ Momentary Mode
704701
</Value>
705702
</configuration>
706703
'''
707-
}
704+
}

0 commit comments

Comments
 (0)