Repository navigation
Expand file tree
/
Copy pathcommand.html
More file actions
130 lines (125 loc) · 6.1 KB
/
Copy pathcommand.html
File metadata and controls
130 lines (125 loc) · 6.1 KB
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
<script type="text/javascript">
RED.nodes.registerType('mattercommand',{
category: 'Matter',
color: '#95cc95',
icon: "font-awesome/fa-arrow-circle-o-down",
inputs:1,
outputs:1,
defaults: {
name: {value:""},
controller: { value: "", type: "mattercontroller", required: true },
device: {value:"", required:true},
deviceType: {value:"matterDevice"},
deviceName: {value:""},
endpoint: {value:""},
cluster: {value:"", required:true},
clusterType: {value:"matterCluster"},
clusterName: {value:""},
command: {value:"", required:true},
commandType: {value:"matterCommand"},
data: {value:"{}"},
dataType: {value:""},
simpleMode: {value: "true"}
},
paletteLabel: "Command",
label: function() {
if (this.name) return this.name
if (this.deviceType === 'matterDevice' && isRealValue(this.deviceName) &&
this.commandType === 'matterCommand' && isRealValue(this.command))
return this.deviceName + ' | ' + this.command
return "Command"
},
oneditprepare: function() {
$('#node-input-data').typedInput({
types: ['json', 'msg', 'flow', 'global', 'jsonata', 'env'],
typeField: $('#node-input-dataType')
});
initTypedField('node-input-device', 'node-input-deviceType', this.device, this.deviceName, deviceTypeDef(null), deviceNameCache)
initTypedField('node-input-cluster', 'node-input-clusterType', this.cluster, this.clusterName, clusterTypeDef(null), clusterNameCache)
initTypedField('node-input-command', 'node-input-commandType', this.command, null, actionTypeDef('matterCommand', 'Command', null))
$('#refresh-devices').on("click", getDevicesTyped);
$('#refresh-clusters').on("click", getClustersTyped);
$('#refresh-commands').on("click", getCommandsTyped);
$('#refresh-sample').on("click", getCommandOpts);
bindRefreshVisibility('node-input-device', 'matterDevice', ['refresh-devices'])
bindRefreshVisibility('node-input-cluster', 'matterCluster', ['refresh-clusters'])
bindRefreshVisibility('node-input-command', 'matterCommand', ['refresh-commands', 'refresh-sample'])
},
oneditsave: function() {
if ($('#node-input-device').typedInput('type') === 'matterDevice') {
var v = $('#node-input-device').typedInput('value')
this.deviceName = deviceNameCache[v] || v
} else {
this.deviceName = ''
}
if ($('#node-input-cluster').typedInput('type') === 'matterCluster') {
var cv = $('#node-input-cluster').typedInput('value')
this.clusterName = clusterNameCache[cv] || cv
} else {
this.clusterName = ''
}
}
});
</script>
<script type="text/x-red" data-template-name="mattercommand">
<div class="form-row">
<label for="node-input-name"><i class="icon-tag"></i> Name</label>
<input type="text" id="node-input-name" placeholder="Name">
</div>
<div class="form-row">
<label for="node-input-controller">Controller</label>
<input type="text" id="node-input-controller" style="width:70%;">
</div>
<div class="form-row">
<label for="node-input-simpleMode">Simple Mode</label>
<input type="checkbox" id="node-input-simpleMode" value="true" >
</div>
<div class="form-row">
<label for="node-input-device">Device</label>
<input type="hidden" id="node-input-deviceType">
<input type="text" id="node-input-device" style="width:50%;">
<a id="refresh-devices" class="btn"><i class="fa fa-refresh"></i></a>
</div>
<div class="form-row">
<label for="node-input-cluster">Cluster</label>
<input type="hidden" id="node-input-clusterType">
<input type="text" id="node-input-cluster" style="width:50%;">
<a id="refresh-clusters" class="btn"><i class="fa fa-refresh"></i></a>
</div>
<div class="form-row">
<label for="node-input-command">Command</label>
<input type="hidden" id="node-input-commandType">
<input type="text" id="node-input-command" style="width:50%;">
<a id="refresh-commands" class="btn"><i class="fa fa-refresh"></i></a>
</div>
<div class="form-row">
<label for="node-input-data">Params</label>
<input type="hidden" id="node-input-dataType">
<input type="text" id="node-input-data">
<div class="form-tips" style="width:90%;">
<b>Sample Params</b>
<a id="refresh-sample" class="btn"><i class="fa fa-refresh"></i></a>
<pre id="sample-data"></pre>
</div>
</div>
</script>
<script type="text/x-red" data-help-name="mattercommand">
<p>Send a command to a Matter device.</p>
<h3>Device / Cluster / Command fields</h3>
<p>Each of these fields is a typed input. Choose the dropdown type to pick a
value fetched from the controller, or switch the type to <b>msg</b>, <b>flow</b>,
<b>global</b>, <b>env</b> or <b>JSONata</b> to supply the value at runtime (for
example type <b>msg</b> with <code>device</code> to read <code>msg.device</code>).
This lets a single node send different commands to different devices.</p>
<p>A device value is in <code>nodeId-endpoint</code> format (e.g.
<code>"1234-1"</code>); the cluster is a numeric cluster ID (e.g. <code>6</code>
for OnOff); the command is a command name (e.g. <code>"toggle"</code>).</p>
<p>Parameters for the command are set in the <b>Params</b> field, or fall back to
<code>msg.payload</code> when Params is left blank. Pass <code>{}</code> or
<code>null</code> for commands with no parameters.</p>
<h3>Output</h3>
<dl class="message-properties">
<dt>payload <span class="property-type">string</span></dt>
<dd><code>"ok"</code> on success.</dd>
</dl>
</script>