From 2f08872c25ec3b9f9aaaef8409072ec148596313 Mon Sep 17 00:00:00 2001 From: markse Date: Thu, 15 Nov 2018 11:53:48 -0800 Subject: [PATCH] published to npm --- TeslaJS.min.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/TeslaJS.min.js b/TeslaJS.min.js index 62800f7..dbc4940 100644 --- a/TeslaJS.min.js +++ b/TeslaJS.min.js @@ -10,4 +10,4 @@ * * Refer to included LICENSE file for usage rights and restrictions */ -"use strict";function log(e,o){logLevelt&&(e=t),e}function get_command(e,o,t){log(API_CALL_LEVEL,"GET call: "+o+" start."),t=t||function(e,o){};var n={method:"GET",url:portalBaseURI+"/api/1/vehicles/"+e.vehicleID+"/"+o,headers:{Authorization:"Bearer "+e.authToken,"Content-Type":"application/json; charset=utf-8"}};log(API_REQUEST_LEVEL,"\nRequest: "+JSON.stringify(n)),request(n,function(e,n,s){if(e)return log(API_ERR_LEVEL,e),t(e,null);if(200!=n.statusCode){var r="Error response: "+n.statusCode;return log(API_ERR_LEVEL,r),t(r,null)}log(API_BODY_LEVEL,"\nBody: "+JSON.stringify(s)),log(API_RESPONSE_LEVEL,"\nResponse: "+JSON.stringify(n));try{s=s.response,t(null,s)}catch(e){log(API_ERR_LEVEL,"Error parsing GET call response"),t(e,null)}log(API_RETURN_LEVEL,"\nGET request: "+o+" completed.")})}function post_command(e,o,t,n){log(API_CALL_LEVEL,"POST call: "+o+" start."),n=n||function(e,o){};var s={method:"POST",url:portalBaseURI+"/api/1/vehicles/"+e.vehicleID+"/"+o,headers:{Authorization:"Bearer "+e.authToken,"content-type":"application/json; charset=UTF-8"},body:t||null};log(API_REQUEST_LEVEL,"\nRequest: "+JSON.stringify(s)),request(s,function(e,t,s){if(e)return log(API_ERR_LEVEL,e),n(e,null);if(200!=t.statusCode){var r="Error response: "+t.statusCode;return log(API_ERR_LEVEL,r),n(r,null)}log(API_BODY_LEVEL,"\nBody: "+JSON.stringify(s)),log(API_RESPONSE_LEVEL,"\nResponse: "+JSON.stringify(t));try{s=s.response,n(null,s)}catch(e){log(API_ERR_LEVEL,"Error parsing POST call response"),n(e,null)}log(API_RETURN_LEVEL,"\nPOST command: "+o+" completed.")})}var request=require("request").defaults({headers:{"x-tesla-user-agent":"TeslaApp/3.4.4-350/fad4a582e/android/8.1.0","user-agent":"Mozilla/5.0 (Linux; Android 8.1.0; Pixel XL Build/OPM4.171019.021.D1; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/68.0.3440.91 Mobile Safari/537.36"},json:!0,gzip:!0,body:{}}),Promise=require("promise"),streamingPortal="https://streaming.vn.teslamotors.com/stream";exports.streamingPortal=streamingPortal;var streamingBaseURI=process.env.TESLAJS_STREAMING||streamingPortal,portal="https://owner-api.teslamotors.com";exports.portal=portal;var portalBaseURI=process.env.TESLAJS_SERVER||portal,API_LOG_ALWAYS=0;exports.API_LOG_ALWAYS=API_LOG_ALWAYS;var API_ERR_LEVEL=1;exports.API_ERR_LEVEL=API_ERR_LEVEL;var API_CALL_LEVEL=2;exports.API_CALL_LEVEL=API_CALL_LEVEL;var API_RETURN_LEVEL=3;exports.API_RETURN_LEVEL=API_RETURN_LEVEL;var API_BODY_LEVEL=4;exports.API_BODY_LEVEL=API_BODY_LEVEL;var API_REQUEST_LEVEL=5;exports.API_REQUEST_LEVEL=API_REQUEST_LEVEL;var API_RESPONSE_LEVEL=6;exports.API_RESPONSE_LEVEL=API_RESPONSE_LEVEL;var API_LOG_ALL=255;exports.API_LOG_ALL=API_LOG_ALL;var logLevel=process.env.TESLAJS_LOG||0;exports.setLogLevel=function(e){logLevel=e},exports.getLogLevel=function(){return logLevel},exports.setPortalBaseURI=function(e){portalBaseURI=e||portal},exports.getPortalBaseURI=function(){return portalBaseURI},exports.setStreamingBaseURI=function(e){streamingBaseURI=e||streamingPortal},exports.getStreamingBaseURI=function(){return streamingBaseURI},exports.getModel=function(e){return-1!=e.option_codes.indexOf("MDLX")?"Model X":-1!=e.option_codes.indexOf("MDL3")?"Model 3":"Model S"},exports.getPaintColor=function(e){return{PBCW:"white",PBSB:"black",PMAB:"metallic brown",PMBL:"metallic black",PMMB:"metallic blue",PMMR:"multi-coat red",PPMR:"multi-coat red",PMNG:"steel grey",PMSG:"metallic green",PMSS:"metallic silver",PPSB:"ocean blue",PPSR:"signature red",PPSW:"pearl white",PPTI:"titanium",PMTG:"metallic grey"}[e.option_codes.match(/PBCW|PBSB|PMAB|PMBL|PMMB|PMMR|PPMR|PMNG|PMSG|PMSS|PPSB|PPSR|PPSW|PPTI|PMTG/)]||"black"},exports.getVin=function(e){if(!e||!e.vin)throw new Error("invalid parameter");return e.vin},exports.getShortVin=function(e){if(!e||!e.vin)throw new Error("invalid parameter");return e.vin.substr(11)},exports.login=function(e,o,t){if(log(API_CALL_LEVEL,"TeslaJS.login()"),t=t||function(e,o){},!e||!o)return void t("login() requires username and password",null);var n={method:"POST",url:portalBaseURI+"/oauth/token",body:{grant_type:"password",client_id:c_id,client_secret:c_sec,email:process.env.TESLAJS_USER||e,password:process.env.TESLAJS_PASS||o}};log(API_REQUEST_LEVEL,"\nRequest: "+JSON.stringify(n)),request(n,function(e,o,n){log(API_RESPONSE_LEVEL,"\nResponse: "+n);var s=n;t(e,{error:e,response:o,body:JSON.stringify(n),authToken:s.access_token,refreshToken:s.refresh_token}),log(API_RETURN_LEVEL,"TeslaJS.login() completed.")})},exports.loginAsync=Promise.denodeify(exports.login),exports.refreshToken=function(e,o){if(log(API_CALL_LEVEL,"TeslaJS.refreshToken()"),o=o||function(e,o){},!e)return void o("refreshToken() requires a refresh_token",null);var t={method:"POST",url:portalBaseURI+"/oauth/token",body:{grant_type:"refresh_token",client_id:c_id,client_secret:c_sec,refresh_token:e}};log(API_REQUEST_LEVEL,"\nRequest: "+JSON.stringify(t)),request(t,function(e,t,n){log(API_RESPONSE_LEVEL,"\nResponse: "+n),o(e,{error:e,response:t,body:JSON.stringify(n),authToken:n.access_token,refreshToken:n.refresh_token}),log(API_RETURN_LEVEL,"TeslaJS.refreshToken() completed.")})},exports.refreshTokenAsync=Promise.denodeify(exports.refreshToken),exports.logout=function(e,o){log(API_CALL_LEVEL,"TeslaJS.logout()"),o=o||function(e,o){},request({method:"POST",url:portalBaseURI+"/oauth/revoke",headers:{Authorization:"Bearer "+e,"Content-Type":"application/json; charset=utf-8"}},function(e,t,n){o(e,{error:e,response:t,body:JSON.stringify(n)}),log(API_RETURN_LEVEL,"TeslaJS.logout() completed.")})},exports.logoutAsync=Promise.denodeify(exports.logout),exports.vehicles=function(e,o){log(API_CALL_LEVEL,"TeslaJS.vehicles()"),o=o||function(e,o){};var t={method:"GET",url:portalBaseURI+"/api/1/vehicles",headers:{Authorization:"Bearer "+e.authToken,"Content-Type":"application/json; charset=utf-8"}};log(API_REQUEST_LEVEL,"\nRequest: "+JSON.stringify(t)),request(t,function(t,n,s){if(t)return log(API_ERR_LEVEL,t),o(t,null);if(200!=n.statusCode)return o(n.statusMessage,null);log(API_BODY_LEVEL,"\nBody: "+JSON.stringify(s)),log(API_RESPONSE_LEVEL,"\nResponse: "+JSON.stringify(n));try{s=s.response[e.carIndex||0],s.id=s.id_s,e.vehicleID=s.id,o(null,s)}catch(e){log(API_ERR_LEVEL,"Error parsing vehicles response"),o(e,null)}log(API_RETURN_LEVEL,"\nGET request: /vehicles completed.")})},exports.vehicle=exports.vehicles,exports.vehicleAsync=Promise.denodeify(exports.vehicles),exports.vehiclesAsync=Promise.denodeify(exports.vehicles),exports.allVehicles=function(e,o){log(API_CALL_LEVEL,"TeslaJS.allVehicles()"),o=o||function(e,o){};var t={method:"GET",url:portalBaseURI+"/api/1/vehicles",headers:{Authorization:"Bearer "+e.authToken,"Content-Type":"application/json; charset=utf-8"}};log(API_REQUEST_LEVEL,"\nRequest: "+JSON.stringify(t)),request(t,function(e,t,n){if(e)return log(API_ERR_LEVEL,e),o(e,null);if(200!=t.statusCode)return o(t.statusMessage,null);log(API_BODY_LEVEL,"\nBody: "+JSON.stringify(n)),log(API_RESPONSE_LEVEL,"\nResponse: "+JSON.stringify(t));try{n=n.response,o(null,n)}catch(e){log(API_ERR_LEVEL,"Error parsing vehicles response"),o(e,null)}log(API_RETURN_LEVEL,"\nGET request: /vehicles completed.")})},exports.allVehiclesAsync=Promise.denodeify(exports.allVehicles),exports.get_command=get_command,exports.get_commandAsync=Promise.denodeify(exports.get_command),exports.post_command=post_command,exports.post_commandAsync=Promise.denodeify(exports.post_command),exports.vehicleData=function(e,o){get_command(e,"data",o)},exports.vehicleDataAsync=Promise.denodeify(exports.vehicleData),exports.vehicleConfig=function(e,o){get_command(e,"data_request/vehicle_config",o)},exports.vehicleConfigAsync=Promise.denodeify(exports.vehicleConfig),exports.vehicleState=function(e,o){get_command(e,"data_request/vehicle_state",o)},exports.vehicleStateAsync=Promise.denodeify(exports.vehicleState),exports.climateState=function(e,o){get_command(e,"data_request/climate_state",o)},exports.climateStateAsync=Promise.denodeify(exports.climateState),exports.driveState=function(e,o){get_command(e,"data_request/drive_state",o)},exports.driveStateAsync=Promise.denodeify(exports.driveState),exports.chargeState=function(e,o){get_command(e,"data_request/charge_state",o)},exports.chargeStateAsync=Promise.denodeify(exports.chargeState),exports.guiSettings=function(e,o){get_command(e,"data_request/gui_settings",o)},exports.guiSettingsAsync=Promise.denodeify(exports.guiSettings),exports.mobileEnabled=function(e,o){get_command(e,"mobile_enabled",o)},exports.mobileEnabledAsync=Promise.denodeify(exports.mobileEnabled),exports.honkHorn=function(e,o){post_command(e,"command/honk_horn",null,o)},exports.honkHornAsync=Promise.denodeify(exports.honkHorn),exports.flashLights=function(e,o){post_command(e,"command/flash_lights",null,o)},exports.flashLightsAsync=Promise.denodeify(exports.flashLights),exports.startCharge=function(e,o){post_command(e,"command/charge_start",null,o)},exports.startChargeAsync=Promise.denodeify(exports.startCharge),exports.stopCharge=function(e,o){post_command(e,"command/charge_stop",null,o)},exports.stopChargeAsync=Promise.denodeify(exports.stopCharge),exports.openChargePort=function(e,o){post_command(e,"command/charge_port_door_open",null,o)},exports.openChargePortAsync=Promise.denodeify(exports.openChargePort),exports.closeChargePort=function(e,o){post_command(e,"command/charge_port_door_close",null,o)},exports.closeChargePortAsync=Promise.denodeify(exports.closeChargePort),exports.scheduleSoftwareUpdate=function(e,o,t){post_command(e,"command/schedule_software_update",{offset_sec:o},t)},exports.scheduleSoftwareUpdateAsync=Promise.denodeify(exports.scheduleSoftwareUpdate),exports.cancelSoftwareUpdate=function(e,o){post_command(e,"command/cancel_software_update",null,o)},exports.cancelSoftwareUpdateAsync=Promise.denodeify(exports.cancelSoftwareUpdate),exports.navigationRequest=function(e,o,t,n,s){post_command(e,"command/navigation_request",{type:"share_ext_content_raw",value:{"android.intent.ACTION":"android.intent.action.SEND","android.intent.TYPE":"text/plain","android.intent.extra.SUBJECT":o,"android.intent.extra.TEXT":t},locale:n,timestamp_ms:Date.now()},s)},exports.navigationRequestAsync=Promise.denodeify(exports.navigationRequest),exports.mediaTogglePlayback=function(e,o){post_command(e,"command/media_toggle_playback",null,o)},exports.mediaTogglePlaybackAsync=Promise.denodeify(exports.mediaTogglePlayback),exports.mediaPlayNext=function(e,o){post_command(e,"command/media_next_track",null,o)},exports.mediaPlayNextAsync=Promise.denodeify(exports.mediaPlayNext),exports.mediaPlayPrevious=function(e,o){post_command(e,"command/media_prev_track",null,o)},exports.mediaPlayPreviousAsync=Promise.denodeify(exports.mediaPlayPrevious),exports.mediaPlayNextFavorite=function(e,o){post_command(e,"command/media_next_fav",null,o)},exports.mediaPlayNextFavoriteAsync=Promise.denodeify(exports.mediaPlayNextFavorite),exports.mediaPlayPreviousFavorite=function(e,o){post_command(e,"command/media_prev_fav",null,o)},exports.mediaPlayPreviousFavoriteAsync=Promise.denodeify(exports.mediaPlayPreviousFavorite),exports.mediaVolumeUp=function(e,o){post_command(e,"command/media_volume_up",null,o)},exports.mediaVolumeUpAsync=Promise.denodeify(exports.mediaVolumeUp),exports.mediaVolumeDown=function(e,o){post_command(e,"command/media_volume_down",null,o)},exports.mediaVolumeDownAsync=Promise.denodeify(exports.mediaVolumeDown),exports.speedLimitActivate=function(e,o,t){post_command(e,"command/speed_limit_activate",{pin:o},t)},exports.speedLimitActivateAsync=Promise.denodeify(exports.speedLimitActivate),exports.speedLimitDeactivate=function(e,o,t){post_command(e,"command/speed_limit_deactivate",{pin:o},t)},exports.speedLimitDeactivateAsync=Promise.denodeify(exports.speedLimitDeactivate),exports.speedLimitClearPin=function(e,o,t){post_command(e,"command/speed_limit_clear_pin",{pin:o},t)},exports.speedLimitClearPinAsync=Promise.denodeify(exports.speedLimitClearPin),exports.speedLimitSetLimit=function(e,o,t){post_command(e,"command/speed_limit_set_limit",{limit_mph:o},t)},exports.speedLimitSetLimitAsync=Promise.denodeify(exports.speedLimitSetLimit),exports.CHARGE_STORAGE=50,exports.CHARGE_DAILY=70,exports.CHARGE_STANDARD=90,exports.CHARGE_RANGE=100,exports.setChargeLimit=function(e,o,t){o=clamp(o,exports.CHARGE_STANDARD,exports.CHARGE_RANGE),post_command(e,"command/set_charge_limit",{percent:o},t)},exports.setChargeLimitAsync=Promise.denodeify(exports.setChargeLimit),exports.chargeStandard=function(e,o){post_command(e,"command/charge_standard",null,o)},exports.chargeStandardAsync=Promise.denodeify(exports.chargeStandard),exports.chargeMaxRange=function(e,o){post_command(e,"command/charge_max_range",null,o)},exports.chargeMaxRangeAsync=Promise.denodeify(exports.chargeMaxRange),exports.doorLock=function(e,o){post_command(e,"command/door_lock",null,o)},exports.doorLockAsync=Promise.denodeify(exports.doorLock),exports.doorUnlock=function(e,o){post_command(e,"command/door_unlock",null,o)},exports.doorUnlockAsync=Promise.denodeify(exports.doorUnlock),exports.climateStart=function(e,o){post_command(e,"command/auto_conditioning_start",null,o)},exports.climateStartAsync=Promise.denodeify(exports.climateStart),exports.climateStop=function(e,o){post_command(e,"command/auto_conditioning_stop",null,o)},exports.climateStopAsync=Promise.denodeify(exports.climateStop),exports.SUNROOF_VENT="vent",exports.SUNROOF_CLOSED="close",exports.sunRoofControl=function(e,o,t){post_command(e,"command/sun_roof_control",{state:o},t)},exports.sunRoofControlAsync=Promise.denodeify(exports.sunRoofControl),exports.sunRoofMove=function(e,o,t){post_command(e,"command/sun_roof_control",{state:"move",percent:o},t)},exports.sunRoofMoveAsync=Promise.denodeify(exports.sunRoofMove),exports.MIN_TEMP=15,exports.MAX_TEMP=28,exports.setTemps=function(e,o,t,n){void 0===t&&(t=o),o=clamp(o,exports.MIN_TEMP,exports.MAX_TEMP),t=clamp(t,exports.MIN_TEMP,exports.MAX_TEMP),post_command(e,"command/set_temps",{driver_temp:o,passenger_temp:t},n)},exports.setTempsAsync=Promise.denodeify(exports.setTemps),exports.remoteStart=function(e,o,t){post_command(e,"command/remote_start_drive",{password:o},t)},exports.remoteStartAsync=Promise.denodeify(exports.remoteStart),exports.FRUNK="front",exports.TRUNK="rear",exports.openTrunk=function(e,o,t){post_command(e,"command/actuate_trunk",{which_trunk:o},t)},exports.openTrunkAsync=Promise.denodeify(exports.openTrunk),exports.wakeUp=function(e,o){post_command(e,"wake_up",null,o)},exports.wakeUpAsync=Promise.denodeify(exports.wakeUp),exports.setValetMode=function(e,o,t,n){post_command(e,"command/set_valet_mode",{on:o,password:t},n)},exports.setValetModeAsync=Promise.denodeify(exports.setValetMode),exports.resetValetPin=function(e,o){post_command(e,"command/reset_valet_pin",null,o)},exports.resetValetPinAsync=Promise.denodeify(exports.resetValetPin),exports.calendar=function(e,o,t){post_command(e,"command/upcoming_calendar_entries",o,t)},exports.calendarAsync=Promise.denodeify(exports.calendar),exports.makeCalendarEntry=function(e,o,t,n,s,r){return{calendar_data:{access_disabled:!1,calendars:[{color:"ff9a9cff",events:[{allday:!1,color:"ff9a9cff",end:n||(new Date).getTime(),start:t||(new Date).getTime(),cancelled:!1,tentative:!1,location:o||"",name:e||"Event name",organizer:""}],name:s||""}],phone_name:r,uuid:"333239059961778"}}},exports.homelink=function(e,o,t,n,s){post_command(e,"command/trigger_homelink",{lat:o,long:t,token:n},s)},exports.homelinkAsync=Promise.denodeify(exports.homelink),exports.streamingColumns=["elevation","est_heading","est_lat","est_lng","est_range","heading","odometer","power","range","shift_state","speed","soc"],exports.startStreaming=function(e,o,t){log(API_CALL_LEVEL,"TeslaJS.startStreaming()"),o=o||function(e,o,t){},t=t||function(e){},e.values=e.values||exports.streamingColumns;var n={method:"GET",url:streamingBaseURI+"/"+e.vehicle_id+"/?values="+e.values.join(","),auth:{username:e.username,password:e.password}};log(API_REQUEST_LEVEL,"\nRequest: "+JSON.stringify(n)),request(n,o).on("data",function(e){t(e.toString())})};var _0x2dc0=["e4a9949fcfa04068f59abb5a658f2bac0a3428e4652315490b659d5ab3f35a9e","c75f14bbadc8bee3a7594412c31416f8300256d7668ea7e6e7f06727bfb9d220"],c_id=_0x2dc0[0],c_sec=_0x2dc0[1]; \ No newline at end of file +"use strict";var request=require("request").defaults({headers:{"x-tesla-user-agent":"TeslaApp/3.4.4-350/fad4a582e/android/8.1.0","user-agent":"Mozilla/5.0 (Linux; Android 8.1.0; Pixel XL Build/OPM4.171019.021.D1; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/68.0.3440.91 Mobile Safari/537.36"},json:!0,gzip:!0,body:{}}),Promise=require("promise"),streamingPortal="https://streaming.vn.teslamotors.com/stream";exports.streamingPortal=streamingPortal;var streamingBaseURI=process.env.TESLAJS_STREAMING||streamingPortal,portal="https://owner-api.teslamotors.com";exports.portal=portal;var portalBaseURI=process.env.TESLAJS_SERVER||portal,API_LOG_ALWAYS=0;exports.API_LOG_ALWAYS=API_LOG_ALWAYS;var API_ERR_LEVEL=1;exports.API_ERR_LEVEL=API_ERR_LEVEL;var API_CALL_LEVEL=2;exports.API_CALL_LEVEL=API_CALL_LEVEL;var API_RETURN_LEVEL=3;exports.API_RETURN_LEVEL=API_RETURN_LEVEL;var API_BODY_LEVEL=4;exports.API_BODY_LEVEL=API_BODY_LEVEL;var API_REQUEST_LEVEL=5;exports.API_REQUEST_LEVEL=API_REQUEST_LEVEL;var API_RESPONSE_LEVEL=6;exports.API_RESPONSE_LEVEL=API_RESPONSE_LEVEL;var API_LOG_ALL=255;exports.API_LOG_ALL=API_LOG_ALL;var logLevel=process.env.TESLAJS_LOG||0;function log(e,o){logLevel