Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 28 additions & 9 deletions devicetypes/smartthings/zigbee-scene-keypad.src/zigbee-scene-keypad.groovy
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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, displayed: false)
sendEventToChild(endpoint, event)
}
}

sendEvent(name: "button", value: "pushed", isStateChange: true, displayed: false)
sendEvent(name: "supportedButtonValues", value: supportedButtonValues.encodeAsJSON(), displayed: false)
}

def updated() {
Expand All @@ -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 childLabel = (device.displayName.endsWith(' 1') ? device.displayName[0..-2] : device.displayName) + "${endpoint}"
def child = addChildDevice("Child Button", childDni, device.getHub().getId(), [
completedSetup: true,
label : childLabel,
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
Expand Down