Skip to content

Commit

Permalink
Merge dc83d0d into f482413
Browse files Browse the repository at this point in the history
  • Loading branch information
samrum committed Jul 19, 2020
2 parents f482413 + dc83d0d commit 450d838
Show file tree
Hide file tree
Showing 4 changed files with 63 additions and 46 deletions.
69 changes: 44 additions & 25 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,11 @@

Homebridge support for OnStar!

A climate control switch is available by default. Charge Override, Alert, and Door Lock/Unlock functionality can be enabled via configuration options as seen in the example config below.

**Use at your own risk. This is an unofficial plugin.**

## Example config.json:
# Configuration

Use a random version 4 uuid as a deviceId. There are online generators you can use to generate one.
## Basic Config (Climate)

{
"accessories": [
Expand All @@ -21,37 +19,58 @@ Use a random version 4 uuid as a deviceId. There are online generators you can u
"name": "Car",
"deviceId": "XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX",
"vin": "11111111111111111",
"username": "dev@rubenmedina.com",
"username": "foo@bar.com",
"password": "p@ssw0rd",
"onStarPin": "1234",
"enableCharger": true,
"enableAlert": true,
"enableDoors": true,
"doorsDefaultToUnlocked": false,
"onStarPin": "1234"
}
]
}

## Siri Commands
Use a random version 4 uuid as a deviceId. Generator avaiable [here](https://www.uuidgenerator.net/version4).

With this config, a climate control (remote start) switch will be available in the Home app.

Siri Command: "Turn on the Car climate"

## Additional Config Options

### Lock/Unlock Doors Switch

"enableDoors": true

Enables locking/unlocking the vehicle doors.

Querying the current state of locks through OnStar is slow, so the switch will always reset to a locked state.

Siri command: "Unlock the Car"

### Reset Doors Switch to an Unlocked State

"doorsDefaultToUnlocked": true

Default the doors switch to an unlocked state.

### Charger Switch

"enableCharger": true

Enable a switch that will set the vehicle charge mode to immediate (for EV/PHEV). Turning the switch off does nothing.

Siri command: "Turn on the Car charger"

### Alert Switch

For the above example config, the following Siri commands would be available.
"enableAlert": true

- _"Turn on the Car climate"_ - Precondition/remote start the Vehicle
- _"Turn on the Car charger"_ - Set charge mode to immediate (For EV/PHEV)
- _"Turn on the Car alert"_ - Trigger a horn/lights alert
- _"Unlock the Car"_ - Send an unlock command to the Vehicle
- _"Turn on the Car"_ - Turns on all available switches
Enable a switch that triggers an alert for the vehicle (horn + lights flashing).

Turning off switches is also possible via Siri, but not via the Home UI as the switches default to off.
Note that turning off the charger is not supported.
Siri command: "Turn on the Car alert"

# Important Notes
# Notes

- The Doors Lock component will always reset to a Locked state due to the fact that querying for the current state of the lock via the API is not reponsive enough to do quickly or keep in sync very easily. Siri commands to lock doors will work even if the lock component is in the locked state.
- Use the _doorsDefaultToUnlocked_ option to default the lock to an Unlocked state instead
- Request failures after the initial request are made won't be processed. The plugin will return success once requests are considered _In Progress_.
- Siri service names are essentially global, so the name you set in config (or in the home app itself) should be unique. If it matches app names or other Siri commands, Siri will get confused.
- This plugin may stop working every few months when secret keys are rotated by MyChevrolet/OnStar. Feel free to open an issue when this happens.
- Toggling switches off is possible using Siri/Shortcuts/Scenes
- When secret keys are rotated by MyChevrolet/OnStar, the plugin may stop working until the keys are updated.
- homebridge-onstar will return success once requests are considered _In Progress_. As such, OnStar request failures after the initial request are made won't be handled.

# Credits

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
"@types/jest": "^24.0.11",
"coveralls": "^3.0.3",
"jest": "^24.7.1",
"prettier": "^1.16.4",
"prettier": "^2.0.5",
"rollup": "^1.9.0",
"rollup-plugin-typescript2": "^0.20.1",
"ts-jest": "^24.0.2",
Expand Down
30 changes: 14 additions & 16 deletions src/CommandDelegator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,18 @@ import { Result } from "onstarjs/dist/types";
import { OnStarJsMethod } from "./types";

class CommandDelegator {
private doorLockCurrentState: number;

constructor(
private onStar: OnStar,
private log: Function,
private hapCharacteristic: any,
private doorsDefaultToUnlocked: boolean,
) {}
) {
this.doorLockCurrentState = this.getDefaultLockState(
this.hapCharacteristic.LockCurrentState,
);
}

async getFalse(_: OnStarJsMethod, reply: Function) {
reply(null, false);
Expand All @@ -31,10 +37,7 @@ class CommandDelegator {
}

async getDoorLockCurrentState(reply: Function) {
reply(
null,
this.getDefaultLockState(this.hapCharacteristic.LockCurrentState),
);
reply(null, this.doorLockCurrentState);
}

async getDoorLockTargetState(reply: Function) {
Expand All @@ -56,28 +59,23 @@ class CommandDelegator {

const error = await this.makeRequest(method);

let currentState = this.getDefaultLockState(
this.hapCharacteristic.LockCurrentState,
);

if (!error) {
currentState = isLockTarget
this.doorLockCurrentState = isLockTarget
? this.hapCharacteristic.LockCurrentState.SECURED
: this.hapCharacteristic.LockCurrentState.UNSECURED;
}

await this.pause(1);
reply(error);

lockService.setCharacteristic(
await this.pause(5000);

this.doorLockCurrentState = this.getDefaultLockState(
this.hapCharacteristic.LockCurrentState,
currentState,
);

reply(error);
}

private pause(ms: number) {
return new Promise(resolve => {
return new Promise((resolve) => {
setTimeout(resolve, ms);
});
}
Expand Down
8 changes: 4 additions & 4 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2703,10 +2703,10 @@ prelude-ls@~1.1.2:
resolved "https://registry.yarnpkg.com/prelude-ls/-/prelude-ls-1.1.2.tgz#21932a549f5e52ffd9a827f570e04be62a97da54"
integrity sha1-IZMqVJ9eUv/ZqCf1cOBL5iqX2lQ=

prettier@^1.16.4:
version "1.19.1"
resolved "https://registry.yarnpkg.com/prettier/-/prettier-1.19.1.tgz#f7d7f5ff8a9cd872a7be4ca142095956a60797cb"
integrity sha512-s7PoyDv/II1ObgQunCbB9PdLmUcBZcnWOcxDh7O0N/UwDEsHyqkW+Qh28jW+mVuCdx7gLB0BotYI1Y6uI9iyew==
prettier@^2.0.5:
version "2.0.5"
resolved "https://registry.yarnpkg.com/prettier/-/prettier-2.0.5.tgz#d6d56282455243f2f92cc1716692c08aa31522d4"
integrity sha512-7PtVymN48hGcO4fGjybyBSIWDsLU4H4XlvOHfq91pz9kkGlonzwTfYkaIEwiRg/dAJF9YlbsduBAgtYLi+8cFg==

pretty-format@^24.9.0:
version "24.9.0"
Expand Down

0 comments on commit 450d838

Please sign in to comment.