Skip to content

Commit

Permalink
Fix device removal on failed refresh
Browse files Browse the repository at this point in the history
  • Loading branch information
StefanNienhuis committed Oct 13, 2022
1 parent ccc366e commit 2d84c43
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 9 deletions.
4 changes: 2 additions & 2 deletions plugin/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion plugin/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "homebridge-bold",
"displayName": "Homebridge Bold",
"version": "2.1.4",
"version": "2.1.5",
"description": "HomeKit support for the Bold Smart Locks.",
"main": "build/index.js",
"engines": {
Expand Down
7 changes: 2 additions & 5 deletions plugin/src/bold.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,9 +81,7 @@ export class BoldAPI {
let response = await this.request('GET', '/v1/effective-device-permissions');

if (!response.success) {
this.log.error(`Error ${response.error.code ? `(${response.error.code}) ` : ''}while getting devices: ${response.error.message}`);

return [];
throw new Error(`Error ${response.error.code ? `(${response.error.code}) ` : ''}while getting devices: ${response.error.message}`);
}

if (Array.isArray(response.data)) {
Expand All @@ -94,8 +92,7 @@ export class BoldAPI {

return supportedDevices;
} else {
this.log.error(`Unknown reponse while getting devices: ${response.data}`);
return [];
throw new Error('Unknown reponse while getting devices: ${response.data}');
}
}

Expand Down
14 changes: 13 additions & 1 deletion plugin/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,19 @@ class BoldPlatform implements DynamicPlatformPlugin {
// Bold API

async updateDevices() {
let devices = await this.bold.getDevices();
let devices: Device[];

try {
devices = await this.bold.getDevices();
} catch (error) {
if (this.accessories.length == 0) {
this.log.error('Unable to get devices. Check your authentication details.');
} else {
this.log.warn('Unable to refresh devices. Preserving cached accessories, which might be incorrect. Check your authentication details.');
}

return;
}

// Add devices
let addDevices = devices.filter((device) => !this.accessories.find((accessory) => accessory.context.device.id == device.id));
Expand Down

0 comments on commit 2d84c43

Please sign in to comment.