Fixing climate functionality
This commit is contained in:
@ -2,6 +2,7 @@
|
|||||||
@model IndexModel
|
@model IndexModel
|
||||||
@{
|
@{
|
||||||
Model.token = Request.Cookies["Auth"];
|
Model.token = Request.Cookies["Auth"];
|
||||||
|
ViewData["Title"] = "Command";
|
||||||
}
|
}
|
||||||
|
|
||||||
@if (string.IsNullOrEmpty(Model.token))
|
@if (string.IsNullOrEmpty(Model.token))
|
||||||
@ -12,7 +13,8 @@
|
|||||||
Login with Token
|
Login with Token
|
||||||
</div>
|
</div>
|
||||||
<div class="card-body">
|
<div class="card-body">
|
||||||
<p class="card-text">Enter your authorization token below:</p>
|
<p class="card-text">Enter your authorization token below. This token is stored locally, in your browser and
|
||||||
|
not on the NikolaNet Server.</p>
|
||||||
<input asp-for="token" id="token" />
|
<input asp-for="token" id="token" />
|
||||||
</div>
|
</div>
|
||||||
<div class="card-footer">
|
<div class="card-footer">
|
||||||
@ -26,10 +28,12 @@ else
|
|||||||
<div class="card-deck" style="display: none;">
|
<div class="card-deck" style="display: none;">
|
||||||
|
|
||||||
<input id="json_data" type="hidden" value="" />
|
<input id="json_data" type="hidden" value="" />
|
||||||
<div class="card" style="width: 18rem;">
|
<div class="card">
|
||||||
<div class="card-body">
|
<div class="card-header">
|
||||||
<h5 class="card-title" id="vehicle_name">Vehicle Name</h5>
|
<h5 class="card-title" id="vehicle_name">Vehicle Name</h5>
|
||||||
<h6 class="card-subtitle mb-2 text-muted" id="vehicle_vin"></h6>
|
<p class="card-subtitle mb-2 text-muted" id="vehicle_vin"></p>
|
||||||
|
</div>
|
||||||
|
<div class="card-body">
|
||||||
<p class="card-text">Current Battery Status: <a id="battery_level"></a>%</p>
|
<p class="card-text">Current Battery Status: <a id="battery_level"></a>%</p>
|
||||||
<p class="card-text">Range: <a id="battery_range"></a> <a id="range_units"></a></p>
|
<p class="card-text">Range: <a id="battery_range"></a> <a id="range_units"></a></p>
|
||||||
</div>
|
</div>
|
||||||
@ -43,7 +47,7 @@ else
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="card" style="width: 18rem;">
|
<div class="card">
|
||||||
<div class="card-header">
|
<div class="card-header">
|
||||||
Climate
|
Climate
|
||||||
</div>
|
</div>
|
||||||
@ -51,35 +55,47 @@ else
|
|||||||
<p class="card-text">Climate Status: <a id="climate_status"></a></p>
|
<p class="card-text">Climate Status: <a id="climate_status"></a></p>
|
||||||
<p class="card-text">Outside Temp: <a id="outside_temp"></a> <a class="temp_units"></a></p>
|
<p class="card-text">Outside Temp: <a id="outside_temp"></a> <a class="temp_units"></a></p>
|
||||||
<p class="card-text">Inside Temp: <a id="inside_temp"></a> <a class="temp_units"></a></p>
|
<p class="card-text">Inside Temp: <a id="inside_temp"></a> <a class="temp_units"></a></p>
|
||||||
<p class="card-text">Climate Set Temp: <input asp-for="climateTemp" type="number" id="climate_setting" />
|
<p class="card-text">Climate Set Temp: <input asp-for="climateTemp" type="number"
|
||||||
|
id="climate_setting" />
|
||||||
</p>
|
</p>
|
||||||
</div>
|
</div>
|
||||||
<div class="card-footer">
|
<div class="card-footer">
|
||||||
<a href="/?handler=Command&command=@Tesla.BasicCommands.ClimateOn" class="card-link">Start Climate</a>
|
|
||||||
|
<a href="#" id="climate_btn" onclick="runClimate();">Start Climate</a>
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|
||||||
<div class="card" id="charge_state_card" style="width: 18rem; display: none;">
|
<div class="card" id="charge_state_card" style="width: 18rem; display: none;">
|
||||||
<div class="card-header">
|
<div class="card-header">
|
||||||
Charge Status
|
Charge Status
|
||||||
</div>
|
</div>
|
||||||
<div class="card-body">
|
<div class="card-body">
|
||||||
<p class="card-text">Connected Cable: <a id="connected_cable"></a></p>
|
<p class="card-text">Connected Cable: <a id="connected_cable"></a></p>
|
||||||
|
<p class="card-text">Status: <a id="connection_ind"></a></p>
|
||||||
<p class="card-text">Current power: <a id="current_current"></a> kW</p>
|
<p class="card-text">Current power: <a id="current_current"></a> kW</p>
|
||||||
<p id="till_full" class="card-text" style="display: none;">Time till full: <a id="time_to_full"></a></p>
|
<p id="till_full" class="card-text" style="display: none;">Time till full: <a id="time_to_full"></a></p>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="card-footer">
|
<div class="card-footer">
|
||||||
<small class="text-muted" id="connection_ind"></small>
|
|
||||||
<a asp-page-handler="Command" id="charge_ctrl_btn" class="card-link">Stop Charging</a>
|
<a asp-page-handler="Command" id="charge_ctrl_btn" class="card-link">Stop Charging</a>
|
||||||
<a asp-page-handler="Command" id="toggle_charge_port" class="card-link">Unlock Charge Port</a>
|
<a asp-page-handler="Command" id="toggle_charge_port" class="card-link">Unlock Charge Port</a>
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<div class="card" id="driving_card" style="width: 18rem; display: none;">
|
||||||
|
<div class="card-header">
|
||||||
|
Driving Status
|
||||||
|
</div>
|
||||||
|
<div class="card-body">
|
||||||
|
<p class="card-text">Shift State: <a id="drive_state"></a></p>
|
||||||
|
<p class="card-text">Current Speed: <a id="curr_speed"></a></p>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
|
||||||
</div>
|
|
||||||
|
|
||||||
|
</div>
|
||||||
}
|
}
|
||||||
|
|||||||
@ -21,10 +21,6 @@ namespace NikolaNet.Pages
|
|||||||
public string jsonData;
|
public string jsonData;
|
||||||
public string token {get; set;}
|
public string token {get; set;}
|
||||||
public string climateTemp {get; set;}
|
public string climateTemp {get; set;}
|
||||||
public string GetVehicleName()
|
|
||||||
{
|
|
||||||
return VehicleName;
|
|
||||||
}
|
|
||||||
public IndexModel(ILogger<IndexModel> logger)
|
public IndexModel(ILogger<IndexModel> logger)
|
||||||
{
|
{
|
||||||
_logger = logger;
|
_logger = logger;
|
||||||
@ -49,17 +45,18 @@ namespace NikolaNet.Pages
|
|||||||
{
|
{
|
||||||
Client c = setupClient();
|
Client c = setupClient();
|
||||||
if (Request.Query["command"].Equals(BasicCommands.ClimateOn)) {
|
if (Request.Query["command"].Equals(BasicCommands.ClimateOn)) {
|
||||||
//c.RunCommand(ExtendedCommands.SetClimateTemp, $"{{\"driver_temp\": \"{Request.Form["climateTemp"]}\"}}");
|
string parms = $"{{\"driver_temp\": \"{Request.Query["climateTemp"]}\", \"passenger_temp\":\"{Request.Query["climateTemp"]}\"}}";
|
||||||
return;
|
c.RunCommand(ExtendedCommands.SetClimateTemp, parms);
|
||||||
}
|
}
|
||||||
c.RunCommand(Request.Query["command"]);
|
c.RunCommand(Request.Query["command"]);
|
||||||
|
Response.Redirect("/");
|
||||||
|
|
||||||
}
|
}
|
||||||
public void OnGetFrunk() {
|
|
||||||
}
|
|
||||||
public void OnPostSetToken() {
|
public void OnPostSetToken() {
|
||||||
this.token = Request.Form["token"];
|
this.token = Request.Form["token"];
|
||||||
Response.Cookies.Append("Auth", token);
|
Response.Cookies.Append("Auth", token);
|
||||||
|
Response.Redirect("/");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -2,7 +2,7 @@
|
|||||||
// for details on configuring this project to bundle and minify static web assets.
|
// for details on configuring this project to bundle and minify static web assets.
|
||||||
|
|
||||||
// Write your JavaScript code.
|
// Write your JavaScript code.
|
||||||
$(function() {
|
$(function () {
|
||||||
if ($("#login_card").length == 0) {
|
if ($("#login_card").length == 0) {
|
||||||
$.ajax({
|
$.ajax({
|
||||||
type: "GET",
|
type: "GET",
|
||||||
@ -19,7 +19,7 @@ $(function() {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
$("#json_data").change(function() {
|
$("#json_data").change(function () {
|
||||||
var jsonData = JSON.parse($("#json_data").val());
|
var jsonData = JSON.parse($("#json_data").val());
|
||||||
console.log(jsonData);
|
console.log(jsonData);
|
||||||
$("#vehicle_name").html(jsonData.display_name);
|
$("#vehicle_name").html(jsonData.display_name);
|
||||||
@ -29,13 +29,6 @@ $("#json_data").change(function() {
|
|||||||
$("#range_units").html(jsonData.gui_settings.gui_distance_units.includes("mi") ? " mi" : " km");
|
$("#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);
|
$("#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");
|
$("#climate_status").html(jsonData.climate_state.is_climate_on.includes("true") ? "On" : "Off");
|
||||||
/*
|
|
||||||
if (jsonData.gui_settings.gui_temperature_units.includes("F")) {
|
|
||||||
jsonData.climate_state.outside_temp = ((jsonData.climate_state.outside_temp * 1.8) + 32).toFixed(0);
|
|
||||||
jsonData.climate_state.inside_temp = ((jsonData.climate_state.inside_temp * 1.8) + 32).toFixed(0);
|
|
||||||
jsonData.climate_state.driver_temp_setting = ((jsonData.climate_state.driver_temp_setting * 1.8) + 32).toFixed(0);
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
$("#outside_temp").html(jsonData.climate_state.outside_temp);
|
$("#outside_temp").html(jsonData.climate_state.outside_temp);
|
||||||
$("#inside_temp").html(jsonData.climate_state.inside_temp);
|
$("#inside_temp").html(jsonData.climate_state.inside_temp);
|
||||||
$("#climate_setting").val(jsonData.climate_state.driver_temp_setting)
|
$("#climate_setting").val(jsonData.climate_state.driver_temp_setting)
|
||||||
@ -47,21 +40,53 @@ $("#json_data").change(function() {
|
|||||||
if (!jsonData.charge_state.charging_state.includes("Disconnected")) {
|
if (!jsonData.charge_state.charging_state.includes("Disconnected")) {
|
||||||
$("#charge_state_card").css("display", "flex");
|
$("#charge_state_card").css("display", "flex");
|
||||||
$("#connected_cable").html(jsonData.charge_state.conn_charge_cable);
|
$("#connected_cable").html(jsonData.charge_state.conn_charge_cable);
|
||||||
if (jsonData.charge_state.minutes_to_full_charge != 0 ) {
|
if (jsonData.charge_state.minutes_to_full_charge != 0) {
|
||||||
$("#till_full").css("display", "block");
|
$("#till_full").css("display", "block");
|
||||||
$("#time_to_full").html(jsonData.charge_state.minutes_to_full_charge);
|
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").html("Stop Charging")
|
||||||
$("#charge_ctrl_btn").attr("href", "/?handler=Command&command=charge_stop");
|
$("#charge_ctrl_btn").attr("href", "/?handler=Command&command=charge_stop");
|
||||||
} else {
|
} else {
|
||||||
$("#charge_ctrl_btn").html("Start Charging")
|
$("#charge_ctrl_btn").html("Start Charging")
|
||||||
$("#charge_ctrl_btn").attr("href", "/?handler=Command&command=charge_start");
|
$("#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")) {
|
if (jsonData.charge_state.fast_charger_brand.includes("Tesla")) {
|
||||||
$("#connection_ind").html("Supercharging")
|
$("#connection_ind").html("Supercharging")
|
||||||
} else {
|
} else {
|
||||||
$("#connection_ind").html(jsonData.charge_state.charging_state)
|
$("#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");
|
$(".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;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user