homebridge-verisure 2.0.2 → 3.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +33 -2
- package/config.schema.json +30 -0
- package/dist/accessories/alarm.d.ts +28 -0
- package/dist/accessories/alarm.js +129 -0
- package/dist/accessories/alarm.js.map +1 -0
- package/dist/accessories/base.d.ts +39 -0
- package/dist/accessories/base.js +63 -0
- package/dist/accessories/base.js.map +1 -0
- package/dist/accessories/climateSensor.d.ts +14 -0
- package/dist/accessories/climateSensor.js +60 -0
- package/dist/accessories/climateSensor.js.map +1 -0
- package/dist/accessories/contactSensor.d.ts +14 -0
- package/dist/accessories/contactSensor.js +39 -0
- package/dist/accessories/contactSensor.js.map +1 -0
- package/dist/accessories/doorLock.d.ts +32 -0
- package/dist/accessories/doorLock.js +162 -0
- package/dist/accessories/doorLock.js.map +1 -0
- package/dist/accessories/smartPlug.d.ts +15 -0
- package/dist/accessories/smartPlug.js +54 -0
- package/dist/accessories/smartPlug.js.map +1 -0
- package/dist/bin/verisure.d.ts +2 -0
- package/dist/bin/verisure.js +56 -0
- package/dist/bin/verisure.js.map +1 -0
- package/dist/cache.d.ts +14 -0
- package/dist/cache.js +35 -0
- package/dist/cache.js.map +1 -0
- package/dist/deviceNames.d.ts +3 -0
- package/dist/deviceNames.js +16 -0
- package/dist/deviceNames.js.map +1 -0
- package/dist/i18n/index.d.ts +1 -0
- package/dist/i18n/index.js +18 -0
- package/dist/i18n/index.js.map +1 -0
- package/dist/i18n/nb_NO.json +22 -0
- package/dist/i18n/sv_SE.json +22 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.js +7 -0
- package/dist/index.js.map +1 -0
- package/dist/operations.d.ts +27 -0
- package/dist/operations.js +322 -0
- package/dist/operations.js.map +1 -0
- package/dist/overviewPoller.d.ts +53 -0
- package/dist/overviewPoller.js +169 -0
- package/dist/overviewPoller.js.map +1 -0
- package/dist/platform.d.ts +27 -0
- package/dist/platform.js +272 -0
- package/dist/platform.js.map +1 -0
- package/dist/settings.d.ts +21 -0
- package/dist/settings.js +25 -0
- package/dist/settings.js.map +1 -0
- package/dist/types.d.ts +117 -0
- package/dist/types.js +12 -0
- package/dist/types.js.map +1 -0
- package/package.json +39 -16
- package/CHANGELOG.md +0 -180
- package/bin/verisure +0 -55
- package/index.js +0 -6
- package/lib/accessories/alarm.js +0 -111
- package/lib/accessories/climatesensor.js +0 -68
- package/lib/accessories/contactsensor.js +0 -45
- package/lib/accessories/doorlock.js +0 -216
- package/lib/accessories/index.js +0 -13
- package/lib/accessories/smartplug.js +0 -60
- package/lib/accessories/verisure.js +0 -62
- package/lib/i18n/index.js +0 -11
- package/lib/i18n/nb_NO.json +0 -22
- package/lib/i18n/sv_SE.json +0 -22
- package/lib/operations.js +0 -225
- package/lib/platform.js +0 -156
|
@@ -0,0 +1,162 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.DoorLock = void 0;
|
|
4
|
+
const cache_1 = require("../cache");
|
|
5
|
+
const operations_1 = require("../operations");
|
|
6
|
+
const settings_1 = require("../settings");
|
|
7
|
+
const base_1 = require("./base");
|
|
8
|
+
class DoorLock extends base_1.VerisureAccessoryHandler {
|
|
9
|
+
lockService;
|
|
10
|
+
autoLockService;
|
|
11
|
+
audioService;
|
|
12
|
+
doorCode;
|
|
13
|
+
/** The lock state we're actively trying to reach, if any. Cleared as soon
|
|
14
|
+
* as the change settles (success or failure) so getTargetLockState() falls
|
|
15
|
+
* straight back to the device's actual state - keeping it "stuck" here
|
|
16
|
+
* indefinitely was the cause of the Yale-lock report/reconcile loop that
|
|
17
|
+
* burned through the daily API quota in issues #159, #173, #181, #168. */
|
|
18
|
+
pendingTargetState;
|
|
19
|
+
getLockConfig;
|
|
20
|
+
constructor(platform, accessory, installation) {
|
|
21
|
+
super(platform, accessory, installation);
|
|
22
|
+
this.doorCode = String(this.platformConfig.doorCode ?? this.platformConfig.doorcode ?? '');
|
|
23
|
+
this.getLockConfig = (0, cache_1.memoizeAsync)(async () => {
|
|
24
|
+
const { installation: { smartLocks: [smartLock] } } = await this.installation
|
|
25
|
+
.client((0, operations_1.doorLockConfigOperation)(this.serialNumber));
|
|
26
|
+
return smartLock;
|
|
27
|
+
}, settings_1.DOOR_LOCK_CONFIG_CACHE_TTL_MS);
|
|
28
|
+
const { Service, Characteristic } = this.hap;
|
|
29
|
+
this.lockService = this.accessory.getService(Service.LockMechanism)
|
|
30
|
+
?? this.accessory.addService(Service.LockMechanism, accessory.displayName);
|
|
31
|
+
this.lockService.getCharacteristic(Characteristic.LockCurrentState)
|
|
32
|
+
.onGet(() => this.getCurrentLockState());
|
|
33
|
+
this.lockService.getCharacteristic(Characteristic.LockTargetState)
|
|
34
|
+
.onGet(() => this.getTargetLockState())
|
|
35
|
+
.onSet((value) => this.setTargetLockState(value));
|
|
36
|
+
if (this.platformConfig.showAutoLockSwitch !== false) {
|
|
37
|
+
this.autoLockService = this.accessory.getServiceById(Service.Switch, 'auto-lock')
|
|
38
|
+
?? this.accessory.addService(Service.Switch, `${accessory.displayName} Auto-lock`, 'auto-lock');
|
|
39
|
+
this.autoLockService.getCharacteristic(Characteristic.On)
|
|
40
|
+
.onGet(() => this.getAutoLockState())
|
|
41
|
+
.onSet((value) => this.setAutoLockState(value));
|
|
42
|
+
}
|
|
43
|
+
if (this.platformConfig.showAudioSwitch !== false) {
|
|
44
|
+
this.audioService = this.accessory.getServiceById(Service.Switch, 'audio')
|
|
45
|
+
?? this.accessory.addService(Service.Switch, `${accessory.displayName} Audio`, 'audio');
|
|
46
|
+
this.audioService.getCharacteristic(Characteristic.On)
|
|
47
|
+
.onGet(() => this.getAudioState())
|
|
48
|
+
.onSet((value) => this.setAudioState(value));
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
resolveCurrentLockState({ currentLockState, motorJam }) {
|
|
52
|
+
const { LockCurrentState } = this.hap.Characteristic;
|
|
53
|
+
if (motorJam) {
|
|
54
|
+
return LockCurrentState.JAMMED;
|
|
55
|
+
}
|
|
56
|
+
return currentLockState === 'LOCKED' ? LockCurrentState.SECURED : LockCurrentState.UNSECURED;
|
|
57
|
+
}
|
|
58
|
+
findDevice(overview) {
|
|
59
|
+
return overview.doorlocks?.find((doorlock) => doorlock.device.deviceLabel === this.serialNumber);
|
|
60
|
+
}
|
|
61
|
+
async getDoorLock() {
|
|
62
|
+
this.logPrefixed('Getting current lock state.', 'debug');
|
|
63
|
+
const overview = await this.platform.poller(this.installation).getOverview();
|
|
64
|
+
const doorLock = this.findDevice(overview);
|
|
65
|
+
if (!doorLock) {
|
|
66
|
+
throw new this.hap.HapStatusError(-70402 /* this.hap.HAPStatus.SERVICE_COMMUNICATION_FAILURE */);
|
|
67
|
+
}
|
|
68
|
+
return doorLock;
|
|
69
|
+
}
|
|
70
|
+
async getCurrentLockState() {
|
|
71
|
+
return this.resolveCurrentLockState(await this.getDoorLock());
|
|
72
|
+
}
|
|
73
|
+
async getTargetLockState() {
|
|
74
|
+
this.logPrefixed('Getting target lock state.', 'debug');
|
|
75
|
+
const { LockTargetState } = this.hap.Characteristic;
|
|
76
|
+
const { currentLockState } = await this.getDoorLock();
|
|
77
|
+
const targetLockState = this.pendingTargetState ?? currentLockState;
|
|
78
|
+
return targetLockState === 'LOCKED' ? LockTargetState.SECURED : LockTargetState.UNSECURED;
|
|
79
|
+
}
|
|
80
|
+
async setTargetLockState(value) {
|
|
81
|
+
this.logPrefixed(`Setting target lock state to: ${value}`);
|
|
82
|
+
const { LockCurrentState } = this.hap.Characteristic;
|
|
83
|
+
this.pendingTargetState = value === LockCurrentState.SECURED ? 'LOCKED' : 'UNLOCKED';
|
|
84
|
+
const targetLockState = this.pendingTargetState;
|
|
85
|
+
const operation = targetLockState === 'LOCKED' ? operations_1.doorLockOperation : operations_1.doorUnlockOperation;
|
|
86
|
+
try {
|
|
87
|
+
const { transactionId } = await this.installation
|
|
88
|
+
.client(operation(this.serialNumber, this.doorCode));
|
|
89
|
+
await this.resolveChangeResult((0, operations_1.pollLockStateOperation)(transactionId, this.serialNumber, targetLockState));
|
|
90
|
+
}
|
|
91
|
+
catch (error) {
|
|
92
|
+
const alreadyAtTarget = error.errors
|
|
93
|
+
?.some(({ data }) => data?.errorCode === 'VAL_00819');
|
|
94
|
+
if (!alreadyAtTarget) {
|
|
95
|
+
throw error;
|
|
96
|
+
}
|
|
97
|
+
// Lock was already at the desired state - not an error.
|
|
98
|
+
}
|
|
99
|
+
finally {
|
|
100
|
+
this.pendingTargetState = undefined;
|
|
101
|
+
}
|
|
102
|
+
// A stale cached overview from just before this change must not answer
|
|
103
|
+
// the read HomeKit does right after to confirm it (see OverviewPoller#invalidate).
|
|
104
|
+
this.platform.poller(this.installation).invalidate();
|
|
105
|
+
setImmediate(() => {
|
|
106
|
+
this.lockService.updateCharacteristic(LockCurrentState, value);
|
|
107
|
+
});
|
|
108
|
+
}
|
|
109
|
+
resolveAutoLockState(config) {
|
|
110
|
+
return config.autoLockEnabled === true;
|
|
111
|
+
}
|
|
112
|
+
async getAutoLockState() {
|
|
113
|
+
this.logPrefixed('Getting current auto lock config.', 'debug');
|
|
114
|
+
const { configuration } = await this.getLockConfig();
|
|
115
|
+
return this.resolveAutoLockState(configuration);
|
|
116
|
+
}
|
|
117
|
+
async setAutoLockState(value) {
|
|
118
|
+
this.logPrefixed(`Setting auto lock to: ${value}`);
|
|
119
|
+
try {
|
|
120
|
+
await this.installation.client((0, operations_1.doorLockUpdateConfigOperation)(this.serialNumber, { autoLockEnabled: value }));
|
|
121
|
+
this.getLockConfig.invalidate();
|
|
122
|
+
}
|
|
123
|
+
catch (error) {
|
|
124
|
+
this.logPrefixed(error.message, 'debug');
|
|
125
|
+
throw error;
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
async getAudioState() {
|
|
129
|
+
this.logPrefixed('Getting current audio config.', 'debug');
|
|
130
|
+
const { configuration } = await this.getLockConfig();
|
|
131
|
+
if (configuration.volume === undefined) {
|
|
132
|
+
// Non-Yale locks (e.g. DanaLock) don't report a volume at all.
|
|
133
|
+
throw new this.hap.HapStatusError(-70402 /* this.hap.HAPStatus.SERVICE_COMMUNICATION_FAILURE */);
|
|
134
|
+
}
|
|
135
|
+
return configuration.volume !== this.platformConfig.audioOffValue;
|
|
136
|
+
}
|
|
137
|
+
async setAudioState(value) {
|
|
138
|
+
const volume = value ? this.platformConfig.audioOnValue : this.platformConfig.audioOffValue;
|
|
139
|
+
this.logPrefixed(`Setting audio volume to: ${volume}`);
|
|
140
|
+
try {
|
|
141
|
+
await this.installation.client((0, operations_1.doorLockUpdateConfigOperation)(this.serialNumber, { volume }));
|
|
142
|
+
this.getLockConfig.invalidate();
|
|
143
|
+
}
|
|
144
|
+
catch (error) {
|
|
145
|
+
this.logPrefixed(error.message, 'debug');
|
|
146
|
+
throw error;
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
onOverview(overview) {
|
|
150
|
+
const doorLock = this.findDevice(overview);
|
|
151
|
+
if (!doorLock) {
|
|
152
|
+
return;
|
|
153
|
+
}
|
|
154
|
+
this.lockService.updateCharacteristic(this.hap.Characteristic.LockCurrentState, this.resolveCurrentLockState(doorLock));
|
|
155
|
+
if (!this.pendingTargetState) {
|
|
156
|
+
const { LockTargetState } = this.hap.Characteristic;
|
|
157
|
+
this.lockService.updateCharacteristic(LockTargetState, doorLock.currentLockState === 'LOCKED' ? LockTargetState.SECURED : LockTargetState.UNSECURED);
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
exports.DoorLock = DoorLock;
|
|
162
|
+
//# sourceMappingURL=doorLock.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"doorLock.js","sourceRoot":"","sources":["../../src/accessories/doorLock.ts"],"names":[],"mappings":";;;AAGA,oCAAwC;AAExC,8CAMuB;AACvB,0CAA4D;AAG5D,iCAAkD;AAKlD,MAAa,QAAS,SAAQ,+BAAwB;IACn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BAAkB,EAAE,CAAC;YAC7B,MAAM,EAAE,eAAe,EAAE,GAAG,IAAI,CAAC,GAAG,CAAC,cAAc,CAAC;YACpD,IAAI,CAAC,WAAW,CAAC,oBAAoB,CACnC,eAAe,EACf,QAAQ,CAAC,gBAAgB,KAAK,QAAQ,CAAC,CAAC,CAAC,eAAe,CAAC,OAAO,CAAC,CAAC,CAAC,eAAe,CAAC,SAAS,CAC7F,CAAC;QACJ,CAAC;IACH,CAAC;CACF;AAtLD,4BAsLC"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { PlatformAccessory } from 'homebridge';
|
|
2
|
+
import type { VerisureInstallation } from 'verisure';
|
|
3
|
+
import type { VerisurePlatform } from '../platform';
|
|
4
|
+
import type { Overview, SmartPlugDevice } from '../types';
|
|
5
|
+
import { VerisureAccessoryHandler } from './base';
|
|
6
|
+
import type { AccessoryContext } from './base';
|
|
7
|
+
export declare class SmartPlug extends VerisureAccessoryHandler {
|
|
8
|
+
private readonly service;
|
|
9
|
+
constructor(platform: VerisurePlatform, accessory: PlatformAccessory<AccessoryContext>, installation: VerisureInstallation, initial: SmartPlugDevice);
|
|
10
|
+
private static resolveSwitchState;
|
|
11
|
+
private findDevice;
|
|
12
|
+
private getSwitchState;
|
|
13
|
+
private setSwitchState;
|
|
14
|
+
protected onOverview(overview: Overview): void;
|
|
15
|
+
}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.SmartPlug = void 0;
|
|
4
|
+
const operations_1 = require("../operations");
|
|
5
|
+
const base_1 = require("./base");
|
|
6
|
+
class SmartPlug extends base_1.VerisureAccessoryHandler {
|
|
7
|
+
service;
|
|
8
|
+
constructor(platform, accessory, installation, initial) {
|
|
9
|
+
super(platform, accessory, installation);
|
|
10
|
+
const { Service, Characteristic } = this.hap;
|
|
11
|
+
this.accessoryInformation.setCharacteristic(Characteristic.Model, 'SMARTPLUG');
|
|
12
|
+
this.service = this.accessory.getService(Service.Switch)
|
|
13
|
+
?? this.accessory.addService(Service.Switch, accessory.displayName);
|
|
14
|
+
this.service.getCharacteristic(Characteristic.On)
|
|
15
|
+
.onGet(() => this.getSwitchState())
|
|
16
|
+
.onSet((value) => this.setSwitchState(value));
|
|
17
|
+
this.service.updateCharacteristic(Characteristic.On, SmartPlug.resolveSwitchState(initial.currentState));
|
|
18
|
+
}
|
|
19
|
+
static resolveSwitchState(input) {
|
|
20
|
+
return input === 'ON';
|
|
21
|
+
}
|
|
22
|
+
findDevice(overview) {
|
|
23
|
+
return overview.smartplugs?.find((smartplug) => smartplug.device.deviceLabel === this.serialNumber);
|
|
24
|
+
}
|
|
25
|
+
async getSwitchState() {
|
|
26
|
+
this.logPrefixed('Getting current switch state.', 'debug');
|
|
27
|
+
const overview = await this.platform.poller(this.installation).getOverview();
|
|
28
|
+
const device = this.findDevice(overview);
|
|
29
|
+
if (!device) {
|
|
30
|
+
throw new this.hap.HapStatusError(-70402 /* this.hap.HAPStatus.SERVICE_COMMUNICATION_FAILURE */);
|
|
31
|
+
}
|
|
32
|
+
return SmartPlug.resolveSwitchState(device.currentState);
|
|
33
|
+
}
|
|
34
|
+
async setSwitchState(value) {
|
|
35
|
+
this.logPrefixed(`Setting switch state to: ${value}`);
|
|
36
|
+
try {
|
|
37
|
+
await this.installation.client((0, operations_1.smartPlugStateOperation)(this.serialNumber, value));
|
|
38
|
+
this.platform.poller(this.installation).invalidate();
|
|
39
|
+
}
|
|
40
|
+
catch (error) {
|
|
41
|
+
this.logPrefixed(`Error setting switch state: ${error.message}`, 'debug');
|
|
42
|
+
throw error;
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
onOverview(overview) {
|
|
46
|
+
const device = this.findDevice(overview);
|
|
47
|
+
if (!device) {
|
|
48
|
+
return;
|
|
49
|
+
}
|
|
50
|
+
this.service.updateCharacteristic(this.hap.Characteristic.On, SmartPlug.resolveSwitchState(device.currentState));
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
exports.SmartPlug = SmartPlug;
|
|
54
|
+
//# sourceMappingURL=smartPlug.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"smartPlug.js","sourceRoot":"","sources":["../../src/accessories/smartPlug.ts"],"names":[],"mappings":";;;AAGA,8CAAwD;AAGxD,iCAAkD;AAGlD,MAAa,SAAU,SAAQ,+BAAwB;IACpC,OAAO,CAAU;IAElC,YACE,QAA0B,EAC1B,SAA8C,EAC9C,YAAkC,EAClC,OAAwB;QAExB,KAAK,CAAC,QAAQ,EAAE,SAAS,EAAE,YAAY,CAAC,CAAC;QAEzC,MAAM,EAAE,OAAO,EAAE,cAAc,EAAE,GAAG,IAAI,CAAC,GAAG,CAAC;QAC7C,IAAI,CAAC,oBAAoB,CAAC,iBAAiB,CAAC,cAAc,CAAC,KAAK,EAAE,WAAW,CAAC,CAAC;QAE/E,IAAI,CAAC,OAAO,GAAG,IAAI,CAAC,SAAS,CAAC,UAAU,CAAC,OAAO,CAAC,MAAM,CAAC;eACnD,IAAI,CAAC,SAAS,CAAC,UAAU,CAAC,OAAO,CAAC,MAAM,EAAE,SAAS,CAAC,WAAW,CAAC,CAAC;QAEtE,IAAI,CAAC,OAAO,CAAC,iBAAiB,CAAC,cAAc,CAAC,EAAE,CAAC;aAC9C,KAAK,CAAC,GAAG,EAAE,CAAC,IAAI,CAAC,cAAc,EAAE,CAAC;aAClC,KAAK,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,IAAI,CAAC,cAAc,CAAC,KAAK,CAAC,CAAC,CAAC;QAEhD,IAAI,CAAC,OAAO,CAAC,oBAAoB,CAAC,cAAc,CAAC,EAAE,EAAE,SAAS,CAAC,kBAAkB,CAAC,OAAO,CAAC,YAAY,CAAC,CAAC,CAAC;IAC3G,CAAC;IAEO,MAAM,CAAC,kBAAkB,CAAC,KAAa;QAC7C,OAAO,KAAK,KAAK,IAAI,CAAC;IACxB,CAAC;IAE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AAC;QACzC,IAAI,CAAC,MAAM,EAAE,CAAC;YACZ,OAAO;QACT,CAAC;QACD,IAAI,CAAC,OAAO,CAAC,oBAAoB,CAAC,IAAI,CAAC,GAAG,CAAC,cAAc,CAAC,EAAE,EAAE,SAAS,CAAC,kBAAkB,CAAC,MAAM,CAAC,YAAY,CAAC,CAAC,CAAC;IACnH,CAAC;CACF;AA5DD,8BA4DC"}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
"use strict";
|
|
3
|
+
/* eslint-disable no-console */
|
|
4
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
5
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
6
|
+
};
|
|
7
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
8
|
+
const enquirer_1 = __importDefault(require("enquirer"));
|
|
9
|
+
const verisure_1 = __importDefault(require("verisure"));
|
|
10
|
+
// enquirer's bundled types only declare `prompt`/`Prompt`, not the individual
|
|
11
|
+
// prompt classes (like `Password`) it also exports at runtime.
|
|
12
|
+
const { prompt } = enquirer_1.default;
|
|
13
|
+
const Password = enquirer_1.default.Password;
|
|
14
|
+
const validate = (value) => !!value.length;
|
|
15
|
+
const run = async () => {
|
|
16
|
+
const { email } = await prompt({
|
|
17
|
+
type: 'input',
|
|
18
|
+
name: 'email',
|
|
19
|
+
message: 'What is your login email?',
|
|
20
|
+
validate,
|
|
21
|
+
});
|
|
22
|
+
const password = await new Password({
|
|
23
|
+
name: 'password',
|
|
24
|
+
message: 'What is your password?',
|
|
25
|
+
validate,
|
|
26
|
+
}).run();
|
|
27
|
+
const verisure = new verisure_1.default(email.trim(), password);
|
|
28
|
+
await verisure.getToken();
|
|
29
|
+
if (!verisure.getCookie('vid')) {
|
|
30
|
+
console.log('\n', 'One-time code sent.', '\n');
|
|
31
|
+
const { code } = await prompt({
|
|
32
|
+
type: 'input',
|
|
33
|
+
name: 'code',
|
|
34
|
+
message: 'What is your one-time code?',
|
|
35
|
+
validate,
|
|
36
|
+
});
|
|
37
|
+
await verisure.getToken(code.trim());
|
|
38
|
+
}
|
|
39
|
+
const missingCookies = ['vid', 'vs-access', 'vs-refresh']
|
|
40
|
+
.filter((prefix) => !verisure.getCookie(prefix));
|
|
41
|
+
if (missingCookies.length > 0) {
|
|
42
|
+
console.log('\n', `Warning: didn't receive a ${missingCookies.join(', ')} cookie. Your config below may not work - try running this again.`, '\n');
|
|
43
|
+
}
|
|
44
|
+
console.log('\n', 'Your config is ready.', '\n');
|
|
45
|
+
console.log(JSON.stringify({
|
|
46
|
+
platform: 'verisure',
|
|
47
|
+
name: 'Verisure',
|
|
48
|
+
email,
|
|
49
|
+
cookies: verisure.cookies,
|
|
50
|
+
}, null, 2));
|
|
51
|
+
};
|
|
52
|
+
run().catch((error) => {
|
|
53
|
+
console.error(error.message);
|
|
54
|
+
process.exitCode = 1;
|
|
55
|
+
});
|
|
56
|
+
//# sourceMappingURL=verisure.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"verisure.js","sourceRoot":"","sources":["../../src/bin/verisure.ts"],"names":[],"mappings":";;AACA,+BAA+B;;;;;AAE/B,wDAAgC;AAChC,wDAAgC;AAEhC,8EAA8E;AAC9E,+DAA+D;AAC/D,MAAM,EAAE,MAAM,EAAE,GAAG,kBAAQ,CAAC;AAC5B,MAAM,QAAQ,GAAI,kBAEhB,CAAC,QAAQ,CAAC;AAEZ,MAAM,QAAQ,GAAG,CAAC,KAAa,EAAE,EAAE,CAAC,CAAC,CAAC,KAAK,CAAC,MAAM,CAAC;AAEnD,MAAM,GAAG,GAAG,KAAK,IAAmB,EAAE;IACpC,MAAM,EAAE,KAAK,EAAE,GAAG,MAAM,MAAM,CAAoB;QAChD,IAAI,EAAE,OAAO;QACb,IAAI,EAAE,OAAO;QACb,OAAO,EAAE,2BAA2B;QACpC,QAAQ;KACT,CAAC,CAAC;IAEH,MAAM,QAAQ,GAAG,MAAM,IAAI,QA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AAE,IAAI,EAAE,CAAC,CAAC,CAAC,CAAC;AACf,CAAC,CAAC;AAEF,GAAG,EAAE,CAAC,KAAK,CAAC,CAAC,KAAY,EAAE,EAAE;IAC3B,OAAO,CAAC,KAAK,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC;IAC7B,OAAO,CAAC,QAAQ,GAAG,CAAC,CAAC;AACvB,CAAC,CAAC,CAAC"}
|
package/dist/cache.d.ts
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
export interface Memoized<T> {
|
|
2
|
+
(): Promise<T>;
|
|
3
|
+
/** Discards the cached value, so the next call fetches fresh. Call this
|
|
4
|
+
* right after a mutation that would make the cached value stale - see
|
|
5
|
+
* OverviewPoller#invalidate for why this matters for HomeKit UX. */
|
|
6
|
+
invalidate(): void;
|
|
7
|
+
}
|
|
8
|
+
/**
|
|
9
|
+
* Wraps an async function so repeated calls within `ttlMs` reuse the same
|
|
10
|
+
* result (and concurrent calls collapse into a single in-flight request)
|
|
11
|
+
* instead of each hitting the network. Used to keep bursts of near-identical
|
|
12
|
+
* HomeKit "get" requests from turning into a burst of Verisure API calls.
|
|
13
|
+
*/
|
|
14
|
+
export declare function memoizeAsync<T>(fn: () => Promise<T>, ttlMs: number): Memoized<T>;
|
package/dist/cache.js
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.memoizeAsync = memoizeAsync;
|
|
4
|
+
/**
|
|
5
|
+
* Wraps an async function so repeated calls within `ttlMs` reuse the same
|
|
6
|
+
* result (and concurrent calls collapse into a single in-flight request)
|
|
7
|
+
* instead of each hitting the network. Used to keep bursts of near-identical
|
|
8
|
+
* HomeKit "get" requests from turning into a burst of Verisure API calls.
|
|
9
|
+
*/
|
|
10
|
+
function memoizeAsync(fn, ttlMs) {
|
|
11
|
+
let cached;
|
|
12
|
+
let pending;
|
|
13
|
+
const memoized = () => {
|
|
14
|
+
const now = Date.now();
|
|
15
|
+
if (cached && now - cached.time < ttlMs) {
|
|
16
|
+
return Promise.resolve(cached.value);
|
|
17
|
+
}
|
|
18
|
+
if (!pending) {
|
|
19
|
+
pending = fn()
|
|
20
|
+
.then((value) => {
|
|
21
|
+
cached = { value, time: Date.now() };
|
|
22
|
+
return value;
|
|
23
|
+
})
|
|
24
|
+
.finally(() => {
|
|
25
|
+
pending = undefined;
|
|
26
|
+
});
|
|
27
|
+
}
|
|
28
|
+
return pending;
|
|
29
|
+
};
|
|
30
|
+
memoized.invalidate = () => {
|
|
31
|
+
cached = undefined;
|
|
32
|
+
};
|
|
33
|
+
return memoized;
|
|
34
|
+
}
|
|
35
|
+
//# sourceMappingURL=cache.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cache.js","sourceRoot":"","sources":["../src/cache.ts"],"names":[],"mappings":";;AAcA,oCA2BC;AAjCD;;;;;GAKG;AACH,SAAgB,YAAY,CAAI,EAAoB,EAAE,KAAa;IACjE,IAAI,MAA8C,CAAC;IACnD,IAAI,OAA+B,CAAC;IAEpC,MAAM,QAAQ,GAAG,GAAe,EAAE;QAChC,MAAM,GAAG,GAAG,IAAI,CAAC,GAAG,EAAE,CAAC;QACvB,IAAI,MAAM,IAAI,GAAG,GAAG,MAAM,CAAC,IAAI,GAAG,KAAK,EAAE,CAAC;YACxC,OAAO,OAAO,CAAC,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;QACvC,CAAC;QACD,IAAI,CAAC,OAAO,EAAE,CAAC;YACb,OAAO,GAAG,EAAE,EAAE;iBACX,IAAI,CAAC,CAAC,KAAK,EAAE,EAAE;gBACd,MAAM,GAAG,EAAE,KAAK,EAAE,IAAI,EAAE,IAAI,CAAC,GAAG,EAAE,EAAE,CAAC;gBACrC,OAAO,KAAK,CAAC;YACf,CAAC,CAAC;iBACD,OAAO,CAAC,GAAG,EAAE;gBACZ,OAAO,GAAG,SAAS,CAAC;YACtB,CAAC,CAAC,CAAC;QACP,CAAC;QACD,OAAO,OAAO,CAAC;IACjB,CAAC,CAAC;IAEF,QAAQ,CAAC,UAAU,GAAG,GAAS,EAAE;QAC/B,MAAM,GAAG,SAAS,CAAC;IACrB,CAAC,CAAC;IAEF,OAAO,QAAQ,CAAC;AAClB,CAAC"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.CLIMATE_DEVICE_NAMES = void 0;
|
|
4
|
+
/** Maps Verisure's internal climate/gui device labels to a human name, which
|
|
5
|
+
* is then run through `i18n()` for display. */
|
|
6
|
+
exports.CLIMATE_DEVICE_NAMES = {
|
|
7
|
+
HOMEPAD: 'VoiceBox',
|
|
8
|
+
HUMIDITY: 'Climate sensor',
|
|
9
|
+
SIREN: 'Siren',
|
|
10
|
+
SMOKE: 'Smoke detector',
|
|
11
|
+
VOICEBOX: 'VoiceBox',
|
|
12
|
+
// Old ones, not verified from GraphQL.
|
|
13
|
+
SMARTCAMERA1: 'SmartCam',
|
|
14
|
+
WATER1: 'Water detector',
|
|
15
|
+
};
|
|
16
|
+
//# sourceMappingURL=deviceNames.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"deviceNames.js","sourceRoot":"","sources":["../src/deviceNames.ts"],"names":[],"mappings":";;;AAAA;+CAC+C;AAClC,QAAA,oBAAoB,GAA2B;IAC1D,OAAO,EAAE,UAAU;IACnB,QAAQ,EAAE,gBAAgB;IAC1B,KAAK,EAAE,OAAO;IACd,KAAK,EAAE,gBAAgB;IACvB,QAAQ,EAAE,UAAU;IACpB,uCAAuC;IACvC,YAAY,EAAE,UAAU;IACxB,MAAM,EAAE,gBAAgB;CACzB,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const i18n: (locale?: string) => (input?: string) => string | undefined;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.i18n = void 0;
|
|
7
|
+
const nb_NO_json_1 = __importDefault(require("./nb_NO.json"));
|
|
8
|
+
const sv_SE_json_1 = __importDefault(require("./sv_SE.json"));
|
|
9
|
+
const locales = {
|
|
10
|
+
nb_NO: nb_NO_json_1.default,
|
|
11
|
+
sv_SE: sv_SE_json_1.default,
|
|
12
|
+
};
|
|
13
|
+
const i18n = (locale) => {
|
|
14
|
+
const strings = (locale && locales[locale]) || {};
|
|
15
|
+
return (input) => (input && strings[input]) || input;
|
|
16
|
+
};
|
|
17
|
+
exports.i18n = i18n;
|
|
18
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/i18n/index.ts"],"names":[],"mappings":";;;;;;AAAA,8DAAgC;AAChC,8DAAgC;AAIhC,MAAM,OAAO,GAA+B;IAC1C,KAAK,EAAE,oBAAI;IACX,KAAK,EAAE,oBAAI;CACZ,CAAC;AAEK,MAAM,IAAI,GAAG,CAAC,MAAe,EAAE,EAAE;IACtC,MAAM,OAAO,GAAG,CAAC,MAAM,IAAI,OAAO,CAAC,MAAM,CAAC,CAAC,IAAI,EAAE,CAAC;IAClD,OAAO,CAAC,KAAc,EAAsB,EAAE,CAAC,CAAC,KAAK,IAAI,OAAO,CAAC,KAAK,CAAC,CAAC,IAAI,KAAK,CAAC;AACpF,CAAC,CAAC;AAHW,QAAA,IAAI,QAGf"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
{
|
|
2
|
+
"Climate sensor": "Klimasensor",
|
|
3
|
+
"Heat pump": "Varmepumpe",
|
|
4
|
+
"Keypad": "Betjeningspanel",
|
|
5
|
+
"Magnetic contact": "Magnetkontakt",
|
|
6
|
+
"Motion detector": "Bevegelsedetektor",
|
|
7
|
+
"Mouse detector": "Musedetektor",
|
|
8
|
+
"Night Control": "Nattsikringspanel",
|
|
9
|
+
"Siren": "Sirene",
|
|
10
|
+
"SmartCam": "Smartkamera",
|
|
11
|
+
"SmartLock": "Låsmodul",
|
|
12
|
+
"SmartPlug": "Smartkontakt",
|
|
13
|
+
"Smoke detector": "Røykvarsler",
|
|
14
|
+
"VBox Micro": "Smarthjemsentral",
|
|
15
|
+
"VBox Mini": "Smarthjemsentral",
|
|
16
|
+
"VBox Pro": "Hovedenhet",
|
|
17
|
+
"VBox": "Hovedenhet",
|
|
18
|
+
"Vibration detector": "Sjokksensor med magnet",
|
|
19
|
+
"VoiceBox": "Verisure Voice",
|
|
20
|
+
"Water detector with cable": "Vanndetektor med kabel",
|
|
21
|
+
"Water detector": "Vanndetektor"
|
|
22
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
{
|
|
2
|
+
"Climate sensor": "Klimatdetektor",
|
|
3
|
+
"Heat pump": "Värmepump",
|
|
4
|
+
"Keypad": "Manöverpanel",
|
|
5
|
+
"Magnetic contact": "Dörr-/fönsterdetektor",
|
|
6
|
+
"Motion detector": "Rörelsedetektor",
|
|
7
|
+
"Mouse detector": "Musdetektor",
|
|
8
|
+
"Night Control": "Trygghetspanel",
|
|
9
|
+
"Siren": "Inomhussiren med värmedetektor",
|
|
10
|
+
"SmartCam": "Smart kamera",
|
|
11
|
+
"SmartLock": "Smart lås",
|
|
12
|
+
"SmartPlug": "Smart plug",
|
|
13
|
+
"Smoke detector": "Rökdetektor",
|
|
14
|
+
"VBox Micro": "Microenhet",
|
|
15
|
+
"VBox Mini": "Minienhet",
|
|
16
|
+
"VBox Pro": "Huvudenhet",
|
|
17
|
+
"VBox": "Huvudenhet",
|
|
18
|
+
"Vibration detector": "Vibrationsdetektor",
|
|
19
|
+
"VoiceBox": "Röstenhet",
|
|
20
|
+
"Water detector with cable": "Vattendetektor med kabel",
|
|
21
|
+
"Water detector": "Vattendetektor"
|
|
22
|
+
}
|
package/dist/index.d.ts
ADDED
package/dist/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AAEA,yCAA8C;AAC9C,yCAA2C;AAE3C,iBAAS,CAAC,GAAQ,EAAQ,EAAE;IAC1B,GAAG,CAAC,gBAAgB,CAAC,wBAAa,EAAE,2BAAgB,CAAC,CAAC;AACxD,CAAC,CAAC"}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import type { GraphqlOperation } from 'verisure';
|
|
2
|
+
/**
|
|
3
|
+
* The combined query used on the common/fast path: one request covers every
|
|
4
|
+
* accessory type. Some installations (observed on certain PreSense/non-Yale
|
|
5
|
+
* setups) have Verisure's own GraphQL server reject this query outright with
|
|
6
|
+
* e.g. `Expected Iterable, but did not find one for field
|
|
7
|
+
* "Installation.doorWindows"` when a sub-resolver returns `null` instead of
|
|
8
|
+
* `[]` - see issues #188, #189. `OverviewPoller` catches that and falls back
|
|
9
|
+
* to the individual per-domain queries below, so a broken field for one
|
|
10
|
+
* installation doesn't take down every accessory type on it.
|
|
11
|
+
*/
|
|
12
|
+
export declare const overviewOperation: GraphqlOperation;
|
|
13
|
+
export declare const armStateOperation: GraphqlOperation;
|
|
14
|
+
export declare const climatesOperation: GraphqlOperation;
|
|
15
|
+
export declare const doorWindowsOperation: GraphqlOperation;
|
|
16
|
+
export declare const smartplugsOperation: GraphqlOperation;
|
|
17
|
+
export declare const doorlocksOperation: GraphqlOperation;
|
|
18
|
+
export declare const armAwayOperation: (code: string, forceArm: boolean) => GraphqlOperation;
|
|
19
|
+
export declare const armHomeOperation: (code: string, forceArm: boolean) => GraphqlOperation;
|
|
20
|
+
export declare const disarmOperation: (code: string) => GraphqlOperation;
|
|
21
|
+
export declare const pollArmStateOperation: (transactionId: string, futureState: string) => GraphqlOperation;
|
|
22
|
+
export declare const smartPlugStateOperation: (deviceLabel: string, state: boolean) => GraphqlOperation;
|
|
23
|
+
export declare const doorLockOperation: (deviceLabel: string, code: string) => GraphqlOperation;
|
|
24
|
+
export declare const doorUnlockOperation: (deviceLabel: string, code: string) => GraphqlOperation;
|
|
25
|
+
export declare const pollLockStateOperation: (transactionId: string, deviceLabel: string, futureState: string) => GraphqlOperation;
|
|
26
|
+
export declare const doorLockConfigOperation: (deviceLabel: string) => GraphqlOperation;
|
|
27
|
+
export declare const doorLockUpdateConfigOperation: (deviceLabel: string, input: Record<string, unknown>) => GraphqlOperation;
|