-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmatterTools.OnOffClusterMethods0x0006.groovy
128 lines (109 loc) · 7.23 KB
/
matterTools.OnOffClusterMethods0x0006.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
/*
Reference: Matter Application Cluster Specification Version 1.2 ("Matter Cluster Spec"), Section 1.5 "On/Off Cluster"
Dependencies: Need to import the following
matterTools.endpointAndChildDeviceTools // needed for getEndpointIdInt() function if you have not defined your own!
Library also assumes that descMap also includes the endpoint as an integer (descMap.endpointIdInt).
This isn't part of the standard "descMap" parsing, but descMap can be augmented immediately after the parseDescriptionAsMap using
descMap = matter.parseDescriptionAsMap(description)
descMap.put("endpointInt", (Integer.parseInt(descMap.endpoint, 16)))
See matterTools.commonDriverMethods library for example
*/
library (
base: "driver",
author: "jvm33",
category: "matter",
description: "On Off Cluster 0x0006 Tools",
name: "OnOffClusterMethods0x0006",
namespace: "matterTools",
documentationLink: "https://github.com/jvmahon/Hubitat-Matter",
version: "0.0.1"
)
import hubitat.helper.HexUtils
Boolean supportsOffTimer(){
if (logEnable) log.debug "supportsOffTime function not fully implemented in matterTools.OnOffCluster0x0006. Defaults to 'true' as this is Mandatory in Lighting device types"
return true
}
// off implements Matter 1.2 Cluster Spec Section 1.5.7.1, Off command
void componentOff(com.hubitat.app.DeviceWrapper cd){ off(ep:getEndpointIdInt(cd)) } // "component" variant for legacy Generic Component child device driver support
void off( Map params = [:] ){
try {
Map inputs = [ ep:getEndpointIdInt(device) ] << params
assert inputs.ep instanceof Integer // Use Integer, not Hex!
sendHubCommand(new hubitat.device.HubAction(matter.invoke(inputs.ep, 0x0006, 0x00), hubitat.device.Protocol.MATTER))
} catch (AssertionError e) {
log.error "Incorrect parameter type or value used in off() method.<br><pre>${e}<br><br>Stack trace:<br>${getStackTrace(e) }"
} catch(e){
log.error "<pre>${e}<br><br>when processing off with inputs ${inputs}<br><br>Stack trace:<br>${getStackTrace(e) }"
}
}
// on implements Matter 1.2 Cluster Spec Section 1.5.7.2, On command
void componentOn(com.hubitat.app.DeviceWrapper cd){ on( ep:getEndpointIdInt(cd)) } // "component" variant for legacy Generic Component child device driver support
void on( Map params = [:] ){
try {
Map inputs = [ ep:getEndpointIdInt(device)] << params
assert inputs.ep instanceof Integer // Use Integer, not Hex!
sendHubCommand(new hubitat.device.HubAction(matter.invoke(inputs.ep, 0x0006, 0x01 ), hubitat.device.Protocol.MATTER))
} catch (AssertionError e) {
log.error "Incorrect parameter type or value used in on() method.<br><pre>${e}<br><br>Stack trace:<br>${getStackTrace(e) }"
} catch(e){
log.error "<pre>${e}<br><br>when processing on with inputs ${inputs}<br><br>Stack trace:<br>${getStackTrace(e) }"
}
}
// toggleOnOff implements Matter 1.2 Cluster Spec Section 1.5.7.3, Toggle command
// Omission of a "component" version is intentional since it is not needed for legacy Generic Child driver support
// child device drivers can directly call the named parameter function supplying its endpoint in the call.
void toggleOnOff( Map params = [:] ){
try {
Map inputs = [ ep:getEndpointIdInt(device)] << params
assert inputs.ep instanceof Integer // Use Integer, not Hex!
sendHubCommand(new hubitat.device.HubAction(matter.invoke(inputs.ep, 0x0006, 0x02), hubitat.device.Protocol.MATTER))
} catch (AssertionError e) {
log.error "Incorrect parameter type or value used in toggleOnOff() method.<br><pre>${e}<br><br>Stack trace:<br>${getStackTrace(e) }"
} catch(e){
log.error "<pre>${e}<br><br>when processing toggleOnOff with inputs ${inputs}<br><br>Stack trace:<br>${getStackTrace(e) }"
}
}
//offWithEffect implements Matter 1.2 Cluster Spec Section 1.5.7.4, OffWithEffect command
// Omission of a "component" version is intentional since it is not needed for legacy Generic Child driver support
// child device drivers can directly call the named parameter function supplying its endpoint in the call.
void offWithEffect( Map params = [:] ){
try {
Map inputs = [ ep: getEndpointIdInt(device), effectIdentifier: 0, effectVariant:0] << params
assert inputs.ep instanceof Integer // Use Integer, not Hex!
assert inputs.effectIdentifier instanceof Integer && (0..1).contains(inputs.effectIdentifier)
assert (inputs.effectVariant instanceof Integer) && (0..2).contains(inputs.effectVariant )
List<Map<String, String>> fields = []
fields.add(matter.cmdField(DataType.UINT8, 0, HexUtils.integerToHexString(inputs.effectIdentifier, 1) )) // effectIdentifier
fields.add(matter.cmdField(DataType.UINT16, 1, HexUtils.integerToHexString(inputs.effectVariant , 1) )) // effectVariant
String cmd = matter.invoke(inputs.ep, 0x0006, 0x40, fields)
sendHubCommand(new hubitat.device.HubAction(cmd, hubitat.device.Protocol.MATTER))
} catch (AssertionError e) {
log.error "Incorrect parameter type or value used in offWithEffect() method.<br><pre>${e}<br><br>Stack trace:<br>${getStackTrace(e) }"
} catch(e){
log.error "<pre>${e}<br><br>when processing offWithEffect with inputs ${inputs}<br><br>Stack trace:<br>${getStackTrace(e) }"
}
}
//onWithTimedOff implements Matter 1.2 Cluster Spec Section 1.5.7.6, OnWithTimedOff command
// Omission of a "component" version is intentional since it is not needed for legacy Generic Child driver support
// child device drivers can directly call the named parameter function supplying its endpoint in the call.
void onWithTimedOff( Map params = [:] ){
try {
Map inputs = [ ep: getEndpointIdInt(device), onTime10ths: 10, offWaitTime10ths:0] << params
assert inputs.ep instanceof Integer // Use Integer, not Hex!
assert inputs.onTime10ths instanceof Integer
assert inputs.offWaitTime10ths instanceof Integer // Doesn't seem to do anything!
String hexOnTime10ths = HexUtils.integerToHexString(inputs.onTime10ths, 2)
String hexOffWaitTime10ths = HexUtils.integerToHexString(inputs.offWaitTime10ths, 2)
List<Map<String, String>> fields = []
fields.add(matter.cmdField(DataType.UINT8, 0, "00")) // OnOffControlBitmap
fields.add(matter.cmdField(DataType.UINT16, 1, (hexOnTime10ths[2..3] + hexOnTime10ths[0..1]) )) // OnTime, byte swapped
fields.add(matter.cmdField(DataType.UINT16, 2, (hexOffWaitTime10ths[2..3] + hexOffWaitTime10ths[0..1]) )) // OffWaitTime - guarded wait time, byte swapped
String cmd = matter.invoke(inputs.ep, 0x0006, 0x42, fields)
if (logEnable) log.debug "${device.displayName}: Turning on timed Off using parameters ${inputs}"
sendHubCommand(new hubitat.device.HubAction(cmd, hubitat.device.Protocol.MATTER))
} catch (AssertionError e) {
log.error "Incorrect parameter type or value used in onWithTimedOff() method.<br><pre>${e}<br><br>Stack trace:<br>${getStackTrace(e) }"
} catch(e){
log.error "<pre>${e}<br><br>when processing onWithTimedOff with inputs ${inputs}<br><br>Stack trace:<br>${getStackTrace(e) }"
}
}