/
driver.js
105 lines (85 loc) · 2.84 KB
/
driver.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
const TeslaOAuth2Driver = require('../../lib/TeslaOAuth2Driver');
module.exports = class CarDriver extends TeslaOAuth2Driver {
async onOAuth2Init() {
// Register Flow Cards etc.
await super.onOAuth2Init();
}
async onPairListDevices({ oAuth2Client }) {
let devices = [];
let data = await oAuth2Client.getVehicles();
for (let i=0; i<data.length; i++){
devices.push({
data: {
id: data[i].vin,
},
name: data[i].display_name,
settings: {
car_data_vin: data[i].vin
}
});
}
return devices;
}
// onFilterDevice(device) {
// }
// async onPairListDevices({ oAuth2Client }) {
// const things = await oAuth2Client.getThings({ color: 'red' });
// return things.map(thing => {
// return {
// name: thing.name,
// data: {
// id: thing.id,
// },
// }
// });
// }
}
// "use strict";
// const Homey = require('homey');
// const API_URL = "https://auth.tesla.com/oauth2/v3/authorize?response_type=code";
// const CALLBACK_URL = "https://callback.athom.com/oauth2/callback";
// const CLIENT_ID = Homey.env.CLIENT_ID;
// const OAUTH_URL = `${API_URL}&client_id=${CLIENT_ID}&redirect_uri=${CALLBACK_URL}&scope=openid%20vehicle_device_data%20offline_access%20vehicle_cmds%20vehicle_charging_cmd`;
// class accountDriver extends Homey.Driver {
// async onPair(session) {
// this.log("onPair()");
// const myOAuth2Callback = await this.homey.cloud.createOAuth2Callback(OAUTH_URL);
// myOAuth2Callback
// .on("url", (url) => {
// // dend the URL to the front-end to open a popup
// session.emit("url", url);
// })
// .on("code", (code) => {
// // ... swap your code here for an access token
// // tell the front-end we're done
// session.emit("authorized");
// });
// session.setHandler("list_devices", async () => {
// return await this.onPairListDevices(session);
// });
// } // end onPair
// async onPairListDevices(session) {
// this.log("onPairListDevices()" );
// let devices = [];
// devices.push(
// {
// name: "Tesla Account",
// data: {
// id: this.getUIID()
// }
// }
// );
// this.log("Found devices:");
// this.log(devices);
// return devices;
// }
// getUIID() {
// function s4() {
// return Math.floor((1 + Math.random()) * 0x10000)
// .toString(16)
// .substring(1);
// }
// return `${s4() + s4()}-${s4()}-${s4()}-${s4()}-${s4()}${s4()}${s4()}`;
// }
// }
// module.exports = accountDriver;