Skip to content

Commit

Permalink
Merge pull request #50 from Hacksore/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
SondreNjaastad authored Jul 14, 2020
2 parents 953235d + 3ca078d commit 139bbbc
Show file tree
Hide file tree
Showing 33 changed files with 6,781 additions and 3,753 deletions.
9 changes: 5 additions & 4 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
module.exports = {
root: true,
parser: '@typescript-eslint/parser',
plugins: [
'@typescript-eslint',
],
plugins: ['@typescript-eslint'],
extends: [
'eslint:recommended',
'plugin:@typescript-eslint/eslint-recommended',
'plugin:@typescript-eslint/recommended',
],
rules: {
'no-console': 2,
},
env: {
browser: true,
node: true,
}
},
};
20 changes: 20 additions & 0 deletions .github/workflows/auth.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
name: auth

on: push

jobs:
login:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/setup-node@v1
with:
node-version: 12
- run: npm ci
- run: npm run build
- run: node auth.js "US"
- run: node auth.js "EU"
env:
HYUNDAI_USER: ${{secrets.HYUNDAI_USER}}
HYUNDAI_PASS: ${{secrets.HYUNDAI_PASS}}
HYUNDAI_PIN: ${{secrets.HYUNDAI_PIN}}
3 changes: 2 additions & 1 deletion .prettierrc
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,6 @@
"semi": true,
"printWidth": 100,
"singleQuote": true,
"quoteProps": "preserve"
"quoteProps": "preserve",
"arrowParens": "avoid"
}
12 changes: 6 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# bluelinky

An unoffcial API wrapper for Hyundai BlueLink
An unoffcial nodejs API wrapper for Hyundai BlueLink

[![CI](https://img.shields.io/circleci/build/github/Hacksore/bluelinky.svg)](https://circleci.com/gh/Hacksore/bluelinky/tree/master)
[![npm](https://img.shields.io/npm/v/bluelinky.svg)](https://www.npmjs.com/package/bluelinky)
Expand Down Expand Up @@ -31,7 +31,7 @@ client.on('ready', async () => {
```

## Documentation
Checkout out the docs [bluelinky-docs](https://hacksore.github.io/bluelinky-docs/) for more info.
Checkout out the [bluelinky-docs](https://hacksore.github.io/bluelinky-docs/) for more info.

## Supported Features
- Lock
Expand All @@ -43,11 +43,11 @@ Checkout out the docs [bluelinky-docs](https://hacksore.github.io/bluelinky-docs
## Supported Regions
| [Regions](https://github.com/Hacksore/bluelinky/wiki/Regions) | Current Status |
|-----------|--------------|
| USA | Working |
| Canada | Working |
| Europe | Working |
| USA | |
| Canada | |
| Europe | |
| Korea | ▯▯▯▯▯▯ |
| Australia | sorry m8 |
| Australia | [See #9](https://github.com/Hacksore/bluelinky/issues/9) |

## Show your support

Expand Down
4 changes: 2 additions & 2 deletions __tests__/bluelinky.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -115,8 +115,8 @@ describe('BlueLinky', () => {
const veh1 = client.getVehicle('JEST_TESTING_1');
const veh2 = client.getVehicle('JEST_TESTING_2');

expect(veh1.vin).toEqual('JEST_TESTING_1');
expect(veh2.vin).toEqual('JEST_TESTING_2');
expect(veh1.vin()).toEqual('JEST_TESTING_1');
expect(veh2.vin()).toEqual('JEST_TESTING_2');

done();
});
Expand Down
7 changes: 5 additions & 2 deletions __tests__/controller.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ describe('EuropeanController', () => {

it('call getVehicles and check length', async () => {
const controller = getController('EU');
controller.session.accessToken = 'MockToken';

(got as any).mockReturnValueOnce({
body: {
Expand All @@ -73,7 +74,8 @@ describe('EuropeanController', () => {
brandIndicator: 'H',
regId: '123123',
gen: '2',
name: 'Car',
name: 'Car',
id: '12345',
},
],
},
Expand All @@ -88,7 +90,8 @@ describe('EuropeanController', () => {
{
basic: {
modelYear: '2019',
vin: '5555'
vin: '5555',
id: '123456'
}
}
],
Expand Down
57 changes: 30 additions & 27 deletions __tests__/vehicle.spec.ts
Original file line number Diff line number Diff line change
@@ -1,52 +1,55 @@
/* eslint-disable */
import got from 'got';

import AmericanVehicle from '../lib/vehicles/americanVehicle';
import AmericanVehicle from '../lib/vehicles/american.vehicle';
import { AmericanController } from '../lib/controllers/american.controller';

import EuropeanVehicle from '../lib/vehicles/europianVehicle';
import EuropeanVehicle from '../lib/vehicles/european.vehicle';
import { EuropeanController } from '../lib/controllers/european.controller';

import CanadianVehicle from '../lib/vehicles/canadianVehicle';
import CanadianVehicle from '../lib/vehicles/canadian.vehicle';
import { CanadianController } from '../lib/controllers/canadian.controller';

jest.mock('got');

const referenceMap = {
US: {
controller: AmericanController,
vehicle: AmericanVehicle,
},
EU: {
controller: EuropeanController,
vehicle: EuropeanVehicle,
},
CA: {
controller: CanadianController,
vehicle: CanadianVehicle,
},
};

const getVehicle = region => {
const referenceMap = {
US: {
controller: AmericanController,
vehicle: AmericanVehicle,
},
EU: {
controller: EuropeanController,
vehicle: EuropeanVehicle,
},
CA: {
controller: CanadianController,
vehicle: CanadianVehicle,
},
};
const Vehicle = referenceMap[region].vehicle;
const Controller = referenceMap[region].controller;

const controller = new referenceMap[region].controller({
const controller = new Controller({
username: '[email protected]',
password: 'test',
region: 'US',
autoLogin: true,
pin: '1234',
vin: '4444444444444',
vehicleId: undefined
vehicleId: undefined,
});

const vehicle = new referenceMap[region].vehicle(
const vehicle = new Vehicle(
{
nickname: 'Jest is best',
name: 'Jest is best',
vin: '444',
regDate: 'test',
brandIndicator: 'H',
regId: '123123',
gen: '2',
name: 'Car',
generation: '2',
},
controller
);
Expand All @@ -58,7 +61,7 @@ describe('AmericanVehicle', () => {
const vehicle = getVehicle('US');

it('define new vehicle', () => {
expect(vehicle.config.nickname).toEqual('Jest is best');
expect(vehicle.nickname()).toEqual('Jest is best');
});

it('call lock commmand', async () => {
Expand All @@ -69,22 +72,21 @@ describe('AmericanVehicle', () => {

const response = await vehicle.lock();
expect(response).toEqual('Lock successful');

});
});

describe('CanadianVehicle', () => {
const vehicle = getVehicle('CA');

it('define new vehicle', () => {
expect(vehicle.config.nickname).toEqual('Jest is best');
expect(vehicle.nickname()).toEqual('Jest is best');
});

it('call lock commmand', async () => {
(got as any).mockReturnValueOnce({
body: {
result: {
pAuth: 'test'
pAuth: 'test',
},
responseHeader: {
responseCode: 0,
Expand All @@ -111,9 +113,10 @@ describe('EuropeanVehicle', () => {
const vehicle = getVehicle('EU');

it('define new vehicle', () => {
expect(vehicle.config.nickname).toEqual('Jest is best');
expect(vehicle.nickname()).toEqual('Jest is best');
});

// TODO: EU lead gets to write these :)
// it('call lock commmand', async () => {
// (got as any).mockReturnValueOnce({
// body: {},
Expand Down
28 changes: 28 additions & 0 deletions auth.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/* eslint-disable */

// test login for each region
const BlueLinky = require('./dist/index');
const { HYUNDAI_USER, HYUNDAI_PASS, HYUNDAI_PIN } = process.env;
const REGION_TO_TEST = process.argv[2];

const testRegionLogin = region => {
const client = new BlueLinky({
username: HYUNDAI_USER,
password: HYUNDAI_PASS,
region: region,
pin: HYUNDAI_PIN,
deviceUuid: 'e8db10f3-7190-42ca-91db-7a6af6e5ea1f',
});

client.on('ready', () => {
console.log(`🦮 Connected to ${region} successfully 😎`);
});
};

try {
testRegionLogin(REGION_TO_TEST);
} catch (error) {
console.log(error);
// exit with an error so the build job fails
process.exit(1);
}
43 changes: 24 additions & 19 deletions debug.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

/* eslint-disable */
// TODO: add all calls from EU and CA

Expand All @@ -9,6 +8,7 @@ const inquirer = require('inquirer');
const apiCalls = [
{ name: 'exit', value: 'exit' },
{ name: 'start', value: 'start' },
{ name: 'odometer', value: 'odometer' },
{ name: 'stop', value: 'stop' },
{ name: 'status (on bluelink cache)', value: 'status' },
{ name: 'status refresh (fetch vehicle)', value: 'statusR' },
Expand All @@ -22,43 +22,40 @@ const { username, password, vin, pin, deviceUuid } = config;

const onReadyHandler = vehicles => {
vehicle = vehicles[0];
askForCommandInput();
};

const askForRegionInput = () => {

inquirer
.prompt([
{
type: 'list',
name: 'region',
message: 'What Region are you in?',
choices: [
'US', 'EU', 'CA'
],
}
choices: ['US', 'EU', 'CA'],
},
])
.then(answers => {
if (answers.command == 'exit') {
console.log('bye');
return;
} else {
console.log(answers)
console.log('Logging in...');
createInstance(answers.region);
askForCommandInput();
}
});
}
};

const createInstance = (region) => {
const createInstance = region => {
const client = new BlueLinky({
username,
password,
region: region,
pin,
deviceUuid
deviceUuid,
});
client.on('ready', onReadyHandler);
}
};

function askForCommandInput() {
console.log('');
Expand All @@ -73,12 +70,11 @@ function askForCommandInput() {
])
.then(answers => {
if (answers.command == 'exit') {
console.log('bye');
return;
} else {
performCommand(answers.command);
}
});
});
}

async function performCommand(command) {
Expand All @@ -87,15 +83,25 @@ async function performCommand(command) {
case 'exit':
return;
case 'locate':
const locate = await vehicle.locate();
const locate = await vehicle.location();
console.log('locate : ' + JSON.stringify(locate, null, 2));
break;
case 'odometer':
const odometer = await vehicle.odometer();
console.log('odometer', JSON.stringify(odometer, null, 2));
break;
case 'status':
const status = await vehicle.status(false);
const status = await vehicle.status({
refresh: false,
parsed: true,
});
console.log('status : ' + JSON.stringify(status, null, 2));
break;
case 'statusR':
const statusR = await vehicle.status(true);
const statusR = await vehicle.status({
refresh: true,
parsed: true
});
console.log('status remote : ' + JSON.stringify(statusR, null, 2));
break;
case 'start':
Expand Down Expand Up @@ -124,9 +130,8 @@ async function performCommand(command) {

askForCommandInput();
} catch (err) {
console.log(err.body);
console.log(err);
}
}


askForRegionInput();
Loading

0 comments on commit 139bbbc

Please sign in to comment.