-
Notifications
You must be signed in to change notification settings - Fork 73
/
commands_test.go
225 lines (197 loc) · 6.07 KB
/
commands_test.go
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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
package tesla
import (
"testing"
. "github.com/smartystreets/goconvey/convey"
)
var (
CommandResponseJSON = `{"response":{"reason":"","result":true}}`
WakeupResponseJSON = `{"response":{"color":null,"display_name":"Macak","id":900,"option_codes":"MS04,RENA,AU01,BC0R,BP01,BR01,BS00,CDM0,CH00,PBSB,CW02,DA02,DCF0,DRLH,DSH7,DV4W,FG02,HP00,IDPB,IX01,LP01,ME02,MI00,PA00,PF01,PI01,PK00,PS01,PX00,PX4D,QNEB,RFP2,SC01,SP00,SR01,SU01,TM00,TP03,TR01,UTAB,WTSG,WTX0,X001,X003,X007,X011,X013,X019,X024,X027,X028,X031,X037,X040,YF01,COUS","user_id":789,"vehicle_id":456,"vin":"abc123","tokens":["1","2"],"state":"online","id_s":"123","remote_start_enabled":true,"calendar_enabled":true,"notifications_enabled":true,"backseat_token":null,"backseat_token_updated_at":null}}`
ChargeAlreadySetJSON = `{"response":{"reason":"already_standard","result":false}}`
ChargedJSON = `{"response":{"reason":"complete","result":false}}`
)
func TestCommandsSpec(t *testing.T) {
ts := serveHTTP(t)
defer ts.Close()
previousAuthURL := AuthURL
previousURL := BaseURL
AuthURL = ts.URL + "/oauth/token"
BaseURL = ts.URL + "/api/1"
auth := &Auth{
GrantType: "password",
ClientID: "abc123",
ClientSecret: "def456",
Email: "elon@tesla.com",
Password: "go",
}
client, _ := NewClient(auth)
Convey("Should auto park abort Autopark", t, func() {
vehicles, err := client.Vehicles()
So(err, ShouldBeNil)
vehicle := vehicles[0]
err = vehicle.AutoparkAbort()
So(err, ShouldBeNil)
})
Convey("Should auto park car forward", t, func() {
vehicles, err := client.Vehicles()
So(err, ShouldBeNil)
vehicle := vehicles[0]
err = vehicle.AutoparkForward()
So(err, ShouldBeNil)
})
Convey("Should turn on sentry mode", t, func() {
vehicles, err := client.Vehicles()
So(err, ShouldBeNil)
vehicle := vehicles[0]
err = vehicle.EnableSentry()
So(err, ShouldBeNil)
})
Convey("Should auto park car forward", t, func() {
vehicles, err := client.Vehicles()
So(err, ShouldBeNil)
vehicle := vehicles[0]
err = vehicle.AutoparkReverse()
So(err, ShouldBeNil)
})
Convey("Should toggle the garage door based on Homelink", t, func() {
vehicles, err := client.Vehicles()
So(err, ShouldBeNil)
vehicle := vehicles[0]
err = vehicle.TriggerHomelink()
So(err, ShouldBeNil)
})
Convey("Should wakeup the car", t, func() {
vehicles, err := client.Vehicles()
So(err, ShouldBeNil)
vehicle := vehicles[0]
_, err = vehicle.Wakeup()
So(err, ShouldBeNil)
})
Convey("Should flash lights", t, func() {
vehicles, err := client.Vehicles()
So(err, ShouldBeNil)
vehicle := vehicles[0]
err = vehicle.FlashLights()
So(err, ShouldBeNil)
})
Convey("Should honk the horn", t, func() {
vehicles, err := client.Vehicles()
So(err, ShouldBeNil)
vehicle := vehicles[0]
err = vehicle.HonkHorn()
So(err, ShouldBeNil)
})
Convey("Should open the charge port", t, func() {
vehicles, err := client.Vehicles()
So(err, ShouldBeNil)
vehicle := vehicles[0]
err = vehicle.OpenChargePort()
So(err, ShouldBeNil)
})
Convey("Should reset the valet pin", t, func() {
vehicles, err := client.Vehicles()
So(err, ShouldBeNil)
vehicle := vehicles[0]
err = vehicle.ResetValetPIN()
So(err, ShouldBeNil)
})
Convey("Should set the car charge limit", t, func() {
vehicles, err := client.Vehicles()
So(err, ShouldBeNil)
vehicle := vehicles[0]
err = vehicle.SetChargeLimit(50)
So(err, ShouldBeNil)
})
Convey("Should set the car to standard charge level", t, func() {
vehicles, err := client.Vehicles()
So(err, ShouldBeNil)
vehicle := vehicles[0]
err = vehicle.SetChargeLimitStandard()
So(err.Error(), ShouldEqual, "already_standard")
})
Convey("Should attempt to charge the car", t, func() {
vehicles, err := client.Vehicles()
So(err, ShouldBeNil)
vehicle := vehicles[0]
err = vehicle.StartCharging()
So(err.Error(), ShouldEqual, "complete")
})
Convey("Should attempt to stop charging the car", t, func() {
vehicles, err := client.Vehicles()
So(err, ShouldBeNil)
vehicle := vehicles[0]
err = vehicle.StopCharging()
So(err, ShouldBeNil)
})
Convey("Should set charge limit maximum", t, func() {
vehicles, err := client.Vehicles()
So(err, ShouldBeNil)
vehicle := vehicles[0]
err = vehicle.SetChargeLimitMax()
So(err, ShouldBeNil)
})
Convey("Should set air conditioning on", t, func() {
vehicles, err := client.Vehicles()
So(err, ShouldBeNil)
vehicle := vehicles[0]
err = vehicle.StartAirConditioning()
So(err, ShouldBeNil)
})
Convey("Should set air conditioning off", t, func() {
vehicles, err := client.Vehicles()
So(err, ShouldBeNil)
vehicle := vehicles[0]
err = vehicle.StopAirConditioning()
So(err, ShouldBeNil)
})
Convey("Should unlock the doors", t, func() {
vehicles, err := client.Vehicles()
So(err, ShouldBeNil)
vehicle := vehicles[0]
err = vehicle.UnlockDoors()
So(err, ShouldBeNil)
})
Convey("Should lock the doors", t, func() {
vehicles, err := client.Vehicles()
So(err, ShouldBeNil)
vehicle := vehicles[0]
err = vehicle.LockDoors()
So(err, ShouldBeNil)
})
Convey("Should set the temprature", t, func() {
vehicles, err := client.Vehicles()
So(err, ShouldBeNil)
vehicle := vehicles[0]
err = vehicle.SetTemprature(72.0, 72.0)
So(err, ShouldBeNil)
})
Convey("Should start the car", t, func() {
vehicles, err := client.Vehicles()
So(err, ShouldBeNil)
vehicle := vehicles[0]
err = vehicle.Start("foo")
So(err, ShouldBeNil)
})
Convey("Should move the Pano Roof around", t, func() {
vehicles, err := client.Vehicles()
So(err, ShouldBeNil)
vehicle := vehicles[0]
Convey("Should vent the pano roof", func() {
err := vehicle.MovePanoRoof("vent", 0)
So(err, ShouldBeNil)
})
Convey("Should open the pano roof", func() {
err := vehicle.MovePanoRoof("open", 0)
So(err, ShouldBeNil)
})
Convey("Should move the pano roof to 50", func() {
err := vehicle.MovePanoRoof("move", 50)
So(err, ShouldBeNil)
})
Convey("Should close the pano roof", func() {
err := vehicle.MovePanoRoof("close", 0)
So(err, ShouldBeNil)
})
})
AuthURL = previousAuthURL
BaseURL = previousURL
}