-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathzigbeeTools.groupCluster0x0004.groovy
135 lines (120 loc) · 5.3 KB
/
zigbeeTools.groupCluster0x0004.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
library (
base: "driver",
author: "jvm33",
category: "zigbee",
description: "group Cluster 0x0004 Tools",
name: "groupCluster0x0004",
namespace: "zigbeeTools",
documentationLink: "https://github.com/jvmahon/Hubitat-Zigbee",
version: "0.5.0"
)
List<String> getGroupData(Map params = [:]){
Map inputs = [ep: null ] << params
// Groups can change, so treat as dynamic data
List<String> groups = getDataRecordForEndpoint(*:inputs, isDynamicData: true )
.get("groups", [])
return groups
}
// Used in the group responses to process the Get Group Membership Response Command, ZCL 3.6.2.4.3
List<String> clearGroupData(Map params = [:]){
Map inputs = [ep: null ] << params
// Groups can change, so treat as dynamic data
List<String> groups = getDataRecordForEndpoint(*:inputs, isDynamicData: true ).remove("groups")
return groups
}
void processSpecificResponse0x0104_0004(Map descMap) {
String ep = descMap.sourceEndpoint ?: descMap.endpoint
String status = descMap.data[0]
switch (descMap.command){
case "00" : //add group response, ZCL 3.6.2.4.1
if (status in ["00","8A"]) { // Status enumerations are in ZCL Table 2.6.3
group = descMap.data[1] + descMap.data[2]
if (group in getGroupData(ep:ep)) {
if (txtEnable) log.info "group membership refreshed"
} else {
getGroupData(ep:ep).add(group)
if (txtEnable) log.info "group membership added"
}
} else {
log.warn "${device.displayName}'s group table is full, unable to add group..."
}
break
case "01": // View Group Response, ZCL 3.6.2.4.2
log.warn "Received a View Group command that is not processed. This is generally harmless, but may want to add processing to display the group name: ${descMap.inspect()}"
break
case "02" : //group membership response. Does not include a "status", ZCL 3.6.2.4.3
Integer groupCount = hexStrToUnsignedInt(descMap.data[1])
if (groupCount == 0 && getGroupData(ep:ep) != []) {
List<String> cmds = []
getGroupData(ep:ep).each {
cmds.addAll(zigbee.command(0x0004,0x00,[[destEndpoint:ep]],0,"${it} 00")) // Add Group Command for group ${it} with "00" as name
if (txtEnable) log.warn "update group:${it} on device"
}
clearGroupData(ep:ep)
sendHubCommand(new hubitat.device.HubMultiAction(cmds, hubitat.device.Protocol.ZIGBEE))
} else {
//get groups and update groupData...
Integer crntByte = 0
for (int i = 0; i < groupCount; i++) {
crntByte = (i * 2) + 2
group = descMap.data[crntByte] + descMap.data[crntByte + 1]
if ( !(group in getGroupData(ep:ep)) ) {
getGroupData(ep:ep).add(group)
if (txtEnable) log.info "group added to global data storage list"
} else {
if (logEnable) log.debug "group already exists in global data storage list..."
}
}
}
break
case "03" : //remove group response, ZCL 3.6.2.4.4
if (status == "00") {
group = descMap.data[1] + descMap.data[2]
getGroupData(ep:ep).remove(group)
if (txtEnable) log.info "group membership ${group} removed"
}
break
default :
log.error "group command not handled:${descMap.inspect()}"
}
// state.deviceStaticData = getDataRecordByNetworkId(isDynamicData: false )
state.deviceDynamicData = getDataRecordByNetworkId(isDynamicData: true )
}
void processGlobalResponse0x0104_0004(Map descMap) {
assert ! (descMap.sourceEndpoint.is( null ) && descMap.endpoint.is (null) )
String ep = descMap.sourceEndpoint ?: descMap.endpoint
}
void processClusterResponse0x0104_0004(Map descMap) {
if (descMap.clusterInt != 0x0004) return
if(descMap.isClusterSpecific == true){
processSpecificResponse0x0104_0004(descMap) // Cluster Specific Commands
} else {
processGlobalResponse0x0104_0004(descMap) // Global Commands
}
}
void getGroupMembership(Map params = [:] ) {
Map inputs = [ep: null ] << params
if (logEnable) log.debug "Getting group membership with inputs: ${inputs}"
sendZCLAdvanced(
destinationEndpoint: (inputs.ep) ,
clusterId: "0004" ,
isClusterSpecific: true ,
commandId: 0x02, // Get Group membership command, ZCL 3.6.2.3.4, ZCL Table 3-37
commandPayload: "00", // Value of 00 gets all groups in whcih the device is a member. ZCL 3.6.2.3.4.1
)
}
void configure0x0104_0004(String ep = getEndpointId(device)) {
getGroupMembership(ep:ep)
}
void unbind0x0104_0004(String ep = getEndpointId(device)) {
String cmd = "zdo unbind 0x${device.deviceNetworkId} 0x${ep} 0x01 0x0004 {${device.zigbeeId}} {}"
if (logEnable) log.debug "Unbinding 0x0004: ${cmd}"
sendHubCommand(new hubitat.device.HubAction( cmd, hubitat.device.Protocol.ZIGBEE))
}
void initialize0x0104_0004(String ep = getEndpointId(device)) {
// configure0x0104_0004(ep)
refresh0x0104_0004(ep)
}
void refresh0x0104_0004(String ep = getEndpointId(device)) {
getGroupMembership(ep:ep)
}