@switchbot/homebridge-switchbot 5.2.9-beta.1 → 5.2.10-beta.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/dist/devices/genericDevice.d.ts.map +1 -1
- package/dist/devices/genericDevice.js +528 -118
- package/dist/devices/genericDevice.js.map +1 -1
- package/dist/homebridge-ui/public/js/advanced-settings.d.ts.map +1 -1
- package/dist/homebridge-ui/public/js/advanced-settings.js +3 -1
- package/dist/homebridge-ui/public/js/advanced-settings.js.map +1 -1
- package/dist/homebridge-ui/public/js/advanced-settings.ts +3 -1
- package/dist/homebridge-ui/public/js/api.d.ts.map +1 -1
- package/dist/homebridge-ui/public/js/api.js +21 -7
- package/dist/homebridge-ui/public/js/api.js.map +1 -1
- package/dist/homebridge-ui/public/js/api.ts +21 -7
- package/dist/homebridge-ui/public/js/app.js +74 -16
- package/dist/homebridge-ui/public/js/app.js.map +2 -2
- package/dist/homebridge-ui/public/js/credentials.d.ts.map +1 -1
- package/dist/homebridge-ui/public/js/credentials.js +9 -3
- package/dist/homebridge-ui/public/js/credentials.js.map +1 -1
- package/dist/homebridge-ui/public/js/credentials.ts +9 -3
- package/dist/homebridge-ui/public/js/devices-delete.d.ts.map +1 -1
- package/dist/homebridge-ui/public/js/devices-delete.js +6 -2
- package/dist/homebridge-ui/public/js/devices-delete.js.map +1 -1
- package/dist/homebridge-ui/public/js/devices-delete.ts +6 -2
- package/dist/homebridge-ui/public/js/devices.d.ts.map +1 -1
- package/dist/homebridge-ui/public/js/devices.js +3 -1
- package/dist/homebridge-ui/public/js/devices.js.map +1 -1
- package/dist/homebridge-ui/public/js/devices.ts +3 -1
- package/dist/homebridge-ui/public/js/discovery.d.ts.map +1 -1
- package/dist/homebridge-ui/public/js/discovery.js +89 -25
- package/dist/homebridge-ui/public/js/discovery.js.map +1 -1
- package/dist/homebridge-ui/public/js/discovery.ts +89 -25
- package/dist/homebridge-ui/public/js/modals.d.ts.map +1 -1
- package/dist/homebridge-ui/public/js/modals.js +13 -3
- package/dist/homebridge-ui/public/js/modals.js.map +1 -1
- package/dist/homebridge-ui/public/js/modals.ts +13 -3
- package/dist/homebridge-ui/public/js/render.d.ts.map +1 -1
- package/dist/homebridge-ui/public/js/render.js +67 -17
- package/dist/homebridge-ui/public/js/render.js.map +1 -1
- package/dist/homebridge-ui/public/js/render.ts +67 -17
- package/dist/homebridge-ui/public/js/toast.d.ts.map +1 -1
- package/dist/homebridge-ui/public/js/toast.js +6 -2
- package/dist/homebridge-ui/public/js/toast.js.map +1 -1
- package/dist/homebridge-ui/public/js/toast.ts +6 -2
- package/docs/variables/default.html +1 -1
- package/package.json +9 -9
- package/src/devices/genericDevice.ts +529 -129
- package/src/homebridge-ui/public/js/advanced-settings.ts +3 -1
- package/src/homebridge-ui/public/js/api.ts +21 -7
- package/src/homebridge-ui/public/js/credentials.ts +9 -3
- package/src/homebridge-ui/public/js/devices-delete.ts +6 -2
- package/src/homebridge-ui/public/js/devices.ts +3 -1
- package/src/homebridge-ui/public/js/discovery.ts +89 -25
- package/src/homebridge-ui/public/js/modals.ts +13 -3
- package/src/homebridge-ui/public/js/render.ts +67 -17
- package/src/homebridge-ui/public/js/toast.ts +6 -2
- package/test/client/node-switchbot-commands.spec.ts +44 -8
- package/test/client/switchbot-client-debounce.spec.ts +24 -3
- package/test/client/switchbot-client-discovery.spec.ts +26 -5
- package/test/client/switchbot-client-keys.spec.ts +30 -7
- package/test/client/switchbot-client-openapi.spec.ts +6 -1
- package/test/client/switchbotClient.spec.ts +30 -6
- package/test/device/bot-hap.spec.ts +131 -22
- package/test/device/curtain-ble-position.spec.ts +15 -3
- package/test/device/deviceBase.spec.ts +6 -1
- package/test/device/deviceFactory-edge.spec.ts +12 -2
- package/test/device/deviceFactory.spec.ts +6 -1
- package/test/device/fan-swing.spec.ts +9 -2
- package/test/device/genericDevice-blepoll.spec.ts +17 -3
- package/test/device/getstate-cache.spec.ts +37 -6
- package/test/device/getstate-returns-status.spec.ts +65 -13
- package/test/device/lock-users.spec.ts +24 -7
- package/test/device/matter-descriptors.spec.ts +6 -1
- package/test/device/matter-device-state.spec.ts +6 -1
- package/test/device/meter-battery.spec.ts +86 -14
- package/test/device/meter-co2.spec.ts +65 -10
- package/test/device/model-identities.spec.ts +6 -1
- package/test/device/water-detector-battery.spec.ts +19 -3
- package/test/device/water-detector-leak.spec.ts +6 -1
- package/test/helpers/matter-harness.ts +21 -4
- package/test/platform/accessory-restore.spec.ts +18 -3
- package/test/platform/hap-cache-restart.spec.ts +66 -13
- package/test/platform/matter-childbridge.spec.ts +16 -3
- package/test/platform/matter-integration.spec.ts +6 -1
- package/test/platform/matter-registration.spec.ts +47 -10
- package/test/platform/platform-edge.spec.ts +13 -3
- package/test/platform/platform.integration.spec.ts +16 -3
- package/test/utils/utils.spec.ts +42 -8
|
@@ -5,7 +5,9 @@ import { MATTER_ATTRIBUTE_IDS, MATTER_CLUSTER_IDS } from '../utils.js';
|
|
|
5
5
|
import { DeviceBase } from './deviceBase.js';
|
|
6
6
|
function validateBLEResponseLength(buf, expected, context = '', log) {
|
|
7
7
|
if (!buf || typeof buf.length !== 'number' || buf.length !== expected) {
|
|
8
|
-
log.warn(`[BLE] Invalid response length${context
|
|
8
|
+
log.warn(`[BLE] Invalid response length${context
|
|
9
|
+
? ` for ${context}`
|
|
10
|
+
: ''}: expected ${expected}, got ${buf?.length}`);
|
|
9
11
|
return false;
|
|
10
12
|
}
|
|
11
13
|
return true;
|
|
@@ -176,7 +178,10 @@ export class GenericDevice extends DeviceBase {
|
|
|
176
178
|
// at its fallback for the whole window after one transient error.
|
|
177
179
|
return { id: this.opts.id, type: this.opts.type, unreadable: true };
|
|
178
180
|
}
|
|
179
|
-
this.stateCache = {
|
|
181
|
+
this.stateCache = {
|
|
182
|
+
at: Date.now(),
|
|
183
|
+
value,
|
|
184
|
+
};
|
|
180
185
|
return value;
|
|
181
186
|
})
|
|
182
187
|
.finally(() => {
|
|
@@ -193,7 +198,12 @@ export class GenericDevice extends DeviceBase {
|
|
|
193
198
|
if (raw && (raw instanceof Buffer || Array.isArray(raw) || raw instanceof Uint8Array)) {
|
|
194
199
|
// Default to 12, override per device if needed
|
|
195
200
|
if (!validateBLEResponseLength(raw, 12, this.opts.type, this.log)) {
|
|
196
|
-
return {
|
|
201
|
+
return {
|
|
202
|
+
id: this.opts.id,
|
|
203
|
+
type: this.opts.type,
|
|
204
|
+
error: 'invalid_ble_response_length',
|
|
205
|
+
raw,
|
|
206
|
+
};
|
|
197
207
|
}
|
|
198
208
|
}
|
|
199
209
|
// Normalize common response shapes
|
|
@@ -215,7 +225,9 @@ export class GenericDevice extends DeviceBase {
|
|
|
215
225
|
}
|
|
216
226
|
}
|
|
217
227
|
catch (e) {
|
|
218
|
-
this.log?.debug?.(`getState: could not read status for ${this.opts.id}:`, e instanceof Error
|
|
228
|
+
this.log?.debug?.(`getState: could not read status for ${this.opts.id}:`, e instanceof Error
|
|
229
|
+
? e.message
|
|
230
|
+
: e);
|
|
219
231
|
}
|
|
220
232
|
}
|
|
221
233
|
catch (e) {
|
|
@@ -338,8 +350,14 @@ export class GenericDevice extends DeviceBase {
|
|
|
338
350
|
type: 'OnOff',
|
|
339
351
|
clusterId: MATTER_CLUSTER_IDS.OnOff,
|
|
340
352
|
attributes: {
|
|
341
|
-
onOff: {
|
|
342
|
-
|
|
353
|
+
onOff: {
|
|
354
|
+
read: async () => !!(await this.getState()).on || (await this.getState()).power === 'on' || (await this.getState()).state === 'on',
|
|
355
|
+
write: async (v) => this.setState({ on: !!v }),
|
|
356
|
+
},
|
|
357
|
+
[MATTER_ATTRIBUTE_IDS.OnOff.OnOff]: {
|
|
358
|
+
read: async () => !!(await this.getState()).on || (await this.getState()).power === 'on' || (await this.getState()).state === 'on',
|
|
359
|
+
write: async (v) => this.setState({ on: !!v }),
|
|
360
|
+
},
|
|
343
361
|
},
|
|
344
362
|
});
|
|
345
363
|
}
|
|
@@ -349,8 +367,18 @@ export class GenericDevice extends DeviceBase {
|
|
|
349
367
|
type: 'LevelControl',
|
|
350
368
|
clusterId: MATTER_CLUSTER_IDS.LevelControl,
|
|
351
369
|
attributes: {
|
|
352
|
-
currentLevel: {
|
|
353
|
-
|
|
370
|
+
currentLevel: {
|
|
371
|
+
read: async () => (await this.getState()).brightness ?? 100,
|
|
372
|
+
write: async (v) => this.setState({
|
|
373
|
+
brightness: Number(v),
|
|
374
|
+
}),
|
|
375
|
+
},
|
|
376
|
+
[MATTER_ATTRIBUTE_IDS.LevelControl.CurrentLevel]: {
|
|
377
|
+
read: async () => (await this.getState()).brightness ?? 100,
|
|
378
|
+
write: async (v) => this.setState({
|
|
379
|
+
brightness: Number(v),
|
|
380
|
+
}),
|
|
381
|
+
},
|
|
354
382
|
},
|
|
355
383
|
});
|
|
356
384
|
}
|
|
@@ -360,15 +388,51 @@ export class GenericDevice extends DeviceBase {
|
|
|
360
388
|
type: 'ColorControl',
|
|
361
389
|
clusterId: MATTER_CLUSTER_IDS.ColorControl,
|
|
362
390
|
attributes: {
|
|
363
|
-
colorMode: {
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
391
|
+
colorMode: {
|
|
392
|
+
read: async () => 0,
|
|
393
|
+
},
|
|
394
|
+
colorHue: {
|
|
395
|
+
read: async () => (await this.getState()).hue ?? 0,
|
|
396
|
+
write: async (v) => this.setState({
|
|
397
|
+
hue: Number(v),
|
|
398
|
+
}),
|
|
399
|
+
},
|
|
400
|
+
[MATTER_ATTRIBUTE_IDS.ColorControl.CurrentHue]: {
|
|
401
|
+
read: async () => (await this.getState()).hue ?? 0,
|
|
402
|
+
write: async (v) => this.setState({
|
|
403
|
+
hue: Number(v),
|
|
404
|
+
}),
|
|
405
|
+
},
|
|
406
|
+
colorSaturation: {
|
|
407
|
+
read: async () => (await this.getState()).saturation ?? 0,
|
|
408
|
+
write: async (v) => this.setState({
|
|
409
|
+
saturation: Number(v),
|
|
410
|
+
}),
|
|
411
|
+
},
|
|
412
|
+
[MATTER_ATTRIBUTE_IDS.ColorControl.CurrentSaturation]: {
|
|
413
|
+
read: async () => (await this.getState()).saturation ?? 0,
|
|
414
|
+
write: async (v) => this.setState({
|
|
415
|
+
saturation: Number(v),
|
|
416
|
+
}),
|
|
417
|
+
},
|
|
368
418
|
...(typeof state.colorTemperature === 'number' || typeof state.kelvin === 'number'
|
|
369
419
|
? {
|
|
370
|
-
colorTemperature: {
|
|
371
|
-
|
|
420
|
+
colorTemperature: {
|
|
421
|
+
read: async () => typeof (await this.getState()).colorTemperature === 'number'
|
|
422
|
+
? (await this.getState()).colorTemperature
|
|
423
|
+
: Math.round(1000000 / ((await this.getState()).kelvin ?? 2500)),
|
|
424
|
+
write: async (v) => this.setState({
|
|
425
|
+
colorTemperature: Number(v),
|
|
426
|
+
}),
|
|
427
|
+
},
|
|
428
|
+
[MATTER_ATTRIBUTE_IDS.ColorControl.ColorTemperatureMireds]: {
|
|
429
|
+
read: async () => typeof (await this.getState()).colorTemperature === 'number'
|
|
430
|
+
? (await this.getState()).colorTemperature
|
|
431
|
+
: Math.round(1000000 / ((await this.getState()).kelvin ?? 2500)),
|
|
432
|
+
write: async (v) => this.setState({
|
|
433
|
+
colorTemperature: Number(v),
|
|
434
|
+
}),
|
|
435
|
+
},
|
|
372
436
|
}
|
|
373
437
|
: {}),
|
|
374
438
|
},
|
|
@@ -380,7 +444,9 @@ export class GenericDevice extends DeviceBase {
|
|
|
380
444
|
type: 'TemperatureMeasurement',
|
|
381
445
|
// No clusterId, not present in MATTER_CLUSTER_IDS
|
|
382
446
|
attributes: {
|
|
383
|
-
measuredValue: {
|
|
447
|
+
measuredValue: {
|
|
448
|
+
read: async () => (await this.getState()).temperature ?? 0,
|
|
449
|
+
},
|
|
384
450
|
},
|
|
385
451
|
});
|
|
386
452
|
}
|
|
@@ -390,7 +456,9 @@ export class GenericDevice extends DeviceBase {
|
|
|
390
456
|
type: 'RelativeHumidityMeasurement',
|
|
391
457
|
clusterId: MATTER_CLUSTER_IDS.RelativeHumidityMeasurement,
|
|
392
458
|
attributes: {
|
|
393
|
-
measuredValue: {
|
|
459
|
+
measuredValue: {
|
|
460
|
+
read: async () => (await this.getState()).humidity ?? 0,
|
|
461
|
+
},
|
|
394
462
|
},
|
|
395
463
|
});
|
|
396
464
|
}
|
|
@@ -399,7 +467,9 @@ export class GenericDevice extends DeviceBase {
|
|
|
399
467
|
clusters.push({
|
|
400
468
|
type: 'AirQuality',
|
|
401
469
|
attributes: {
|
|
402
|
-
CO2: {
|
|
470
|
+
CO2: {
|
|
471
|
+
read: async () => (await this.getState()).CO2 ?? 0,
|
|
472
|
+
},
|
|
403
473
|
},
|
|
404
474
|
});
|
|
405
475
|
}
|
|
@@ -409,7 +479,12 @@ export class GenericDevice extends DeviceBase {
|
|
|
409
479
|
type: 'DoorLock',
|
|
410
480
|
clusterId: MATTER_CLUSTER_IDS.DoorLock,
|
|
411
481
|
attributes: {
|
|
412
|
-
lockState: {
|
|
482
|
+
lockState: {
|
|
483
|
+
read: async () => (await this.getState()).lockState ?? (await this.getState()).locked
|
|
484
|
+
? 1
|
|
485
|
+
: 0,
|
|
486
|
+
write: async (v) => this.setState({ locked: !!v }),
|
|
487
|
+
},
|
|
413
488
|
},
|
|
414
489
|
});
|
|
415
490
|
}
|
|
@@ -419,7 +494,11 @@ export class GenericDevice extends DeviceBase {
|
|
|
419
494
|
type: 'OccupancySensing',
|
|
420
495
|
// No clusterId, not present in MATTER_CLUSTER_IDS
|
|
421
496
|
attributes: {
|
|
422
|
-
occupancy: {
|
|
497
|
+
occupancy: {
|
|
498
|
+
read: async () => (await this.getState()).moveDetected === true || (await this.getState()).motion === true
|
|
499
|
+
? 1
|
|
500
|
+
: 0,
|
|
501
|
+
},
|
|
423
502
|
},
|
|
424
503
|
});
|
|
425
504
|
}
|
|
@@ -429,7 +508,11 @@ export class GenericDevice extends DeviceBase {
|
|
|
429
508
|
type: 'BooleanState',
|
|
430
509
|
// No clusterId, not present in MATTER_CLUSTER_IDS
|
|
431
510
|
attributes: {
|
|
432
|
-
stateValue: {
|
|
511
|
+
stateValue: {
|
|
512
|
+
read: async () => (await this.getState()).openState === 'open' || (await this.getState()).open === true
|
|
513
|
+
? 1
|
|
514
|
+
: 0,
|
|
515
|
+
},
|
|
433
516
|
},
|
|
434
517
|
});
|
|
435
518
|
}
|
|
@@ -438,7 +521,11 @@ export class GenericDevice extends DeviceBase {
|
|
|
438
521
|
clusters.push({
|
|
439
522
|
type: 'LeakSensor',
|
|
440
523
|
attributes: {
|
|
441
|
-
leakDetected: {
|
|
524
|
+
leakDetected: {
|
|
525
|
+
read: async () => (await this.getState()).leak === true || (await this.getState()).status === 1
|
|
526
|
+
? 1
|
|
527
|
+
: 0,
|
|
528
|
+
},
|
|
442
529
|
},
|
|
443
530
|
});
|
|
444
531
|
}
|
|
@@ -448,9 +535,15 @@ export class GenericDevice extends DeviceBase {
|
|
|
448
535
|
type: 'ElectricalMeasurement',
|
|
449
536
|
// No clusterId, not present in MATTER_CLUSTER_IDS
|
|
450
537
|
attributes: {
|
|
451
|
-
voltage: {
|
|
452
|
-
|
|
453
|
-
|
|
538
|
+
voltage: {
|
|
539
|
+
read: async () => (await this.getState()).voltage ?? 0,
|
|
540
|
+
},
|
|
541
|
+
power: {
|
|
542
|
+
read: async () => (await this.getState()).power ?? 0,
|
|
543
|
+
},
|
|
544
|
+
electricCurrent: {
|
|
545
|
+
read: async () => (await this.getState()).electricCurrent ?? 0,
|
|
546
|
+
},
|
|
454
547
|
},
|
|
455
548
|
});
|
|
456
549
|
}
|
|
@@ -460,7 +553,12 @@ export class GenericDevice extends DeviceBase {
|
|
|
460
553
|
type: 'FanControl',
|
|
461
554
|
clusterId: MATTER_CLUSTER_IDS.FanControl,
|
|
462
555
|
attributes: {
|
|
463
|
-
speedCurrent: {
|
|
556
|
+
speedCurrent: {
|
|
557
|
+
read: async () => (await this.getState()).speed ?? (await this.getState()).fanSpeed ?? 0,
|
|
558
|
+
write: async (v) => this.setState({
|
|
559
|
+
speed: Number(v),
|
|
560
|
+
}),
|
|
561
|
+
},
|
|
464
562
|
},
|
|
465
563
|
});
|
|
466
564
|
}
|
|
@@ -469,7 +567,9 @@ export class GenericDevice extends DeviceBase {
|
|
|
469
567
|
clusters.push({
|
|
470
568
|
type: 'RobotVacuumCleaner',
|
|
471
569
|
attributes: {
|
|
472
|
-
workingStatus: {
|
|
570
|
+
workingStatus: {
|
|
571
|
+
read: async () => (await this.getState()).workingStatus ?? 'StandBy',
|
|
572
|
+
},
|
|
473
573
|
},
|
|
474
574
|
});
|
|
475
575
|
}
|
|
@@ -506,55 +606,124 @@ export class BotDevice extends GenericDevice {
|
|
|
506
606
|
if (pressMode && !on) {
|
|
507
607
|
return;
|
|
508
608
|
}
|
|
509
|
-
const command = pressMode
|
|
609
|
+
const command = pressMode
|
|
610
|
+
? 'press'
|
|
611
|
+
: on ? 'turnOn' : 'turnOff';
|
|
510
612
|
const result = await this.setState({ command, parameter: 'default', commandType: 'command' });
|
|
511
613
|
if (result !== true && result?.success !== true) {
|
|
512
614
|
throw new Error(`SwitchBot Bot ${command} failed: ${result?.reason ?? 'unknown error'}`);
|
|
513
615
|
}
|
|
514
616
|
if (!pressMode) {
|
|
515
|
-
this.lastCommand = {
|
|
617
|
+
this.lastCommand = {
|
|
618
|
+
on,
|
|
619
|
+
at: Date.now(),
|
|
620
|
+
};
|
|
516
621
|
}
|
|
517
622
|
};
|
|
518
623
|
const control = (name, active, inactive, requestedOn) => ({
|
|
519
|
-
get: async () => (await isOn())
|
|
624
|
+
get: async () => (await isOn())
|
|
625
|
+
? active
|
|
626
|
+
: inactive,
|
|
520
627
|
set: async (value) => setOn(requestedOn(value)),
|
|
521
|
-
...(pressMode
|
|
628
|
+
...(pressMode
|
|
629
|
+
? {
|
|
630
|
+
refreshAfterSet: [name],
|
|
631
|
+
}
|
|
632
|
+
: {}),
|
|
522
633
|
});
|
|
523
634
|
const position = () => ({
|
|
524
|
-
CurrentPosition: {
|
|
525
|
-
|
|
635
|
+
CurrentPosition: {
|
|
636
|
+
get: async () => (await isOn())
|
|
637
|
+
? 100
|
|
638
|
+
: 0,
|
|
639
|
+
},
|
|
640
|
+
PositionState: {
|
|
641
|
+
get: async () => 2,
|
|
642
|
+
},
|
|
526
643
|
TargetPosition: control('TargetPosition', 100, 0, value => Number(value) > 0),
|
|
527
644
|
});
|
|
528
645
|
const active = (value) => Number(value) === 1;
|
|
529
646
|
const presentations = {
|
|
530
|
-
switch: {
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
647
|
+
switch: {
|
|
648
|
+
type: 'Switch',
|
|
649
|
+
characteristics: {
|
|
650
|
+
On: control('On', true, false, value => value === true),
|
|
651
|
+
},
|
|
652
|
+
},
|
|
653
|
+
outlet: {
|
|
654
|
+
type: 'Outlet',
|
|
655
|
+
characteristics: {
|
|
656
|
+
On: control('On', true, false, value => value === true),
|
|
657
|
+
},
|
|
658
|
+
},
|
|
659
|
+
door: {
|
|
660
|
+
type: 'Door',
|
|
661
|
+
characteristics: position(),
|
|
662
|
+
},
|
|
663
|
+
window: {
|
|
664
|
+
type: 'Window',
|
|
665
|
+
characteristics: position(),
|
|
666
|
+
},
|
|
667
|
+
windowcovering: {
|
|
668
|
+
type: 'WindowCovering',
|
|
669
|
+
characteristics: position(),
|
|
670
|
+
},
|
|
671
|
+
garagedoor: {
|
|
672
|
+
type: 'GarageDoorOpener',
|
|
673
|
+
characteristics: {
|
|
674
|
+
CurrentDoorState: {
|
|
675
|
+
get: async () => (await isOn())
|
|
676
|
+
? 0
|
|
677
|
+
: 1,
|
|
678
|
+
},
|
|
537
679
|
TargetDoorState: control('TargetDoorState', 0, 1, value => Number(value) === 0),
|
|
538
|
-
ObstructionDetected: {
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
680
|
+
ObstructionDetected: {
|
|
681
|
+
get: async () => false,
|
|
682
|
+
},
|
|
683
|
+
},
|
|
684
|
+
},
|
|
685
|
+
lock: {
|
|
686
|
+
type: 'LockMechanism',
|
|
687
|
+
characteristics: {
|
|
688
|
+
LockCurrentState: {
|
|
689
|
+
get: async () => (await isOn())
|
|
690
|
+
? 0
|
|
691
|
+
: 1,
|
|
692
|
+
},
|
|
542
693
|
LockTargetState: control('LockTargetState', 0, 1, value => Number(value) === 0),
|
|
543
|
-
}
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
694
|
+
},
|
|
695
|
+
},
|
|
696
|
+
faucet: {
|
|
697
|
+
type: 'Faucet',
|
|
698
|
+
characteristics: {
|
|
699
|
+
Active: control('Active', 1, 0, active),
|
|
700
|
+
},
|
|
701
|
+
},
|
|
702
|
+
fan: {
|
|
703
|
+
type: 'Fanv2',
|
|
704
|
+
characteristics: {
|
|
705
|
+
Active: control('Active', 1, 0, active),
|
|
706
|
+
},
|
|
707
|
+
},
|
|
708
|
+
stateful: {
|
|
709
|
+
type: 'StatefulProgrammableSwitch',
|
|
710
|
+
characteristics: {
|
|
547
711
|
ProgrammableSwitchEvent: {},
|
|
548
712
|
ProgrammableSwitchOutputState: {
|
|
549
713
|
...control('ProgrammableSwitchOutputState', 1, 0, active),
|
|
550
|
-
...(pressMode
|
|
714
|
+
...(pressMode
|
|
715
|
+
? {
|
|
716
|
+
refreshAfterSet: ['ProgrammableSwitchOutputState'],
|
|
717
|
+
}
|
|
718
|
+
: {}),
|
|
551
719
|
afterSet: (value, service, hap) => {
|
|
552
720
|
if (!pressMode || active(value)) {
|
|
553
721
|
service.getCharacteristic(hap.Characteristic.ProgrammableSwitchEvent).sendEventNotification(0);
|
|
554
722
|
}
|
|
555
723
|
},
|
|
556
724
|
},
|
|
557
|
-
}
|
|
725
|
+
},
|
|
726
|
+
},
|
|
558
727
|
};
|
|
559
728
|
return {
|
|
560
729
|
services: [presentations[display] ?? presentations.switch],
|
|
@@ -637,9 +806,15 @@ export class CurtainDevice extends GenericDevice {
|
|
|
637
806
|
}
|
|
638
807
|
const previousPosition = this.lastKnownPosition;
|
|
639
808
|
this.lastTargetPosition = position;
|
|
640
|
-
this.positionState = position > this.lastKnownPosition
|
|
809
|
+
this.positionState = position > this.lastKnownPosition
|
|
810
|
+
? 1
|
|
811
|
+
: position < this.lastKnownPosition
|
|
812
|
+
? 0
|
|
813
|
+
: 2;
|
|
641
814
|
try {
|
|
642
|
-
const result = await this.setState({
|
|
815
|
+
const result = await this.setState({
|
|
816
|
+
position: this.toSwitchBotPosition(position),
|
|
817
|
+
});
|
|
643
818
|
if (result === false || result?.success === false) {
|
|
644
819
|
throw new Error(result?.reason ?? 'Curtain position command failed');
|
|
645
820
|
}
|
|
@@ -673,16 +848,22 @@ export class CurtainDevice extends GenericDevice {
|
|
|
673
848
|
currentPositionLiftPercent100ths: {
|
|
674
849
|
read: async () => {
|
|
675
850
|
const s = await this.getState();
|
|
676
|
-
return typeof s.position === 'number'
|
|
851
|
+
return typeof s.position === 'number'
|
|
852
|
+
? Math.round(s.position * 100)
|
|
853
|
+
: 0;
|
|
677
854
|
},
|
|
678
855
|
write: undefined,
|
|
679
856
|
},
|
|
680
857
|
targetPositionLiftPercent100ths: {
|
|
681
858
|
read: async () => {
|
|
682
859
|
const s = await this.getState();
|
|
683
|
-
return typeof s.position === 'number'
|
|
860
|
+
return typeof s.position === 'number'
|
|
861
|
+
? Math.round(s.position * 100)
|
|
862
|
+
: 0;
|
|
684
863
|
},
|
|
685
|
-
write: async (v) => this.setState({
|
|
864
|
+
write: async (v) => this.setState({
|
|
865
|
+
position: Math.round(Number(v) / 100),
|
|
866
|
+
}),
|
|
686
867
|
},
|
|
687
868
|
operationalStatus: {
|
|
688
869
|
read: async () => state.operationalStatus ?? { global: 0, lift: 0, tilt: 0 },
|
|
@@ -710,16 +891,22 @@ export class CurtainDevice extends GenericDevice {
|
|
|
710
891
|
attributes.currentPositionTiltPercent100ths = {
|
|
711
892
|
read: async () => {
|
|
712
893
|
const s = await this.getState();
|
|
713
|
-
return typeof s.tilt === 'number'
|
|
894
|
+
return typeof s.tilt === 'number'
|
|
895
|
+
? Math.round(s.tilt * 100)
|
|
896
|
+
: 0;
|
|
714
897
|
},
|
|
715
898
|
write: undefined,
|
|
716
899
|
};
|
|
717
900
|
attributes.targetPositionTiltPercent100ths = {
|
|
718
901
|
read: async () => {
|
|
719
902
|
const s = await this.getState();
|
|
720
|
-
return typeof s.tilt === 'number'
|
|
903
|
+
return typeof s.tilt === 'number'
|
|
904
|
+
? Math.round(s.tilt * 100)
|
|
905
|
+
: 0;
|
|
721
906
|
},
|
|
722
|
-
write: async (v) => this.setState({
|
|
907
|
+
write: async (v) => this.setState({
|
|
908
|
+
tilt: Math.round(Number(v) / 100),
|
|
909
|
+
}),
|
|
723
910
|
};
|
|
724
911
|
}
|
|
725
912
|
const windowCoveringCluster = {
|
|
@@ -760,10 +947,14 @@ export class FanDevice extends GenericDevice {
|
|
|
760
947
|
RotationSpeed: {
|
|
761
948
|
get: async () => {
|
|
762
949
|
const s = await this.getState();
|
|
763
|
-
return typeof s.speed === 'number'
|
|
950
|
+
return typeof s.speed === 'number'
|
|
951
|
+
? s.speed
|
|
952
|
+
: 0;
|
|
764
953
|
},
|
|
765
954
|
set: async (v) => {
|
|
766
|
-
await this.setState({
|
|
955
|
+
await this.setState({
|
|
956
|
+
speed: Number(v),
|
|
957
|
+
});
|
|
767
958
|
},
|
|
768
959
|
},
|
|
769
960
|
},
|
|
@@ -777,7 +968,11 @@ export class FanDevice extends GenericDevice {
|
|
|
777
968
|
}
|
|
778
969
|
// Oscillation support
|
|
779
970
|
if (typeof change.oscillate === 'boolean') {
|
|
780
|
-
const body = {
|
|
971
|
+
const body = {
|
|
972
|
+
command: 'setOscillation',
|
|
973
|
+
parameter: change.oscillate ? 'on' : 'off',
|
|
974
|
+
commandType: 'command',
|
|
975
|
+
};
|
|
781
976
|
try {
|
|
782
977
|
return await this.client.setDeviceState(this.opts.id, body);
|
|
783
978
|
}
|
|
@@ -833,9 +1028,15 @@ export class FanDevice extends GenericDevice {
|
|
|
833
1028
|
type: 'OnOff',
|
|
834
1029
|
clusterId: MATTER_CLUSTER_IDS.OnOff,
|
|
835
1030
|
attributes: {
|
|
836
|
-
onOff: {
|
|
1031
|
+
onOff: {
|
|
1032
|
+
read: async () => { const s = await this.getState(); return !!(s && (s.on === true || s.state === 'on')); },
|
|
1033
|
+
write: async (v) => this.setState({ on: !!v }),
|
|
1034
|
+
},
|
|
837
1035
|
// numeric attribute id for onOff
|
|
838
|
-
[MATTER_ATTRIBUTE_IDS.OnOff.OnOff]: {
|
|
1036
|
+
[MATTER_ATTRIBUTE_IDS.OnOff.OnOff]: {
|
|
1037
|
+
read: async () => { const s = await this.getState(); return !!(s && (s.on === true || s.state === 'on')); },
|
|
1038
|
+
write: async (v) => this.setState({ on: !!v }),
|
|
1039
|
+
},
|
|
839
1040
|
},
|
|
840
1041
|
},
|
|
841
1042
|
{
|
|
@@ -843,10 +1044,36 @@ export class FanDevice extends GenericDevice {
|
|
|
843
1044
|
type: 'FanControl',
|
|
844
1045
|
clusterId: MATTER_CLUSTER_IDS.FanControl,
|
|
845
1046
|
attributes: {
|
|
846
|
-
rotationSpeed: {
|
|
847
|
-
|
|
848
|
-
|
|
849
|
-
|
|
1047
|
+
rotationSpeed: {
|
|
1048
|
+
read: async () => {
|
|
1049
|
+
const s = await this.getState();
|
|
1050
|
+
return typeof s.speed === 'number'
|
|
1051
|
+
? s.speed
|
|
1052
|
+
: 0;
|
|
1053
|
+
},
|
|
1054
|
+
write: async (v) => this.setState({
|
|
1055
|
+
speed: Number(v),
|
|
1056
|
+
}),
|
|
1057
|
+
},
|
|
1058
|
+
[MATTER_ATTRIBUTE_IDS.FanControl.SpeedCurrent]: {
|
|
1059
|
+
read: async () => {
|
|
1060
|
+
const s = await this.getState();
|
|
1061
|
+
return typeof s.speed === 'number'
|
|
1062
|
+
? s.speed
|
|
1063
|
+
: 0;
|
|
1064
|
+
},
|
|
1065
|
+
write: async (v) => this.setState({
|
|
1066
|
+
speed: Number(v),
|
|
1067
|
+
}),
|
|
1068
|
+
},
|
|
1069
|
+
oscillation: {
|
|
1070
|
+
read: async () => { const s = await this.getState(); return !!s?.oscillating; },
|
|
1071
|
+
write: async (v) => this.setState({ oscillate: !!v }),
|
|
1072
|
+
},
|
|
1073
|
+
swingMode: {
|
|
1074
|
+
read: async () => { const s = await this.getState(); return s?.swingMode ?? null; },
|
|
1075
|
+
write: async (v) => this.setState({ swingMode: v }),
|
|
1076
|
+
},
|
|
850
1077
|
},
|
|
851
1078
|
},
|
|
852
1079
|
],
|
|
@@ -873,10 +1100,14 @@ export class LightDevice extends GenericDevice {
|
|
|
873
1100
|
props: { minValue: 0, maxValue: 100, minStep: 1 },
|
|
874
1101
|
get: async () => {
|
|
875
1102
|
const s = await this.getState();
|
|
876
|
-
return typeof s.brightness === 'number'
|
|
1103
|
+
return typeof s.brightness === 'number'
|
|
1104
|
+
? s.brightness
|
|
1105
|
+
: 100;
|
|
877
1106
|
},
|
|
878
1107
|
set: async (v) => {
|
|
879
|
-
await this.setState({
|
|
1108
|
+
await this.setState({
|
|
1109
|
+
brightness: Number(v),
|
|
1110
|
+
});
|
|
880
1111
|
},
|
|
881
1112
|
},
|
|
882
1113
|
Hue: {
|
|
@@ -926,7 +1157,9 @@ export class LightDevice extends GenericDevice {
|
|
|
926
1157
|
return 0;
|
|
927
1158
|
},
|
|
928
1159
|
set: async (v) => {
|
|
929
|
-
await this.setState({
|
|
1160
|
+
await this.setState({
|
|
1161
|
+
hue: Number(v),
|
|
1162
|
+
});
|
|
930
1163
|
},
|
|
931
1164
|
},
|
|
932
1165
|
Saturation: {
|
|
@@ -946,13 +1179,17 @@ export class LightDevice extends GenericDevice {
|
|
|
946
1179
|
const mx = Math.max(r, g, b);
|
|
947
1180
|
const mn = Math.min(r, g, b);
|
|
948
1181
|
const d = mx - mn;
|
|
949
|
-
const sat = mx === 0
|
|
1182
|
+
const sat = mx === 0
|
|
1183
|
+
? 0
|
|
1184
|
+
: Math.round((d / mx) * 100);
|
|
950
1185
|
return sat;
|
|
951
1186
|
}
|
|
952
1187
|
return 0;
|
|
953
1188
|
},
|
|
954
1189
|
set: async (v) => {
|
|
955
|
-
await this.setState({
|
|
1190
|
+
await this.setState({
|
|
1191
|
+
saturation: Number(v),
|
|
1192
|
+
});
|
|
956
1193
|
},
|
|
957
1194
|
},
|
|
958
1195
|
ColorTemperature: {
|
|
@@ -973,7 +1210,9 @@ export class LightDevice extends GenericDevice {
|
|
|
973
1210
|
return 400;
|
|
974
1211
|
},
|
|
975
1212
|
set: async (v) => {
|
|
976
|
-
await this.setState({
|
|
1213
|
+
await this.setState({
|
|
1214
|
+
colorTemperature: Number(v),
|
|
1215
|
+
});
|
|
977
1216
|
},
|
|
978
1217
|
},
|
|
979
1218
|
},
|
|
@@ -1050,8 +1289,14 @@ export class LightDevice extends GenericDevice {
|
|
|
1050
1289
|
type: 'OnOff',
|
|
1051
1290
|
clusterId: MATTER_CLUSTER_IDS.OnOff,
|
|
1052
1291
|
attributes: {
|
|
1053
|
-
onOff: {
|
|
1054
|
-
|
|
1292
|
+
onOff: {
|
|
1293
|
+
read: async () => { const s = await this.getState(); return !!(s && (s.on === true || s.state === 'on' || s.power === 'on')); },
|
|
1294
|
+
write: async (v) => this.setState({ on: !!v }),
|
|
1295
|
+
},
|
|
1296
|
+
[MATTER_ATTRIBUTE_IDS.OnOff.OnOff]: {
|
|
1297
|
+
read: async () => { const s = await this.getState(); return !!(s && (s.on === true || s.state === 'on' || s.power === 'on')); },
|
|
1298
|
+
write: async (v) => this.setState({ on: !!v }),
|
|
1299
|
+
},
|
|
1055
1300
|
},
|
|
1056
1301
|
},
|
|
1057
1302
|
{
|
|
@@ -1059,8 +1304,28 @@ export class LightDevice extends GenericDevice {
|
|
|
1059
1304
|
type: 'LevelControl',
|
|
1060
1305
|
clusterId: MATTER_CLUSTER_IDS.LevelControl,
|
|
1061
1306
|
attributes: {
|
|
1062
|
-
currentLevel: {
|
|
1063
|
-
|
|
1307
|
+
currentLevel: {
|
|
1308
|
+
read: async () => {
|
|
1309
|
+
const s = await this.getState();
|
|
1310
|
+
return typeof s.brightness === 'number'
|
|
1311
|
+
? s.brightness
|
|
1312
|
+
: 100;
|
|
1313
|
+
},
|
|
1314
|
+
write: async (v) => this.setState({
|
|
1315
|
+
brightness: Number(v),
|
|
1316
|
+
}),
|
|
1317
|
+
},
|
|
1318
|
+
[MATTER_ATTRIBUTE_IDS.LevelControl.CurrentLevel]: {
|
|
1319
|
+
read: async () => {
|
|
1320
|
+
const s = await this.getState();
|
|
1321
|
+
return typeof s.brightness === 'number'
|
|
1322
|
+
? s.brightness
|
|
1323
|
+
: 100;
|
|
1324
|
+
},
|
|
1325
|
+
write: async (v) => this.setState({
|
|
1326
|
+
brightness: Number(v),
|
|
1327
|
+
}),
|
|
1328
|
+
},
|
|
1064
1329
|
},
|
|
1065
1330
|
},
|
|
1066
1331
|
{
|
|
@@ -1069,12 +1334,55 @@ export class LightDevice extends GenericDevice {
|
|
|
1069
1334
|
clusterId: MATTER_CLUSTER_IDS.ColorControl,
|
|
1070
1335
|
attributes: {
|
|
1071
1336
|
// Required colorMode attribute for Matter conformance (0 = currentHueAndSaturation)
|
|
1072
|
-
colorMode: {
|
|
1073
|
-
|
|
1074
|
-
|
|
1075
|
-
|
|
1076
|
-
|
|
1077
|
-
|
|
1337
|
+
colorMode: {
|
|
1338
|
+
read: async () => 0,
|
|
1339
|
+
},
|
|
1340
|
+
colorHue: {
|
|
1341
|
+
read: async () => {
|
|
1342
|
+
const s = await this.getState();
|
|
1343
|
+
return typeof s.hue === 'number'
|
|
1344
|
+
? s.hue
|
|
1345
|
+
: 0;
|
|
1346
|
+
},
|
|
1347
|
+
write: async (v) => this.setState({
|
|
1348
|
+
hue: Number(v),
|
|
1349
|
+
}),
|
|
1350
|
+
},
|
|
1351
|
+
[MATTER_ATTRIBUTE_IDS.ColorControl.CurrentHue]: {
|
|
1352
|
+
read: async () => {
|
|
1353
|
+
const s = await this.getState();
|
|
1354
|
+
return typeof s.hue === 'number'
|
|
1355
|
+
? s.hue
|
|
1356
|
+
: 0;
|
|
1357
|
+
},
|
|
1358
|
+
write: async (v) => this.setState({
|
|
1359
|
+
hue: Number(v),
|
|
1360
|
+
}),
|
|
1361
|
+
},
|
|
1362
|
+
colorSaturation: {
|
|
1363
|
+
read: async () => {
|
|
1364
|
+
const s = await this.getState();
|
|
1365
|
+
return typeof s.saturation === 'number'
|
|
1366
|
+
? s.saturation
|
|
1367
|
+
: 0;
|
|
1368
|
+
},
|
|
1369
|
+
write: async (v) => this.setState({
|
|
1370
|
+
saturation: Number(v),
|
|
1371
|
+
}),
|
|
1372
|
+
},
|
|
1373
|
+
[MATTER_ATTRIBUTE_IDS.ColorControl.CurrentSaturation]: {
|
|
1374
|
+
read: async () => {
|
|
1375
|
+
const s = await this.getState();
|
|
1376
|
+
return typeof s.saturation === 'number'
|
|
1377
|
+
? s.saturation
|
|
1378
|
+
: 0;
|
|
1379
|
+
},
|
|
1380
|
+
write: async (v) => this.setState({
|
|
1381
|
+
saturation: Number(v),
|
|
1382
|
+
}),
|
|
1383
|
+
},
|
|
1384
|
+
colorTemperature: {
|
|
1385
|
+
read: async () => {
|
|
1078
1386
|
const s = await this.getState();
|
|
1079
1387
|
if (typeof s.colorTemperature === 'number') {
|
|
1080
1388
|
return s.colorTemperature;
|
|
@@ -1083,8 +1391,13 @@ export class LightDevice extends GenericDevice {
|
|
|
1083
1391
|
return Math.round(1000000 / s.kelvin);
|
|
1084
1392
|
}
|
|
1085
1393
|
return 400;
|
|
1086
|
-
},
|
|
1087
|
-
|
|
1394
|
+
},
|
|
1395
|
+
write: async (v) => this.setState({
|
|
1396
|
+
colorTemperature: Number(v),
|
|
1397
|
+
}),
|
|
1398
|
+
},
|
|
1399
|
+
[MATTER_ATTRIBUTE_IDS.ColorControl.ColorTemperatureMireds]: {
|
|
1400
|
+
read: async () => {
|
|
1088
1401
|
const s = await this.getState();
|
|
1089
1402
|
if (typeof s.colorTemperature === 'number') {
|
|
1090
1403
|
return s.colorTemperature;
|
|
@@ -1093,7 +1406,11 @@ export class LightDevice extends GenericDevice {
|
|
|
1093
1406
|
return Math.round(1000000 / s.kelvin);
|
|
1094
1407
|
}
|
|
1095
1408
|
return 400;
|
|
1096
|
-
},
|
|
1409
|
+
},
|
|
1410
|
+
write: async (v) => this.setState({
|
|
1411
|
+
colorTemperature: Number(v),
|
|
1412
|
+
}),
|
|
1413
|
+
},
|
|
1097
1414
|
},
|
|
1098
1415
|
},
|
|
1099
1416
|
],
|
|
@@ -1126,7 +1443,11 @@ export class MotionSensorDevice extends GenericDevice {
|
|
|
1126
1443
|
}
|
|
1127
1444
|
// Oscillation support
|
|
1128
1445
|
if (typeof change.oscillate === 'boolean') {
|
|
1129
|
-
const body = {
|
|
1446
|
+
const body = {
|
|
1447
|
+
command: 'setOscillation',
|
|
1448
|
+
parameter: change.oscillate ? 'on' : 'off',
|
|
1449
|
+
commandType: 'command',
|
|
1450
|
+
};
|
|
1130
1451
|
try {
|
|
1131
1452
|
return await this.client.setDeviceState(this.opts.id, body);
|
|
1132
1453
|
}
|
|
@@ -1181,7 +1502,9 @@ export class ContactSensorDevice extends GenericDevice {
|
|
|
1181
1502
|
ContactSensorState: {
|
|
1182
1503
|
get: async () => {
|
|
1183
1504
|
const s = await this.getState();
|
|
1184
|
-
return s && s.open
|
|
1505
|
+
return s && s.open
|
|
1506
|
+
? 1
|
|
1507
|
+
: 0;
|
|
1185
1508
|
},
|
|
1186
1509
|
},
|
|
1187
1510
|
},
|
|
@@ -1206,13 +1529,17 @@ export class LockDevice extends GenericDevice {
|
|
|
1206
1529
|
LockCurrentState: {
|
|
1207
1530
|
get: async () => {
|
|
1208
1531
|
const s = await this.getState();
|
|
1209
|
-
return s && s.locked
|
|
1532
|
+
return s && s.locked
|
|
1533
|
+
? 1
|
|
1534
|
+
: 0;
|
|
1210
1535
|
},
|
|
1211
1536
|
},
|
|
1212
1537
|
LockTargetState: {
|
|
1213
1538
|
get: async () => {
|
|
1214
1539
|
const s = await this.getState();
|
|
1215
|
-
return s && s.locked
|
|
1540
|
+
return s && s.locked
|
|
1541
|
+
? 1
|
|
1542
|
+
: 0;
|
|
1216
1543
|
},
|
|
1217
1544
|
set: async (v) => {
|
|
1218
1545
|
await this.setState({ locked: !!v });
|
|
@@ -1239,7 +1566,11 @@ export class LockDevice extends GenericDevice {
|
|
|
1239
1566
|
}
|
|
1240
1567
|
if (action === 'removeUser' && (change.user || change.userId)) {
|
|
1241
1568
|
const user = change.user ?? change.userId;
|
|
1242
|
-
const body = {
|
|
1569
|
+
const body = {
|
|
1570
|
+
command: 'removeUserCode',
|
|
1571
|
+
parameter: String(user),
|
|
1572
|
+
commandType: 'command',
|
|
1573
|
+
};
|
|
1243
1574
|
return await this.client.setDeviceState(this.opts.id, body);
|
|
1244
1575
|
}
|
|
1245
1576
|
if (action === 'listUsers') {
|
|
@@ -1266,7 +1597,11 @@ export class LockDevice extends GenericDevice {
|
|
|
1266
1597
|
// Support setting lock PIN/passcode via `pin` or `passcode` (fallback)
|
|
1267
1598
|
const pin = change?.pin ?? change?.passcode ?? change?.code;
|
|
1268
1599
|
if (typeof pin === 'string' || typeof pin === 'number') {
|
|
1269
|
-
const body = {
|
|
1600
|
+
const body = {
|
|
1601
|
+
command: 'setLockPin',
|
|
1602
|
+
parameter: String(pin),
|
|
1603
|
+
commandType: 'command',
|
|
1604
|
+
};
|
|
1270
1605
|
try {
|
|
1271
1606
|
return await this.client.setDeviceState(this.opts.id, body);
|
|
1272
1607
|
}
|
|
@@ -1295,8 +1630,14 @@ export class LockDevice extends GenericDevice {
|
|
|
1295
1630
|
type: 'DoorLock',
|
|
1296
1631
|
clusterId: MATTER_CLUSTER_IDS.DoorLock,
|
|
1297
1632
|
attributes: {
|
|
1298
|
-
lockState: {
|
|
1299
|
-
|
|
1633
|
+
lockState: {
|
|
1634
|
+
read: async () => { const s = await this.getState(); return !!(s && s.locked); },
|
|
1635
|
+
write: async (v) => this.setState({ locked: !!v }),
|
|
1636
|
+
},
|
|
1637
|
+
[MATTER_ATTRIBUTE_IDS.DoorLock.LockState]: {
|
|
1638
|
+
read: async () => { const s = await this.getState(); return !!(s && s.locked); },
|
|
1639
|
+
write: async (v) => this.setState({ locked: !!v }),
|
|
1640
|
+
},
|
|
1300
1641
|
},
|
|
1301
1642
|
},
|
|
1302
1643
|
{
|
|
@@ -1304,10 +1645,19 @@ export class LockDevice extends GenericDevice {
|
|
|
1304
1645
|
type: 'DoorLockUserManagement',
|
|
1305
1646
|
clusterId: 0x0301,
|
|
1306
1647
|
attributes: {
|
|
1307
|
-
addUser: {
|
|
1308
|
-
|
|
1309
|
-
|
|
1310
|
-
|
|
1648
|
+
addUser: {
|
|
1649
|
+
write: async (v) => this.setState({ action: 'addUser', user: v?.user, pin: v?.pin }),
|
|
1650
|
+
},
|
|
1651
|
+
removeUser: {
|
|
1652
|
+
write: async (v) => this.setState({ action: 'removeUser', user: v?.user }),
|
|
1653
|
+
},
|
|
1654
|
+
listUsers: {
|
|
1655
|
+
read: async () => { const r = await this.setState({ action: 'listUsers' }); return r; },
|
|
1656
|
+
write: undefined,
|
|
1657
|
+
},
|
|
1658
|
+
unlockWithPin: {
|
|
1659
|
+
write: async (v) => this.setState({ action: 'unlockWithPin', pin: v?.pin }),
|
|
1660
|
+
},
|
|
1311
1661
|
},
|
|
1312
1662
|
},
|
|
1313
1663
|
],
|
|
@@ -1324,7 +1674,9 @@ export class HumidifierDevice extends GenericDevice {
|
|
|
1324
1674
|
Active: {
|
|
1325
1675
|
get: async () => {
|
|
1326
1676
|
const s = await this.getState();
|
|
1327
|
-
return s && s.on
|
|
1677
|
+
return s && s.on
|
|
1678
|
+
? 1
|
|
1679
|
+
: 0;
|
|
1328
1680
|
},
|
|
1329
1681
|
set: async (v) => {
|
|
1330
1682
|
await this.setState({ on: v === 1 });
|
|
@@ -1333,7 +1685,9 @@ export class HumidifierDevice extends GenericDevice {
|
|
|
1333
1685
|
CurrentHumidifierDehumidifierState: {
|
|
1334
1686
|
get: async () => {
|
|
1335
1687
|
const s = await this.getState();
|
|
1336
|
-
return s && s.on
|
|
1688
|
+
return s && s.on
|
|
1689
|
+
? 2
|
|
1690
|
+
: 0; // 0 = Inactive, 2 = Humidifying
|
|
1337
1691
|
},
|
|
1338
1692
|
},
|
|
1339
1693
|
TargetHumidifierDehumidifierState: {
|
|
@@ -1345,16 +1699,22 @@ export class HumidifierDevice extends GenericDevice {
|
|
|
1345
1699
|
CurrentRelativeHumidity: {
|
|
1346
1700
|
get: async () => {
|
|
1347
1701
|
const s = await this.getState();
|
|
1348
|
-
return typeof s.humidity === 'number'
|
|
1702
|
+
return typeof s.humidity === 'number'
|
|
1703
|
+
? s.humidity
|
|
1704
|
+
: 0;
|
|
1349
1705
|
},
|
|
1350
1706
|
},
|
|
1351
1707
|
RelativeHumidityHumidifierThreshold: {
|
|
1352
1708
|
get: async () => {
|
|
1353
1709
|
const s = await this.getState();
|
|
1354
|
-
return typeof s.targetHumidity === 'number'
|
|
1710
|
+
return typeof s.targetHumidity === 'number'
|
|
1711
|
+
? s.targetHumidity
|
|
1712
|
+
: 50;
|
|
1355
1713
|
},
|
|
1356
1714
|
set: async (v) => {
|
|
1357
|
-
await this.setState({
|
|
1715
|
+
await this.setState({
|
|
1716
|
+
humidity: Number(v),
|
|
1717
|
+
});
|
|
1358
1718
|
},
|
|
1359
1719
|
},
|
|
1360
1720
|
},
|
|
@@ -1384,7 +1744,11 @@ export class HumidifierDevice extends GenericDevice {
|
|
|
1384
1744
|
}
|
|
1385
1745
|
}
|
|
1386
1746
|
if (typeof change.dry === 'boolean') {
|
|
1387
|
-
const body = {
|
|
1747
|
+
const body = {
|
|
1748
|
+
command: 'setDry',
|
|
1749
|
+
parameter: change.dry ? 'on' : 'off',
|
|
1750
|
+
commandType: 'command',
|
|
1751
|
+
};
|
|
1388
1752
|
try {
|
|
1389
1753
|
return await this.client.setDeviceState(this.opts.id, body);
|
|
1390
1754
|
}
|
|
@@ -1415,16 +1779,38 @@ export class HumidifierMatterDevice extends HumidifierDevice {
|
|
|
1415
1779
|
type: 'RelativeHumiditySensor',
|
|
1416
1780
|
clusterId: MATTER_CLUSTER_IDS.RelativeHumidityMeasurement,
|
|
1417
1781
|
attributes: {
|
|
1418
|
-
currentRelativeHumidity: {
|
|
1419
|
-
|
|
1782
|
+
currentRelativeHumidity: {
|
|
1783
|
+
read: async () => {
|
|
1784
|
+
const s = await this.getState();
|
|
1785
|
+
return typeof s.humidity === 'number'
|
|
1786
|
+
? s.humidity
|
|
1787
|
+
: 0;
|
|
1788
|
+
},
|
|
1789
|
+
write: undefined,
|
|
1790
|
+
},
|
|
1791
|
+
[MATTER_ATTRIBUTE_IDS.RelativeHumidityMeasurement.MeasuredValue]: {
|
|
1792
|
+
read: async () => {
|
|
1793
|
+
const s = await this.getState();
|
|
1794
|
+
return typeof s.humidity === 'number'
|
|
1795
|
+
? s.humidity
|
|
1796
|
+
: 0;
|
|
1797
|
+
},
|
|
1798
|
+
write: undefined,
|
|
1799
|
+
},
|
|
1420
1800
|
},
|
|
1421
1801
|
},
|
|
1422
1802
|
{
|
|
1423
1803
|
type: 'OnOff',
|
|
1424
1804
|
clusterId: MATTER_CLUSTER_IDS.OnOff,
|
|
1425
1805
|
attributes: {
|
|
1426
|
-
onOff: {
|
|
1427
|
-
|
|
1806
|
+
onOff: {
|
|
1807
|
+
read: async () => { const s = await this.getState(); return !!s?.on; },
|
|
1808
|
+
write: async (v) => this.setState({ on: !!v }),
|
|
1809
|
+
},
|
|
1810
|
+
[MATTER_ATTRIBUTE_IDS.OnOff.OnOff]: {
|
|
1811
|
+
read: async () => { const s = await this.getState(); return !!s?.on; },
|
|
1812
|
+
write: async (v) => this.setState({ on: !!v }),
|
|
1813
|
+
},
|
|
1428
1814
|
},
|
|
1429
1815
|
},
|
|
1430
1816
|
],
|
|
@@ -1441,7 +1827,9 @@ export class TemperatureSensorDevice extends GenericDevice {
|
|
|
1441
1827
|
CurrentTemperature: {
|
|
1442
1828
|
get: async () => {
|
|
1443
1829
|
const s = await this.getState();
|
|
1444
|
-
return typeof s.temperature === 'number'
|
|
1830
|
+
return typeof s.temperature === 'number'
|
|
1831
|
+
? s.temperature
|
|
1832
|
+
: 0;
|
|
1445
1833
|
},
|
|
1446
1834
|
},
|
|
1447
1835
|
},
|
|
@@ -1474,7 +1862,9 @@ export class PlugDevice extends GenericDevice {
|
|
|
1474
1862
|
OutletInUse: {
|
|
1475
1863
|
get: async () => {
|
|
1476
1864
|
const s = await this.getState();
|
|
1477
|
-
return s && s.inUse
|
|
1865
|
+
return s && s.inUse
|
|
1866
|
+
? 1
|
|
1867
|
+
: 0;
|
|
1478
1868
|
},
|
|
1479
1869
|
},
|
|
1480
1870
|
},
|
|
@@ -1506,7 +1896,9 @@ export class MeterDevice extends GenericDevice {
|
|
|
1506
1896
|
/** The ppm at which HomeKit reports carbon dioxide as detected. */
|
|
1507
1897
|
co2AbnormalThreshold() {
|
|
1508
1898
|
const value = Number(this.cfg?.co2AbnormalThreshold);
|
|
1509
|
-
return Number.isFinite(value) && value > 0
|
|
1899
|
+
return Number.isFinite(value) && value > 0
|
|
1900
|
+
? value
|
|
1901
|
+
: CO2_ABNORMAL_PPM_DEFAULT;
|
|
1510
1902
|
}
|
|
1511
1903
|
createHAPAccessory(api) {
|
|
1512
1904
|
const services = [
|
|
@@ -1516,7 +1908,9 @@ export class MeterDevice extends GenericDevice {
|
|
|
1516
1908
|
CurrentTemperature: {
|
|
1517
1909
|
get: async () => {
|
|
1518
1910
|
const s = await this.getState();
|
|
1519
|
-
return typeof s.temperature === 'number'
|
|
1911
|
+
return typeof s.temperature === 'number'
|
|
1912
|
+
? s.temperature
|
|
1913
|
+
: 0;
|
|
1520
1914
|
},
|
|
1521
1915
|
},
|
|
1522
1916
|
},
|
|
@@ -1527,7 +1921,9 @@ export class MeterDevice extends GenericDevice {
|
|
|
1527
1921
|
CurrentRelativeHumidity: {
|
|
1528
1922
|
get: async () => {
|
|
1529
1923
|
const s = await this.getState();
|
|
1530
|
-
return typeof s.humidity === 'number'
|
|
1924
|
+
return typeof s.humidity === 'number'
|
|
1925
|
+
? s.humidity
|
|
1926
|
+
: 0;
|
|
1531
1927
|
},
|
|
1532
1928
|
},
|
|
1533
1929
|
},
|
|
@@ -1536,7 +1932,9 @@ export class MeterDevice extends GenericDevice {
|
|
|
1536
1932
|
if (this.reportsCO2()) {
|
|
1537
1933
|
const co2 = async () => {
|
|
1538
1934
|
const s = await this.getState();
|
|
1539
|
-
return typeof s.co2 === 'number'
|
|
1935
|
+
return typeof s.co2 === 'number'
|
|
1936
|
+
? s.co2
|
|
1937
|
+
: 0;
|
|
1540
1938
|
};
|
|
1541
1939
|
services.push({
|
|
1542
1940
|
type: 'CarbonDioxideSensor',
|
|
@@ -1545,7 +1943,9 @@ export class MeterDevice extends GenericDevice {
|
|
|
1545
1943
|
get: co2,
|
|
1546
1944
|
},
|
|
1547
1945
|
CarbonDioxideDetected: {
|
|
1548
|
-
get: async () => ((await co2()) >= this.co2AbnormalThreshold()
|
|
1946
|
+
get: async () => ((await co2()) >= this.co2AbnormalThreshold()
|
|
1947
|
+
? 1
|
|
1948
|
+
: 0),
|
|
1549
1949
|
},
|
|
1550
1950
|
},
|
|
1551
1951
|
});
|
|
@@ -1567,7 +1967,9 @@ export class MeterDevice extends GenericDevice {
|
|
|
1567
1967
|
get: battery,
|
|
1568
1968
|
},
|
|
1569
1969
|
StatusLowBattery: {
|
|
1570
|
-
get: async () => ((await battery()) < 20
|
|
1970
|
+
get: async () => ((await battery()) < 20
|
|
1971
|
+
? 1
|
|
1972
|
+
: 0),
|
|
1571
1973
|
},
|
|
1572
1974
|
ChargingState: {
|
|
1573
1975
|
get: async () => 2,
|
|
@@ -1606,7 +2008,13 @@ export class WaterDetectorDevice extends GenericDevice {
|
|
|
1606
2008
|
return status === 1;
|
|
1607
2009
|
}
|
|
1608
2010
|
if (typeof status === 'string') {
|
|
1609
|
-
return [
|
|
2011
|
+
return [
|
|
2012
|
+
'1',
|
|
2013
|
+
'leak',
|
|
2014
|
+
'leaked',
|
|
2015
|
+
'detected',
|
|
2016
|
+
'water_leak_detected',
|
|
2017
|
+
].includes(status.toLowerCase());
|
|
1610
2018
|
}
|
|
1611
2019
|
return undefined;
|
|
1612
2020
|
}
|
|
@@ -1742,7 +2150,9 @@ export class WaterDetectorDevice extends GenericDevice {
|
|
|
1742
2150
|
StatusLowBattery: {
|
|
1743
2151
|
get: () => {
|
|
1744
2152
|
const b = this.getBatteryFast(api);
|
|
1745
|
-
return b < 20
|
|
2153
|
+
return b < 20
|
|
2154
|
+
? 1
|
|
2155
|
+
: 0;
|
|
1746
2156
|
},
|
|
1747
2157
|
},
|
|
1748
2158
|
ChargingState: {
|