homebridge-tuya-plus 4.3.0-dev.106 → 4.3.0-dev.108
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 +5 -1
- package/index.js +2 -0
- package/lib/CustomMultiLightAccessory.js +21 -0
- package/lib/CustomMultiOutletAccessory.js +22 -7
- package/package.json +1 -1
- package/test/CustomMultiLightAccessory.test.js +146 -0
- package/test/getCategory.test.js +1 -0
- package/wiki/Supported-Device-Types.md +26 -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": {
|
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]])
|
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.108",
|
|
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
|
+
});
|
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
|
|