Skip to content

Commit

Permalink
Upgrade onstarjs (#31)
Browse files Browse the repository at this point in the history
* Upgrade onstarjs

* Fix type errors

* Version 1.3.5
  • Loading branch information
samrum committed Jul 15, 2020
1 parent 472d493 commit b4b4c7d
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 61 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "homebridge-onstar",
"version": "1.3.4",
"version": "1.3.5",
"description": "Unofficial OnStar plugin for Homebridge",
"main": "dist/index.js",
"module": "dist/index.esm.js",
Expand Down
2 changes: 1 addition & 1 deletion src/CommandDelegator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ class CommandDelegator {

result = await this.onStar[method]();

this.log(`${method}: Finished`, result.response.data);
this.log(`${method}: Finished`, result.response?.data);

return null;
} catch (e) {
Expand Down
70 changes: 14 additions & 56 deletions test/CommandDelegator.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,13 @@ function createCommandDelegator(doorsDefaultToUnlocked: boolean = false) {
);
}

const onStarJsResponseInProgress = {
status: "success",
response: {
data: "In Progress",
},
};

describe("CommandDelegator", () => {
beforeEach(() => {
commandDelegator = createCommandDelegator();
Expand Down Expand Up @@ -76,14 +83,7 @@ describe("CommandDelegator", () => {
});

test("setDoorLockTargetState - SECURED", done => {
when(onStarMock.lockDoor()).thenResolve({
status: "success",
response: {
data: {
status: "In Progress",
},
},
});
when(onStarMock.lockDoor()).thenResolve(onStarJsResponseInProgress);

commandDelegator.setDoorLockTargetState(
HapService.LockMechanism("lock"),
Expand All @@ -96,14 +96,7 @@ describe("CommandDelegator", () => {
});

test("setDoorLockTargetState - UNSECURED", done => {
when(onStarMock.unlockDoor()).thenResolve({
status: "success",
response: {
data: {
status: "In Progress",
},
},
});
when(onStarMock.unlockDoor()).thenResolve(onStarJsResponseInProgress);

commandDelegator.setDoorLockTargetState(
HapService.LockMechanism("unlock"),
Expand Down Expand Up @@ -132,14 +125,7 @@ describe("CommandDelegator", () => {
});

test("setSwitch - Start On", done => {
when(onStarMock.start()).thenResolve({
status: "success",
response: {
data: {
status: "In Progress",
},
},
});
when(onStarMock.start()).thenResolve(onStarJsResponseInProgress);

commandDelegator.setSwitch("start", true, (error: string) => {
expect(error).toBeNull();
Expand All @@ -148,14 +134,7 @@ describe("CommandDelegator", () => {
});

test("setSwitch - Start Off", done => {
when(onStarMock.cancelStart()).thenResolve({
status: "success",
response: {
data: {
status: "In Progress",
},
},
});
when(onStarMock.cancelStart()).thenResolve(onStarJsResponseInProgress);

commandDelegator.setSwitch("start", false, (error: string) => {
expect(error).toBeNull();
Expand All @@ -164,14 +143,7 @@ describe("CommandDelegator", () => {
});

test("setSwitch - Alert On", done => {
when(onStarMock.alert()).thenResolve({
status: "success",
response: {
data: {
status: "In Progress",
},
},
});
when(onStarMock.alert()).thenResolve(onStarJsResponseInProgress);

commandDelegator.setSwitch("alert", true, (error: string) => {
expect(error).toBeNull();
Expand All @@ -180,14 +152,7 @@ describe("CommandDelegator", () => {
});

test("setSwitch - Alert Off", done => {
when(onStarMock.cancelAlert()).thenResolve({
status: "success",
response: {
data: {
status: "In Progress",
},
},
});
when(onStarMock.cancelAlert()).thenResolve(onStarJsResponseInProgress);

commandDelegator.setSwitch("alert", false, (error: string) => {
expect(error).toBeNull();
Expand All @@ -196,14 +161,7 @@ describe("CommandDelegator", () => {
});

test("setSwitch - Charger On", done => {
when(onStarMock.chargeOverride()).thenResolve({
status: "success",
response: {
data: {
status: "In Progress",
},
},
});
when(onStarMock.chargeOverride()).thenResolve(onStarJsResponseInProgress);

commandDelegator.setSwitch("chargeOverride", true, (error: string) => {
expect(error).toBeNull();
Expand Down
6 changes: 3 additions & 3 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2558,9 +2558,9 @@ once@^1.3.0, once@^1.3.1, once@^1.4.0:
wrappy "1"

onstarjs@^2.0.6:
version "2.0.8"
resolved "https://registry.yarnpkg.com/onstarjs/-/onstarjs-2.0.8.tgz#34199917004ef0e8e093ae9c9ac70c6fe1a88c10"
integrity sha512-pZzQ9lKm2eAvcTyhbvViPUe2VnYyDXCdhjE1I5Z3syN1TW0faiof3geDm6rEc6jpTrLjorRbLwHyRFjmhWuw/Q==
version "2.0.9"
resolved "https://registry.yarnpkg.com/onstarjs/-/onstarjs-2.0.9.tgz#bb893e5bfe0869db4b44b9585a4581868082498e"
integrity sha512-f6UDODuh7rF9+b67qZ95C08cXtBWy9sOeZNfOreE/1cAuEam2Ll9h8/8StmTZ8TF5kGSk4VDu+3JMSO0tN/ndw==
dependencies:
axios "^0.18.0"
jsonwebtoken "^8.5.1"
Expand Down

0 comments on commit b4b4c7d

Please sign in to comment.