homebridge-philips-hue-sync-box 0.7.3 → 0.8.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +11 -1
- package/config.schema.json +10 -0
- package/package.json +1 -1
- package/src/philips-hue-sync-box-platform.js +4 -2
- package/src/sync-box-device.js +158 -54
package/README.md
CHANGED
|
@@ -2,10 +2,13 @@
|
|
|
2
2
|
|
|
3
3
|
Homebridge plugin for the Philips Hue Sync Box.
|
|
4
4
|
|
|
5
|
-
The Sync Box
|
|
5
|
+
The Sync Box can be exposed as a lightbulb. The following features are supported:
|
|
6
6
|
* On/Off
|
|
7
7
|
* Brightness
|
|
8
8
|
|
|
9
|
+
The Sync Box can be exposed as a switch. The following features are supported:
|
|
10
|
+
* On/Off
|
|
11
|
+
|
|
9
12
|
You can also enable additional TV accessories that support:
|
|
10
13
|
* Switching HDMI inputs
|
|
11
14
|
* Switching modes
|
|
@@ -33,6 +36,10 @@ You have to create new credentials to communicate with the Philips Hue Sync Box:
|
|
|
33
36
|
* Immediately make the request again
|
|
34
37
|
* The response contains an `accessToken` string
|
|
35
38
|
|
|
39
|
+
Hints:
|
|
40
|
+
* One way to do this is to enter the following into the Terminal: `curl -H "Content-Type: application/json" -X POST -d '{"appName": "homebridge", "appSecret":"MDAwMTExMDAwMTExMDAwMTExMDAwMTExMDAwMTExMDA=", "instanceName": "homebridge"}' https://<SYNC-BOX-IP>/api/v1/registrations`, replacing `<SYNC-BOX-IP>` with the IP address of your Sync Box. If an issue occurs due to a certificate error, add the parameter `-k` to the cURL command.
|
|
41
|
+
* Another way may be to use tools like **Postman**. Set the request method to `POST` and enter `https://<SYNC-BOX-IP>/api/v1/registrations` as the request URL (replace `<SYNC-BOX-IP>` with the IP address of your Sync Box). Next, open the tab "Body", set the type to "raw" and select "JSON" as the content type in the dropdown. Then, enter `{ "appName": "homebridge", "appSecret": "MDAwMTExMDAwMTExMDAwMTExMDAwMTExMDAwMTExMDA=", "instanceName": "homebridge" }` into the text box for the body. Click on the "Send" button at the top right to send the request. If an issue occurs due to a certificate error, you can disable certificate verification in Postman. Go to the global settings, open the tab "General" and disable the toggle switch for "SSL certificate verification".
|
|
42
|
+
|
|
36
43
|
## Configuration
|
|
37
44
|
|
|
38
45
|
```json
|
|
@@ -44,6 +51,7 @@ You have to create new credentials to communicate with the Philips Hue Sync Box:
|
|
|
44
51
|
"syncBoxApiAccessToken": "<ACCESS-TOKEN>",
|
|
45
52
|
"defaultOnMode": "video",
|
|
46
53
|
"defaultOffMode": "passthrough",
|
|
54
|
+
"baseAccessory": "lightbulb",
|
|
47
55
|
"tvAccessory": false,
|
|
48
56
|
"tvAccessoryType": "tv",
|
|
49
57
|
"modeTvAccessory": false,
|
|
@@ -66,6 +74,8 @@ You have to create new credentials to communicate with the Philips Hue Sync Box:
|
|
|
66
74
|
|
|
67
75
|
**defaultOffMode** (optional): The mode that is used when switching the Sync Box off via HomeKit. Defaults to `passthrough`. Possible values are `powersave` or `passthrough`.
|
|
68
76
|
|
|
77
|
+
**baseAccessory** (optional): Determines the type of the base accessory for the Sync Box. Defaults to `lightbulb`. Possible values are `lightbulb`, `switch` or `none`. If `none` is used, no base accessory is exposed.
|
|
78
|
+
|
|
69
79
|
**tvAccessory** (optional): Enables a TV Accessory for switching the inputs of the Sync Box. Defaults to `false`.
|
|
70
80
|
|
|
71
81
|
**tvAccessoryType** (optional): Type of icon that the Apple Home app should show. Possible values are `tv`, `settopbox`, `tvstick` or `audioreceiver`. Defaults to `tv`.
|
package/config.schema.json
CHANGED
|
@@ -33,6 +33,16 @@
|
|
|
33
33
|
"placeholder": "passthrough",
|
|
34
34
|
"description": "The mode that is used when switching the Sync Box off via HomeKit. Possible values are 'powersave' or 'passthrough'."
|
|
35
35
|
},
|
|
36
|
+
"baseAccessory": {
|
|
37
|
+
"title": "Base Accessory Type",
|
|
38
|
+
"type": "string",
|
|
39
|
+
"default": "Lightbulb",
|
|
40
|
+
"oneOf": [
|
|
41
|
+
{ "title": "Lightbulb", "enum": ["lightbulb"] },
|
|
42
|
+
{ "title": "Switch", "enum": ["switch"] },
|
|
43
|
+
{ "title": "None", "enum": ["none"] }
|
|
44
|
+
]
|
|
45
|
+
},
|
|
36
46
|
"tvAccessory": {
|
|
37
47
|
"title": "Enable HDMI TV",
|
|
38
48
|
"type": "boolean",
|
package/package.json
CHANGED
|
@@ -38,7 +38,9 @@ function PhilipsHueSyncBoxPlatform(log, config, api) {
|
|
|
38
38
|
// Initializes the configuration
|
|
39
39
|
platform.config.syncBoxIpAddress = platform.config.syncBoxIpAddress || null;
|
|
40
40
|
platform.config.syncBoxApiAccessToken = platform.config.syncBoxApiAccessToken || null;
|
|
41
|
-
platform.config.
|
|
41
|
+
platform.config.defaultOnMode = platform.config.defaultOnMode || 'video';
|
|
42
|
+
platform.config.defaultOffMode = platform.config.defaultOffMode || 'passthrough';
|
|
43
|
+
platform.config.baseAccessory = platform.config.baseAccessory || 'lightbulb';
|
|
42
44
|
platform.config.isApiEnabled = platform.config.isApiEnabled || false;
|
|
43
45
|
platform.config.apiPort = platform.config.apiPort || 40220;
|
|
44
46
|
platform.config.apiToken = platform.config.apiToken || null;
|
|
@@ -68,7 +70,7 @@ function PhilipsHueSyncBoxPlatform(log, config, api) {
|
|
|
68
70
|
platform.api = api;
|
|
69
71
|
|
|
70
72
|
// Checks if all required information is provided
|
|
71
|
-
if (!platform.config.syncBoxIpAddress ||
|
|
73
|
+
if (!platform.config.syncBoxIpAddress || !platform.config.syncBoxApiAccessToken) {
|
|
72
74
|
platform.log('No Sync Box IP address or access token provided.');
|
|
73
75
|
return;
|
|
74
76
|
}
|
package/src/sync-box-device.js
CHANGED
|
@@ -20,17 +20,41 @@ function SyncBoxDevice(platform, state) {
|
|
|
20
20
|
let newDeviceAccessories = [];
|
|
21
21
|
let deviceAccessories = [];
|
|
22
22
|
|
|
23
|
+
let mainAccessory;
|
|
24
|
+
|
|
23
25
|
// Gets the main light bulb accessory
|
|
24
|
-
let lightBulbAccessory
|
|
25
|
-
if
|
|
26
|
-
unusedDeviceAccessories.
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
26
|
+
let lightBulbAccessory;
|
|
27
|
+
if(platform.config.baseAccessory === 'lightbulb') {
|
|
28
|
+
lightBulbAccessory = unusedDeviceAccessories.find(function (a) { return a.context.kind === 'LightBulbAccessory'; });
|
|
29
|
+
if (lightBulbAccessory) {
|
|
30
|
+
unusedDeviceAccessories.splice(unusedDeviceAccessories.indexOf(lightBulbAccessory), 1);
|
|
31
|
+
} else {
|
|
32
|
+
platform.log('Adding new accessory with kind LightBulbAccessory.');
|
|
33
|
+
lightBulbAccessory = new Accessory(state.device.name, UUIDGen.generate('LightBulbAccessory'));
|
|
34
|
+
lightBulbAccessory.context.kind = 'LightBulbAccessory';
|
|
35
|
+
newDeviceAccessories.push(lightBulbAccessory);
|
|
36
|
+
}
|
|
37
|
+
deviceAccessories.push(lightBulbAccessory);
|
|
38
|
+
|
|
39
|
+
mainAccessory = lightBulbAccessory;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
// Gets the main switch accessory
|
|
43
|
+
let switchAccessory;
|
|
44
|
+
if(platform.config.baseAccessory === 'switch') {
|
|
45
|
+
switchAccessory = unusedDeviceAccessories.find(function (a) { return a.context.kind === 'SwitchAccessory'; });
|
|
46
|
+
if (switchAccessory) {
|
|
47
|
+
unusedDeviceAccessories.splice(unusedDeviceAccessories.indexOf(switchAccessory), 1);
|
|
48
|
+
} else {
|
|
49
|
+
platform.log('Adding new accessory with kind SwitchAccessory.');
|
|
50
|
+
switchAccessory = new Accessory(state.device.name, UUIDGen.generate('SwitchAccessory'));
|
|
51
|
+
switchAccessory.context.kind = 'SwitchAccessory';
|
|
52
|
+
newDeviceAccessories.push(switchAccessory);
|
|
53
|
+
}
|
|
54
|
+
deviceAccessories.push(switchAccessory);
|
|
55
|
+
|
|
56
|
+
mainAccessory = switchAccessory;
|
|
32
57
|
}
|
|
33
|
-
deviceAccessories.push(lightBulbAccessory);
|
|
34
58
|
|
|
35
59
|
// Gets the tv accessory
|
|
36
60
|
let tvAccessory;
|
|
@@ -139,55 +163,100 @@ function SyncBoxDevice(platform, state) {
|
|
|
139
163
|
}
|
|
140
164
|
}
|
|
141
165
|
|
|
142
|
-
//
|
|
143
|
-
|
|
144
|
-
if (!lightBulbService) {
|
|
145
|
-
lightBulbService = lightBulbAccessory.addService(Service.Lightbulb);
|
|
146
|
-
}
|
|
166
|
+
// Handles the lightbulb accessory if it is enabled
|
|
167
|
+
if (lightBulbAccessory) {
|
|
147
168
|
|
|
148
|
-
|
|
149
|
-
|
|
169
|
+
// Updates the light bulb service
|
|
170
|
+
let lightBulbService = lightBulbAccessory.getServiceByUUIDAndSubType(Service.Lightbulb);
|
|
171
|
+
if (!lightBulbService) {
|
|
172
|
+
lightBulbService = lightBulbAccessory.addService(Service.Lightbulb);
|
|
173
|
+
}
|
|
150
174
|
|
|
151
|
-
|
|
152
|
-
|
|
175
|
+
// Stores the light bulb service
|
|
176
|
+
device.lightBulbService = lightBulbService;
|
|
153
177
|
|
|
154
|
-
//
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
if (
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
178
|
+
// Subscribes for changes of the on characteristic
|
|
179
|
+
lightBulbService.getCharacteristic(Characteristic.On).on('set', function (value, callback) {
|
|
180
|
+
|
|
181
|
+
// Saves the changes
|
|
182
|
+
if (value) {
|
|
183
|
+
platform.log.debug('Switch state to ON');
|
|
184
|
+
let onMode = platform.config.defaultOnMode;
|
|
185
|
+
if (onMode === 'lastSyncMode') {
|
|
186
|
+
if (device.state && device.state.execution && device.state.execution.lastSyncMode) {
|
|
187
|
+
onMode = device.state.execution.lastSyncMode;
|
|
188
|
+
} else {
|
|
189
|
+
onMode = 'video';
|
|
190
|
+
}
|
|
163
191
|
}
|
|
192
|
+
platform.limiter.schedule(function () { return platform.client.updateExecution({ 'mode': onMode }); }).then(function () { }, function () {
|
|
193
|
+
platform.log('Failed to switch state to ON');
|
|
194
|
+
});
|
|
195
|
+
} else {
|
|
196
|
+
platform.log.debug('Switch state to OFF');
|
|
197
|
+
platform.limiter.schedule(function () { return platform.client.updateExecution({ 'mode': platform.config.defaultOffMode }); }).then(function () { }, function () {
|
|
198
|
+
platform.log('Failed to switch state to OFF');
|
|
199
|
+
});
|
|
164
200
|
}
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
}
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
201
|
+
|
|
202
|
+
// Performs the callback
|
|
203
|
+
callback(null);
|
|
204
|
+
});
|
|
205
|
+
|
|
206
|
+
// Subscribes for changes of the brightness characteristic
|
|
207
|
+
lightBulbService.getCharacteristic(Characteristic.Brightness).on('set', function (value, callback) {
|
|
208
|
+
|
|
209
|
+
// Saves the changes
|
|
210
|
+
platform.log.debug('Switch brightness to ' + value);
|
|
211
|
+
platform.limiter.schedule(function () { return platform.client.updateExecution({ 'brightness': Math.round((value / 100.0) * 200) }); }).then(function () { }, function () {
|
|
212
|
+
platform.log('Failed to switch brightness to ' + value);
|
|
172
213
|
});
|
|
214
|
+
|
|
215
|
+
// Performs the callback
|
|
216
|
+
callback(null);
|
|
217
|
+
});
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
// Handles the switch accessory if it is enabled
|
|
221
|
+
if (switchAccessory) {
|
|
222
|
+
|
|
223
|
+
// Updates the switch service
|
|
224
|
+
let switchService = switchAccessory.getServiceByUUIDAndSubType(Service.Switch);
|
|
225
|
+
if (!switchService) {
|
|
226
|
+
switchService = switchAccessory.addService(Service.Switch);
|
|
173
227
|
}
|
|
174
228
|
|
|
175
|
-
//
|
|
176
|
-
|
|
177
|
-
});
|
|
229
|
+
// Stores the switch service
|
|
230
|
+
device.switchService = switchService;
|
|
178
231
|
|
|
179
|
-
|
|
180
|
-
|
|
232
|
+
// Subscribes for changes of the on characteristic
|
|
233
|
+
switchService.getCharacteristic(Characteristic.On).on('set', function (value, callback) {
|
|
181
234
|
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
235
|
+
// Saves the changes
|
|
236
|
+
if (value) {
|
|
237
|
+
platform.log.debug('Switch state to ON');
|
|
238
|
+
let onMode = platform.config.defaultOnMode;
|
|
239
|
+
if (onMode === 'lastSyncMode') {
|
|
240
|
+
if (device.state && device.state.execution && device.state.execution.lastSyncMode) {
|
|
241
|
+
onMode = device.state.execution.lastSyncMode;
|
|
242
|
+
} else {
|
|
243
|
+
onMode = 'video';
|
|
244
|
+
}
|
|
245
|
+
}
|
|
246
|
+
platform.limiter.schedule(function () { return platform.client.updateExecution({ 'mode': onMode }); }).then(function () { }, function () {
|
|
247
|
+
platform.log('Failed to switch state to ON');
|
|
248
|
+
});
|
|
249
|
+
} else {
|
|
250
|
+
platform.log.debug('Switch state to OFF');
|
|
251
|
+
platform.limiter.schedule(function () { return platform.client.updateExecution({ 'mode': platform.config.defaultOffMode }); }).then(function () { }, function () {
|
|
252
|
+
platform.log('Failed to switch state to OFF');
|
|
253
|
+
});
|
|
254
|
+
}
|
|
187
255
|
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
256
|
+
// Performs the callback
|
|
257
|
+
callback(null);
|
|
258
|
+
});
|
|
259
|
+
}
|
|
191
260
|
|
|
192
261
|
// Handles the TV accessory if it is enabled
|
|
193
262
|
if(tvAccessory) {
|
|
@@ -198,7 +267,15 @@ function SyncBoxDevice(platform, state) {
|
|
|
198
267
|
tvService = tvAccessory.addService(Service.Television);
|
|
199
268
|
|
|
200
269
|
// Sets the TV name
|
|
201
|
-
|
|
270
|
+
if (mainAccessory) {
|
|
271
|
+
tvService.setCharacteristic(Characteristic.ConfiguredName, mainAccessory.context.tvAccessoryConfiguredName || state.device.name);
|
|
272
|
+
tvService.getCharacteristic(Characteristic.ConfiguredName).on('set', function (value, callback) {
|
|
273
|
+
mainAccessory.context.tvAccessoryConfiguredName = value;
|
|
274
|
+
callback(null);
|
|
275
|
+
});
|
|
276
|
+
} else {
|
|
277
|
+
tvService.setCharacteristic(Characteristic.ConfiguredName, state.device.name);
|
|
278
|
+
}
|
|
202
279
|
}
|
|
203
280
|
|
|
204
281
|
// Register HDMI sources
|
|
@@ -209,8 +286,11 @@ function SyncBoxDevice(platform, state) {
|
|
|
209
286
|
hdmiInputService = tvAccessory.addService(Service.InputSource, 'hdmi' + i, 'HDMI ' + i);
|
|
210
287
|
|
|
211
288
|
// Sets the TV name
|
|
289
|
+
const hdmiState = state.hdmi['input' + i];
|
|
290
|
+
const hdmiName = hdmiState.name || ('HDMI ' + i);
|
|
291
|
+
|
|
212
292
|
hdmiInputService
|
|
213
|
-
.setCharacteristic(Characteristic.ConfiguredName,
|
|
293
|
+
.setCharacteristic(Characteristic.ConfiguredName, hdmiName)
|
|
214
294
|
.setCharacteristic(Characteristic.IsConfigured, Characteristic.IsConfigured.CONFIGURED)
|
|
215
295
|
.setCharacteristic(Characteristic.CurrentVisibilityState, Characteristic.CurrentVisibilityState.SHOWN)
|
|
216
296
|
.setCharacteristic(Characteristic.TargetVisibilityState, Characteristic.TargetVisibilityState.SHOWN);
|
|
@@ -224,7 +304,7 @@ function SyncBoxDevice(platform, state) {
|
|
|
224
304
|
hdmiInputServices.push(hdmiInputService);
|
|
225
305
|
}
|
|
226
306
|
|
|
227
|
-
// Sets sleep discovery characteristic (which is always discoverable as
|
|
307
|
+
// Sets sleep discovery characteristic (which is always discoverable as Homebridge is always running)
|
|
228
308
|
tvService.setCharacteristic(Characteristic.SleepDiscoveryMode, Characteristic.SleepDiscoveryMode.ALWAYS_DISCOVERABLE);
|
|
229
309
|
|
|
230
310
|
// Handles on/off events
|
|
@@ -288,7 +368,15 @@ function SyncBoxDevice(platform, state) {
|
|
|
288
368
|
modeTvService = modeTvAccessory.addService(Service.Television, 'Mode', 'ModeTVAccessory');
|
|
289
369
|
|
|
290
370
|
// Sets the TV name
|
|
291
|
-
|
|
371
|
+
if (mainAccessory) {
|
|
372
|
+
modeTvService.setCharacteristic(Characteristic.ConfiguredName, mainAccessory.context.modeTvAccessoryConfiguredName || state.device.name);
|
|
373
|
+
modeTvService.getCharacteristic(Characteristic.ConfiguredName).on('set', function (value, callback) {
|
|
374
|
+
mainAccessory.context.modeTvAccessoryConfiguredName = value;
|
|
375
|
+
callback(null);
|
|
376
|
+
});
|
|
377
|
+
} else {
|
|
378
|
+
modeTvService.setCharacteristic(Characteristic.ConfiguredName, state.device.name);
|
|
379
|
+
}
|
|
292
380
|
}
|
|
293
381
|
|
|
294
382
|
// Register mode input sources
|
|
@@ -315,7 +403,7 @@ function SyncBoxDevice(platform, state) {
|
|
|
315
403
|
modeInputServices.push(modeInputService);
|
|
316
404
|
}
|
|
317
405
|
|
|
318
|
-
// Sets sleep discovery characteristic (which is always discoverable as
|
|
406
|
+
// Sets sleep discovery characteristic (which is always discoverable as Homebridge is always running)
|
|
319
407
|
modeTvService.setCharacteristic(Characteristic.SleepDiscoveryMode, Characteristic.SleepDiscoveryMode.ALWAYS_DISCOVERABLE);
|
|
320
408
|
|
|
321
409
|
// Handles on/off events
|
|
@@ -394,7 +482,15 @@ function SyncBoxDevice(platform, state) {
|
|
|
394
482
|
intensityTvService = intensityTvAccessory.addService(Service.Television, 'Intensity', 'IntensityTVAccessory');
|
|
395
483
|
|
|
396
484
|
// Sets the TV name
|
|
397
|
-
|
|
485
|
+
if (mainAccessory) {
|
|
486
|
+
intensityTvService.setCharacteristic(Characteristic.ConfiguredName, mainAccessory.context.intensityTvAccessoryConfiguredName || state.device.name);
|
|
487
|
+
intensityTvService.getCharacteristic(Characteristic.ConfiguredName).on('set', function (value, callback) {
|
|
488
|
+
mainAccessory.context.intensityTvAccessoryConfiguredName = value;
|
|
489
|
+
callback(null);
|
|
490
|
+
});
|
|
491
|
+
} else {
|
|
492
|
+
intensityTvService.setCharacteristic(Characteristic.ConfiguredName, state.device.name);
|
|
493
|
+
}
|
|
398
494
|
}
|
|
399
495
|
|
|
400
496
|
// Register intensity input sources
|
|
@@ -421,7 +517,7 @@ function SyncBoxDevice(platform, state) {
|
|
|
421
517
|
intensityInputServices.push(intensityInputService);
|
|
422
518
|
}
|
|
423
519
|
|
|
424
|
-
// Sets sleep discovery characteristic (which is always discoverable as
|
|
520
|
+
// Sets sleep discovery characteristic (which is always discoverable as Homebridge is always running)
|
|
425
521
|
intensityTvService.setCharacteristic(Characteristic.SleepDiscoveryMode, Characteristic.SleepDiscoveryMode.ALWAYS_DISCOVERABLE);
|
|
426
522
|
|
|
427
523
|
// Handles on/off events
|
|
@@ -523,6 +619,14 @@ SyncBoxDevice.prototype.update = function (state) {
|
|
|
523
619
|
device.lightBulbService.updateCharacteristic(Characteristic.Brightness, Math.round((state.execution.brightness / 200.0) * 100));
|
|
524
620
|
}
|
|
525
621
|
|
|
622
|
+
// Updates the corresponding service
|
|
623
|
+
if (device.switchService) {
|
|
624
|
+
|
|
625
|
+
// Updates the on characteristic
|
|
626
|
+
device.platform.log.debug('Updated state to ' + state.execution.mode);
|
|
627
|
+
device.switchService.updateCharacteristic(Characteristic.On, state.execution.mode !== 'powersave' && state.execution.mode !== 'passthrough');
|
|
628
|
+
}
|
|
629
|
+
|
|
526
630
|
// Updates the corresponding service of the TV accessory
|
|
527
631
|
if (device.tvService) {
|
|
528
632
|
|