homebridge-tuya-plus 4.3.0-dev.106 → 4.3.0-dev.110
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/config.schema.json +45 -1
- package/index.js +2 -0
- package/lib/CustomMultiLightAccessory.js +21 -0
- package/lib/CustomMultiOutletAccessory.js +22 -7
- package/lib/SimpleFanAccessory.js +54 -2
- package/package.json +1 -1
- package/test/CustomMultiLightAccessory.test.js +146 -0
- package/test/SimpleFanAccessory.test.js +85 -0
- package/test/getCategory.test.js +1 -0
- package/wiki/Supported-Device-Types.md +42 -0
package/config.schema.json
CHANGED
|
@@ -115,6 +115,10 @@
|
|
|
115
115
|
"title": "Non-sequential Power Strip",
|
|
116
116
|
"enum": ["CustomMultiOutlet"]
|
|
117
117
|
},
|
|
118
|
+
{
|
|
119
|
+
"title": "Multi-channel Light Switch",
|
|
120
|
+
"enum": ["CustomMultiLight"]
|
|
121
|
+
},
|
|
118
122
|
{
|
|
119
123
|
"title": "Air Conditioner",
|
|
120
124
|
"enum": ["AirConditioner"]
|
|
@@ -429,7 +433,7 @@
|
|
|
429
433
|
}
|
|
430
434
|
},
|
|
431
435
|
"condition": {
|
|
432
|
-
"functionBody": "return model.devices && model.devices[arrayIndices] && ['CustomMultiOutlet'].includes(model.devices[arrayIndices].type);"
|
|
436
|
+
"functionBody": "return model.devices && model.devices[arrayIndices] && ['CustomMultiOutlet', 'CustomMultiLight'].includes(model.devices[arrayIndices].type);"
|
|
433
437
|
}
|
|
434
438
|
},
|
|
435
439
|
"noCool": {
|
|
@@ -585,6 +589,46 @@
|
|
|
585
589
|
"functionBody": "return model.devices && model.devices[arrayIndices] && ['Fan'].includes(model.devices[arrayIndices].type);"
|
|
586
590
|
}
|
|
587
591
|
},
|
|
592
|
+
"swingOnValue": {
|
|
593
|
+
"title": "Swing/oscillation on value",
|
|
594
|
+
"description": "Value to send to the swing DP to start oscillating, for fans whose oscillation DP is an enum of angles (e.g. 120). Set together with the swing off value. Leave empty for a boolean DP.",
|
|
595
|
+
"type": "string",
|
|
596
|
+
"condition": {
|
|
597
|
+
"functionBody": "return model.devices && model.devices[arrayIndices] && ['Fan'].includes(model.devices[arrayIndices].type);"
|
|
598
|
+
}
|
|
599
|
+
},
|
|
600
|
+
"swingOffValue": {
|
|
601
|
+
"title": "Swing/oscillation off value",
|
|
602
|
+
"description": "Value of the swing DP that means not oscillating (e.g. OFF). Any other value is shown as oscillating. Set together with the swing on value. Leave empty for a boolean DP.",
|
|
603
|
+
"type": "string",
|
|
604
|
+
"condition": {
|
|
605
|
+
"functionBody": "return model.devices && model.devices[arrayIndices] && ['Fan'].includes(model.devices[arrayIndices].type);"
|
|
606
|
+
}
|
|
607
|
+
},
|
|
608
|
+
"dpSwingVertical": {
|
|
609
|
+
"title": "Vertical swing DP",
|
|
610
|
+
"description": "Data point of a second (vertical) oscillation axis. When set, a separate switch is shown in the Home app. Leave empty if the fan has no vertical oscillation.",
|
|
611
|
+
"type": "integer",
|
|
612
|
+
"condition": {
|
|
613
|
+
"functionBody": "return model.devices && model.devices[arrayIndices] && ['Fan'].includes(model.devices[arrayIndices].type);"
|
|
614
|
+
}
|
|
615
|
+
},
|
|
616
|
+
"swingVerticalOnValue": {
|
|
617
|
+
"title": "Vertical swing on value",
|
|
618
|
+
"description": "Value to send to the vertical swing DP to start oscillating (e.g. 60). Set together with the vertical swing off value. Leave empty for a boolean DP.",
|
|
619
|
+
"type": "string",
|
|
620
|
+
"condition": {
|
|
621
|
+
"functionBody": "return model.devices && model.devices[arrayIndices] && ['Fan'].includes(model.devices[arrayIndices].type);"
|
|
622
|
+
}
|
|
623
|
+
},
|
|
624
|
+
"swingVerticalOffValue": {
|
|
625
|
+
"title": "Vertical swing off value",
|
|
626
|
+
"description": "Value of the vertical swing DP that means not oscillating (e.g. OFF). Set together with the vertical swing on value. Leave empty for a boolean DP.",
|
|
627
|
+
"type": "string",
|
|
628
|
+
"condition": {
|
|
629
|
+
"functionBody": "return model.devices && model.devices[arrayIndices] && ['Fan'].includes(model.devices[arrayIndices].type);"
|
|
630
|
+
}
|
|
631
|
+
},
|
|
588
632
|
"noDirection": {
|
|
589
633
|
"title": "Hide the rotation direction control",
|
|
590
634
|
"description": "Enable if the fan has no forward/reverse direction, or if the direction data point is actually a mode enum. Prevents writing forward/reverse into that data point.",
|
package/index.js
CHANGED
|
@@ -9,6 +9,7 @@ const OccupancySensorAccessory = require('./lib/OccupancySensorAccessory');
|
|
|
9
9
|
const SimpleLightAccessory = require('./lib/SimpleLightAccessory');
|
|
10
10
|
const MultiOutletAccessory = require('./lib/MultiOutletAccessory');
|
|
11
11
|
const CustomMultiOutletAccessory = require('./lib/CustomMultiOutletAccessory');
|
|
12
|
+
const CustomMultiLightAccessory = require('./lib/CustomMultiLightAccessory');
|
|
12
13
|
const RGBTWLightAccessory = require('./lib/RGBTWLightAccessory');
|
|
13
14
|
const RGBTWOutletAccessory = require('./lib/RGBTWOutletAccessory');
|
|
14
15
|
const TWLightAccessory = require('./lib/TWLightAccessory');
|
|
@@ -53,6 +54,7 @@ const CLASS_DEF = {
|
|
|
53
54
|
twlight: TWLightAccessory,
|
|
54
55
|
multioutlet: MultiOutletAccessory,
|
|
55
56
|
custommultioutlet: CustomMultiOutletAccessory,
|
|
57
|
+
custommultilight: CustomMultiLightAccessory,
|
|
56
58
|
airconditioner: AirConditionerAccessory,
|
|
57
59
|
airpurifier: AirPurifierAccessory,
|
|
58
60
|
dehumidifier: DehumidifierAccessory,
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
const CustomMultiOutletAccessory = require('./CustomMultiOutletAccessory');
|
|
2
|
+
|
|
3
|
+
// Multi-gang on/off light controllers (e.g. 2-gang wall switches) with the same
|
|
4
|
+
// `outlets` channel config as CustomMultiOutlet, but each channel exposed as a
|
|
5
|
+
// Lightbulb: Outlets show a plug icon and are left out of Siri's "turn on the
|
|
6
|
+
// lights" and the Home app's Lights group.
|
|
7
|
+
class CustomMultiLightAccessory extends CustomMultiOutletAccessory {
|
|
8
|
+
static getCategory(Categories) {
|
|
9
|
+
return Categories.LIGHTBULB;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
_channelService() {
|
|
13
|
+
return this.hap.Service.Lightbulb;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
_channelSubtypePrefix() {
|
|
17
|
+
return 'light';
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
module.exports = CustomMultiLightAccessory;
|
|
@@ -9,6 +9,18 @@ class CustomMultiOutletAccessory extends BaseAccessory {
|
|
|
9
9
|
super(...props);
|
|
10
10
|
}
|
|
11
11
|
|
|
12
|
+
// The HomeKit service and subtype prefix each channel is exposed as.
|
|
13
|
+
// CustomMultiLightAccessory overrides these to expose the same channels as
|
|
14
|
+
// Lightbulbs. The subtype is part of the service identity in HomeKit, so
|
|
15
|
+
// changing it for an existing type would orphan paired channels.
|
|
16
|
+
_channelService() {
|
|
17
|
+
return this.hap.Service.Outlet;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
_channelSubtypePrefix() {
|
|
21
|
+
return 'outlet';
|
|
22
|
+
}
|
|
23
|
+
|
|
12
24
|
_registerPlatformAccessory() {
|
|
13
25
|
this._verifyCachedPlatformAccessory();
|
|
14
26
|
this._justRegistered = true;
|
|
@@ -19,7 +31,8 @@ class CustomMultiOutletAccessory extends BaseAccessory {
|
|
|
19
31
|
_verifyCachedPlatformAccessory() {
|
|
20
32
|
if (this._justRegistered) return;
|
|
21
33
|
|
|
22
|
-
const
|
|
34
|
+
const ChannelService = this._channelService();
|
|
35
|
+
const prefix = this._channelSubtypePrefix();
|
|
23
36
|
|
|
24
37
|
if (!Array.isArray(this.device.context.outlets)) {
|
|
25
38
|
throw new Error('The outlets definition is missing or is malformed: ' + this.device.context.outlets);
|
|
@@ -30,15 +43,15 @@ class CustomMultiOutletAccessory extends BaseAccessory {
|
|
|
30
43
|
throw new Error('The outlet definition #${i} is missing or is malformed: ' + outlet);
|
|
31
44
|
|
|
32
45
|
const name = ((outlet.name || '').trim() || 'Unnamed') + ' - ' + this.device.context.name;
|
|
33
|
-
let service = this.accessory.getServiceById(
|
|
46
|
+
let service = this.accessory.getServiceById(ChannelService, prefix + ' ' + outlet.dp);
|
|
34
47
|
if (service) this._checkServiceName(service, name);
|
|
35
|
-
else service = this.accessory.addService(
|
|
48
|
+
else service = this.accessory.addService(ChannelService, name, prefix + ' ' + outlet.dp);
|
|
36
49
|
|
|
37
50
|
_validServices.push(service);
|
|
38
51
|
});
|
|
39
52
|
|
|
40
53
|
this.accessory.services
|
|
41
|
-
.filter(service => service.UUID ===
|
|
54
|
+
.filter(service => service.UUID === ChannelService.UUID && !_validServices.includes(service))
|
|
42
55
|
.forEach(service => {
|
|
43
56
|
this.accessory.removeService(service);
|
|
44
57
|
});
|
|
@@ -47,14 +60,16 @@ class CustomMultiOutletAccessory extends BaseAccessory {
|
|
|
47
60
|
_registerCharacteristics(dps) {
|
|
48
61
|
this._verifyCachedPlatformAccessory();
|
|
49
62
|
|
|
50
|
-
const {
|
|
63
|
+
const {Characteristic} = this.hap;
|
|
64
|
+
const ChannelService = this._channelService();
|
|
65
|
+
const subtypePattern = new RegExp('^' + this._channelSubtypePrefix() + ' (\\d+)$');
|
|
51
66
|
|
|
52
67
|
const characteristics = {};
|
|
53
68
|
this.accessory.services.forEach(service => {
|
|
54
|
-
if (service.UUID !==
|
|
69
|
+
if (service.UUID !== ChannelService.UUID || !service.subtype) return false;
|
|
55
70
|
|
|
56
71
|
let match;
|
|
57
|
-
if ((match = service.subtype.match(
|
|
72
|
+
if ((match = service.subtype.match(subtypePattern)) === null) return;
|
|
58
73
|
|
|
59
74
|
characteristics[match[1]] = service.getCharacteristic(Characteristic.On)
|
|
60
75
|
.updateValue(dps[match[1]])
|
|
@@ -38,6 +38,7 @@ class SimpleFanAccessory extends BaseAccessory {
|
|
|
38
38
|
this.dpRotationSpeed = this._getCustomDP(this.device.context.dpRotationSpeed) || '3';
|
|
39
39
|
this.dpFanDirection = this._getCustomDP(this.device.context.dpFanDirection) || '2';
|
|
40
40
|
this.dpSwing = this._getCustomDP(this.device.context.dpSwing);
|
|
41
|
+
this.dpSwingVertical = this._getCustomDP(this.device.context.dpSwingVertical);
|
|
41
42
|
|
|
42
43
|
this.dpCurrentTemperature = this._getCustomDP(this.device.context.dpCurrentTemperature);
|
|
43
44
|
|
|
@@ -81,6 +82,23 @@ class SimpleFanAccessory extends BaseAccessory {
|
|
|
81
82
|
.onSet(value => this.setSwingMode(value));
|
|
82
83
|
} else this._removeCharacteristic(serviceFan, Characteristic.SwingMode);
|
|
83
84
|
|
|
85
|
+
let serviceSwingVertical = this.accessory.getServiceById(Service.Switch, 'swing-vertical');
|
|
86
|
+
if (this.dpSwingVertical && !serviceSwingVertical) {
|
|
87
|
+
serviceSwingVertical = this.accessory.addService(Service.Switch, this._getSwingVerticalName(), 'swing-vertical');
|
|
88
|
+
} else if (!this.dpSwingVertical && serviceSwingVertical) {
|
|
89
|
+
this.accessory.removeService(serviceSwingVertical);
|
|
90
|
+
serviceSwingVertical = null;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
let characteristicSwingVertical;
|
|
94
|
+
if (serviceSwingVertical) {
|
|
95
|
+
this._checkServiceName(serviceSwingVertical, this._getSwingVerticalName());
|
|
96
|
+
characteristicSwingVertical = serviceSwingVertical.getCharacteristic(Characteristic.On)
|
|
97
|
+
.updateValue(this._getSwingVertical(dps[this.dpSwingVertical]))
|
|
98
|
+
.onGet(() => this.getSwingVertical())
|
|
99
|
+
.onSet(value => this.setSwingVertical(value));
|
|
100
|
+
}
|
|
101
|
+
|
|
84
102
|
let characteristicTemperature;
|
|
85
103
|
if (this.dpCurrentTemperature && serviceTemp) {
|
|
86
104
|
characteristicTemperature = serviceTemp.getCharacteristic(Characteristic.CurrentTemperature)
|
|
@@ -105,6 +123,11 @@ class SimpleFanAccessory extends BaseAccessory {
|
|
|
105
123
|
if (characteristicSwingMode.value !== swing) characteristicSwingMode.updateValue(swing);
|
|
106
124
|
}
|
|
107
125
|
|
|
126
|
+
if (characteristicSwingVertical && changes.hasOwnProperty(this.dpSwingVertical)) {
|
|
127
|
+
const swingVertical = this._getSwingVertical(changes[this.dpSwingVertical]);
|
|
128
|
+
if (characteristicSwingVertical.value !== swingVertical) characteristicSwingVertical.updateValue(swingVertical);
|
|
129
|
+
}
|
|
130
|
+
|
|
108
131
|
if (characteristicTemperature && changes.hasOwnProperty(this.dpCurrentTemperature)) {
|
|
109
132
|
const temp = this._getCurrentTemperature(changes[this.dpCurrentTemperature]);
|
|
110
133
|
if (characteristicTemperature.value !== temp) characteristicTemperature.updateValue(temp);
|
|
@@ -195,12 +218,41 @@ class SimpleFanAccessory extends BaseAccessory {
|
|
|
195
218
|
|
|
196
219
|
_getSwingMode(dp) {
|
|
197
220
|
const {Characteristic} = this.hap;
|
|
198
|
-
return dp ? Characteristic.SwingMode.SWING_ENABLED : Characteristic.SwingMode.SWING_DISABLED;
|
|
221
|
+
return this._isSwinging(dp, this.device.context.swingOffValue) ? Characteristic.SwingMode.SWING_ENABLED : Characteristic.SwingMode.SWING_DISABLED;
|
|
199
222
|
}
|
|
200
223
|
|
|
201
224
|
setSwingMode(value) {
|
|
202
225
|
const {Characteristic} = this.hap;
|
|
203
|
-
|
|
226
|
+
const enabled = value === Characteristic.SwingMode.SWING_ENABLED;
|
|
227
|
+
return this.setStateAsync(this.dpSwing, this._getSwingDPValue(enabled, this.device.context.swingOnValue, this.device.context.swingOffValue));
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
getSwingVertical() {
|
|
231
|
+
return this._getSwingVertical(this.getStateAsync(this.dpSwingVertical));
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
_getSwingVertical(dp) {
|
|
235
|
+
return this._isSwinging(dp, this.device.context.swingVerticalOffValue);
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
setSwingVertical(value) {
|
|
239
|
+
return this.setStateAsync(this.dpSwingVertical, this._getSwingDPValue(!!value, this.device.context.swingVerticalOnValue, this.device.context.swingVerticalOffValue));
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
_getSwingVerticalName() {
|
|
243
|
+
return this.device.context.name + ' Vertical Swing';
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
// Many fans model oscillation as an enum of sweep angles (e.g. "OFF"/"30"/"120")
|
|
247
|
+
// rather than a boolean; with an off value configured, any other value means swinging.
|
|
248
|
+
_isSwinging(dp, offValue) {
|
|
249
|
+
if (offValue == null || offValue === '') return !!dp;
|
|
250
|
+
return dp != null && String(dp) !== String(offValue);
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
_getSwingDPValue(enabled, onValue, offValue) {
|
|
254
|
+
const value = enabled ? onValue : offValue;
|
|
255
|
+
return (value == null || value === '') ? enabled : value;
|
|
204
256
|
}
|
|
205
257
|
|
|
206
258
|
getCurrentTemperature() {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "homebridge-tuya-plus",
|
|
3
|
-
"version": "4.3.0-dev.
|
|
3
|
+
"version": "4.3.0-dev.110",
|
|
4
4
|
"description": "A community-maintained Homebridge plugin for controlling Tuya devices locally over LAN, with an optional Tuya Cloud fallback for whatever the LAN can't reach. Includes new features, fixes, and updated device support. PRs welcome: if it runs, it ships (almost).",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"scripts": {
|
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const CustomMultiLightAccessory = require('../lib/CustomMultiLightAccessory');
|
|
4
|
+
const CustomMultiOutletAccessory = require('../lib/CustomMultiOutletAccessory');
|
|
5
|
+
const { HAP, makeInstance, makeMockCharacteristic } = require('./support/mocks');
|
|
6
|
+
|
|
7
|
+
const { Service, Characteristic } = HAP;
|
|
8
|
+
|
|
9
|
+
const CHANNELS = [{ name: 'Ceiling', dp: 1 }, { name: 'LED', dp: 2 }];
|
|
10
|
+
|
|
11
|
+
// An accessory that actually keeps its services, so the tests can assert which
|
|
12
|
+
// HomeKit service type and subtype each channel ends up as.
|
|
13
|
+
function makeServiceStore(accessory, existing = []) {
|
|
14
|
+
const makeService = (type, displayName, subtype) => {
|
|
15
|
+
const chars = new Map();
|
|
16
|
+
return {
|
|
17
|
+
UUID: type.UUID, displayName, subtype,
|
|
18
|
+
getCharacteristic: jest.fn(c => {
|
|
19
|
+
if (!chars.has(c)) chars.set(c, makeMockCharacteristic());
|
|
20
|
+
return chars.get(c);
|
|
21
|
+
}),
|
|
22
|
+
};
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
accessory.services = existing.map(([type, name, subtype]) => makeService(type, name, subtype));
|
|
26
|
+
accessory.addService = jest.fn((type, name, subtype) => {
|
|
27
|
+
const service = makeService(type, name, subtype);
|
|
28
|
+
accessory.services.push(service);
|
|
29
|
+
return service;
|
|
30
|
+
});
|
|
31
|
+
accessory.getServiceById = jest.fn((type, subtype) =>
|
|
32
|
+
accessory.services.find(s => s.UUID === type.UUID && s.subtype === subtype));
|
|
33
|
+
accessory.removeService = jest.fn(service => {
|
|
34
|
+
accessory.services = accessory.services.filter(s => s !== service);
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
function make(AccessoryClass, { outlets = CHANNELS, existing, state = { 1: false, 2: true } } = {}) {
|
|
39
|
+
const built = makeInstance(AccessoryClass, state, { name: 'Hallway', type: 'CustomMultiLight', outlets });
|
|
40
|
+
makeServiceStore(built.accessory, existing);
|
|
41
|
+
built.instance._checkServiceName = jest.fn();
|
|
42
|
+
return built;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
const summary = accessory => accessory.services.map(s => [s.UUID, s.subtype, s.displayName]);
|
|
46
|
+
|
|
47
|
+
describe('CustomMultiLightAccessory', () => {
|
|
48
|
+
test('is a LIGHTBULB accessory', () => {
|
|
49
|
+
expect(CustomMultiLightAccessory.getCategory(HAP.Categories)).toBe(HAP.Categories.LIGHTBULB);
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
test('exposes each channel as a Lightbulb with a "light <dp>" subtype', () => {
|
|
53
|
+
const { instance, accessory } = make(CustomMultiLightAccessory);
|
|
54
|
+
instance._verifyCachedPlatformAccessory();
|
|
55
|
+
|
|
56
|
+
expect(summary(accessory)).toEqual([
|
|
57
|
+
[Service.Lightbulb.UUID, 'light 1', 'Ceiling - Hallway'],
|
|
58
|
+
[Service.Lightbulb.UUID, 'light 2', 'LED - Hallway'],
|
|
59
|
+
]);
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
test('reuses cached channel services and drops channels no longer configured', () => {
|
|
63
|
+
const { instance, accessory } = make(CustomMultiLightAccessory, {
|
|
64
|
+
outlets: [CHANNELS[0]],
|
|
65
|
+
existing: [
|
|
66
|
+
[Service.AccessoryInformation, 'Hallway', undefined],
|
|
67
|
+
[Service.Lightbulb, 'Ceiling - Hallway', 'light 1'],
|
|
68
|
+
[Service.Lightbulb, 'Old - Hallway', 'light 7'],
|
|
69
|
+
],
|
|
70
|
+
});
|
|
71
|
+
const cached = accessory.services[1];
|
|
72
|
+
|
|
73
|
+
instance._verifyCachedPlatformAccessory();
|
|
74
|
+
|
|
75
|
+
expect(accessory.addService).not.toHaveBeenCalled();
|
|
76
|
+
expect(accessory.services).toContain(cached);
|
|
77
|
+
expect(summary(accessory)).toEqual([
|
|
78
|
+
[Service.AccessoryInformation.UUID, undefined, 'Hallway'],
|
|
79
|
+
[Service.Lightbulb.UUID, 'light 1', 'Ceiling - Hallway'],
|
|
80
|
+
]);
|
|
81
|
+
});
|
|
82
|
+
|
|
83
|
+
test('rejects a malformed channel definition', () => {
|
|
84
|
+
const { instance } = make(CustomMultiLightAccessory, { outlets: [{ name: 'No DP' }] });
|
|
85
|
+
expect(() => instance._verifyCachedPlatformAccessory()).toThrow(/malformed/);
|
|
86
|
+
});
|
|
87
|
+
|
|
88
|
+
describe('channel control', () => {
|
|
89
|
+
beforeEach(() => jest.useFakeTimers());
|
|
90
|
+
afterEach(() => jest.useRealTimers());
|
|
91
|
+
|
|
92
|
+
function wired() {
|
|
93
|
+
const built = make(CustomMultiLightAccessory);
|
|
94
|
+
built.instance._registerCharacteristics(built.device.state);
|
|
95
|
+
const on = dp => built.accessory.getServiceById(Service.Lightbulb, 'light ' + dp).getCharacteristic(Characteristic.On);
|
|
96
|
+
const onChange = built.device.on.mock.calls.find(([event]) => event === 'change')[1];
|
|
97
|
+
return { ...built, on, onChange };
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
test('seeds each channel from the device state', () => {
|
|
101
|
+
const { on } = wired();
|
|
102
|
+
expect(on(1).value).toBe(false);
|
|
103
|
+
expect(on(2).value).toBe(true);
|
|
104
|
+
});
|
|
105
|
+
|
|
106
|
+
test('a device change updates only the matching channel', () => {
|
|
107
|
+
const { on, onChange } = wired();
|
|
108
|
+
onChange({ 1: true });
|
|
109
|
+
expect(on(1).value).toBe(true);
|
|
110
|
+
expect(on(2).updateValue).toHaveBeenCalledTimes(1); // only the initial seed
|
|
111
|
+
});
|
|
112
|
+
|
|
113
|
+
test('setting a channel writes its DP', async () => {
|
|
114
|
+
const { on, device } = wired();
|
|
115
|
+
const setHandler = on(2).onSet.mock.calls[0][0];
|
|
116
|
+
|
|
117
|
+
const done = setHandler(false);
|
|
118
|
+
jest.advanceTimersByTime(500);
|
|
119
|
+
await done;
|
|
120
|
+
|
|
121
|
+
expect(device.update).toHaveBeenCalledWith({ 2: false });
|
|
122
|
+
});
|
|
123
|
+
});
|
|
124
|
+
});
|
|
125
|
+
|
|
126
|
+
// The channel hooks were extracted from CustomMultiOutletAccessory; its
|
|
127
|
+
// services must keep their exact type and subtype so paired outlets survive.
|
|
128
|
+
describe('CustomMultiOutletAccessory (unchanged by the channel hooks)', () => {
|
|
129
|
+
test('still exposes each channel as an Outlet with an "outlet <dp>" subtype', () => {
|
|
130
|
+
const { instance, accessory } = make(CustomMultiOutletAccessory);
|
|
131
|
+
instance._verifyCachedPlatformAccessory();
|
|
132
|
+
|
|
133
|
+
expect(summary(accessory)).toEqual([
|
|
134
|
+
[Service.Outlet.UUID, 'outlet 1', 'Ceiling - Hallway'],
|
|
135
|
+
[Service.Outlet.UUID, 'outlet 2', 'LED - Hallway'],
|
|
136
|
+
]);
|
|
137
|
+
});
|
|
138
|
+
|
|
139
|
+
test('wires the On characteristic of outlet services', () => {
|
|
140
|
+
const { instance, accessory } = make(CustomMultiOutletAccessory);
|
|
141
|
+
instance._registerCharacteristics(instance.device.state);
|
|
142
|
+
const on = accessory.getServiceById(Service.Outlet, 'outlet 1').getCharacteristic(Characteristic.On);
|
|
143
|
+
expect(on.onSet).toHaveBeenCalled();
|
|
144
|
+
expect(on.value).toBe(false);
|
|
145
|
+
});
|
|
146
|
+
});
|
|
@@ -17,6 +17,7 @@ function makeFan(state = {}, context = {}) {
|
|
|
17
17
|
instance.dpRotationSpeed = '3';
|
|
18
18
|
instance.dpFanDirection = '2';
|
|
19
19
|
instance.dpSwing = instance._getCustomDP(context.dpSwing);
|
|
20
|
+
instance.dpSwingVertical = instance._getCustomDP(context.dpSwingVertical);
|
|
20
21
|
return result;
|
|
21
22
|
}
|
|
22
23
|
|
|
@@ -67,6 +68,75 @@ describe('SimpleFanAccessory.getSwingMode / setSwingMode', () => {
|
|
|
67
68
|
});
|
|
68
69
|
});
|
|
69
70
|
|
|
71
|
+
// ---------------------------------------------------------------------------
|
|
72
|
+
// Enum swing DPs — fans that model oscillation as sweep angles ("OFF"/"30"/"120")
|
|
73
|
+
// ---------------------------------------------------------------------------
|
|
74
|
+
describe('SimpleFanAccessory swing on/off values', () => {
|
|
75
|
+
const enumSwing = { dpSwing: 7, swingOnValue: '120', swingOffValue: 'OFF' };
|
|
76
|
+
|
|
77
|
+
test('the off value disables swing and any other value enables it', () => {
|
|
78
|
+
const { instance } = makeFan({}, enumSwing);
|
|
79
|
+
expect(instance._getSwingMode('OFF')).toBe(SwingMode.SWING_DISABLED);
|
|
80
|
+
expect(instance._getSwingMode('30')).toBe(SwingMode.SWING_ENABLED);
|
|
81
|
+
expect(instance._getSwingMode('120')).toBe(SwingMode.SWING_ENABLED);
|
|
82
|
+
expect(instance._getSwingMode(undefined)).toBe(SwingMode.SWING_DISABLED);
|
|
83
|
+
});
|
|
84
|
+
|
|
85
|
+
test('setSwingMode writes the configured on value', () => {
|
|
86
|
+
const { instance, device } = makeFan({ '7': 'OFF' }, enumSwing);
|
|
87
|
+
instance.setSwingMode(SwingMode.SWING_ENABLED);
|
|
88
|
+
expect(device.update).toHaveBeenCalledWith({ '7': '120' });
|
|
89
|
+
});
|
|
90
|
+
|
|
91
|
+
test('setSwingMode writes the configured off value', () => {
|
|
92
|
+
const { instance, device } = makeFan({ '7': '120' }, enumSwing);
|
|
93
|
+
instance.setSwingMode(SwingMode.SWING_DISABLED);
|
|
94
|
+
expect(device.update).toHaveBeenCalledWith({ '7': 'OFF' });
|
|
95
|
+
});
|
|
96
|
+
|
|
97
|
+
test('empty on/off values fall back to booleans', () => {
|
|
98
|
+
const { instance, device } = makeFan({ '4': false }, { dpSwing: 4, swingOnValue: '', swingOffValue: '' });
|
|
99
|
+
instance.setSwingMode(SwingMode.SWING_ENABLED);
|
|
100
|
+
expect(device.update).toHaveBeenCalledWith({ '4': true });
|
|
101
|
+
expect(instance._getSwingMode(false)).toBe(SwingMode.SWING_DISABLED);
|
|
102
|
+
});
|
|
103
|
+
});
|
|
104
|
+
|
|
105
|
+
// ---------------------------------------------------------------------------
|
|
106
|
+
// Vertical swing — a second oscillation axis exposed as a Switch
|
|
107
|
+
// ---------------------------------------------------------------------------
|
|
108
|
+
describe('SimpleFanAccessory vertical swing', () => {
|
|
109
|
+
const vertical = { dpSwingVertical: 6, swingVerticalOnValue: '60', swingVerticalOffValue: 'OFF' };
|
|
110
|
+
|
|
111
|
+
test('reads the vertical swing DP through its off value', () => {
|
|
112
|
+
const { instance } = makeFan({ '6': '30' }, vertical);
|
|
113
|
+
expect(instance.getSwingVertical()).toBe(true);
|
|
114
|
+
expect(instance._getSwingVertical('OFF')).toBe(false);
|
|
115
|
+
});
|
|
116
|
+
|
|
117
|
+
test('setSwingVertical writes the configured on value', () => {
|
|
118
|
+
const { instance, device } = makeFan({ '6': 'OFF' }, vertical);
|
|
119
|
+
instance.setSwingVertical(true);
|
|
120
|
+
expect(device.update).toHaveBeenCalledWith({ '6': '60' });
|
|
121
|
+
});
|
|
122
|
+
|
|
123
|
+
test('setSwingVertical writes the configured off value', () => {
|
|
124
|
+
const { instance, device } = makeFan({ '6': '60' }, vertical);
|
|
125
|
+
instance.setSwingVertical(false);
|
|
126
|
+
expect(device.update).toHaveBeenCalledWith({ '6': 'OFF' });
|
|
127
|
+
});
|
|
128
|
+
|
|
129
|
+
test('a boolean vertical swing DP works without on/off values', () => {
|
|
130
|
+
const { instance, device } = makeFan({ '6': false }, { dpSwingVertical: 6 });
|
|
131
|
+
instance.setSwingVertical(true);
|
|
132
|
+
expect(device.update).toHaveBeenCalledWith({ '6': true });
|
|
133
|
+
});
|
|
134
|
+
|
|
135
|
+
test('the switch is named after the device', () => {
|
|
136
|
+
expect(makeFan({}, vertical).instance._getSwingVerticalName()).toBe('Test Device Vertical Swing');
|
|
137
|
+
});
|
|
138
|
+
});
|
|
139
|
+
|
|
70
140
|
// ---------------------------------------------------------------------------
|
|
71
141
|
// Registration — SwingMode is opt-in and RotationDirection is opt-out
|
|
72
142
|
// ---------------------------------------------------------------------------
|
|
@@ -89,6 +159,21 @@ describe('SimpleFanAccessory._registerCharacteristics', () => {
|
|
|
89
159
|
expect(service.getCharacteristic).not.toHaveBeenCalledWith(SwingMode);
|
|
90
160
|
});
|
|
91
161
|
|
|
162
|
+
test('adds the vertical swing Switch when dpSwingVertical is configured', () => {
|
|
163
|
+
const { instance, accessory } = makeInstance(SimpleFanAccessory, {}, { type: 'Fan', dpSwingVertical: 6 });
|
|
164
|
+
instance._registerCharacteristics(instance.device.state);
|
|
165
|
+
expect(accessory.addService).toHaveBeenCalledWith(HAP.Service.Switch, 'Test Device Vertical Swing', 'swing-vertical');
|
|
166
|
+
});
|
|
167
|
+
|
|
168
|
+
test('removes a cached vertical swing Switch when dpSwingVertical is dropped', () => {
|
|
169
|
+
const { instance, accessory } = makeInstance(SimpleFanAccessory, {}, { type: 'Fan' });
|
|
170
|
+
const cached = { UUID: 'switch' };
|
|
171
|
+
accessory.getServiceById.mockReturnValue(cached);
|
|
172
|
+
instance._registerCharacteristics(instance.device.state);
|
|
173
|
+
expect(accessory.removeService).toHaveBeenCalledWith(cached);
|
|
174
|
+
expect(accessory.addService).not.toHaveBeenCalled();
|
|
175
|
+
});
|
|
176
|
+
|
|
92
177
|
test('registers RotationDirection by default', () => {
|
|
93
178
|
const service = register({});
|
|
94
179
|
expect(service.getCharacteristic).toHaveBeenCalledWith(RotationDirection);
|
package/test/getCategory.test.js
CHANGED
|
@@ -17,6 +17,7 @@ const CLASS_DEF = {
|
|
|
17
17
|
twlight: require('../lib/TWLightAccessory'),
|
|
18
18
|
multioutlet: require('../lib/MultiOutletAccessory'),
|
|
19
19
|
custommultioutlet: require('../lib/CustomMultiOutletAccessory'),
|
|
20
|
+
custommultilight: require('../lib/CustomMultiLightAccessory'),
|
|
20
21
|
airconditioner: require('../lib/AirConditionerAccessory'),
|
|
21
22
|
airpurifier: require('../lib/AirPurifierAccessory'),
|
|
22
23
|
dehumidifier: require('../lib/DehumidifierAccessory'),
|
|
@@ -12,6 +12,7 @@ If you are looking for verified configurations for your specific device, please
|
|
|
12
12
|
|White and Color Light Bulb|`RGBTWLight`<sup>[3](#white-and-color-light-bulbs)</sup>|Colored bulbs with tunable white and dimming functionality <small>([instructions](#white-and-color-light-bulbs))</small>|
|
|
13
13
|
|Smart Power Strip|`MultiOutlet`<sup>[4](#smart-power-strips)</sup>|Smart power strips that have sequential data-points and allow each outlet to be turned on and off individually <small>([instructions](#smart-power-strips))</small>|
|
|
14
14
|
|Non-sequential Power Strip|`CustomMultiOutlet`<sup>[5](#non-sequential-power-strips)</sup>|Smart power strips that have non-sequential data-points for each outlet <small>([instructions](#non-sequential-power-strips))</small>|
|
|
15
|
+
|Multi-channel Light Switch|`CustomMultiLight`<sup>[5](#multi-channel-light-switches)</sup>|Multi-gang wall switches / light controllers whose channels should appear as lights, not outlets <small>([instructions](#multi-channel-light-switches))</small>|
|
|
15
16
|
|Barely Smart Power Strip|`Outlet`|Smart power strips that don't allow individual control of the outlets|
|
|
16
17
|
|Air Conditioner|`AirConditioner`<sup>[6](#air-conditioners)</sup>|Cooling and heating devices <small>([instructions](#air-conditioners))</small>|
|
|
17
18
|
|Heat Convector|`Convector`<sup>[7](#heat-convectors)</sup>|Heating panels <small>([instructions](#heat-convectors))</small>|
|
|
@@ -235,6 +236,31 @@ Some smart power strips don't have sequential data-points. Using `CustomMultiOut
|
|
|
235
236
|
}
|
|
236
237
|
```
|
|
237
238
|
|
|
239
|
+
### Multi-channel Light Switches
|
|
240
|
+
Multi-gang wall switches and light controllers (e.g. 2-gang on/off switches) whose channels drive lights. `CustomMultiLight` takes the same `outlets` list as `CustomMultiOutlet`, but exposes each channel as a HomeKit light instead of an outlet, so it gets a bulb icon and responds to Siri's "turn on the lights".
|
|
241
|
+
|
|
242
|
+
```json5
|
|
243
|
+
{
|
|
244
|
+
"name": "Hallway",
|
|
245
|
+
"type": "CustomMultiLight",
|
|
246
|
+
"manufacturer": "Ledvance",
|
|
247
|
+
"model": "Smart+ 2-gang switch",
|
|
248
|
+
"id": "032000123456789abcde",
|
|
249
|
+
"key": "0123456789abcdef",
|
|
250
|
+
/* One entry per channel; each shows up as "<name> - <device name>". */
|
|
251
|
+
"outlets": [
|
|
252
|
+
{
|
|
253
|
+
"name": "Ceiling",
|
|
254
|
+
"dp": 1
|
|
255
|
+
},
|
|
256
|
+
{
|
|
257
|
+
"name": "LED strip",
|
|
258
|
+
"dp": 2
|
|
259
|
+
}
|
|
260
|
+
]
|
|
261
|
+
}
|
|
262
|
+
```
|
|
263
|
+
|
|
238
264
|
### Air Conditioners
|
|
239
265
|
These devices have cooling and/or heating capabilities; they could also have _dry_, _fan_, or others modes but HomeKit's definition doesn't facilitate modes other than _heat_, _cool_, and _auto_. By default, _heat_, _cool_ and _auto_ modes are enabled; to let the plugin know that a device doesn't have heating, cooling or auto capabilities, add an additional parameter named `noHeat`, `noCool` or `noAuto` and set it to `true`.
|
|
240
266
|
|
|
@@ -852,6 +878,22 @@ Every option below is optional — the defaults match a common 3-speed fan. The
|
|
|
852
878
|
(oscillation) control appears in the Home app. Omit if the fan can't oscillate. */
|
|
853
879
|
"dpSwing": 4,
|
|
854
880
|
|
|
881
|
+
/* For fans whose oscillation DP is an enum of sweep angles rather than a
|
|
882
|
+
boolean (e.g. "OFF" / "30" / "75" / "120"): the value to send when
|
|
883
|
+
oscillation is switched on, and the value that means "not oscillating".
|
|
884
|
+
Any other value is shown as oscillating. Set both or neither.
|
|
885
|
+
Default: true / false */
|
|
886
|
+
"swingOnValue": "120",
|
|
887
|
+
"swingOffValue": "OFF",
|
|
888
|
+
|
|
889
|
+
/* Data-point of a second, vertical oscillation axis. When set, a separate
|
|
890
|
+
switch named "<name> Vertical Swing" appears in the Home app. Accepts the
|
|
891
|
+
same on/off values as above.
|
|
892
|
+
Omit if the fan has a single oscillation axis. */
|
|
893
|
+
"dpSwingVertical": 6,
|
|
894
|
+
"swingVerticalOnValue": "60",
|
|
895
|
+
"swingVerticalOffValue": "OFF",
|
|
896
|
+
|
|
855
897
|
/* Drop the direction control entirely — for fans whose "direction" DP is
|
|
856
898
|
actually a mode enum (e.g. nature/sleep/smart), so HomeKit won't write
|
|
857
899
|
forward/reverse into it. Default: false */
|