forked from tedstriker/node-red-contrib-homekit
-
Notifications
You must be signed in to change notification settings - Fork 1
/
homekit.html
206 lines (195 loc) · 7.86 KB
/
homekit.html
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
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
<script type="text/x-red" data-template-name="homekit-service">
<div class="form-row">
<label for="node-input-accessory">
<i class="fa fa-rocket"></i>
Accessory</label>
<input id="node-input-accessory">
</div>
<div class="form-row">
<label for="node-input-serviceName">
<i class="fa fa-cog"></i>
Service</label>
<select id="node-input-serviceName">
<option value="">Choose...</option>
</select>
</div>
<div class="form-row">
<label for="node-input-name">
<i class="fa fa-tag"></i>
Name</label>
<input type="text" id="node-input-name" placeholder="Name">
</div>
</script>
<script type="text/x-red" data-help-name="homekit-service">
<h3 id="toc_5">Service</h3>
<p>The Service nodes add functionality to your Accessories. You can assign multiple Services to one Accessory. </p>
<ul>
<li><strong>Accessory</strong>: What Accessory this Service is for.</li>
<li><strong>Service</strong>: Choose the type of Service from the list.</li>
<li><strong>Name</strong>: <em>optional</em></li>
</ul>
<h2 id="toc_6">Input Messages</h2>
<p>Input messages can be used to update any <em>Characteristic</em> that the selected <em>Service</em> provides. Simply pass the values-to-update as <code>msg.payload</code> object. </p>
<p><strong>Example</strong>: to signal that an <em>Outlet</em> is turned on and in use, send the following payload</p>
<div><pre><code class="language-javascript">{
"On": 1,
"OutletInUse": 1
}</code></pre></div>
<p><strong>Hint</strong>: to find out what <em>Characteristics</em> you can address, just send <code>{"foo":"bar"}</code> and watch the debug tab ;)</p>
<h2 id="toc_7">Output Messages</h2>
<p>Output messages are in the same format as input messages. They are emitted from the node when it receives <em>Characteristics</em> updates from a paired iOS device.</p>
</script>
<script type="text/x-red" data-template-name="homekit-accessory">
<div class="form-row">
<label for="node-config-input-pinCode"><i class="fa fa-lock"></i> Pin Code</label>
<input type="text" id="node-config-input-pinCode" placeholder="xxx-xx-xxx">
</div>
<div class="form-row">
<label for="node-config-input-port"><i class="fa fa-plug"></i> Port</label>
<input type="text" id="node-config-input-port" placeholder="Leave blank to auto assign">
</div>
<div class="form-row">
<label for="node-config-input-manufacturer"><i class="fa fa-wrench"></i> Manufacturer</label>
<input type="text" id="node-config-input-manufacturer" placeholder="Manufacturer">
</div>
<div class="form-row">
<label for="node-config-input-serialNo"><i class="fa fa-wrench"></i> Serial Number</label>
<input type="text" id="node-config-input-serialNo" placeholder="Serial Number">
</div>
<div class="form-row">
<label for="node-config-input-model"><i class="fa fa-wrench"></i> Model</label>
<input type="text" id="node-config-input-model" placeholder="Model">
</div>
<div class="form-row">
<label for="node-config-input-accessoryType">
<i class="fa fa-cog"></i>
Type</label>
<select id="node-config-input-accessoryType">
</select>
</div>
<div class="form-row">
<label for="node-config-input-accessoryName"><i class="fa fa-tag"></i> Name</label>
<input type="text" id="node-config-input-accessoryName" placeholder="Name">
</div>
</script>
<script type="text/x-red" data-help-name="homekit-accessory">
<h3 id="toc_4">Accessory</h3>
<p>The Accessory node is a configuration node, specifying the <em>device</em> that iOS sees. </p>
<ul>
<li><strong>Pin Code</strong>: Specify the Pin for the pairing process.</li>
<li><strong>Port</strong>: If you are behind a Firewall, you may want to specify a port. Otherwise leave empty.</li>
<li><strong>Manufacturer, Model, Serial Number</strong>: Can be anything you want.</li>
<li><strong>Name</strong>: If you intend to simulate a rocket, then why don't you call it <em>Rocket</em>.</li>
<li><strong>Type</strong>: A hint to iOS clients, so that for instance an appropriate icon can be drawn.</li>
</ul>
<p><em>Bridged Accessories</em> are not supported at the moment.</p>
</script>
<script type="text/javascript">
var serviceTypes
//HomeKitServiceTypes
$.getJSON('homekit/service/types', function(data) {
serviceTypes = data
});
RED.nodes.registerType('homekit-service', {
category: 'advanced',
paletteLabel: 'homekit',
defaults: {
accessory: {
value: "",
type: "homekit-accessory",
required: true
},
name: {
value: ""
},
serviceName: {
value: "",
required: true
}
},
inputs: 1,
outputs: 1,
icon: "homekit.png",
color: "#fcc127",
label: function() {
return this.name || this.serviceName || "Service";
},
labelStyle: function() {
return this.name ? "node_label_italic" : "";
},
oneditprepare: function() {
var node = this;
var selectField = $("#node-input-serviceName")
for (var key in serviceTypes) {
selectField.append($("<option></option>").val(key).text(key));
}
selectField.find("option").filter(function() {
return $(this).val() == node.serviceName;
}).attr('selected', true);
selectField.change();
},
oneditsave: function() {
this.serviceName = $("node-input-serviceName option:selected").val();
}
});
</script>
<script type="text/javascript">
var accessoryTypes
//HomeKitAccessoryTypes
$.getJSON('homekit/accessory/types', function(data) {
accessoryTypes = data
});
RED.nodes.registerType('homekit-accessory', {
category: 'config',
defaults: {
accessoryName: {
value: "",
required: true
},
pinCode: {
value: "111-11-111",
required: true,
validate: RED.validators.regex(/[0-9]{3}-[0-9]{2}-[0-9]{3}/)
},
port: {
//validate:RED.validators.number()
},
manufacturer: {
value: "Default Manufacturer",
required: true
},
model: {
value: "Default Model",
required: true
},
serialNo: {
value: "Default Serial Number",
required: true
},
accessoryType: {
value: 1, // Default Category "OTHER"
required: false
}
},
label: function() {
return this.accessoryName || this.accessoryType || "Accessory";
},
labelStyle: function() {
return this.accessoryName ? "node_label_italic" : "";
},
oneditprepare: function() {
var node = this;
var selectField = $("#node-config-input-accessoryType")
for (var key in accessoryTypes) {
selectField.append($("<option></option>").val(accessoryTypes[key]).text(key));
}
selectField.find("option").filter(function() {
return $(this).val() == node.accessoryType;
}).attr('selected', true);
selectField.change();
},
oneditsave: function() {
this.accessoryType = $("node-config-input-accessoryType option:selected").val();
}
});
</script>