-
Notifications
You must be signed in to change notification settings - Fork 1
/
zwaveTools.endpointTools.groovy
119 lines (97 loc) · 4.18 KB
/
zwaveTools.endpointTools.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
library (
base: "driver",
author: "jvm33",
category: "zwave",
description: "Tools to Manage an Endpoint Data Record Functions",
name: "endpointTools",
namespace: "zwaveTools",
documentationLink: "https://github.com/jvmahon/HubitatDriverTools",
version: "0.0.1",
dependencies: "zwaveTools.globalDataTools",
librarySource:"https://raw.githubusercontent.com/jvmahon/HubitatDriverTools/main/endpointTools.groovy"
)
/*
classVersions:[44:1, 89:1, 37:1, 0:1, 122:1, 133:2, 112:1, 134:2, 114:1, 115:1, 90:1, 91:3, 50:3, 94:1, 32:1, 43:1],
endpoints:[
0:[ children:[[type:'Generic Component Motion Sensor', 'namespace':'hubitat', childName:"Motion Sensor"]],
classes:[80, 85, 89, 90, 94, 108, 112, 113, 114, 115, 122, 128, 133, 134, 135, 142, 159],
notificationsSupported:[7:[3, 8], 8:[1, 5], 9:[4, 5] ],
metersSupported:[0, 2, 4, 5],
],
*/
/*
Map getDeviceRecord() {
dataRecordByProductType.get("deviceRecord", new ConcurrentHashMap(8, 0.75, 1)) // from globalDataTools
}
*/
Map getFullEndpointRecord() {
dataRecordByProductType.get("endpoints", new ConcurrentHashMap(8, 0.75, 1)) // from globalDataTools
}
@groovy.transform.CompileStatic
Map getThisEndpointData(Integer ep) {
fullEndpointRecord.get((ep ?: 0), [:])
}
List<Integer> getThisEndpointClasses(Integer ep) {
List<Integer> rValue = getThisEndpointData((Integer) ep).get("classes", [])
// If they don't exist and its endpoint 0, create them from the inClusters and secureInClusters data.
if ( ((Integer)(ep ?: 0) == 0) && (rValue.size() == 0 ) ) {
rValue = (getDataValue("inClusters")?.split(",").collect{ (Integer) hexStrToUnsignedInt(it) }) + ( getDataValue("secureInClusters")?.split(",").collect{ (Integer) hexStrToUnsignedInt(it) })
}
return rValue
}
@groovy.transform.CompileStatic
Integer getEndpointCount(){
fullEndpointRecord.findAll({it.key != 0}).size() ?: 0
}
Map<Integer,List> getEndpointNotificationsSupported(Integer ep){
getThisEndpointData(ep).get("notificationsSupported", [:])
}
List<Integer> getEndpointMetersSupported( Integer ep = null ){
getThisEndpointData(ep).get("metersSupported", [])
}
// Get the endpoint number for a child device
@groovy.transform.CompileStatic
Integer getChildEndpointNumber(com.hubitat.app.DeviceWrapper thisChild) {
if (! thisChild) return 0
thisChild.deviceNetworkId.split("-ep")[-1] as Integer
}
// Get List (possibly multiple) child device for a specific endpoint. Child devices can also be of the form '-ep000'
// Child devices associated with the root device end in -ep000
List<com.hubitat.app.DeviceWrapper> getChildDeviceListByEndpoint( Integer ep ) {
childDevices.findAll{ getChildEndpointNumber(it) == (ep ?: 0) }
}
void sendEventToEndpoints(Map inputs)
{
Map params = [ event: null , ep: null , addRootToEndpoint0: true , alwaysSend: null ]
if (! (inputs.every{ k, v -> params.containsKey(k) } ) ) {
log.error "Error calling sendEventToEndpoints. Supported parameters are ${params.keySet()}. Function was called with parameters: ${inputs.keySet()}"
return
}
params << inputs << [ep: ((Integer)(params.ep ?: 0) )]
List<com.hubitat.app.DeviceWrapper> targetDevices = getChildDeviceListByEndpoint(params.ep)
if ((params.ep == 0) && (params.addRootToEndpoint0)) { targetDevices += device }
targetDevices.each {
if (it.hasAttribute(params.event.name) || params.alwaysSend?.contains(params.event.name) ) {
it.sendEvent(params.event)
}
}
}
void sendEventToAll(Map inputs)
{
Map params = [ event: null , addRootToEndpoint0: true , alwaysSend: null ]
if (! (inputs.every{ k, v -> params.containsKey(k) } ) ) {
log.error "Error calling sendEventToEndpoints. Supported parameters are ${params.keySet()}. Function was called with parameters: ${inputs.keySet()}"
return
}
params << inputs
(childDevices + device).each {
if (it.hasAttribute(params.event.name) || params.alwaysSend?.contains(params.event.name) ) {
it.sendEvent(params.event)
}
}
}
// Debugging Functions
void showEndpointlDataRecord() {
// Debugging function - shows the entire concurrent @Field 'global' data record for all devices using a particular driver
log.debug "Endpoint Data record is ${fullEndpointRecord.inspect()}."
}