homebridge-tuya-plus 4.3.0-dev.104 → 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/Changelog.md +1 -0
- package/config.schema.json +5 -1
- package/index.js +2 -0
- package/lib/CustomMultiLightAccessory.js +21 -0
- package/lib/CustomMultiOutletAccessory.js +22 -7
- package/lib/SimpleBlindsAccessory.js +21 -15
- package/package.json +1 -1
- package/test/CustomMultiLightAccessory.test.js +146 -0
- package/test/SimpleBlindsAccessory.test.js +108 -0
- package/test/getCategory.test.js +1 -0
- package/test/support/mocks.js +2 -0
- package/wiki/Supported-Device-Types.md +26 -0
package/Changelog.md
CHANGED
|
@@ -12,6 +12,7 @@ All notable changes to this project will be documented in this file. This projec
|
|
|
12
12
|
* Works with both **Custom** and **Smart Home** Cloud projects (the latter via app-account login).
|
|
13
13
|
* The **IrrigationSystem** accessory no longer has any cloud-specific handling — like every other accessory it's transport-agnostic, with the LAN+cloud fallback handled underneath.
|
|
14
14
|
* If your devices sometimes drop off the LAN and show "No Response", adding cloud credentials is an easy way to smooth that over. See the wiki: **[Tuya Cloud Setup](https://github.com/adrianjagielak/homebridge-tuya-plus/blob/main/wiki/Tuya-Cloud-Setup.md)**.
|
|
15
|
+
* [*] **SimpleBlinds: keep the estimated position within 0–100.** The time-based position estimate wasn't clamped, so a stale run start (e.g. the device never echoed a command because its data-point already held that value) extrapolated to positions like `286` or `147382`. HomeKit rejected them (`characteristic was supplied illegal value … exceeded maximum of 100`), and percentage control then started its timed move from that bogus position. The estimate is now bounded by the physical travel range (`minPosition`–100, so `timeToTighten` still works), and reported positions are clamped to 0–100.
|
|
15
16
|
* [*] **Fix realtime (MQTT) cloud updates being silently dropped** — external changes (physical buttons, the Tuya app, the device's own timers) now show up in HomeKit within a second or two. The decryptor was verifying the AES-GCM auth tag (`decipher.final()`), but Tuya's real status frames don't carry a tag that verifies against the documented AAD, so every realtime message was being thrown away. Now decrypts with `update()` only, matching the official `tuya/tuya-homebridge` and `0x5e/homebridge-tuya-platform` implementations.
|
|
16
17
|
* [*] **Fix cloud irrigation valves that could be turned on but not off** — the per-zone write coalescer was dropping any command that matched the last-known `device.state`. Cloud devices never optimistically advance `state` (it only moves once the realtime stream confirms the device), so an "off" issued before the "on" was echoed matched the stale "off" and was discarded — HomeKit showed the zone closed while it kept running. Queued commands are now sent as-is (callers already queue only genuine changes).
|
|
17
18
|
* [*] **IrrigationSystem: remove the rain sensor.** It never reported reliably on these devices, and bundling a sensor (a different HomeKit category) in the same accessory forced the Home app to fragment the sprinkler into "sub-accessories" — blocking control from the main tile and hiding the system master on/off. The accessory is now a single, clean sprinkler tile (IrrigationSystem + valves + optional battery); any leftover Contact/Leak sensor service from a previous build is removed automatically on restart. The `noRainSensor`, `rainSensorType`, `rainInverted`, `dpRain` and `rainOnValue` options are gone.
|
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]])
|
|
@@ -152,15 +152,10 @@ class SimpleBlindsAccessory extends BaseAccessory {
|
|
|
152
152
|
this.log.debug('[TuyaAccessory] Blinds last change was ' + this.changeTime + '; ' + (Date.now() - this.changeTime) + 'ms ago');
|
|
153
153
|
|
|
154
154
|
if (this.changeTime) {
|
|
155
|
-
|
|
156
|
-
if (this.assumedState === BLINDS_CLOSING) {
|
|
157
|
-
this.assumedPosition = BLINDS_OPEN - disposition;
|
|
158
|
-
} else {
|
|
159
|
-
this.assumedPosition = this.minPosition + disposition;
|
|
160
|
-
}
|
|
155
|
+
this.assumedPosition = this._estimatePosition();
|
|
161
156
|
}
|
|
162
157
|
|
|
163
|
-
const adjustedPosition =
|
|
158
|
+
const adjustedPosition = this._reportedPosition();
|
|
164
159
|
characteristicCurrentPosition.updateValue(adjustedPosition);
|
|
165
160
|
characteristicTargetPosition.updateValue(adjustedPosition);
|
|
166
161
|
characteristicPositionState.updateValue(Characteristic.PositionState.STOPPED);
|
|
@@ -186,7 +181,7 @@ class SimpleBlindsAccessory extends BaseAccessory {
|
|
|
186
181
|
case this.cmdClose:
|
|
187
182
|
return BLINDS_CLOSED;
|
|
188
183
|
default:
|
|
189
|
-
return
|
|
184
|
+
return this._reportedPosition();
|
|
190
185
|
}
|
|
191
186
|
}
|
|
192
187
|
|
|
@@ -201,7 +196,7 @@ class SimpleBlindsAccessory extends BaseAccessory {
|
|
|
201
196
|
case this.cmdClose:
|
|
202
197
|
return BLINDS_CLOSED;
|
|
203
198
|
default:
|
|
204
|
-
return
|
|
199
|
+
return this._reportedPosition();
|
|
205
200
|
}
|
|
206
201
|
}
|
|
207
202
|
|
|
@@ -213,12 +208,7 @@ class SimpleBlindsAccessory extends BaseAccessory {
|
|
|
213
208
|
|
|
214
209
|
if (this.changeTime !== false) {
|
|
215
210
|
this.log.debug('[TuyaAccessory] Blinds ' + (this.assumedState === BLINDS_CLOSING ? 'closing' : 'opening') + ' had started ' + this.changeTime + '; ' + (Date.now() - this.changeTime) + 'ms ago');
|
|
216
|
-
|
|
217
|
-
if (this.assumedState === BLINDS_CLOSING) {
|
|
218
|
-
this.assumedPosition = BLINDS_OPEN - disposition;
|
|
219
|
-
} else {
|
|
220
|
-
this.assumedPosition = this.minPosition + disposition;
|
|
221
|
-
}
|
|
211
|
+
this.assumedPosition = this._estimatePosition();
|
|
222
212
|
this.log.debug('[TuyaAccessory] Blinds\' adjusted assumedPosition is ' + this.assumedPosition);
|
|
223
213
|
}
|
|
224
214
|
|
|
@@ -253,6 +243,22 @@ class SimpleBlindsAccessory extends BaseAccessory {
|
|
|
253
243
|
}
|
|
254
244
|
}
|
|
255
245
|
|
|
246
|
+
// Time-based guess at where the blind is now, given when the current run
|
|
247
|
+
// started. Clamped to the physical travel range: the motor stops at its end
|
|
248
|
+
// limits, and changeTime can go stale (e.g. the device never echoed a
|
|
249
|
+
// command because its DP already held that value), which otherwise
|
|
250
|
+
// extrapolates to positions like 147382 that HomeKit rejects.
|
|
251
|
+
_estimatePosition() {
|
|
252
|
+
const disposition = (Date.now() - this.changeTime) / (10 * this.duration);
|
|
253
|
+
const position = this.assumedState === BLINDS_CLOSING ? BLINDS_OPEN - disposition : this.minPosition + disposition;
|
|
254
|
+
return Math.min(BLINDS_OPEN, Math.max(this.minPosition, position));
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
// assumedPosition dips below 0 when timeToTighten is set; HomeKit only takes 0-100.
|
|
258
|
+
_reportedPosition() {
|
|
259
|
+
return Math.min(BLINDS_OPEN, Math.max(BLINDS_CLOSED, Math.round(this.assumedPosition)));
|
|
260
|
+
}
|
|
261
|
+
|
|
256
262
|
_getPositionState() {
|
|
257
263
|
const {Characteristic} = this.hap;
|
|
258
264
|
|
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
|
+
});
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const SimpleBlindsAccessory = require('../lib/SimpleBlindsAccessory');
|
|
4
|
+
const { HAP, makeInstance, makeMockCharacteristic } = require('./support/mocks');
|
|
5
|
+
|
|
6
|
+
const { CurrentPosition, TargetPosition } = HAP.Characteristic;
|
|
7
|
+
|
|
8
|
+
const HOUR = 60 * 60 * 1000;
|
|
9
|
+
|
|
10
|
+
// Wire up the accessory the way the platform does (first state report), and
|
|
11
|
+
// hand back the device 'change' listener. Each characteristic gets its own mock
|
|
12
|
+
// (the shared default one can't tell CurrentPosition from PositionState).
|
|
13
|
+
function makeBlinds(context = {}, dps = { 1: 'stop' }) {
|
|
14
|
+
const { instance, device, accessory } = makeInstance(SimpleBlindsAccessory, dps, { type: 'SimpleBlinds', ...context });
|
|
15
|
+
// echo writes into state like a real device, so setMultiState's
|
|
16
|
+
// "already at that value" short-circuit behaves as it does in production
|
|
17
|
+
device.update = jest.fn(change => { Object.assign(device.state, change); return true; });
|
|
18
|
+
const chars = new Map();
|
|
19
|
+
accessory._mockService.getCharacteristic = jest.fn(c => {
|
|
20
|
+
if (!chars.has(c)) chars.set(c, makeMockCharacteristic());
|
|
21
|
+
return chars.get(c);
|
|
22
|
+
});
|
|
23
|
+
instance._registerCharacteristics(dps);
|
|
24
|
+
const onChange = device.on.mock.calls.find(([event]) => event === 'change')[1];
|
|
25
|
+
return { instance, device, onChange, current: chars.get(CurrentPosition), target: chars.get(TargetPosition) };
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
beforeEach(() => jest.useFakeTimers({ now: new Date('2026-10-24T08:00:00Z') }));
|
|
29
|
+
afterEach(() => jest.useRealTimers());
|
|
30
|
+
|
|
31
|
+
// ---------------------------------------------------------------------------
|
|
32
|
+
// The time-based position estimate must stay within the physical travel range.
|
|
33
|
+
// A stale changeTime (the device never echoed the command because its DP
|
|
34
|
+
// already held that value) used to extrapolate to values like 147382, which
|
|
35
|
+
// HomeKit rejects — breaking percentage control.
|
|
36
|
+
// ---------------------------------------------------------------------------
|
|
37
|
+
describe('SimpleBlindsAccessory position estimate', () => {
|
|
38
|
+
test('a stop long after opening started reports fully open, not >100', () => {
|
|
39
|
+
const { instance, onChange, current, target } = makeBlinds();
|
|
40
|
+
instance.assumedState = 'opening';
|
|
41
|
+
instance.changeTime = Date.now() - 18 * HOUR;
|
|
42
|
+
|
|
43
|
+
onChange({ 1: 'stop' });
|
|
44
|
+
|
|
45
|
+
expect(current.value).toBe(100);
|
|
46
|
+
expect(target.value).toBe(100);
|
|
47
|
+
expect(instance.assumedPosition).toBe(100);
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
test('a stop long after closing started reports fully closed, not <0', () => {
|
|
51
|
+
const { instance, onChange, current, target } = makeBlinds();
|
|
52
|
+
instance.assumedState = 'closing';
|
|
53
|
+
instance.changeTime = Date.now() - 18 * HOUR;
|
|
54
|
+
|
|
55
|
+
onChange({ 1: 'stop' });
|
|
56
|
+
|
|
57
|
+
expect(current.value).toBe(0);
|
|
58
|
+
expect(target.value).toBe(0);
|
|
59
|
+
expect(instance.assumedPosition).toBe(0);
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
test('a stop mid-travel still reports the proportional position', () => {
|
|
63
|
+
const { instance, onChange, current } = makeBlinds({ timeToOpen: 40 });
|
|
64
|
+
instance.assumedState = 'opening';
|
|
65
|
+
instance.changeTime = Date.now() - 10 * 1000; // 10s of a 40s run
|
|
66
|
+
|
|
67
|
+
onChange({ 1: 'stop' });
|
|
68
|
+
|
|
69
|
+
expect(current.value).toBe(25);
|
|
70
|
+
});
|
|
71
|
+
|
|
72
|
+
test('closing clamps to minPosition when timeToTighten is set', () => {
|
|
73
|
+
const { instance, onChange } = makeBlinds({ timeToOpen: 45, timeToTighten: 5 });
|
|
74
|
+
instance.assumedState = 'closing';
|
|
75
|
+
instance.changeTime = Date.now() - 18 * HOUR;
|
|
76
|
+
|
|
77
|
+
onChange({ 1: 'stop' });
|
|
78
|
+
|
|
79
|
+
expect(instance.assumedPosition).toBe(instance.minPosition);
|
|
80
|
+
});
|
|
81
|
+
|
|
82
|
+
test('setting a percentage after a stale run moves from the real end position', async () => {
|
|
83
|
+
const { instance, device } = makeBlinds({ timeToOpen: 40 });
|
|
84
|
+
instance.assumedState = 'opening';
|
|
85
|
+
instance.changeTime = Date.now() - 18 * HOUR;
|
|
86
|
+
|
|
87
|
+
await instance.setTargetPosition(50);
|
|
88
|
+
|
|
89
|
+
expect(instance.assumedPosition).toBe(100);
|
|
90
|
+
expect(device.update).toHaveBeenLastCalledWith({ 1: 'close' });
|
|
91
|
+
|
|
92
|
+
// 50% of a 40s run, not hours
|
|
93
|
+
jest.advanceTimersByTime(20 * 1000);
|
|
94
|
+
expect(device.update).toHaveBeenLastCalledWith({ 1: 'stop' });
|
|
95
|
+
});
|
|
96
|
+
|
|
97
|
+
test('reported positions are clamped to the HomeKit 0–100 range', () => {
|
|
98
|
+
const { instance } = makeBlinds({ timeToOpen: 45, timeToTighten: 5 });
|
|
99
|
+
|
|
100
|
+
instance.assumedPosition = 368;
|
|
101
|
+
expect(instance._getCurrentPosition('stop')).toBe(100);
|
|
102
|
+
expect(instance._getTargetPosition('stop')).toBe(100);
|
|
103
|
+
|
|
104
|
+
instance.assumedPosition = instance.minPosition;
|
|
105
|
+
expect(instance._getCurrentPosition('stop')).toBe(0);
|
|
106
|
+
expect(instance._getTargetPosition('stop')).toBe(0);
|
|
107
|
+
});
|
|
108
|
+
});
|
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'),
|
package/test/support/mocks.js
CHANGED
|
@@ -15,6 +15,8 @@ const HAP = {
|
|
|
15
15
|
CurrentHeaterCoolerState: { INACTIVE: 0, IDLE: 1, HEATING: 2, COOLING: 3 },
|
|
16
16
|
TargetHeaterCoolerState: { AUTO: 0, HEAT: 1, COOL: 2 },
|
|
17
17
|
PositionState: { DECREASING: 0, INCREASING: 1, STOPPED: 2 },
|
|
18
|
+
CurrentPosition: { UUID: '6D' },
|
|
19
|
+
TargetPosition: { UUID: '7C' },
|
|
18
20
|
LockPhysicalControls: { CONTROL_LOCK_DISABLED: 0, CONTROL_LOCK_ENABLED: 1 },
|
|
19
21
|
TemperatureDisplayUnits: { CELSIUS: 0, FAHRENHEIT: 1 },
|
|
20
22
|
SwingMode: { SWING_DISABLED: 0, SWING_ENABLED: 1 },
|
|
@@ -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
|
|