|
|
|
|
// Please see documentation at https://docs.microsoft.com/aspnet/core/client-side/bundling-and-minification
|
|
|
|
|
// for details on configuring this project to bundle and minify static web assets.
|
|
|
|
|
|
|
|
|
|
// Write your JavaScript code.
|
|
|
|
|
$(function () {
|
|
|
|
|
if ($("#login_card").length == 0) {
|
|
|
|
|
runAjaxTimer();
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
$(window).focus(function() {
|
|
|
|
|
if ($("#login_card").length == 0) {
|
|
|
|
|
runAjax();
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
function runAjax() {
|
|
|
|
|
if (window.document.hasFocus()) {
|
|
|
|
|
$.ajax({
|
|
|
|
|
type: "GET",
|
|
|
|
|
url: "/Index?handler=JsonData",
|
|
|
|
|
contentType: "application/json",
|
|
|
|
|
dataType: "json",
|
|
|
|
|
success: function (response) {
|
|
|
|
|
$("#json_data").val(response).change();
|
|
|
|
|
},
|
|
|
|
|
failure: function (response) {
|
|
|
|
|
alert(response);
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function runAjaxTimer() {
|
|
|
|
|
runAjax();
|
|
|
|
|
setTimeout(runAjaxTimer, 150000);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
$("#json_data").change(function () {
|
|
|
|
|
var jsonData = JSON.parse($("#json_data").val());
|
|
|
|
|
console.log(jsonData);
|
|
|
|
|
$("#vehicle_name").html(jsonData.display_name);
|
|
|
|
|
$("#vehicle_vin").html(jsonData.vin);
|
|
|
|
|
$("#battery_level").html(jsonData.charge_state.battery_level);
|
|
|
|
|
$("#battery_range").html(jsonData.charge_state.battery_range);
|
|
|
|
|
$("#range_units").html(jsonData.gui_settings.gui_distance_units.includes("mi") ? " mi" : " km");
|
|
|
|
|
$("#locate_vehicle_btn").attr("href", "https://whoogle.nmare.net/search?q=" + jsonData.drive_state.latitude + "," + jsonData.drive_state.longitude);
|
|
|
|
|
$("#climate_status").html(jsonData.climate_state.is_climate_on.includes("true") ? "On" : "Off");
|
|
|
|
|
$("#outside_temp").html(jsonData.climate_state.outside_temp);
|
|
|
|
|
$("#inside_temp").html(jsonData.climate_state.inside_temp);
|
|
|
|
|
$("#climate_setting").val(jsonData.climate_state.driver_temp_setting)
|
|
|
|
|
$(".temp_units").html(jsonData.gui_settings.gui_temperature_units);
|
|
|
|
|
if (jsonData.vehicle_state.locked == "true") {
|
|
|
|
|
$("#lock_unlock_btn").html("Unlock")
|
|
|
|
|
$("#lock_unlock_btn").attr("href", "/?handler=Command&command=door_unlock")
|
|
|
|
|
}
|
|
|
|
|
if (!jsonData.charge_state.charging_state.includes("Disconnected")) {
|
|
|
|
|
$("#charge_state_card").css("display", "flex");
|
|
|
|
|
$("#connected_cable").html(jsonData.charge_state.conn_charge_cable);
|
|
|
|
|
if (jsonData.charge_state.minutes_to_full_charge != 0) {
|
|
|
|
|
$("#till_full").css("display", "block");
|
|
|
|
|
minTillFull = jsonData.charge_state.minutes_to_full_charge;
|
|
|
|
|
hoursTillFull = Math.trunc(minTillFull / 60);
|
|
|
|
|
minTillFull = minTillFull % 60
|
|
|
|
|
timeTillFullOutput = "";
|
|
|
|
|
if (hoursTillFull >= 1) {
|
|
|
|
|
timeTillFullOutput += hoursTillFull + "h";
|
|
|
|
|
}
|
|
|
|
|
if (minTillFull >= 1) {
|
|
|
|
|
timeTillFullOutput += minTillFull + "m";
|
|
|
|
|
}
|
|
|
|
|
$("#time_to_full").html(timeTillFullOutput);
|
|
|
|
|
$("#charge_ctrl_btn").html("Stop Charging")
|
|
|
|
|
$("#charge_ctrl_btn").attr("href", "/?handler=Command&command=charge_stop");
|
|
|
|
|
} else {
|
|
|
|
|
$("#charge_ctrl_btn").html("Start Charging")
|
|
|
|
|
$("#charge_ctrl_btn").attr("href", "/?handler=Command&command=charge_start");
|
|
|
|
|
}
|
|
|
|
|
$("#current_current").html((jsonData.charge_state.charger_voltage * jsonData.charge_state.charger_actual_current) / 1000);
|
|
|
|
|
if (jsonData.charge_state.fast_charger_brand.includes("Tesla")) {
|
|
|
|
|
$("#connection_ind").html("Supercharging")
|
|
|
|
|
} else {
|
|
|
|
|
$("#connection_ind").html(jsonData.charge_state.charging_state)
|
|
|
|
|
}
|
|
|
|
|
if (jsonData.climate_state.is_preconditioning == "true") {
|
|
|
|
|
$("#climate_btn").html("Stop Climate");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
$(".card-deck").css("display", "flex");
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
function runClimate() {
|
|
|
|
|
var jsonData = JSON.parse($("#json_data").val());
|
|
|
|
|
climateTemp = $("#climate_setting").val();
|
|
|
|
|
|
|
|
|
|
if (jsonData.gui_settings.gui_temperature_units == "F") {
|
|
|
|
|
climateTemp = (climateTemp * 1.8) + 32;
|
|
|
|
|
}
|
|
|
|
|
if (climateTemp > jsonData.climate_state.max_avail_temp || climateTemp < jsonData.climate_state.min_avail_temp) {
|
|
|
|
|
alert("Invalid temperature setting.");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
if (jsonData.climate_state.is_preconditioning == "true") {
|
|
|
|
|
window.location.href = "/?handler=Command&command=auto_conditioning_stop&climateTemp=" + climateTemp;
|
|
|
|
|
} else {
|
|
|
|
|
window.location.href = "/?handler=Command&command=auto_conditioning_start&climateTemp=" + climateTemp;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|