Skip to content

Commit

Permalink
fix: failed blind state check/no battery now logs and does not crash, f…
Browse files Browse the repository at this point in the history
…ixes #56
  • Loading branch information
apexad committed Apr 5, 2021
1 parent f8e3c5d commit 7b5ba35
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 4 deletions.
6 changes: 3 additions & 3 deletions package-lock.json

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

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
},
"dependencies": {
"jsonwebtoken": "^8.5.1",
"lodash": "^4.17.21",
"prompt": "^1.0.0",
"request": "^2.88.2",
"request-promise": "^4.2.6"
Expand Down
10 changes: 9 additions & 1 deletion src/platform.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ import {
Service,
Characteristic,
} from 'homebridge';
import {
get,
} from 'lodash';
import {
PLATFORM_NAME,
PLUGIN_NAME,
Expand Down Expand Up @@ -158,7 +161,12 @@ export class MySmartBlindsBridgePlatform implements DynamicPlatformPlugin {
this.requestOptions,
{ body: { query: MYSMARTBLINDS_QUERIES.GetBlindSate, variables: { blinds: blind.encodedMacAddress } } },
)).then((response) => {
const blindState = response.data.blindsState[0];
const blindState = get(response, 'data.blindsState[0]', { position: 0, batteryLevel: 0 });

if (blindState.batteryLevel <= 0) {
this.log.error(`${blindName} state fetch failed. Do you have the Hardware bridge? Is the battery charged?`);
}

const homeKitBlindPosition = this.convertPosition(blindState.position);
accessory.context.blind = {
name: blindName,
Expand Down

0 comments on commit 7b5ba35

Please sign in to comment.