homebridge-verisure 1.13.2 → 1.15.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/CHANGELOG.md CHANGED
@@ -1,3 +1,31 @@
1
+ ## 1.15.0 (Jan 11, 2022)
2
+
3
+ ### Plugin
4
+
5
+ * Added config option for installations to initiate.
6
+
7
+ ## 1.14.2 (Jan 4, 2022)
8
+
9
+ ### Plugin
10
+
11
+ * Initiate gracefully, to not affect other plugins.
12
+
13
+ ## 1.14.1 (Oct 8, 2021)
14
+
15
+ ### Dependencies
16
+
17
+ * Bump `verisure` module.
18
+
19
+ ## 1.14.0 (Mar 17, 2021)
20
+
21
+ ### Config
22
+
23
+ * Support for Multi-factor authentication (MFA).
24
+
25
+ ### Dependencies
26
+
27
+ * Bump `verisure` module.
28
+
1
29
  ## 1.13.2 (Feb 28, 2021)
2
30
 
3
31
  ### Plugin
package/README.md CHANGED
@@ -48,19 +48,48 @@ your array (list) of enabled platform plugins. Example config:
48
48
  "name" : "Verisure",
49
49
  "email": "your@email.com",
50
50
  "password": "yourT0p5ecre7Passw0rd",
51
+ "token": "vid=topSecretToken",
51
52
  "alarmCode": "0000",
52
53
  "doorCode": "000000",
54
+ "installations": ["Alias"],
53
55
  "pollInterval": 60
54
56
  }
55
57
  ]
56
58
  ```
57
59
 
58
60
  * __`email`__ Required string containing your Verisure account email address.
59
- * __`password`__ Required string containing your Verisure account password.
61
+ * __`password`__ Required string containing your Verisure account password. Not needed if you use a `token`.
62
+ * __`token`__ Required string for accounts with MFA enabled.
60
63
  * `alarmCode` Optional string containing your security system alarm code.
61
64
  * `doorCode` Optional string containing your door lock code.
65
+ * `installations` Optional array for filtering installations based on Verisure alias. Defaults to `[]`
62
66
  * `pollInterval` Optional integer containing poll interval in seconds. Defaults to `60`.
63
67
 
68
+ ### Multi-factor authentication
69
+
70
+ > [Verisure] MFA is enabled for user. Please see README.
71
+
72
+ In 2021 Verisure started enrolling MFA which requires you to obtain a long lived token. This token is used instead of a `password` in your config and will need to be renewed yearly. After installing the plugin, run `npx homebridge-verisure` in your terminal and copy the output values into your config.
73
+
74
+ ```bash
75
+ $ npx homebridge-verisure
76
+ ✔ What is your login email? · foo@bar.com
77
+ ✔ What is your password? · ********************
78
+
79
+ One-time code sent.
80
+
81
+ ✔ What is your one-time code? · FAKE12
82
+
83
+ Your config is ready.
84
+
85
+ {
86
+ "platform": "verisure",
87
+ "name": "Verisure",
88
+ "email": "foo@bar.com",
89
+ "token": "vid=topSecretToken"
90
+ }
91
+ ```
92
+
64
93
  ### Environment variables
65
94
 
66
95
  For convenience, the following environment variables can be used instead of placing secrets in your `config.json`.
@@ -69,3 +98,4 @@ For convenience, the following environment variables can be used instead of plac
69
98
  * `VERISURE_DOOR_CODE`
70
99
  * `VERISURE_EMAIL`
71
100
  * `VERISURE_PASSWORD`
101
+ * `VERISURE_TOKEN`
package/bin/verisure ADDED
@@ -0,0 +1,55 @@
1
+ #!/usr/bin/env node
2
+ /* eslint-disable no-console */
3
+
4
+ const { prompt, Password } = require('enquirer');
5
+
6
+ const Verisure = require('verisure');
7
+
8
+ const validate = (value) => !!value.length;
9
+
10
+ const run = async () => {
11
+ const { email } = await prompt({
12
+ type: 'input',
13
+ name: 'email',
14
+ message: 'What is your login email?',
15
+ validate,
16
+ });
17
+
18
+ const password = await new Password({
19
+ name: 'password',
20
+ message: 'What is your password?',
21
+ validate,
22
+ }).run();
23
+
24
+ const verisure = new Verisure(email.trim(), password);
25
+
26
+ await verisure.getToken();
27
+
28
+ if (!verisure.getCookie('vid')) {
29
+ console.log('\n', 'One-time code sent.', '\n');
30
+
31
+ const { code } = await prompt({
32
+ type: 'input',
33
+ name: 'code',
34
+ message: 'What is your one-time code?',
35
+ validate,
36
+ });
37
+
38
+ await verisure.getToken(code.trim());
39
+ }
40
+
41
+ console.log('\n', 'Your config is ready.', '\n');
42
+
43
+ console.log(JSON.stringify({
44
+ platform: 'verisure',
45
+ name: 'Verisure',
46
+ email,
47
+ token: verisure.getCookie('vid'),
48
+ }, null, 2));
49
+ };
50
+
51
+ try {
52
+ run();
53
+ } catch (error) {
54
+ console.log(error.message);
55
+ }
@@ -13,7 +13,12 @@
13
13
  "password": {
14
14
  "title": "Password",
15
15
  "type": "string",
16
- "required": true
16
+ "required": false
17
+ },
18
+ "token": {
19
+ "title": "Token",
20
+ "type": "string",
21
+ "required": false
17
22
  },
18
23
  "alarmCode": {
19
24
  "title": "Alarm Code",
@@ -25,6 +30,14 @@
25
30
  "type": "string",
26
31
  "required": false
27
32
  },
33
+ "installations": {
34
+ "title": "Installations",
35
+ "type": "array",
36
+ "items": {
37
+ "type": "string"
38
+ },
39
+ "required": false
40
+ },
28
41
  "pollInterval": {
29
42
  "title": "Poll interval",
30
43
  "type": "integer",
@@ -54,7 +54,7 @@ class VerisureAccessory {
54
54
  }
55
55
 
56
56
  log(message) {
57
- return this.logger('info', `${this.name}: ${message}`);
57
+ return this.logger('info', `${this.installation.config.alias} ${this.name}: ${message}`);
58
58
  }
59
59
  }
60
60
 
package/lib/platform.js CHANGED
@@ -15,13 +15,16 @@ class VerisurePlatform {
15
15
  VERISURE_DOOR_CODE,
16
16
  VERISURE_EMAIL,
17
17
  VERISURE_PASSWORD,
18
+ VERISURE_TOKEN,
18
19
  } = process.env;
19
20
 
20
21
  const {
21
22
  alarmCode,
22
23
  doorcode, doorCode,
23
24
  email,
25
+ token,
24
26
  password,
27
+ installations = [],
25
28
  pollInterval = 60,
26
29
  } = config;
27
30
 
@@ -30,13 +33,19 @@ class VerisurePlatform {
30
33
  doorCode: VERISURE_DOOR_CODE || doorcode || doorCode,
31
34
  email: VERISURE_EMAIL || email,
32
35
  password: VERISURE_PASSWORD || password,
36
+ token: VERISURE_TOKEN || token,
37
+ installations,
33
38
  pollInterval,
34
39
  };
35
40
 
36
41
  this.homebridge = homebridge;
37
42
  this.logger = logger;
38
43
 
39
- this.verisure = new Verisure(this.config.email, this.config.password);
44
+ this.verisure = new Verisure(
45
+ this.config.email,
46
+ this.config.password,
47
+ this.config.token && [this.config.token],
48
+ );
40
49
  }
41
50
 
42
51
  static init(homebridgeRef) {
@@ -84,23 +93,45 @@ class VerisurePlatform {
84
93
  return accessories;
85
94
  }
86
95
 
87
- accessories(callback) {
88
- this.verisure.getToken()
89
- .then(() => this.verisure.getInstallations(), (error) => { throw Error(error); })
90
- .then((installations) => Promise.all(
91
- installations.map((installation) => Promise.all([
92
- installation,
93
- installation.getOverview(),
94
- ])),
95
- ))
96
- .then((overviews) => {
97
- const accessoryLists = overviews.map(this.overviewToAccessories.bind(this));
98
- callback(accessoryLists.reduce((a, b) => [...a, ...b]));
99
- })
100
- .catch((error) => {
101
- this.logger.error((error.response && error.response.data) || error.message);
102
- callback([]);
103
- });
96
+ async accessories(callback) {
97
+ try {
98
+ if (!this.verisure.cookies.length) {
99
+ await this.verisure.getToken();
100
+
101
+ if (!this.verisure.getCookie('vid')) {
102
+ this.logger.error('MFA is enabled for user. Please see README.');
103
+ return callback([]);
104
+ }
105
+ }
106
+
107
+ this.installations = (await this.verisure.getInstallations())
108
+ // Filter out installations based on configuration.
109
+ .filter((installation) => this.config.installations.length === 0
110
+ || this.config.installations.includes(installation.config.alias));
111
+ } catch (error) {
112
+ this.logger.error(`Unable to get installations. Please check configured credentials: ${error.message}`);
113
+ return callback([]);
114
+ }
115
+
116
+ if (this.installations.length === 0) {
117
+ this.logger.error(`No installations found matching config: ${JSON.stringify(this.config.installations)}`);
118
+ return callback([]);
119
+ }
120
+
121
+ const overviews = await Promise.all(
122
+ this.installations.map((installation) => Promise.all([
123
+ installation,
124
+ installation.getOverview(),
125
+ ])),
126
+ );
127
+
128
+ try {
129
+ const accessoryLists = overviews.map(this.overviewToAccessories.bind(this));
130
+ return callback(accessoryLists.reduce((a, b) => [...a, ...b]));
131
+ } catch (error) {
132
+ this.logger.error((error.response && error.response.data) || error.message);
133
+ return callback([]);
134
+ }
104
135
  }
105
136
  }
106
137
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "homebridge-verisure",
3
- "version": "1.13.2",
3
+ "version": "1.15.0",
4
4
  "description": "Verisure plugin for homebridge: https://github.com/nfarina/homebridge",
5
5
  "license": "MIT",
6
6
  "keywords": [
@@ -11,24 +11,30 @@
11
11
  "url": "git://github.com/ptz0n/homebridge-verisure.git"
12
12
  },
13
13
  "scripts": {
14
- "test": "eslint lib && jest --env=node --coverage"
14
+ "test": "eslint lib && jest --coverage"
15
15
  },
16
+ "bin": "bin/verisure",
16
17
  "bugs": {
17
18
  "url": "http://github.com/ptz0n/homebridge-verisure/issues"
18
19
  },
19
20
  "engines": {
20
- "node": ">=8",
21
+ "node": ">=12",
21
22
  "homebridge": ">=0.2.0"
22
23
  },
23
24
  "dependencies": {
24
- "verisure": "^3.1.1"
25
+ "enquirer": "^2.3.6",
26
+ "verisure": "^4.1.0"
25
27
  },
26
28
  "devDependencies": {
29
+ "eslint": "^6.7.2",
27
30
  "eslint-config-airbnb-base": "^14.0.0",
28
31
  "eslint-plugin-import": "^2.8.0",
29
32
  "eslint-plugin-jest": "^23.1.0",
30
- "eslint": "^6.7.2",
31
33
  "hap-nodejs": "^0.7.2",
34
+ "homebridge": "^1.3.9",
32
35
  "jest": "^25.0.0"
36
+ },
37
+ "jest": {
38
+ "testEnvironment": "node"
33
39
  }
34
40
  }