-
Notifications
You must be signed in to change notification settings - Fork 2
/
tesla-tester.py
465 lines (388 loc) · 19 KB
/
tesla-tester.py
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
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
import teslapy
import json
from os import system, name
from getpass import getpass
from time import sleep
#Client info needed for TeslaPy Library. Super annoying.
CLIENT_ID='e4a9949fcfa04068f59abb5a658f2bac0a3428e4652315490b659d5ab3f35a9e'
CLIENT_SECRET='c75f14bbadc8bee3a7594412c31416f8300256d7668ea7e6e7f06727bfb9d220'
# make it clean
def clear():
# winduwz
if name == 'nt':
_ = system('cls')
# nix
else:
_ = system('clear')
#clear the garbage
clear()
#plug
print('-----------------------------------------------------')
print('-----------------------------------------------------')
print('*****[[ Cylect.io: Tesla Connect ]]*****')
print('-----------------------------------------------------')
print('-----------------------------------------------------\n\n')
while True:
#creds
print('Please input your Tesla Credentials:\n')
EMAIL = input('Username:\n')
PASSWORD = getpass()
clear()
print('Testing Connection ... ... ...\n')
try:
with teslapy.Tesla(EMAIL, PASSWORD, CLIENT_ID, CLIENT_SECRET) as tesla:
tesla.fetch_token()
vehicles = tesla.vehicle_list()
vehicles[0].sync_wake_up()
print('... ... ... Connection Successful!\n')
break
except teslapy.HTTPError as e:
print(e)
pass
while True:
#dictionary inception - wtf - get data
data = vehicles[0].get_vehicle_data()
datadumped = json.dumps(data)
dataloaded = json.loads(datadumped)
charge_state = dataloaded.get('charge_state')
climate_state = dataloaded.get('climate_state')
drive_state = dataloaded.get('drive_state')
gui_settings = dataloaded.get('gui_settings')
vehicle_config = dataloaded.get('vehicle_config')
vehicle_state = dataloaded.get('vehicle_state')
print('*****[[ Cylect.io: Tesla Connect ]]*****\n')
print('-------------Connected to: '+ vehicle_state.get('vehicle_name') + ' | ' + vehicle_config.get('car_type'))
print('\n')
print('\n')
print('--------Please select one of the following:----------')
print('0: Unlock Vehicle')
print('1: Lock Vehicle')
print('2: Honk Horn')
print('3: Flash Lights')
print('4: Climate On')
print('5: Climate Off')
print('6: Max Defrost')
print('7: Change Climate Temperature Settings')
print('8: Change Charge Limit')
print('9: Window Control')
print('10: Open Frunk')
print('11: Open Trunk')
print('12: Vehicle Remote Start')
print('13: Trigger Homelink')
print('14: Chargeport Control')
print('15: Charge Control')
print('16: Sentry Mode Control')
print('17: Deactivate Device Token')
print('18: Valet Controls')
selection = input('Please select a number:')
if selection == '0':
try:
vehicles[0].sync_wake_up()
vehicles[0].command('UNLOCK')
clear()
print('-----------------------------------------------------')
print('-----------------------------------------------------')
print('Success: ' + vehicle_state.get('vehicle_name') + ' Unlocked')
print('-----------------------------------------------------')
print('-----------------------------------------------------')
except teslapy.HTTPError as e:
print(e)
pass
elif selection == '1':
try:
vehicles[0].sync_wake_up()
vehicles[0].command('LOCK')
clear()
print('-----------------------------------------------------')
print('-----------------------------------------------------')
print('Success: ' + vehicle_state.get('vehicle_name') + ' Locked')
print('-----------------------------------------------------')
print('-----------------------------------------------------')
except teslapy.HTTPError as e:
print(e)
pass
elif selection == '2':
try:
vehicles[0].sync_wake_up()
vehicles[0].command('HONK_HORN')
clear()
print('-----------------------------------------------------')
print('-----------------------------------------------------')
print('Success: ' + vehicle_state.get('vehicle_name') + ' Honk Initiated')
print('-----------------------------------------------------')
print('-----------------------------------------------------')
except teslapy.HTTPError as e:
print(e)
pass
elif selection == '3':
try:
vehicles[0].sync_wake_up()
vehicles[0].command('FLASH_LIGHTS')
clear()
print('-----------------------------------------------------')
print('-----------------------------------------------------')
print('Success: ' + vehicle_state.get('vehicle_name') + ' Flash Initiated')
print('-----------------------------------------------------')
print('-----------------------------------------------------')
except teslapy.HTTPError as e:
print(e)
pass
elif selection == '4':
try:
vehicles[0].sync_wake_up()
vehicles[0].command('CLIMATE_ON')
clear()
print('-----------------------------------------------------')
print('-----------------------------------------------------')
print('Success: ' + vehicle_state.get('vehicle_name') + ' Climate On')
print('-----------------------------------------------------')
print('-----------------------------------------------------')
except teslapy.HTTPError as e:
print(e)
pass
elif selection == '5':
try:
vehicles[0].sync_wake_up()
vehicles[0].command('CLIMATE_OFF')
clear()
print('-----------------------------------------------------')
print('-----------------------------------------------------')
print('Success: ' + vehicle_state.get('vehicle_name') + ' Climate Off')
print('-----------------------------------------------------')
print('-----------------------------------------------------')
except teslapy.HTTPError as e:
print(e)
pass
elif selection == '6':
try:
vehicles[0].sync_wake_up()
vehicles[0].command('MAX_DEFROST',on='true')
clear()
print('-----------------------------------------------------')
print('-----------------------------------------------------')
print('Success: ' + vehicle_state.get('vehicle_name') + ' Defrost On')
print('-----------------------------------------------------')
print('-----------------------------------------------------')
except teslapy.HTTPError as e:
print(e)
pass
elif selection == '7':
try:
d_temp = input('Please input Driver Temp: ')
p_temp = input('Please input Passenger Temp: ')
vehicles[0].sync_wake_up()
vehicles[0].command('CHANGE_CLIMATE_TEMPERATURE_SETTING', driver_temp=d_temp, passenver_temp=p_temp)
clear()
print('-----------------------------------------------------')
print('Success: ' + vehicle_state.get('vehicle_name') + ' Temperature Set')
print('Driver Temp:'+d_temp)
print('Passenger Temp:'+p_temp)
print('-----------------------------------------------------')
except teslapy.HTTPError as e:
print(e)
pass
elif selection == '8':
try:
charge_limit = input('Please input charge limit %:')
vehicles[0].sync_wake_up()
vehicles[0].command('CHANGE_CHARGE_LIMIT', percent=charge_limit)
clear()
print('-----------------------------------------------------')
print('-----------------------------------------------------')
print('Success: ' + vehicle_state.get('vehicle_name') + ' Charge Limit Set to: '+charge_limit+'%')
print('-----------------------------------------------------')
print('-----------------------------------------------------')
except teslapy.HTTPError as e:
print(e)
pass
elif selection == '9':
try:
if vehicle_state.get('fd_window')==1:
vehicles[0].sync_wake_up()
vehicles[0].command('WINDOW_CONTROL', command='close')
clear()
print('-----------------------------------------------------')
print('-----------------------------------------------------')
print('Success: ' + vehicle_state.get('vehicle_name') + ' Windows Closed:')
print('-----------------------------------------------------')
print('-----------------------------------------------------')
#wait for the car to update status n shit
sleep(3)
else:
vehicles[0].sync_wake_up()
vehicles[0].command('WINDOW_CONTROL', command='vent')
clear()
print('-----------------------------------------------------')
print('-----------------------------------------------------')
print('Success: ' + vehicle_state.get('vehicle_name') + ' Windows Vented:')
print('-----------------------------------------------------')
print('-----------------------------------------------------')
#also waiting for status update
sleep(3)
except teslapy.HTTPError as e:
print(e)
pass
elif selection == '10':
try:
vehicles[0].sync_wake_up()
vehicles[0].command('ACTUATE_TRUNK', which_trunk='front')
clear()
print('-----------------------------------------------------')
print('-----------------------------------------------------')
print('Success: ' + vehicle_state.get('vehicle_name') + ' Frunk Unlocked')
print('-----------------------------------------------------')
print('-----------------------------------------------------')
except teslapy.HTTPError as e:
print(e)
pass
elif selection == '11':
try:
vehicles[0].sync_wake_up()
vehicles[0].command('ACTUATE_TRUNK', which_trunk='rear')
clear()
print('-----------------------------------------------------')
print('-----------------------------------------------------')
print('Success: ' + vehicle_state.get('vehicle_name') + ' Trunk Unlocked')
print('-----------------------------------------------------')
print('-----------------------------------------------------')
except teslapy.HTTPError as e:
print(e)
pass
elif selection == '12':
try:
vehicles[0].sync_wake_up()
vehicles[0].command('REMOTE_START', password=PASSWORD)
clear()
print('-----------------------------------------------------')
print('-----------------------------------------------------')
print('Success: ' + vehicle_state.get('vehicle_name') + ' Remotely Started')
print('-----------------------------------------------------')
print('-----------------------------------------------------')
except teslapy.HTTPError as e:
print(e)
pass
elif selection == '13':
try:
vehicles[0].sync_wake_up()
vehicles[0].command('TRIGGER_HOMELINK', lat=drive_state.get('latitude'),lon=drive_state.get('longitude'))
clear()
print('-----------------------------------------------------')
print('-----------------------------------------------------')
print('Success: ' + vehicle_state.get('vehicle_name') + ' Triggered Homelink')
print('-----------------------------------------------------')
print('-----------------------------------------------------')
except teslapy.HTTPError as e:
print(e)
pass
elif selection == '14':
try:
if charge_state.get('charge_port_door_open')==True:
vehicles[0].sync_wake_up()
vehicles[0].command('CHARGE_PORT_DOOR_CLOSE')
clear()
print('-----------------------------------------------------')
print('-----------------------------------------------------')
print('Success: ' + vehicle_state.get('vehicle_name') + ' Charge Port Closed:')
print('-----------------------------------------------------')
print('-----------------------------------------------------')
sleep(3)
else:
vehicles[0].sync_wake_up()
vehicles[0].command('CHARGE_PORT_DOOR_OPEN')
clear()
print('-----------------------------------------------------')
print('-----------------------------------------------------')
print('Success: ' + vehicle_state.get('vehicle_name') + ' Charge Port Opened:')
print('-----------------------------------------------------')
print('-----------------------------------------------------')
sleep(3)
except teslapy.HTTPError as e:
print(e)
pass
elif selection == '15':
try:
if charge_state.get('charging_state')=="Disconnected":
print('-----------------------------------------------------')
print('-----------------------------------------------------')
print('Error: ' + vehicle_state.get('vehicle_name') + ' is not connected to charger.')
print('-----------------------------------------------------')
print('-----------------------------------------------------')
elif charge_state.get('charging_state')=="Charging":
vehicles[0].sync_wake_up()
vehicles[0].command('STOP_CHARGE')
clear()
print('-----------------------------------------------------')
print('-----------------------------------------------------')
print('Success: ' + vehicle_state.get('vehicle_name') + ' Charging Stopped.')
print('-----------------------------------------------------')
print('-----------------------------------------------------')
sleep(3)
else:
vehicles[0].sync_wake_up()
vehicles[0].command('START_CHARGE')
clear()
print('-----------------------------------------------------')
print('-----------------------------------------------------')
print('Success: ' + vehicle_state.get('vehicle_name') + ' Charging Started.')
print('-----------------------------------------------------')
print('-----------------------------------------------------')
sleep(3)
except teslapy.HTTPError as e:
print(e)
pass
elif selection == '16':
try:
if vehicle_state.get('sentry_mode')==False:
vehicles[0].sync_wake_up()
vehicles[0].command('SET_SENTRY_MODE', on='true')
clear()
print('-----------------------------------------------------')
print('-----------------------------------------------------')
print('Success: ' + vehicle_state.get('vehicle_name') + ' Enabled Sentry Mode')
print('-----------------------------------------------------')
print('-----------------------------------------------------')
#wait for the car to update status n shit
sleep(3)
else:
vehicles[0].sync_wake_up()
vehicles[0].command('SET_SENTRY_MODE', on='false')
clear()
print('-----------------------------------------------------')
print('-----------------------------------------------------')
print('Success: ' + vehicle_state.get('vehicle_name') + ' Disabled Sentry Mode')
print('-----------------------------------------------------')
print('-----------------------------------------------------')
#also waiting for status update
sleep(3)
except teslapy.HTTPError as e:
print(e)
pass
elif selection == '17':
try:
vehicles[0].sync_wake_up()
clear()
print('-----------------------------------------------------')
print('-----------------------------------------------------')
print(vehicles[0].command('DEACTIVATE_DEVICE_TOKEN', device_token=vehicles[0].get_vehicle_data('tokens[0]')))
#print(charge_state.get('charge_port_door_open'))
#print(dataloaded.get('drive_state'))
print('-----------------------------------------------------')
print('-----------------------------------------------------')
except teslapy.HTTPError as e:
print(e)
pass
elif selection == '18':
try:
vehicles[0].sync_wake_up()
clear()
print('-----------------------------------------------------')
print('-----------------------------------------------------')
#print(vehicles[0].get_vehicle_data())
#print(charge_state.get('charge_port_door_open'))
#print(dataloaded.get('drive_state'))
print(vehicles[0].get_vehicle_data('tokens'))
print('-----------------------------------------------------')
print('-----------------------------------------------------')
except teslapy.HTTPError as e:
print(e)
pass