forked from Lindhardsen/homey-tesla.com
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapi.js
59 lines (58 loc) · 1.52 KB
/
api.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
/* global Homey */
var Tesla = require('./lib/tesla.js')
module.exports = [{
// validate account for use with settings page
description: 'Validate Tesla account settings',
method: 'GET',
path: '/validate/account',
requires_authorization: true,
role: 'owner',
fn: function (callback, args) {
var tesla = new Tesla({
user: args.query.user,
password: args.query.password
})
tesla.on('grant', newGrant => {
Homey.manager('settings').set('teslaGrant', newGrant)
})
tesla.login().then(function () {
callback(null, true)
tesla.logout()
}).catch(callback)
}
}, {
description: 'Get location of Homey',
method: 'GET',
path: '/geofence/self',
requires_authorization: true,
role: 'owner',
fn: function (callback, args) {
Homey.manager('geolocation').getLocation(callback)
}
}, {
description: 'Get all vehicles',
method: 'GET',
path: '/vehicles',
requires_authorization: true,
role: 'owner',
fn: function (callback, args) {
var vehicles = []
Homey.manifest.drivers.map((driver) => driver.id).forEach((driver) => {
var drivervehicles = Homey.manager('drivers').getDriver(driver).getVehicles()
Object.keys(drivervehicles).forEach((vehicle) => {
vehicles.push(drivervehicles[vehicle])
})
})
callback(null, vehicles)
}
}, {
description: 'Test Tesla API',
method: 'GET',
path: '/testApi',
requires_authorization: true,
role: 'owner',
fn: function (callback, args) {
callback(null, true)
Homey.app.testApi()
}
}]