-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
mytesla.15m.py
executable file
·2226 lines (1882 loc) · 108 KB
/
mytesla.15m.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
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#!/usr/bin/env PYTHONIOENCODING=UTF-8 /opt/local/bin/python3
# -*- coding: utf-8 -*-
#
# <xbar.title>MyTesla</xbar.title>
# <xbar.version>Tesla API v48</xbar.version>
# <xbar.author>[email protected]</xbar.author>
# <xbar.author.github>pvdabeel</xbar.author.github>
# <xbar.desc>Control your Tesla vehicle from the MacOS menubar</xbar.desc>
# <xbar.dependencies>python</xbar.dependencies>
#
# Licence: GPL v3
# Installation instructions:
# --------------------------
# Execute in terminal.app before running :
# sudo easy_install keyring
#
# Ensure you have xbar installed https://github.com/matryer/xbar/releases/latest
# Copy this file to your xbar plugins folder and chmod +x the file from your terminal in that folder
# Run xbar
_DEBUG_ = False
# Disable if you don't want your car location to be tracked to a local DB
# DB is located in your home directory, under .state/mytesla/mytesla-locations.json
_LOCATION_TRACKING_ = True
# Download high-resolution images from store composer to cache
_COMPOSER_CACHE_HIGH_ = True
# Want battery status in menu bar itself
_BATTERY_MENUBAR_ = False
# Google map size
_MAP_SIZE_ = '800x600'
# Want white logo instead of dark logo in menubar
_WHITE_LOGO_ = True
# Tesla API returns wrong options code for cars. Put your option codes here
# to override those provided by Tesla API. You can get your option list by
# logging in to tesla.com. The option codes can be copied from the url used
# to show the car image in the car detail page. Use your 'vehicle_id' as key
# in the 'key : value' list below. You can retrieve your vehicle_id by
# executing "mytesla.15m.py debug" on the Terminal.
_OVERRIDE_OPTION_CODES_ = { 1669029050 : "BP00,AH00,AD15,GLTL,AU01,X042,APF2,APH2,APPF,X028,BTX6,BS00,CC02,BC0R,CH04,CF00,CW00,COBE,X039,IDCF,X026,DRLH,DU00,AF02,FMP6,FG02,FR01,X007,X011,INBPB,PI01,IX01,X001,LP01,LT3B,MI02,X037,MDLX,DV4W,X025,X003,PMBL,PK00,X031,PF00,X044,TM00,BR00,RCX0,REEU,RFPX,OSSB,X014,S02B,ME02,QLPB,SR04,SP01,X021,SC05,SU01,TP03,TRA1,TR01,TIG2,DSH7,TW01,MT10A,UTAB,WT22,WXP2,YFCC,CPF1",
1382791597 : "MDLX,MTX04,PBSB,WTUT,INBC3W,PI01,APF2,APBS,CC02,SC04,ACL1,CPF1,TW01" }
_SHOW_CAR_PICTURES_ = [ 'STUD_SIDE_V2', 'STUD_3QTR','STUD_REAR','STUD_WHEEL_V2','STUD_SEAT_V2' ] # May work or not for your car: [ 'INTERIOR', 'FRONT34', 'INTERIOR', 'REAR', 'STUD_REAR34', 'STUD_SIDEVIEW' ]
_CAR_DEFAULT_PICTURE_ = 'STUD_SIDE_V2'
_CAR_DEFAULT_PICTURE_2_ = 'STUD_WHEEL_V2'
import base64
import calendar
import datetime
import getpass
import json
import keyring
import math
import os
import random
import re
import requests
import string
import sys
import time
import platform
import urllib
from googlemaps import Client as googleclient
from hashlib import sha256
from tinydb import TinyDB, Query
from urllib.parse import parse_qs
from datetime import date
from datetime import datetime
# Location where to store state files
home = os.path.expanduser("~")
state_dir = home+'/.state/mytesla'
if not os.path.exists(state_dir):
os.makedirs(state_dir)
# The full path to this file
cmd_path = os.path.realpath(__file__)
# Location tracking database
locationdb = TinyDB(state_dir+'/mytesla-locations.json')
# Tesla option codes
tesla_option_codes = {
"ACL1":"Ludicrous Mode",
"AD02":"NEMA 14-50",
"AD04":"European 3-Phase",
"AD05":"European 3-Phase, IT",
"AD06":"Schuko (1 phase, 230V 13A)",
"AD07":"Red IEC309 (3 phase, 400V 16A)",
"AD08":"Blue Charging Adapter",
"AD09":"Adapter, Swiss (1 phase, 10A)",
"AD10":"Adapter, Denmark (1 phase, 13A)",
"AD11":"Adapter, Italy (1 phase, 13A)",
"AD15":"Adapter",
"AD15":"Adapter, J1772",
"ADPC2":"Type 2 to Type 2 Connector",
"ADPX2":"Type 2 Public Charging Connector",
"ADX10":"No - Adapter, Denmark (1 phase, 13A)",
"ADX11":"No - Adapter, Italy (1 phase, 13A)",
"ADX4":"No European 3-Phase",
"ADX5":"European 3-Phase, IT",
"ADX6":"No - Adapter, Schuko (1 phase, 13A)",
"ADX7":"No - 3-ph Red IEC309 (3 phase, 16A)",
"ADX8":"Blue IEC309 (1 phase, 230V 32A)",
"ADX9":"No - Adapter, Swiss (1 phase, 10A)",
"AF00":"No HEPA Filter",
"AF02":"HEPA Filter",
"AH00":"No Accessory Hitch",
"APB1":"Autopilot with convenience features",
"APBS":"Autopilot",
"APE1":"Enhanced Autopilot",
"APF0":"Autopilot Firmware 2.0 Base",
"APF1":"Autopilot Firmware 2.0 Enhanced",
"APF2":"Full Self-Driving Hardware (Activated)",
"APFB":"Full Self-Driving Hardware",
"APH0":"Autopilot 2.0 Hardware",
"APH1":"Autopilot 1.0 Hardware",
"APH2":"Autopilot 2.0 Hardware",
"APH3":"Autopilot 2.5 Hardware",
"APH4":"Autopilot 3.0 Hardware (FSD)",
"APPA":"Autopilot 1.0 Hardware",
"APPB":"Enhanced Autopilot",
"APPF":"Full Self-Driving Capability",
"AU00":"No Audio Package",
"AU01":"Ultra High Fidelity Sound",
"AU3D":"Sound Studio Package",
"AU3P":"Sound Studio Package",
"AUF1":"Premium Speakers Enabled",
"AUF2":"Premium Speakers Disabled",
"BC00":"Brake Calipers M4.42/44",
"BC0B":"Tesla Grey Brake Calipers",
"BC0R":"Tesla Red Brake Calipers",
"BC3B":"Black Brake Calipers, Model 3",
"BC3R":"Performance Brakes",
"BCMB":"Black Brake Calipers, Mando Brakes",
"BCYR":"Performance Brakes",
"BG30":"No Badge",
"BG31":"AWD Badge without underline",
"BG32":"Performance AWD Badge",
"BG33":"China Badge",
"BP00":"No Ludicrous",
"BP01":"Ludicrous Speed Upgrade",
"BP02":"Uncorked Acceleration",
"BR00":"No Battery Firmware Limit",
"BR03":"Battery Firmware Limit (60kWh)",
"BR05":"Battery Firmware Limit (75kWh)",
"BS00":"Blind Spot Sensor Package",
"BS01":"Special Production Flag",
"BT00":"68 kWh (Model Y) 4680 cells",
"BT35":"50 kWh (Model 3/Y) Pre 2021 Panasonic",
"BT36":"62,5 kWh (Model 3/Y) Pre 2021 Panasonic",
"BT37":"75 kWh (Model 3/Y) Pre 2021 Panasonic",
"BT38":"74 kWh (Model 3/Y) LG cells",
"BT3D":"50 kWh (Model 3)",
"BT40":"40 kWh",
"BT41":"55 kWh",
"BT42":"82 kWh (Model 3/Y) 2021 Panasonic",
"BT43":"79 kWh (Model 3/Y) 2021 LG NCA",
"BT60":"60 kWh",
"BT70":"70 kWh",
"BT85":"85 kWh",
"BTF0":"55 kWh CATL Prismatic",
"BTF1":"60 kWh E1 LFP60 CATL Battery Pack",
"BTX4":"90 kWh",
"BTX5":"75 kWh",
"BTX6":"100 kWh",
"BTX7":"75 kWh",
"BTX8":"75 kWh",
"BTX9":"100 kWh with Weight Reduction",
"BTXA":"18650J2 Battery Cell",
"BTXB":"99 kWh 18650 Plaid E5/E6 VIN battery",
"BY00":"Model Y",
"BY01":"One-piece cast rear under body legacy",
"BY02":"One-piece cast front and read under body",
"BY03":"Safety Net Body",
"BY04":"One-oiece cast reader Safety Net Body",
"CC01":"Five Seat Interior",
"CC02":"Six Seat Interior",
"CC03":"Seven Seat Interior",
"CC04":"Seven Seat Interior",
"CC12":"Six Seat Interior with Center Console",
"CDM0":"No CHAdeMO Charging Adaptor",
"CF00":"72amp High amperage charger",
"CF01":"48amp charger",
"CH00":"Standard Charger (40 Amp)",
"CH01":"Dual Chargers (80 Amp)",
"CH04":"72 Amp Charger Gen3",
"CH05":"32/48 Amp Charger",
"CH07":"48 Amp Charger",
"CH09":"72 Amp Charger",
"CH11":"48 Amp Charger Single Phase",
"CH12":"48 Amp Charger Gen3.5 Combo 1",
"CH14":"32 Amp Charger RENA",
"CH15":"48 Amp Charger REEU/REAP",
"CH16":"48 Amp Charger RENA",
"CH17":"48 Amp Charger 1PH/3PH",
"COAT":"Country: Austria",
"COBE":"Country: Belgium",
"COCA":"Country: Canada",
"COCH":"Country: Switzerland",
"COCN":"Country: China",
"CODE":"Country: Germany",
"CODK":"Country: Denmark",
"COES":"Country: Spain",
"COFI":"Country: Finland",
"COFR":"Country: France",
"COGB":"Country: Great Britain",
"COHR":"Country: Croatia",
"COIE":"Country: Ireland",
"COIT":"Country: Italy",
"COJP":"Country: Japan",
"COKR":"Country: South Korea",
"COL0":"Signature",
"COL1":"Solid",
"COL2":"Metallic",
"COL3":"Tesla Multi-Coat",
"COLU":"Country: Luxembourg",
"CONL":"Country: Netherlands",
"CONO":"Country: Norway",
"COPT":"Country: Portugal",
"COSE":"Country: Sweden",
"COSG":"Country: Singaport",
"COUS":"Country: United States",
"CP00":"MX/MS 2021",
"CP01":"Charge Port CCS",
"CPF0":"Standard Connectivity",
"CPF1":"Premium Connectivity",
"CPW1":"20 inch Performance Wheels",
"CW00":"No Cold Weather Package",
"CW02":"Cold Weather Package",
"DA00":"No Autopilot",
"DA01":"Active Safety (ACC,LDW,SA)",
"DA02":"Autopilot Convenience Features",
"DCF0":"No drop-in front console",
"DCF1":"Drop-in front console",
"DCF2":"Inductive Phone charger front console",
"DRLH":"Left Hand Drive",
"DRRH":"Right Hand Drive",
"DSH5":"Dashboard",
"DSH7":"Alcantara Dashboard Accents",
"DSHG":"Dashboard with graphite trim",
"DU00":"Drive Unit - IR",
"DU01":"Drive Unit - Infineon",
"DU02":"Drive Unit - Non-performance front drive",
"DV2W":"Rear-Wheel Drive",
"DV4W":"All-Wheel Drive",
"EUSB":"Safety EU Black",
"FBBB":"Front Brake Brembo Black",
"FBBR":"Front Brake Brembo Red",
"FC01":"Front Console Inductive Phone Charger",
"FC02":"Front Console Premium",
"FC3P":"Front Console Premium",
"FCH2":"Front controller V2",
"FD00":"Low Current IGBT IM130 Drive Unit",
"FD01":"Low Current IGBT IM130 Drive Unit (CN)",
"FD02":"Model S/X 2021 LR",
"FD03":"Model S/X 2021 P",
"FDU2":"Raven Front Drive Unit",
"FG00":"No Exterior Lighting Package",
"FG01":"Exterior Lighting Package (Fog Lamps)",
"FG02":"Exterior Lighting Package (Fog Lamps)",
"FG31":"Exterior Lighting Package (Fog Lamps)",
"FG3B":"No fog Lamps",
"FGF0":"Fog Lamps Disabled",
"FGF1":"Fog Lamps Enabled",
"FM3B":"No Performance Package",
"FM3P":"Performance Package",
"FM3S":"Semi de-rated firmware",
"FM3U":"Acceleration Boost",
"FMP6":"Performance Firmware",
"FR01":"Base Front Row",
"FR02":"Ventilated Front Seats",
"FR03":"Front Row Seats",
"FR04":"Front Row Seats",
"FR05":"Front Row Seats",
"GLCN":"Assembly CN",
"GLFR":"Assembly FR",
"GLTL":"Assembly TL",
"HC00":"No Home Charging installation",
"HC01":"Home Charging Installation",
"HL31":"Head Lamp",
"HL32":"Matrix headlights 2021",
"HM31":"No Homelink",
"HM31":"Homelink",
"HP00":"No HPWC Ordered",
"HP01":"HPWC Ordered",
"I36M":"Rear Drive Unit Inverter 600A Mosfet",
"I38M":"Rear Drive Unit Inverter 800A Mosfet",
"IBB0":"All Black Interior",
"IBB1":"All Black Interior",
"IBC00":"Carbon Fibre & Black Interior",
"IBE00":"Wood & Black Interior",
"IBW0":"Black and White Interior",
"IBW1":"Black and White Interior",
"IC00":"Model S/X (Since Q2 2021)",
"IC01":"Model X (Since Q4 2021)",
"IC02":"Model S/X (Since Q2 2021)",
"IC000":"Carbon Fibre & Cream Interior",
"ICW00":"Wood & Cream Interior",
"ID00":"Model S/X (Since Q2 2021",
"ID02":"All Black with Carbon fibre interior",
"ID03":"Model S/X (Since Q2 2021)",
"ID3A":"Interior White Aluminium",
"ID3W":"Interior Wood Decor",
"IDBA":"Dark Ash Wood Decor",
"IDBO":"Figured Ash Wood Decor",
"IDCF":"Carbon Fiber Decor",
"IDHG":"Interior Horizontal Gloss",
"IDHM":"Matte Obeche Wood Decor",
"IDLW":"Lacewood Decor",
"IDOG":"Gloss Obeche Wood Decor",
"IDOK":"Oak Decor",
"IDOM":"Matte Obeche Wood Decor",
"IDPB":"Piano Black Decor",
"IL31":"Interior Ambient Lighting",
"ILF0":"Interior Ambient Lighting disabled",
"ILF1":"Interior Ambient Lighting enabled",
"IN3BB":"All Black Partial Premium Interior",
"IN3BW":"All White interior",
"IN3PB":"All Black Premium Interior",
"IN3PW":"All White Premium Interior",
"INB3C":"All Cream interior",
"INBBS":"Black Premium",
"INBBW":"White Interior",
"INBC3W":"White Interior",
"INBDS":"Black Premium",
"INBFP":"Classic Black",
"INBFW":"White Premium",
"INBPB":"Premium Black",
"INBPP":"Black Interior",
"INBPW":"White Interior",
"INBTB":"Multi-Pattern Black",
"INBWS":"White Premium",
"INFBP":"Black Premium",
"INLFC":"Cream Premium",
"INLFP":"Black Premium / Light Headliner",
"INLPC":"Cream Interior",
"INLPP":"Black / Light Headliner",
"INWPT":"Tan Interior",
"INYPB":"Black Interior",
"INYPW":"White Interior",
"IVBPP":"Partial Black Interior",
"IVBPP":"All Black Interior",
"IVBSW":"Ultra White Interior",
"IVBTB":"All Black Interior",
"IVLPC":"Vegan Cream",
"IX00":"No Extended Nappa Leather Trim",
"IX01":"Extended Nappa Leather Trim",
"LLP1":"License Plate Liftgate Type NA",
"LLP2":"License Plate Liftgate Type EU",
"LP00":"Lighting Package",
"LP01":"Premium Interior Lighting",
"LS01":"Mfg Line Shanghai - Phase 1",
"LS02":"Mfg Line Shanghai - Phase 2.2",
"LT00":"Vegan interior",
"LT01":"Standard interior",
"LT1B":"Lower Trim",
"LT3W":"LT3W",
"LT4B":"LT4B",
"LT4C":"LT4C",
"LT4W":"LT4W",
"LT5C":"LT5C",
"LT5P":"Black Premium Lower Trim - Black interior"
"MT5W","Black Premium Lower Trim - White interior"
"LT6P":"Black Lower Trim - Performance",
"LT6W":"White Lower Trim",
"LTPB":"Lower Trim PUR Black",
"LTPW":"Lower Trim PUR White",
"LTSB":"Lower Trim Standard Black",
"LVB0":"12V Acid Low Voltage Battery",
"LVB1":"15V Li-Ion Low Voltage Battery",
"LVB2":"CATL 16V Battery",
"M301":"Generation 1 of 2022",
"MDL3":"Model 3",
"MDLS":"Model S",
"MDLX":"Model X",
"MDLY":"Model Y",
"ME01":"Memory Seats",
"ME02":"Memory Seats",
"ME02":"Seat Memory",
"MI00":"1st Generation Production",
"MI01":"2nd Generation Production",
"MI02":"3rd Generation Production",
"MI03":"4th Generation Production",
"MI04":"5th Generation Production",
"MI07":"8th Gneration Production",
"MR30":"Tech Package - Mirror",
"MR31":"Tech Package - Mirror",
"MS03":"Model S",
"MS04":"Model S",
"MS05":"Model S",
"MS06":"Model S",
"MT300":"Model 3 Standard Range Rear-wheel drive",
"MT301":"Model 3 Standard Range Plus Rear-wheel drive",
"MT302":"Model 3 Long Range Rear-Wheel drive",
"MT303":"Model 3 Long Range All-Wheel drive",
"MT304":"Model 3 Long Range All-Wheel drive Performance",
"MT305":"Model 3 Mid Range Rear-Wheel drive",
"MT307":"Model 3 Mid Range Rear-Wheel drive",
"MT308":"Model 3 Standard Range Plus Rear-wheel drive",
"MT309":"Model 3 Standard Range Plus Rear-wheel drive",
"MT310":"Model 3 Long Range All-wheel drive",
"MT311":"Model 3 Long Range All-wheel drive Performance",
"MT314":"Model 3 Standard Range Plus Rear-wheel drive",
"MT315":"Model 3 Long Range All-wheel drive",
"MT316":"Model 3 Long Range All-Wheel drive",
"MT317":"Model 3 Long Range All-Wheel drive Performance",
"MT320":"Model 3 Standard Range Plus Rear-Wheel drive",
"MT321":"Model 3 Long Range All-Wheel drive",
"MT322":"Model 3 Standard Range Plus Rear-Wheel drive",
"MT323":"Model 3 Long Range All-Wheel drive",
"MT324":"Model 3 Long Range All-Wheel drive",
"MT325":"Model 3 Long Range All-Wheel drive Performance",
"MT328":"Model 3 Long Range All-Wheel drive",
"MT336":"Model 3 Standard Range Plus Rear-Wheel drive",
"MT337":"Model 3 Standard Range Plus Rear-Wheel drive",
"MT340":"Model 3 Long Range All-Wheel drive Performance",
"MTS01":"Model S Standard Range",
"MTS03":"Model S Long Range",
"MTS04":"Model S Performance",
"MTS05":"Model S Long Range",
"MTS06":"Model S Performance",
"MTS07":"Model S Long Range Plus",
"MTS08":"Model S Performance",
"MTS09":"Model S Plaid+",
"MTS10":"Model S Long Range",
"MTS11":"Model S Plaid",
"MTS12":"Model S Plaid",
"MTS13":"Model S Dual Motor All-Wheel drive",
"MTS14":"Model S Plaid Tri Motor All-Wheel drive",
"MTX01":"Model X Standard Range",
"MTX03":"Model X Long Range",
"MTX04":"Model X Performance",
"MTX05":"Model X Long Range Plus",
"MTX06":"Model X Performance",
"MTX07":"Model X Long Range Plus",
"MTX08":"Model X Performance",
"MTX09":"Model X Plaid+",
"MTX10":"Model X Long Range",
"MTX11":"Model X Plaid",
"MTX12":"Model X Plaid",
"MTX13":"Model X Plaid",
"MTX14":"Model X Plaid Tri Motor All-Wheel drive",
"MTY01":"Model Y Standard Range Rear-Wheel drive",
"MTY02":"Model Y Long Range Rear-Wheel drive",
"MTY03":"Model Y Long Range All-Wheel drive",
"MTY04":"Model Y Long Range All-Wheel drive Performance",
"MTY05":"Model Y Long Range All-Wheel drive Performance",
"MTY07":"Model Y Long Range All-Wheel drive",
"MTY09":"Model Y Long Range All-Wheel drive",
"MTY11":"Model Y Long Range All-Wheel drive",
"MTY12":"Model Y Long Range All-Wheel drive Performance",
"MTY14":"Model Y Long Range All-Wheel drive",
"MX06":"Model X 2021+",
"MY00":"Model Y Berlin",
"MY01":"Model Y Austin",
"MY02":"Model Y Berlin",
"OSSB":"Safety Belt Black",
"OSSW":"Safety Belt White",
"P85D":"P85D",
"PA00":"No Paint Armor",
"PBCW":"Solid White Color",
"PBSB":"Solid Black Color",
"PBT85":"Performance 85kWh",
"PC30":"No Performance Chassis",
"PC31":"Performance Chassis",
"PF00":"No Performance Legacy Package",
"PF01":"Performance Legacy Package",
"PI00":"No Premium Interior",
"PI01":"Premium Upgrades Package",
"PK00":"No Parking Sensors Legacy",
"PK01":"Parking Sensors",
"PL30":"No Aluminum Pedal",
"PL31":"Performance Pedals",
"PMAB":"Anza Brown Metallic",
"PMBL":"Obsidian Black Multi-Coat Color",
"PMMB":"Monterey Blue Metallic Color",
"PMNG":"Midnight Silver Metallic Color",
"PMMR":"Multi-Coat Red",
"PMNG":"Midnight Silver Metallic Color",
"PMSG":"Sequoia Green Metallic Color",
"PMSS":"San Simeon Silver Metallic Color",
"PMTG":"Dolphin Grey Metallic Color",
"PPMR":"Muir Red Multi-Coat",
"PPSB":"Deep Blue Metallic Color",
"PPSR":"Signature Red Color",
"PPSW":"Shasta Pearl White Multi-Coat Color",
"PPTI":"Titanium Metallic Color",
"PRM30":"Partial Premium Interior",
"PRM31":"Premium Interior",
"PRM3S":"Standard Interior",
"PRMY1":"Premium Interior",
"PS00":"No Parcel Shelf",
"PS01":"Parcel Shelf",
"PT00":"Standard trunk",
"PT01":"Trunk Power Motor",
"PWS0":"Model S 10.2020",
"PSP14":"Four Years Prepaid Service",
"PSPX4":"No Four-year prepaid",
"PX00":"No Performance Plus Package",
"PX01":"Performance Plus",
"PX4D":"90 kWh Performance",
"PX6D":"Zero to 60 in 2.5 sec",
"QLBS":"Black Premium Interior",
"QLFC":"Cream Premium Interior",
"QLFP":"Black Premium Interior",
"QLFW":"White Premium Interior",
"QLPB":"Black Premium Interior",
"QLPW":"White Premium Interior",
"QLWS":"White Premium Interior",
"QNET":"Tan NextGen",
"QPBT":"Black Textile Interior",
"QPMP":"Black seats",
"QTBS":"Black Premium Interior",
"QTBW":"White Premium Seats",
"QTFC":"Cream Premium Interior",
"QTFP":"Black Premium Interior",
"QTFW":"White Premium Interior",
"QTPB":"Black Leather Tesla Premium Seats",
"QTPC":"Cream Premium Seats",
"QTPP":"Black Premium Seats",
"QTPT":"Tan Premium Seats",
"QTTB":"Black Textile Interior",
"QTTB":"Multi-Pattern Black Seats",
"QTWS":"White Premium Interior",
"QVBM":"Multi-Pattern Black Seats",
"QVPC":"Vegan Cream Seats",
"QVPP":"Vegan Cream Seats",
"QVSW":"White Tesla Seats",
"QXMB":"Black Leather Seat",
"RA00":"No Radar Module Sensor",
"RA01":"Radar Module Sensor",
"RBMB":"Rear Brake Mando Black",
"RBMR":"Rear Brake Mando Red",
"RCX0":"No Rear Console",
"RCX1":"Rear Console",
"RD01":"Low Current Mosfet PM216 Rear Drive",
"RD02":"High Current Mosfet PM216 Rear Drive",
"RD03":"Rear Drive Unit LR",
"RD04":"Rear Drive Unit Plaid",
"RDU2":"Rear Drive unit with elec. oil pump",
"RDU3":"Rear small drive unit",
"RDU4":"Rear small drive unit with elec. oil pump",
"REAP":"Region: Asia Pacific",
"REEU":"Region: Europe",
"RENA":"Region: North America",
"RENC":"Region: Canada",
"RF3G":"Glass Roof",
"RFBC":"Body Color Roof",
"RFBK":"Black Roof",
"RFFG":"Glass Roof",
"RFP0":"All Glass Panoramic Roof",
"RFP2":"Sunroof",
"RFPO":"All Glass Panoramic Roof",
"RFPX":"Glass Roof",
"RFPX":"Model X Roof",
"RL00":"Rear tail lights",
"RL01":"Rear tail lights (CSS)",
"RL31":"Rear tail lights (EU)",
"RL32":"Rear tail lights (Global)",
"RNG0":"Standard Battery Range",
"RS3H":"Second Row Seat Rear Seats (Heated)",
"RSF1":"Rear Heated Seats",
"RU00":"No Range Upgrade",
"S01B":"Black Textile Seats",
"S02B":"Seat",
"S02P":"S02P",
"S02W":"White Seats",
"S07W":"White Seats",
"S31B":"S31B",
"S32C":"S32C",
"S32P":"Black performance seats",
"S32W":"S32W",
"S3PB":"Seat Black PUR Premium Seats",
"S3PW":"Seat White PUR Premium Seats",
"SA3P":"Seat Adjustment - Power",
"SC00":"No Supercharging",
"SC01":"Supercharging Enabled",
"SC04":"Pay Per Use Supercharging",
"SC05":"Free Supercharging",
"SC05":"Free Supercharging",
"SC06":"Time bound unlimited free supercharging",
"SLR0":"No Rear Spoiler",
"SG01":"Seering Gear Single Chip",
"SLR1":"Carbon Fibre Spoiler",
"SP00":"No Security Package",
"SP01":"Security Package",
"SPT31":"Unknown",
"SPTY1":"Unknown",
"SR01":"Standard 2nd row",
"SR06":"Seven Seat Interior",
"SR07":"Standard 2nd row",
"ST00":"Non-leather Steering Wheel",
"ST01":"Non-heated Leather Steering Wheel",
"ST02":"Heated Leather Steering Wheel",
"ST03":"Regular Steering Wheel",
"STOY":"Yoke Steering Wheel",
"ST30":"Base Steering Wheel",
"ST31":"Steering Wheel",
"ST33":"Steering Wheel, Round PUR Heated",
"STCP":"Steering Wheel",
"STY5S":"Five Seat Interior",
"STY7S":"Seven Seat Interior",
"SU00":"Standard Suspension",
"SU01":"Smart Air Suspension",
"SU03":"Suspension Update",
"SU3C":"Coil Spring Suspension",
"T3MA":"Tires M3",
"TIC4":"All-Season Tires",
"TIG2":"Summer Tires",
"TIM7":"Summer Tires",
"TIMP":"Tires",
"TIP0":"All-season Tires",
"TM00":"General Production Trim",
"TM02":"General Production Signature Trim",
"TM0A":"ALPHA PRE-PRODUCTION NON-SALEABLE",
"TM0B":"BETA PRE-PRODUCTION NON-SALEABLE",
"TM0C":"PRE-PRODUCTION SALEABLE",
"TP01":"No Technology Package",
"TP01":"Tech Package - No Autopilot",
"TP02":"Tech Package with Autopilot",
"TP03":"Tech Package with Enhanced Autopilot",
"TR00":"No Rear Facing Seats",
"TR01":"Third Row Seating",
"TRA1":"Third Row HVAC",
"TW00":"No Tow Package",
"TW01":"Tow Package",
"UM01":"Universal Mobile Charger - US Port (Single)",
"USSB":"US Safety Kit Black",
"USSW":"US Safety Kit White",
"UT3P":"Suede Grey Premium Headliner",
"UTAB":"Black Alcantara Headliner",
"UTAW":"Light Headliner",
"UTMF":"Headliner",
"UTPB":"Dark Headliner",
"UTSB":"Dark Headliner",
"UTZW":"Light Headliner",
"W32D":"20 inch Gray Performance Wheels",
"W32P":"20 inch Performance Wheels",
"W38B":"18 inch Aero Wheels",
"W39B":"19 inch Sport Wheels",
"WR00":"No Wrap",
"WS10":"21 inch Arachnid Wheels",
"WS90":"19 inch Tempest Wheels",
"WT19":"19 inch Wheels",
"WT20":"20 inch Silver Slipstream Wheels",
"WT22":"22 inch Silver Turbine Wheels",
"WTAB":"21 inch Black Arachnid Wheels",
"WTAS":"19 inch Silver Slipstream Wheels",
"WTDS":"19 inch Sonic Carbon Slipstream Wheels",
"WTHX":"20 inch Turbine Wheels",
"WTNN":"20 inch Nokian Winter Tires (non-studded)",
"WTNS":"20 inch Nokian Winter Tires (studded)",
"WTP2":"20 inch Pirelli Winter Tires",
"WTSC":"20 inch Sonic Carbon Wheels",
"WTSD":"20 inch Two-Tone Slipstream Wheels",
"WTSG":"21 inch Turbine Wheels",
"WTSP":"21 inch Turbine Wheels",
"WTSS":"21 inch Silver Turbine Wheels",
"WTTB":"19 inch Cyclone Wheels",
"WTTC":"21 inch Sonic Carbon Twin Turbine Wheels",
"WTTG":"19 inch Cyclone Wheels",
"WTUT":"22 inch Onyx Black Turbine Wheels",
"WTW2":"19 inch Nokian Winter Wheel Set",
"WTW3":"19 inch Pirelli Winter Wheel Set",
"WTW4":"19 inch Winter Tire Set",
"WTW5":"21 inch Winter Tire Set",
"WTW6":"19 inch Nokian Winter Tires (studded)",
"WTW7":"19 inch Nokian Winter Tires (non-studded)",
"WTW8":"19 inch Pirelli Winter Tires",
"WTX1":"19 inch Michelin Primacy Tire Upgrade",
"WX00":"20 inch Cyberstream Wheels",
"WX20":"22 inch Turbine Wheels",
"WXNN":"No 20 inch Nokian Winter Tires (non-studded)",
"WXNS":"No 20 inch Nokian Winter Tires (studded)",
"WXP2":"No 20 inch Pirelli Winter Tires",
"WXW2":"No 19 inch Wheels with Nokian Winter Tyres",
"WXW3":"No 19 inch Wheels with Pirelli Winter Tyres",
"WXW4":"No 19 inch Winter Tire Set",
"WXW4":"No 19 inch Winter Tyre Set",
"WXW5":"No 21 inch Winter Tire Set",
"WXW6":"No 19 inch Nokian Winter Tires (studded)",
"WXW7":"No 19 inch Nokian Winter Tires (non-studded)",
"WXW8":"No 19 inch Pirelli Winter Tires",
"WY18B":"Unknown",
"WY19B":"Unknown",
"WY20P":"Unknown",
"X001":"Power Liftgate",
"X002":"Manual Liftgate",
"X003":"Navigation",
"X004":"No Navigation",
"X007":"Daytime running lights",
"X010":"Base Mirrors",
"X011":"Homelink",
"X012":"No Homelink",
"X013":"Satellite Radio",
"X014":"No Satellite Radio",
"X019":"Carbon Fibre Spoiler",
"X020":"No Performance Exterior",
"X021":"No Active Spoiler",
"X024":"Performance Package",
"X025":"No Performance Package",
"X026":"Door handle",
"X027":"Lighted Door Handles",
"X028":"Battery Badge",
"X029":"No Battery Badge",
"X030":"No Passive Entry Pkg",
"X031":"Keyless Entry",
"X037":"Powerfolding Mirrors",
"X039":"DAB Radio",
"X040":"No DAB Radio",
"X041":"No Auto Presenting Door",
"X042":"Auto Presenting door",
"X043":"No Phone Dock Kit",
"X044":"Phone Dock Kit",
"YF00":"No Yacht Floor",
"YF01":"Matching Yacht Floor",
"YFCC":"Center Console",
"YFFC":"Integrated Center Console" }
# Nice ANSI colors
CEND = '\33[0m'
CRED = '\33[31m'
CGREEN = '\33[32m'
CYELLOW = '\33[33m'
CBLUE = '\33[36m'
# Support for OS X Dark Mode
DARK_MODE=True if os.getenv('XBARDarkMode','false') == 'true' else False
class TeslaAuthenticator(object):
"""Manages Tesla authentication. Supports MFA"""
client = {
"id" : "81527cff06843c8634fdc09e8ac0abefb46ac849f38fe1e431c2ef2106796384",
"secret" : "c7257eb71a564034f9419ee651c7d0e5f7aa6bfbd18bafb5c5c033b093bb2fa3",
}
headers = {
"Accept" : "application/json"
#"User-Agent" : "github.com/pvdabeel/mytesla",
#"x-tesla-user-agent" : "github.com/pvdabeel/mytesla",
#"X-Requested-With" : "com.teslamotors.tesla"
}
credentials = {}
def __init__(self):
return None
def dialog_username(self):
print (CRED+'Enter your tesla.com username:'+CEND)
return str_input()
def dialog_password(self):
print (CRED+'Enter your tesla.com password:'+CEND)
return getpass.getpass()
def dialog_mfa(self):
print (CRED+'Enter multi-factor authentication code:'+CEND)
return str_input()
def dialog_captcha(self):
print (CRED+'Enter captcha code (Run \'open /tmp/captcha.svg\' in Terminal.app):'+CEND)
return str_input()
def dialog_access_token(self):
print (CRED+'Enter Tesla access code:'+CEND)
return str_input()
def dialog_refresh_token(self):
print (CRED+'Enter Tesla refresh code:'+CEND)
return str_input()
def generate_challenge(self,verifier):
return base64urlencode(sha256(verifier).hexdigest())
def perform_login(self):
session = requests.Session()
state = random_string(12)
code_verifier = random_string(86).encode('utf-8')
code_challenge = self.generate_challenge(code_verifier)
#----------------------------#
# STEP 1: Get the login page #
#----------------------------#
query = {
"client_id" : "ownerapi",
"code_challenge" : code_challenge,
"code_challenge_method" : "S256",
"redirect_uri" : "https://auth.tesla.com/void/callback",
"response_type" : "code",
"scope" : "openid email offline_access",
"state" : state }
response = session.get("https://auth.tesla.com/oauth2/v3/authorize", params=query, headers=self.headers)
if not response.status_code == requests.codes.ok:
raise Exception('Loginpage not available. Please try again later.')
#--------------------------------------#
# STEP 2: Obtain an authorization code #
#--------------------------------------#
email = self.dialog_username()
password = self.dialog_password()
csrf = re.search(r'name="_csrf".+value="([^"]+)"', response.text).group(1)
transaction_id = re.search(r'name="transaction_id".+value="([^"]+)"', response.text).group(1)
captchacode = ""
#-------------------#
# STEP 2a: Captcha #
#-------------------#
if (response.content.find(b'captcha') > 0):
img = session.get("https://auth.tesla.com/captcha", headers=self.headers)
cap_file = open("/tmp/captcha.svg","wb")
cap_file.write(img.content)
cap_file.close()
captchacode = self.dialog_captcha()
formdata = {
"_csrf" : csrf,
"_phase" : "authenticate",
"_process" : "1",
"transaction_id" : transaction_id,
"cancel" : "",
"identity" : email,
"credential" : password,
"captcha" : captchacode }
response = session.post("https://auth.tesla.com/oauth2/v3/authorize", params=query, data=formdata, headers=self.headers, allow_redirects=False)
password = ''
if response.status_code == 401:
raise Exception('Authentication failed: wrong username or password')
password = ''
if response.status_code == 401:
raise Exception('Authentication failed: wrong username or password')
#--------------------------------------#
# STEP 2b: Multi-Factor authentication #
#--------------------------------------#
is_mfa = True if response.status_code == 200 and "/mfa/verify" in response.text else False
if is_mfa:
# Get MFA Factor
response = session.get("https://auth.tesla.com/oauth2/v3/authorize/mfa/factors?transaction_id="+transaction_id, headers=self.headers)
factor_id = response.json()["data"][0]["id"]
# Request MFA code from user
mfa_code = self.dialog_mfa()
# Perform MFA authentication
mfa_data = {"transaction_id": transaction_id, "factor_id": factor_id, "passcode": mfa_code}
response = session.post("https://auth.tesla.com/oauth2/v3/authorize/mfa/verify", json=mfa_data)
if "error" in response.text or not response.json()["data"]["approved"] or not response.json()["data"]["valid"]:
raise Exception('Authentication failed: wrong MFA code')
mfa_data = {"transaction_id": transaction_id}
response = session.post("https://auth.tesla.com/oauth2/v3/authorize",params=query, data=mfa_data, headers=self.headers, allow_redirects=False)
if not response.headers.get("location"):
#print response.headers
#raise Exception('Unable to log in at this time. Please try again later.')
print ("")
print ("Tesla is now requiring you to solve a reCaptcha puzzle. We are working on implementing support.")
print ("In the meanwhile, please generate a Tesla access token using:")
print ("")
print (" https://github.com/adriankumpf/tesla_auth")
print ("")
print ("Input the Tesla access token below to continue.")
print ("")
access_token = self.dialog_access_token()
refresh_token = self.dialog_refresh_token()
print ("")
print ("Manually setting the access and refresh codes in MacOS Keychain.")
print ("")
self.override_credentials(access_token,refresh_token)
return
auth_code = parse_qs(response.headers["location"])["https://auth.tesla.com/void/callback?code"]
#---------------------------------------------#
# STEP 3: Exchange auth code for bearer token #
#---------------------------------------------#
payload = {
"grant_type" : "authorization_code",
"client_id" : "ownerapi",
"code" : auth_code,
"code_verifier" : code_verifier,
"redirect_uri" : "https://auth.tesla.com/void/callback" }
response = session.post("https://auth.tesla.com/oauth2/v3/token", json=payload, headers=self.headers)
resp_json = response.json()
refresh_token = resp_json["refresh_token"]
bearer_token = resp_json["access_token"]
#------------------------------------------------#
# STEP 4: Exchange bearer token for access token #
#------------------------------------------------#
self.headers["authorization"] = "bearer " + bearer_token
payload = {
"grant_type" : "urn:ietf:params:oauth:grant-type:jwt-bearer",
"client_id" : self.client['id'],
"client_secret" : self.client['secret'] }
response = session.post("https://owner-api.teslamotors.com/oauth/token", json=payload, headers=self.headers)
self.credentials = response.json()
self.save_credentials()
def load_credentials(self):
self.credentials = {
"access_token" : keyring.get_password("mytesla-xbar","access_token"),
#"expires_in" : keyring.get_password("mytesla-xbar","expires_in"),
"refresh_token" : keyring.get_password("mytesla-xbar","refresh_token"),
"token_type" : "bearer" }
def save_credentials(self):
#created_at = int(time.mktime(datetime.now().timetuple()))
keyring.set_password("mytesla-xbar","access_token",self.credentials["access_token"])
#keyring.set_password("mytesla-xbar","expires_in",self.credentials["expires_in"])
keyring.set_password("mytesla-xbar","refresh_token",self.credentials["refresh_token"])
#keyring.set_password("mytesla-xbar","created_at",created_at)
def override_credentials(self,access_token,refresh_token):
#created_at = int(time.mktime(datetime.now().timetuple()))
#expires_in = int(28800)
keyring.set_password("mytesla-xbar","access_token",access_token)
#keyring.set_password("mytesla-xbar","expires_in",expires_in)
keyring.set_password("mytesla-xbar","refresh_token",refresh_token)
#keyring.set_password("mytesla-xbar","created_at",created_at)
def refresh_credentials(self):
payload = {
"grant_type" : "refresh_token",
"client_id" : "ownerapi",
"client_secret" : self.client["secret"],
"refresh_token" : self.credentials["refresh_token"],
"scope" : "openid email offline_access" }
session = requests.Session()
response = session.post("https://auth.tesla.com/oauth2/v3/token", json=payload, headers=self.headers)
self.credentials = response.json()
self.save_credentials()