From 65dbe69327b9f19a886d158fde93107696b14ed6 Mon Sep 17 00:00:00 2001 From: zoulianghui Date: Mon, 13 Jan 2020 20:05:58 +0800 Subject: [PATCH 1/4] fix automation issue --- .../zigbee-scene-keypad.groovy | 37 ++++++++++++++----- 1 file changed, 28 insertions(+), 9 deletions(-) mode change 100755 => 100644 devicetypes/smartthings/zigbee-scene-keypad.src/zigbee-scene-keypad.groovy diff --git a/devicetypes/smartthings/zigbee-scene-keypad.src/zigbee-scene-keypad.groovy b/devicetypes/smartthings/zigbee-scene-keypad.src/zigbee-scene-keypad.groovy old mode 100755 new mode 100644 index d4b29993aa2..20f359c6f39 --- a/devicetypes/smartthings/zigbee-scene-keypad.src/zigbee-scene-keypad.groovy +++ b/devicetypes/smartthings/zigbee-scene-keypad.src/zigbee-scene-keypad.groovy @@ -18,7 +18,7 @@ import groovy.json.JsonOutput import physicalgraph.zigbee.zcl.DataType metadata { - definition (name: "Zigbee Scene Keypad", namespace: "smartthings", author: "SmartThings", mcdSync: true) { + definition (name: "Zigbee Scene Keypad", namespace: "smartthings", author: "SmartThings", mcdSync: true, ocfDeviceType: "x.com.st.d.remotecontroller") { capability "Actuator" capability "Button" capability "Configuration" @@ -104,7 +104,16 @@ def installed() { if (!childDevices) { addChildButtons(numberOfButtons) } - sendEvent(name: "supportedButtonValues", value: ["pushed"]) + if(childDevices) { + def event + for(def endpoint : 1..device.currentValue("numberOfButtons")) { + event = createEvent(name: "button", value: "pushed", isStateChange: true) + sendEventToChild(endpoint, event) + } + } + + sendEvent(name: "button", value: "pushed", isStateChange: true, displayed: false) + sendEvent(name: "supportedButtonValues", value: supportedButtonValues.encodeAsJSON(), displayed: false) } def updated() { @@ -116,19 +125,29 @@ def initialize() { } private addChildButtons(numberOfButtons) { - for (def i : 2..numberOfButtons) { + for(def endpoint : 2..numberOfButtons) { try { - String childDni = "${device.deviceNetworkId}:$i" - def componentLabel = (device.displayName.endsWith(' 1') ? device.displayName[0..-2] : device.displayName) + "${i}" - addChildDevice("Child Button", "${device.deviceNetworkId}:${i}", device.hubId, - [completedSetup: true, label: "${device.displayName} button ${i}", - isComponent: true, componentName: "button$i", componentLabel: "Button $i"]) - } catch (Exception e) { + String childDni = "${device.deviceNetworkId}:$endpoint" + def componentLabel = (device.displayName.endsWith(' 1') ? device.displayName[0..-2] : device.displayName) + "${endpoint}" + def child = addChildDevice("Child Button", childDni, device.getHub().getId(), [ + completedSetup: true, + label : componentLabel, + isComponent : true, + componentName : "button$endpoint", + componentLabel: "Button $endpoint" + ]) + child.sendEvent(name: "supportedButtonValues", value: supportedButtonValues.encodeAsJSON(), displayed: false) + } catch(Exception e) { log.debug "Exception: ${e}" } } } +private getSupportedButtonValues() { + def values = ["pushed"] + return values +} + private getChildCount() { if (device.getDataValue("model") == "0106-G") { return 6 From 23973085cc50e37b796f444b796822e0336f39ea Mon Sep 17 00:00:00 2001 From: ZouLianghuiS Date: Tue, 14 Jan 2020 10:44:19 +0800 Subject: [PATCH 2/4] Update zigbee-scene-keypad.groovy --- .../zigbee-scene-keypad.groovy | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/devicetypes/smartthings/zigbee-scene-keypad.src/zigbee-scene-keypad.groovy b/devicetypes/smartthings/zigbee-scene-keypad.src/zigbee-scene-keypad.groovy index 20f359c6f39..da684f44ce2 100644 --- a/devicetypes/smartthings/zigbee-scene-keypad.src/zigbee-scene-keypad.groovy +++ b/devicetypes/smartthings/zigbee-scene-keypad.src/zigbee-scene-keypad.groovy @@ -104,9 +104,9 @@ def installed() { if (!childDevices) { addChildButtons(numberOfButtons) } - if(childDevices) { + if (childDevices) { def event - for(def endpoint : 1..device.currentValue("numberOfButtons")) { + for (def endpoint : 1..device.currentValue("numberOfButtons")) { event = createEvent(name: "button", value: "pushed", isStateChange: true) sendEventToChild(endpoint, event) } @@ -125,16 +125,16 @@ def initialize() { } private addChildButtons(numberOfButtons) { - for(def endpoint : 2..numberOfButtons) { + for (def endpoint : 2..numberOfButtons) { try { String childDni = "${device.deviceNetworkId}:$endpoint" - def componentLabel = (device.displayName.endsWith(' 1') ? device.displayName[0..-2] : device.displayName) + "${endpoint}" + def childLabel = (device.displayName.endsWith(' 1') ? device.displayName[0..-2] : device.displayName) + "${endpoint}" def child = addChildDevice("Child Button", childDni, device.getHub().getId(), [ completedSetup: true, - label : componentLabel, + label : childLabel, isComponent : true, componentName : "button$endpoint", - componentLabel: "Button $endpoint" + childLabel: "Button $endpoint" ]) child.sendEvent(name: "supportedButtonValues", value: supportedButtonValues.encodeAsJSON(), displayed: false) } catch(Exception e) { From e41e584d711bb6bf1003718c278885a5f21b86cd Mon Sep 17 00:00:00 2001 From: ZouLianghuiS Date: Tue, 14 Jan 2020 13:07:15 +0800 Subject: [PATCH 3/4] Update zigbee-scene-keypad.groovy --- .../zigbee-scene-keypad.src/zigbee-scene-keypad.groovy | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/devicetypes/smartthings/zigbee-scene-keypad.src/zigbee-scene-keypad.groovy b/devicetypes/smartthings/zigbee-scene-keypad.src/zigbee-scene-keypad.groovy index da684f44ce2..a335faf9c35 100644 --- a/devicetypes/smartthings/zigbee-scene-keypad.src/zigbee-scene-keypad.groovy +++ b/devicetypes/smartthings/zigbee-scene-keypad.src/zigbee-scene-keypad.groovy @@ -134,7 +134,7 @@ private addChildButtons(numberOfButtons) { label : childLabel, isComponent : true, componentName : "button$endpoint", - childLabel: "Button $endpoint" + componentLabel: "Button $endpoint" ]) child.sendEvent(name: "supportedButtonValues", value: supportedButtonValues.encodeAsJSON(), displayed: false) } catch(Exception e) { From cd066e84073155f3d17c7d7507cc3b0b2f64c88c Mon Sep 17 00:00:00 2001 From: ZouLianghuiS Date: Tue, 14 Jan 2020 13:11:17 +0800 Subject: [PATCH 4/4] Update zigbee-scene-keypad.groovy --- .../zigbee-scene-keypad.src/zigbee-scene-keypad.groovy | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/devicetypes/smartthings/zigbee-scene-keypad.src/zigbee-scene-keypad.groovy b/devicetypes/smartthings/zigbee-scene-keypad.src/zigbee-scene-keypad.groovy index a335faf9c35..a13bd588f1d 100644 --- a/devicetypes/smartthings/zigbee-scene-keypad.src/zigbee-scene-keypad.groovy +++ b/devicetypes/smartthings/zigbee-scene-keypad.src/zigbee-scene-keypad.groovy @@ -107,7 +107,7 @@ def installed() { if (childDevices) { def event for (def endpoint : 1..device.currentValue("numberOfButtons")) { - event = createEvent(name: "button", value: "pushed", isStateChange: true) + event = createEvent(name: "button", value: "pushed", isStateChange: true, displayed: false) sendEventToChild(endpoint, event) } }