hass-taste-test 0.0.15 → 0.1.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 (2) hide show
  1. package/lib/index.js +29 -10
  2. package/package.json +3 -2
package/lib/index.js CHANGED
@@ -99,11 +99,11 @@ class HomeAssistant {
99
99
  await Promise.all([
100
100
  this.findPort().then(() => this.writeYAMLConfiguration(config)),
101
101
  this.setupVenv(),
102
- fs.writeFile(this.path_cache(), JSON.stringify(this.cache)),
103
102
  ]);
103
+ await fs.writeFile(this.path_cache(), JSON.stringify(this.cache));
104
104
  await releaseLock();
105
105
  // Step 3: Start Home Assistant and onboard
106
- this.process = (0, child_process_1.spawn)(this.path_hass(), ['-c', this.configDir, ...this.options.hassArgs], {
106
+ this.process = (0, child_process_1.spawn)(this.path_hass(), ['-c', this.configDir, '-v', ...this.options.hassArgs], {
107
107
  stdio: 'inherit',
108
108
  });
109
109
  this.process.on('error', (e) => {
@@ -114,7 +114,7 @@ class HomeAssistant {
114
114
  // Wait for Home Assistant to start, but quit early if the process exits
115
115
  this.process.on('close', (code) => {
116
116
  if (code != 0)
117
- reject(new Error(`Home assistant exited with code ${code}`));
117
+ reject(new Error(`Home Assistant exited with code ${code}`));
118
118
  });
119
119
  while (!(await this.isUp()))
120
120
  await sleep();
@@ -207,7 +207,7 @@ class HomeAssistant {
207
207
  const libs = await Promise.all(libFolders.map((f) => fs.readdir((0, path_1.join)(this.venvDir, 'lib', f, 'site-packages'))));
208
208
  const homeAssistant = libs
209
209
  .flat()
210
- .map((f) => f.match(/homeassistant-(.*)\.dist-info/))
210
+ .map((f) => f.match(/^homeassistant-(.*)\.dist-info/))
211
211
  .find((f) => f !== null);
212
212
  return homeAssistant ? homeAssistant[1] : null;
213
213
  }
@@ -219,12 +219,27 @@ class HomeAssistant {
219
219
  });
220
220
  /** Complete onboarding and fetch short-lived access token */
221
221
  async onboard() {
222
- const login = await this.post('/api/onboarding/users', {
223
- language: this.options.userLanguage,
224
- name: this.options.userDisplayName,
225
- username: this.options.username,
226
- password: this.options.password,
227
- });
222
+ let login;
223
+ for (let tries = 0; tries < 20; tries++) {
224
+ try {
225
+ login = await this.post('/api/onboarding/users', {
226
+ language: this.options.userLanguage,
227
+ name: this.options.userDisplayName,
228
+ username: this.options.username,
229
+ password: this.options.password,
230
+ });
231
+ if (login.auth_code)
232
+ break;
233
+ else
234
+ await sleep();
235
+ }
236
+ catch (e) {
237
+ console.warn(e);
238
+ await sleep();
239
+ }
240
+ }
241
+ if (!login.auth_code)
242
+ throw new Error('No auth code found');
228
243
  this.accessCode = login.auth_code;
229
244
  await this.launchWebsocket(this.accessCode);
230
245
  // Step through the onboarding pages
@@ -269,6 +284,8 @@ class HomeAssistant {
269
284
  username: this.options.username,
270
285
  password: this.options.password,
271
286
  });
287
+ if (response.error)
288
+ throw new Error(`Login code returned with error ${response.error}`);
272
289
  return response.result;
273
290
  }
274
291
  /** Login and create tokens and websocket */
@@ -286,6 +303,8 @@ class HomeAssistant {
286
303
  body: params,
287
304
  });
288
305
  const tokens = (await response.json());
306
+ if (tokens.error)
307
+ throw new Error(`Tokens returned with error ${tokens.error}`);
289
308
  this.accessToken = tokens.access_token;
290
309
  const auth = new hass.Auth({
291
310
  ...tokens,
package/package.json CHANGED
@@ -1,11 +1,12 @@
1
1
  {
2
2
  "name": "hass-taste-test",
3
- "version": "0.0.15",
3
+ "version": "0.1.0",
4
4
  "description": "Integration testing for Home Assistant cards",
5
5
  "main": "lib/index.js",
6
6
  "scripts": {
7
7
  "test": "jest && ava",
8
- "prepare": "husky install"
8
+ "prepare": "husky install",
9
+ "publish": "tsc && npm publish"
9
10
  },
10
11
  "bin": {
11
12
  "hass-taste-test": "lib/bin.js"