-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmatterTools.modeSelectClusterMethods0x0050.groovy
56 lines (49 loc) · 2.44 KB
/
matterTools.modeSelectClusterMethods0x0050.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
/*
Reference: Matter Application Cluster Specification Version 1.2 ("Matter Cluster Spec"), Section 1.8 ("Mode Select Cluster")
*/
library (
base: "driver",
author: "jvm33",
category: "matter",
description: "mode Select Control Cluster 0x0050 Tools",
name: "modeSelectClusterMethods0x0050",
namespace: "matterTools",
documentationLink: "https://github.com/jvmahon/Hubitat-Matter",
version: "0.0.1"
)
import hubitat.helper.HexUtils
// Following functions implement Matter Spec 1.8.7 "ChangeToMode" command.
void changeToMode( Map params = [:] ) {
try {
Map inputs = [ep: null , mode: null] << params
assert inputs.ep instanceof Integer // Check that endpoint is an integer
assert inputs.mode instanceof Integer
String hexMode = HexUtils.integerToHexString((Integer) inputs.mode, 1)
List<Map<String, String>> fields = []
fields.add(matter.cmdField(DataType.UINT8, 0, hexMode)) // Mode
String cmd = matter.invoke(inputs.ep, 0x0050, 0x00, fields) // ChangeToMode
sendHubCommand(new hubitat.device.HubAction(cmd, hubitat.device.Protocol.MATTER))
} catch (AssertionError e) {
log.error "<pre>${e}<br><br>Stack trace:<br>${getStackTrace(e) }"
} catch(e){
log.error "<pre>${e}<br><br>when processing changeToMode with inputs ${inputs}<br><br>Stack trace:<br>${getStackTrace(e) }"
}
}
Map getModeSelectOptions(Integer ep){
getStoredAttributeData(endpointInt:ep, clusterInt:0x0050, attrInt:0x0002)?.collectEntries({[ (it[1]), (it[0]) ] })
}
Integer getModeSelectCurrentMode(Integer ep){
return getStoredAttributeData(endpointInt:ep, clusterInt:0x0050, attrInt:0x0003)
}
String getModeSelectLabel(Integer ep){
"<b>${getStoredAttributeData(endpointInt:ep, clusterInt:0x0050, attrInt:0x0000) ?: "Initialize Device then Refresh Browser"}</b>"
}
void handleModeSelectClusterUpdate(decodedDescriptionMap){
switch(decodedDescriptionMap.attrInt){
case 0x0003: // Current Mode
String settingsName = "ModeSelect_${decodedDescriptionMap.endpointInt}"
String newValue = "${decodedDescriptionMap.decodedValue}" // Hubitat oddity - all device.settings keys are strings, so newValue must be a number in string format, even though the index to menuItems was originally an Intger number
device.updateSetting(settingsName, [value:newValue, type:"enum"])
break
}
}