Fixed a bug in the batteryupdate progress

This commit is contained in:
Kim 2023-06-01 11:21:13 +02:00
parent b5fbca3f8d
commit 92f0e400e1
3 changed files with 39 additions and 18 deletions

View File

@ -18,7 +18,7 @@ public record InstallationToHtmlInterface(
String EscapedName, String EscapedName,
String Online, String Online,
String LastSeen, String LastSeen,
Int64 NumBatteries, String NumBatteries,
String BatteryVersion, String BatteryVersion,
String ServerIp = "10.2.0.1", //TODO MAKE ME DYNAMIC String ServerIp = "10.2.0.1", //TODO MAKE ME DYNAMIC
String FirmwareVersion = "AF09" //Todo automatically grab newest version? String FirmwareVersion = "AF09" //Todo automatically grab newest version?
@ -42,7 +42,27 @@ public class Controller : ControllerBase
tbody { tbody {
background-color: #e4f0f5; background-color: #e4f0f5;
} }
tbody tr:nth-child(odd) {
background-color: #ECE9E9;
}
th, td { /* cell */
padding: 0.75rem;
font-size: 0.9375rem;
}
th { /* header cell */
font-weight: 700;
text-align: left;
color: #272838;
border-bottom: 2px solid #EB9486;
position: sticky;
top: 0;
background-color: #F9F8F8;
}
table { table {
border-collapse: collapse; border-collapse: collapse;
width: 100%; width: 100%;
@ -50,16 +70,17 @@ public class Controller : ControllerBase
letter-spacing: 1px; letter-spacing: 1px;
font-family: sans-serif; font-family: sans-serif;
font-size: 0.8rem; font-size: 0.8rem;
position: relative; top: 0; bottom: 0; left: 0; right: 0; position: absolute; top: 0; bottom: 0; left: 0; right: 0;
} }
td, thead th {
th {
border: 1px solid rgb(190, 190, 190); border: 1px solid rgb(190, 190, 190);
padding: 5px 10px; padding: 5px 10px;
position: sticky; position: sticky;
position: -webkit-sticky;
top: 0px; top: 0px;
background: white; background: white;
z-index: 999;
} }
td { td {
@ -82,6 +103,7 @@ public class Controller : ControllerBase
<th>Serial</th> <th>Serial</th>
<th>#Batteries</th> <th>#Batteries</th>
<th>Firmware-Version</th> <th>Firmware-Version</th>
<th>Update</th>
</tr> </tr>
{{#inst}} {{#inst}}
{{> installations}} {{> installations}}
@ -146,7 +168,7 @@ public class Controller : ControllerBase
//We need the DeviceName of the battery (ttyUSB?) //We need the DeviceName of the battery (ttyUSB?)
var pathToBattery = await Db.ExecuteBufferedAsyncCommandOnIp(installationIp, "dbus-send --system --dest=com.victronenergy.system --type=method_call --print-reply /ServiceMapping/com_victronenergy_battery_1 com.victronenergy.BusItem.GetText"); var pathToBattery = await Db.ExecuteBufferedAsyncCommandOnIp(installationIp, "dbus-send --system --dest=com.victronenergy.system --type=method_call --print-reply /ServiceMapping/com_victronenergy_battery_1 com.victronenergy.BusItem.GetText");
if (pathToBattery.Split('"')[1] == "Failed") return "Update failed"; if (pathToBattery.Split('"')[1] == "Failed" || pathToBattery.Split(' ')[0] == "Error") return "Update failed";
SendNewBatteryFirmware(installationIp); SendNewBatteryFirmware(installationIp);
@ -155,7 +177,7 @@ public class Controller : ControllerBase
var batteryTtyName = pathToBattery.Split('"')[1].Split(".").Last(); var batteryTtyName = pathToBattery.Split('"')[1].Split(".").Last();
var localCommand = $"/opt/innovenergy/scripts/upload-bms-firmware {batteryTtyName} {batteryId} /opt/innovenergy/bms-firmware/{FirmwareVersion}.bin"; var localCommand = $"/opt/innovenergy/scripts/upload-bms-firmware {batteryTtyName} {batteryId} /opt/innovenergy/bms-firmware/{FirmwareVersion}.bin";
var remoteUpdateCommandResult = Db.ExecuteBufferedAsyncCommandOnIp(installationIp, localCommand); var remoteUpdateCommandResult = await Db.ExecuteBufferedAsyncCommandOnIp(installationIp, localCommand);
// Console.WriteLine(remoteUpdateCommandResult); // Console.WriteLine(remoteUpdateCommandResult);
} }
return "Battery update is successfully initiated! You can close this page now."; return "Battery update is successfully initiated! You can close this page now.";

View File

@ -6,7 +6,7 @@ namespace InnovEnergy.App.VrmGrabber.DataTypes;
public class Installation public class Installation
{ {
public Installation(String? argName, String? argIp, Int64 argVrm, String? argIdentifier, String? serial, String? urlEncode, String? online, String? lastSeen, String details, Int64 numberOfBatteries, String batteryFirmwareVersion) public Installation(String? argName, String? argIp, Int64 argVrm, String? argIdentifier, String? serial, String? urlEncode, String? online, String? lastSeen, String details, String numberOfBatteries, String batteryFirmwareVersion)
{ {
Name = argName; Name = argName;
Ip = argIp; Ip = argIp;
@ -35,7 +35,7 @@ public class Installation
public String? EscapedName { get; set;} public String? EscapedName { get; set;}
public String? Online { get; set;} public String? Online { get; set;}
public String? LastSeen { get; set;} public String? LastSeen { get; set;}
public Int64 NumberOfBatteries { get; set;} public String? NumberOfBatteries { get; set;}
public String? BatteryFirmwareVersion { get; set;} public String? BatteryFirmwareVersion { get; set;}
public String? Details { get; set; } //JSON public String? Details { get; set; } //JSON

View File

@ -73,7 +73,7 @@ public static partial class Db
var installations = await user.GetInstallations(); var installations = await user.GetInstallations();
// var returnDictionary = new Dictionary<VrmInstallation, InstallationDetails>(); // var returnDictionary = new Dictionary<VrmInstallation, InstallationDetails>();
foreach (var installation in installations) foreach (var installation in installations) //Todo remove Skip
{ {
Console.WriteLine(installation.Name); Console.WriteLine(installation.Name);
var details = await GetInstallationDetails(installation); var details = await GetInstallationDetails(installation);
@ -115,19 +115,20 @@ public static partial class Db
var command = $"dbus-send --system --dest={pathToBattery.Split('"')[1]} --type=method_call --print-reply /FirmwareVersion com.victronenergy.BusItem.GetText"; var command = $"dbus-send --system --dest={pathToBattery.Split('"')[1]} --type=method_call --print-reply /FirmwareVersion com.victronenergy.BusItem.GetText";
var returnString = await ExecuteBufferedAsyncCommandOnIp(ip, command); var returnString = await ExecuteBufferedAsyncCommandOnIp(ip, command);
return returnString.Split('"')[1]; var returnStringShortened = returnString.Split('"')[1];
return returnStringShortened.Length > 5 ? "Unknown" : returnStringShortened;
} }
private static async Task<Int64> NumberOfBatteries(String? ip, String? online) private static async Task<String> NumberOfBatteries(String? ip, String? online)
{ {
if (ip is null or "Unknown" || online == "❌") return 0; if (ip is null or "Unknown" || online == "❌") return "Failed";
var pathToBattery = await ExecuteBufferedAsyncCommandOnIp(ip, "dbus-send --system --dest=com.victronenergy.system --type=method_call --print-reply /ServiceMapping/com_victronenergy_battery_1 com.victronenergy.BusItem.GetText"); var pathToBattery = await ExecuteBufferedAsyncCommandOnIp(ip, "dbus-send --system --dest=com.victronenergy.system --type=method_call --print-reply /ServiceMapping/com_victronenergy_battery_1 com.victronenergy.BusItem.GetText");
if (pathToBattery.Split('"')[1].StartsWith("Error")) return 0; if (pathToBattery.Split('"')[1].StartsWith("Error")) return "Failed";
var cmd = await ExecuteBufferedAsyncCommandOnIp(ip,$"dbus-send --system --dest={pathToBattery.Split('"')[1]} --type=method_call --print-reply /NbOfBatteries com.victronenergy.BusItem.GetText" ); var cmd = await ExecuteBufferedAsyncCommandOnIp(ip,$"dbus-send --system --dest={pathToBattery.Split('"')[1]} --type=method_call --print-reply /NbOfBatteries com.victronenergy.BusItem.GetText" );
var cmdResult = cmd.Split('"')[1];
return cmd.Split('"')[1] == "Failed" ? 0 : Int64.Parse(cmd.Split('"')[1]); //No Batteries can be found return cmdResult; //No Batteries can be found
} }
@ -258,6 +259,4 @@ public class AccToken
/* /*
dbus-send --system --dest=com.victronenergy.battery.ttyUSB1 --print-reply /FirmwareVersion \ dbus-send --system --dest=com.victronenergy.battery.ttyUSB1 --print-reply /FirmwareVersion \
org.freedesktop.DBus.Properties.Get string:com.victronenergy.battery.ttyUSB1 org.freedesktop.DBus.Properties.Get string:com.victronenergy.battery.ttyUSB1
*
*
*/ */