Skip to content

Instantly share code, notes, and snippets.

@Kemmey
Created May 31, 2020 07:53
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Kemmey/b18964d42c5617b2247fa7bacbfa2638 to your computer and use it in GitHub Desktop.
Save Kemmey/b18964d42c5617b2247fa7bacbfa2638 to your computer and use it in GitHub Desktop.
Tesla API values to image url - ish
func loadVehicleImage() -> () {
if (!TeslaController.shared().vehicleBackgroundEnabled) {
self.vehicleImage = UIImage()
return
}
//TODO: Currently only show background images for 3 and Y - S and X require more option codes...
if self.vehicleData?.vehicle_config?.car_type == "model3" || self.vehicleData?.vehicle_config?.car_type == "modely"
{
let networking = Networking(baseURL: "https://static-assets.tesla.com")
networking.downloadImage("/v1/compositor/?model=\(carTypeToCode(self.vehicleData?.vehicle_config?.car_type))&view=STUD_3QTR&size=400&bkba_opt=1&options=\(colorNameToCode(self.vehicleData?.vehicle_config?.exterior_color)),\(wheelTypeToCode(self.vehicleData?.vehicle_config?.wheel_type))") { result in
switch result {
case .success(let response):
self.vehicleImage = response.image
break
default:
break
}
}
}
}
func carTypeToCode(_ carType: String?) -> String {
if carType == "model3" { return "m3" }
if carType == "modely" { return "my" }
if carType == "modelx" { return "mx" }
if carType == "models" { return "ms" }
return "m3"
}
func wheelTypeToCode(_ wheelType: String?) -> String {
var wheel: String
switch wheelType {
case "Pinwheel18":
wheel = "W38B"
case "AeroTurbine20": // MODEL X
wheel = "WT20"
case "Sportwheel19", "Stiletto19":
wheel = "W39B"
case "AeroTurbine19":
wheel = "WTAS"
case "Turbine19":
wheel = "WTTB"
case "Arachnid21Grey":
wheel = "WTAB"
// FIXME: Too dark.
case "Performancewheel20", "Stiletto20":
wheel = "W32P"
case "AeroTurbine22":
wheel = "WT22"
case "Super21Gray":
wheel = "WTSG"
default:
wheel = "W38B"
}
return wheel
/*
<optgroup class="my m3" label="18″">
<option class="my" value="WY18B">18″ Aero</option>
<option class="m3" value="W38B">18″ Aero</option>
</optgroup>
<optgroup class="my m3" label="19″">
<option class="my" value="WY19B">19″ Sport</option>
<option class="m3" value="W39B">19″ Sport</option>
<option class="my" value="WY19P">19″ Performance</option>
<option class="m3" value="W39P">19″ Performance</option>
</optgroup>
<optgroup class="my m3" label="20″">
<option class="my" value="WY20P">20″ Performance</option>
<option class="m3" value="W32P">20″ Sport</option>
<option class="m3" value="W32D">20″ Sport Gray Performance</option>
</optgroup>
<optgroup class="td" label="16″/17″">
<option class="rd" value="WHL1">Cast Aluminum</option>
<option class="rd" selected="selected" value="WHL2">Forged Silver</option>
<option class="rd" value="WHL3">Forged Black</option>
</optgroup>
<optgroup class="ms" label="19″">
<option class="ms-2012" value="WT19">Silver Split 5-Spoke</option>
<option class="ms-2012" value="WTAE">Silver Aero</option>
<option value="WTTB">Silver Cyclone</option>
<option class="ms-2012" value="WTGP">Carbon Cyclone</option>
<option value="WTAS">Silver Slipstream</option>
<option class="ms-2016" value="WTDS">Carbon Slipstream</option>
</optgroup>
<optgroup class="mx" label="20″">
<option value="WT20">Silver Slipstream</option>
<option value="WTSC">Carbon Slipstream</option>
<option value="WTHX">Silver Helix</option>
</optgroup>
<optgroup class="ms" label="21″">
<option value="WT21">Silver Turbine</option>
<option value="WTSG">Carbon Turbine</option>
<option class="ms-2016" value="WTTC">Carbon Twin Turbine</option>
<option class="ms-2016" value="WTAB">Black Arachnid</option>
</optgroup>
<optgroup class="mx" label="22″">
<option value="WT22">Silver Turbine</option>
<option value="WTUT">Black Turbine</option>
</optgroup>
<optgroup label="Visual">
<option value="WT00">None</option>
</optgroup>
*/
}
func colorNameToCode(_ colorName: String?) -> String {
var color: String
switch colorName {
case "ObsidianBlack", "SolidBlack", "MetallicBlack":
color = "PMBL"
case "DeepBlueMetallic", "DeepBlue":
color = "PPSB"
case "RedMulticoat", "Red":
color = "PPMR"
case "MidnightSilverMetallic", "MidnightSilver", "SteelGrey", "SilverMetallic":
color = "PMNG"
case "MetallicBrown", "Brown":
color = "PMAB"
case "Silver":
color = "PMSS"
case "TitaniumCopper":
color = "PPTI"
case "DolphinGrey":
color = "PMTG"
case "Green", "MetallicGreen":
color = "PMSG"
case "PearlWhiteMulticoat", "PearlWhite", "Pearl":
color = "PPSW"
case "SolidWhite", "White":
color = "PBCW"
case "SignatureBlue", "MetallicBlue":
color = "PMMB"
case "SignatureRed":
color = "PPSR"
default:
color = "PBSB"
}
return color
/*
label>Paint
<select id="paint">
<optgroup class="ms-2012" label="Signature">
<option value="COL0-PPSR">Red</option>
</optgroup>
<optgroup label="Solid">
<option class="m3 my" value="PBSB">Black</option>
<option class="ms mx" value="COL1-PBSB">Eclipse Black</option>
<option class="ms mx" value="COL1-PBCW">Catalina White</option>
<option class="rd" value="COL1-FURD">Fusion Red</option>
<option class="rd" value="COL1-RAGR">Racing Green</option>
</optgroup>
<optgroup label="Metallic">
<option class="m3 my" value="PPSB">Deep Blue</option>
<option class="m3" value="PMBL">Obsidian Black</option>
<option class="m3 my" value="PMNG">Midnight Silver</option>
<option class="m3" value="PMSS">Starlight Silver</option>
<option class="ms mx" value="COL2-PPSB">Deep Blue</option>
<option class="ms mx" value="COL2-PMBL">Obsidian Black</option>
<option class="ms mx" value="COL2-PMNG">Midnight Silver</option>
<option class="ms mx" value="COL2-PMSS">Starlight Silver</option>
<option class="ms mx" value="COL2-PPTI">Titanium</option>
<option class="ms-2012" value="COL2-PMAB">Anza Brown</option>
<option class="ms-2012" value="COL2-PMTG">Dolphin Gray</option>
<option class="ms-2012" value="COL2-PMMB">Pacific Blue</option>
<option class="ms-2012" value="COL2-PMSG">Sequoia Green</option>
<option class="rd" value="COL2-RARD">Radiant Red</option>
<option class="rd" value="COL2-BRYL">Brilliant Yellow</option>
<option class="rd" value="COL2-GLBL">Glacier Blue</option>
<option class="rd" value="COL2-OBBK">Obsidian Black</option>
<option class="rd" value="COL2-STSL">Sterling Silver</option>
<option class="rd" value="COL2-TWBL">Twilight Blue</option>
</optgroup>
<optgroup class="m3 ms mx my" label="Multi-Coat">
<option class="m3 my" value="PPSW">Pearl White</option>
<option class="m3 my" value="PPMR">Red</option>
<option class="ms mx" value="COL3-PPSW">Pearl White</option>
<option class="ms mx" value="COL3-PPMR">Sunset Red</option>
</optgroup>
<optgroup class="rd" label="Premium">
<option value="COL3-THGR">Thunder Grey</option>
<option value="COL3-VYOR">Very Orange</option>
<option value="COL3-JTBK">Jet Black</option>
<option value="COL3-ELBL">Electric Blue</option>
<option value="COL3-LIGR">Lightning Green</option>
<option value="COL3-ARWH">Arctic White</option>
</optgroup>
</select>
https://damieng.github.io/tesla-preview/?model=ms-2016&view=STUD_3QTR&background=1&flip=n&paint=COL3-PPSW&wheels=WTAS&roof=RFFG&brakes=BC0R&X019=n&drive=DRLH&seats=QTTB,FR04&headliner=UTAB&decor=IDCF&dash=DSH5&extras=#
PPTI: "titanium metallic",
PBSB: "black",
PMBL: "obsidian black",
PBCW: "solid white",
PMSS: "silver",
PMNG: "midnight silver metallic",
PMTG: "dolphin gray metallic",
PMAB: "metallic brown",
PMMB: "metallic blue",
PPSB: "deep metallic blue",
PMSG: "metallic green",
PPSW: "pearl white",
PPMR: "multi-coat red",
PPSR: "signature red",
Wheels model s
WTAS, WTDS and WTSG for 19” silver slipstream, 19” grey slipstream and 21” grey turbine
*/
return "COL3-PPSW"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment