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.
Files changed (68) hide show
  1. package/README.md +33 -2
  2. package/config.schema.json +30 -0
  3. package/dist/accessories/alarm.d.ts +28 -0
  4. package/dist/accessories/alarm.js +129 -0
  5. package/dist/accessories/alarm.js.map +1 -0
  6. package/dist/accessories/base.d.ts +39 -0
  7. package/dist/accessories/base.js +63 -0
  8. package/dist/accessories/base.js.map +1 -0
  9. package/dist/accessories/climateSensor.d.ts +14 -0
  10. package/dist/accessories/climateSensor.js +60 -0
  11. package/dist/accessories/climateSensor.js.map +1 -0
  12. package/dist/accessories/contactSensor.d.ts +14 -0
  13. package/dist/accessories/contactSensor.js +39 -0
  14. package/dist/accessories/contactSensor.js.map +1 -0
  15. package/dist/accessories/doorLock.d.ts +32 -0
  16. package/dist/accessories/doorLock.js +162 -0
  17. package/dist/accessories/doorLock.js.map +1 -0
  18. package/dist/accessories/smartPlug.d.ts +15 -0
  19. package/dist/accessories/smartPlug.js +54 -0
  20. package/dist/accessories/smartPlug.js.map +1 -0
  21. package/dist/bin/verisure.d.ts +2 -0
  22. package/dist/bin/verisure.js +56 -0
  23. package/dist/bin/verisure.js.map +1 -0
  24. package/dist/cache.d.ts +14 -0
  25. package/dist/cache.js +35 -0
  26. package/dist/cache.js.map +1 -0
  27. package/dist/deviceNames.d.ts +3 -0
  28. package/dist/deviceNames.js +16 -0
  29. package/dist/deviceNames.js.map +1 -0
  30. package/dist/i18n/index.d.ts +1 -0
  31. package/dist/i18n/index.js +18 -0
  32. package/dist/i18n/index.js.map +1 -0
  33. package/dist/i18n/nb_NO.json +22 -0
  34. package/dist/i18n/sv_SE.json +22 -0
  35. package/dist/index.d.ts +3 -0
  36. package/dist/index.js +7 -0
  37. package/dist/index.js.map +1 -0
  38. package/dist/operations.d.ts +27 -0
  39. package/dist/operations.js +322 -0
  40. package/dist/operations.js.map +1 -0
  41. package/dist/overviewPoller.d.ts +53 -0
  42. package/dist/overviewPoller.js +169 -0
  43. package/dist/overviewPoller.js.map +1 -0
  44. package/dist/platform.d.ts +27 -0
  45. package/dist/platform.js +272 -0
  46. package/dist/platform.js.map +1 -0
  47. package/dist/settings.d.ts +21 -0
  48. package/dist/settings.js +25 -0
  49. package/dist/settings.js.map +1 -0
  50. package/dist/types.d.ts +117 -0
  51. package/dist/types.js +12 -0
  52. package/dist/types.js.map +1 -0
  53. package/package.json +39 -16
  54. package/CHANGELOG.md +0 -180
  55. package/bin/verisure +0 -55
  56. package/index.js +0 -6
  57. package/lib/accessories/alarm.js +0 -111
  58. package/lib/accessories/climatesensor.js +0 -68
  59. package/lib/accessories/contactsensor.js +0 -45
  60. package/lib/accessories/doorlock.js +0 -216
  61. package/lib/accessories/index.js +0 -13
  62. package/lib/accessories/smartplug.js +0 -60
  63. package/lib/accessories/verisure.js +0 -62
  64. package/lib/i18n/index.js +0 -11
  65. package/lib/i18n/nb_NO.json +0 -22
  66. package/lib/i18n/sv_SE.json +0 -22
  67. package/lib/operations.js +0 -225
  68. package/lib/platform.js +0 -156
@@ -1,60 +0,0 @@
1
- const VerisureAccessory = require('./verisure');
2
- const { overviewOperation, smartPlugStateOperation } = require('../operations');
3
-
4
- class SmartPlug extends VerisureAccessory {
5
- constructor(...args) {
6
- super(...args);
7
-
8
- this.model = 'SMARTPLUG';
9
- this.name = VerisureAccessory.getUniqueAccessoryName(`SmartPlug - ${this.config.device.area}`);
10
- this.value = SmartPlug.resolveSwitchState(this.config.currentState);
11
- }
12
-
13
- static resolveSwitchState(input) {
14
- return input === 'ON';
15
- }
16
-
17
- getSwitchState(callback) {
18
- this.log('Getting current switch state.');
19
-
20
- this.installation.client(overviewOperation)
21
- .then((overview) => overview.installation.smartplugs
22
- .find((smartplug) => smartplug.device.deviceLabel === this.serialNumber))
23
- .then((smartplug) => {
24
- this.value = SmartPlug.resolveSwitchState(smartplug.currentState);
25
- callback(null, this.value);
26
- })
27
- .catch(callback);
28
- }
29
-
30
- setSwitchState(value, callback) {
31
- this.log(`Setting switch state to: ${value}`);
32
-
33
- this.value = value;
34
-
35
- this.installation.client(smartPlugStateOperation(this.serialNumber, value))
36
- // TODO: Poll for result?
37
- .then(() => callback(null))
38
- .catch((error) => {
39
- this.log(`Error setting switch state: ${error.errorMessage}`);
40
- callback({ message: error.errorMessage });
41
- });
42
- }
43
-
44
- getServices() {
45
- const { Service, Characteristic } = this.homebridge.hap;
46
-
47
- this.service = new Service.Switch(this.name);
48
- this.service
49
- .getCharacteristic(Characteristic.On)
50
- .on('get', this.getSwitchState.bind(this))
51
- .on('set', this.setSwitchState.bind(this))
52
- .value = this.value;
53
-
54
- this.accessoryInformation.setCharacteristic(Characteristic.Model, this.model);
55
-
56
- return [this.accessoryInformation, this.service];
57
- }
58
- }
59
-
60
- module.exports = SmartPlug;
@@ -1,62 +0,0 @@
1
- const uniqueAccessoryNames = [];
2
-
3
- class VerisureAccessory {
4
- constructor(homebridge, logger, config, installation, platformConfig) {
5
- this.homebridge = homebridge;
6
- this.logger = logger;
7
- this.config = config;
8
- this.installation = installation;
9
- this.platformConfig = platformConfig;
10
-
11
- this.serialNumber = config.device && config.device.deviceLabel;
12
-
13
- this.value = null;
14
- this.service = null;
15
- this.pollCharacteristics = [];
16
-
17
- const { Characteristic, Service } = homebridge.hap;
18
-
19
- this.accessoryInformation = new Service.AccessoryInformation();
20
- this.accessoryInformation
21
- .setCharacteristic(Characteristic.Manufacturer, 'Verisure')
22
- .setCharacteristic(Characteristic.SerialNumber, this.serialNumber);
23
-
24
- if (platformConfig && platformConfig.pollInterval) {
25
- setInterval(() => {
26
- this.pollCharacteristics.forEach((characteristic) => characteristic.getValue());
27
- }, platformConfig.pollInterval * 1000);
28
- }
29
- }
30
-
31
- static getUniqueAccessoryName(name) {
32
- if (uniqueAccessoryNames.includes(name)) {
33
- const match = name.match(/(.+) #(\d+)/) || [null, name, 1];
34
- return VerisureAccessory.getUniqueAccessoryName(`${match[1]} #${parseInt(match[2], 10) + 1}`);
35
- }
36
- uniqueAccessoryNames.push(name);
37
- return name;
38
- }
39
-
40
- resolveChangeResult(operation) {
41
- this.log(`Resolving: ${operation.operationName}`);
42
- // TODO: Handle max retries
43
-
44
- return this.installation.client(operation)
45
- .then(({ installation: { pollResult: { result } } }) => {
46
- this.log(`Got "${result}" back from: ${operation.operationName}`);
47
- if (result === null) {
48
- return new Promise((resolve) => setTimeout(
49
- () => resolve(this.resolveChangeResult(operation)),
50
- 200,
51
- ));
52
- }
53
- return result;
54
- });
55
- }
56
-
57
- log(message, level = 'info') {
58
- return this.logger[level](`${this.installation.config.alias} ${this.name}: ${message}`);
59
- }
60
- }
61
-
62
- module.exports = VerisureAccessory;
package/lib/i18n/index.js DELETED
@@ -1,11 +0,0 @@
1
- module.exports = (locale) => {
2
- let strings;
3
- try {
4
- // eslint-disable-next-line global-require, import/no-dynamic-require
5
- strings = require(`./${locale}`);
6
- } catch (e) {
7
- strings = {};
8
- }
9
-
10
- return (string) => (strings[string] ? strings[string] : string);
11
- };
@@ -1,22 +0,0 @@
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
- }
@@ -1,22 +0,0 @@
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/lib/operations.js DELETED
@@ -1,225 +0,0 @@
1
- module.exports = {
2
- overviewOperation: {
3
- operationName: 'Overview',
4
- query: `query Overview($giid: String!) {
5
- installation(giid: $giid) {
6
- alias
7
- locale
8
-
9
- climates {
10
- device {
11
- deviceLabel
12
- area
13
- gui {
14
- label
15
- __typename
16
- }
17
- __typename
18
- }
19
- humidityEnabled
20
- humidityTimestamp
21
- humidityValue
22
- temperatureTimestamp
23
- temperatureValue
24
- thresholds {
25
- aboveMaxAlert
26
- belowMinAlert
27
- sensorType
28
- __typename
29
- }
30
- __typename
31
- }
32
-
33
- armState {
34
- type
35
- statusType
36
- date
37
- name
38
- changedVia
39
- __typename
40
- }
41
-
42
- doorWindows {
43
- device {
44
- deviceLabel
45
- area
46
- gui {
47
- support
48
- label
49
- __typename
50
- }
51
- __typename
52
- }
53
- type
54
- state
55
- wired
56
- reportTime
57
- __typename
58
- }
59
-
60
- smartplugs {
61
- device {
62
- deviceLabel
63
- area
64
- gui {
65
- support
66
- label
67
- __typename
68
- }
69
- __typename
70
- }
71
- currentState
72
- icon
73
- isHazardous
74
- __typename
75
- }
76
-
77
- doorlocks {
78
- device {
79
- area
80
- deviceLabel
81
- __typename
82
- }
83
- currentLockState
84
- __typename
85
- }
86
-
87
- __typename
88
- }
89
- }`,
90
- },
91
-
92
- armAwayOperation: (code) => ({
93
- operationName: 'armAway',
94
- variables: { code },
95
- query: `mutation armAway($giid: String!, $code: String!) {
96
- transactionId: armStateArmAway(giid: $giid, code: $code)
97
- }`,
98
- }),
99
-
100
- armHomeOperation: (code) => ({
101
- operationName: 'armHome',
102
- variables: { code },
103
- query: `mutation armHome($giid: String!, $code: String!) {
104
- transactionId: armStateArmHome(giid: $giid, code: $code)
105
- }`,
106
- }),
107
-
108
- disarmOperation: (code) => ({
109
- operationName: 'disarm',
110
- variables: { code },
111
- query: `mutation disarm($giid: String!, $code: String!) {
112
- transactionId: armStateDisarm(giid: $giid, code: $code)
113
- }`,
114
- }),
115
-
116
- pollArmStateOperation: (transactionId, futureState) => ({
117
- operationName: 'pollArmState',
118
- variables: {
119
- transactionId,
120
- futureState,
121
- },
122
- query: `query pollArmState($giid: String!, $transactionId: String, $futureState: ArmStateStatusTypes!) {
123
- installation(giid: $giid) {
124
- pollResult: armStateChangePollResult(transactionId: $transactionId, futureState: $futureState) {
125
- result
126
- createTime
127
- __typename
128
- }
129
- __typename
130
- }
131
- }`,
132
- }),
133
-
134
- smartPlugStateOperation: (deviceLabel, state) => ({
135
- operationName: 'smartPlugState',
136
- variables: {
137
- deviceLabel,
138
- state,
139
- },
140
- query: `mutation smartPlugState($giid: String!, $deviceLabel: String!, $state: Boolean!) {
141
- SmartPlugSetState(giid: $giid, input: [{deviceLabel: $deviceLabel, state: $state}])
142
- }`,
143
- }),
144
-
145
- doorLockOperation: (deviceLabel, code) => ({
146
- operationName: 'DoorLock',
147
- variables: {
148
- deviceLabel,
149
- input: { code },
150
- },
151
- query: `mutation DoorLock($giid: String!, $deviceLabel: String!, $input: LockDoorInput!) {
152
- transactionId: DoorLock(giid: $giid, deviceLabel: $deviceLabel, input: $input)
153
- }`,
154
- }),
155
-
156
- doorUnlockOperation: (deviceLabel, code) => ({
157
- operationName: 'DoorUnlock',
158
- variables: {
159
- deviceLabel,
160
- input: { code },
161
- },
162
- query: `mutation DoorUnlock($giid: String!, $deviceLabel: String!, $input: LockDoorInput!) {
163
- transactionId: DoorUnlock(giid: $giid, deviceLabel: $deviceLabel, input: $input)
164
- }`,
165
- }),
166
-
167
- pollLockStateOperation: (transactionId, deviceLabel, futureState) => ({
168
- operationName: 'pollLockState',
169
- variables: {
170
- transactionId,
171
- deviceLabel,
172
- futureState,
173
- },
174
- query: `query pollLockState($giid: String!, $transactionId: String, $deviceLabel: String!, $futureState: DoorLockState!) {
175
- installation(giid: $giid) {
176
- pollResult: doorLockStateChangePollResult(transactionId: $transactionId, deviceLabel: $deviceLabel, futureState: $futureState) {
177
- result
178
- createTime
179
- __typename
180
- }
181
- __typename
182
- }
183
- }`,
184
- }),
185
-
186
- doorLockConfigOperation: (deviceLabel) => ({
187
- operationName: 'DoorLockConfiguration',
188
- variables: {
189
- deviceLabel,
190
- },
191
- query: `query DoorLockConfiguration($giid: String!, $deviceLabel: String!) {
192
- installation(giid: $giid) {
193
- smartLocks(filter: {deviceLabels: [$deviceLabel]}) {
194
- device {
195
- area
196
- deviceLabel
197
- __typename
198
- }
199
- configuration {
200
- ... on YaleLockConfiguration {
201
- autoLockEnabled
202
- voiceLevel
203
- volume
204
- __typename
205
- }
206
- __typename
207
- }
208
- __typename
209
- }
210
- __typename
211
- }
212
- }`,
213
- }),
214
-
215
- doorLockUpdateConfigOperation: (deviceLabel, input) => ({
216
- operationName: 'DoorLockUpdateConfig',
217
- variables: {
218
- deviceLabel,
219
- input,
220
- },
221
- query: `mutation DoorLockUpdateConfig($giid: String!, $deviceLabel: String!, $input: DoorLockUpdateConfigInput!) {
222
- DoorLockUpdateConfig(giid: $giid, deviceLabel: $deviceLabel, input: $input)
223
- }`,
224
- }),
225
- };
package/lib/platform.js DELETED
@@ -1,156 +0,0 @@
1
- const Verisure = require('verisure');
2
-
3
- const accessoryClasses = require('./accessories');
4
- const { overviewOperation } = require('./operations');
5
-
6
- let homebridge = null;
7
-
8
- class VerisurePlatform {
9
- constructor(logger, config) {
10
- if (!homebridge) {
11
- throw Error('Module not initiated.');
12
- }
13
-
14
- const {
15
- VERISURE_ALARM_CODE,
16
- VERISURE_DOOR_CODE,
17
- VERISURE_EMAIL,
18
- VERISURE_PASSWORD,
19
- VERISURE_COOKIES,
20
- VERISURE_TOKEN, // Deprecated.
21
- } = process.env;
22
-
23
- const {
24
- alarmCode,
25
- doorcode, doorCode,
26
- email,
27
- cookies,
28
- password,
29
- installations = [],
30
- pollInterval = 60,
31
- showAutoLockSwitch = true,
32
- showAudioSwitch = true,
33
- audioOffValue = 'LOW',
34
- audioOnValue = 'HIGH',
35
- token, // Deprecated.
36
- } = config;
37
-
38
- this.config = {
39
- alarmCode: VERISURE_ALARM_CODE || alarmCode,
40
- doorCode: VERISURE_DOOR_CODE || doorcode || doorCode,
41
- email: VERISURE_EMAIL || email,
42
- password: VERISURE_PASSWORD || password,
43
- cookies: (VERISURE_COOKIES && VERISURE_COOKIES.split(';')) || cookies,
44
- installations,
45
- pollInterval,
46
- showAutoLockSwitch,
47
- showAudioSwitch,
48
- audioOffValue,
49
- audioOnValue,
50
- };
51
-
52
- this.homebridge = homebridge;
53
- this.logger = logger;
54
-
55
- if (VERISURE_TOKEN || token) {
56
- this.logger.error('DEPRECATED: Property "token" in config. Please see README to get and configure "cookies".');
57
- }
58
-
59
- this.verisure = new Verisure(
60
- this.config.email,
61
- this.config.password,
62
- this.config.cookies,
63
- );
64
- }
65
-
66
- static init(homebridgeRef) {
67
- homebridge = homebridgeRef;
68
- }
69
-
70
- static overviewToDeviceConfigs(overview) {
71
- const alarm = overview.armState
72
- ? [{ statusType: overview.armState.statusType }]
73
- : [];
74
-
75
- // TODO: Use renaming in query instead.
76
- const deviceTypes = {
77
- alarm,
78
- climateSensor: overview.climates || [],
79
- contactSensor: overview.doorWindows || [],
80
- doorLock: overview.doorlocks || [],
81
- smartPlug: overview.smartplugs || [],
82
- };
83
-
84
- return deviceTypes;
85
- }
86
-
87
- overviewToAccessories([installation, { installation: overview }]) {
88
- const accessories = [];
89
- const deviceTypes = VerisurePlatform.overviewToDeviceConfigs(overview);
90
-
91
- Object.keys(deviceTypes).forEach((deviceType) => {
92
- if (deviceType === 'alarm' && !this.config.alarmCode) {
93
- return;
94
- }
95
-
96
- if (deviceType === 'doorLock' && !this.config.doorcode && !this.config.doorCode) {
97
- return;
98
- }
99
-
100
- deviceTypes[deviceType].forEach((deviceConfig) => {
101
- accessories.push(new accessoryClasses[deviceType](
102
- homebridge,
103
- this.logger,
104
- deviceConfig,
105
- installation,
106
- this.config,
107
- ));
108
- });
109
- });
110
-
111
- return accessories;
112
- }
113
-
114
- async accessories(callback) {
115
- try {
116
- if (!this.verisure.cookies.length) {
117
- await this.verisure.getToken();
118
-
119
- if (!this.verisure.getCookie('vid')) {
120
- this.logger.error('MFA is enabled for user. Please see README.');
121
- return callback([]);
122
- }
123
- }
124
-
125
- this.installations = (await this.verisure.getInstallations())
126
- // Filter out installations based on configuration.
127
- .filter((installation) => this.config.installations.length === 0
128
- || this.config.installations.includes(installation.config.alias));
129
- } catch (error) {
130
- this.logger.error(`Unable to get installations. Please check configured credentials: ${error.message}`);
131
- return callback([]);
132
- }
133
-
134
- if (this.installations.length === 0) {
135
- this.logger.error(`No installations found matching config: ${JSON.stringify(this.config.installations)}`);
136
- return callback([]);
137
- }
138
-
139
- const overviews = await Promise.all(
140
- this.installations.map((installation) => Promise.all([
141
- installation,
142
- installation.client(overviewOperation),
143
- ])),
144
- );
145
-
146
- try {
147
- const accessoryLists = overviews.map(this.overviewToAccessories.bind(this));
148
- return callback(accessoryLists.reduce((a, b) => [...a, ...b]));
149
- } catch (error) {
150
- this.logger.error((error.response && error.response.data) || error.message);
151
- return callback([]);
152
- }
153
- }
154
- }
155
-
156
- module.exports = VerisurePlatform;