added VrmGrabber to replicate VRM installations in memory (to run run the server.py file with flask run) FLASK_APP=server.py
This commit is contained in:
parent
9f0d37ce03
commit
d1fb0a8ac2
Binary file not shown.
|
@ -0,0 +1,10 @@
|
||||||
|
defaultaccount = "Kim"
|
||||||
|
|
||||||
|
[[accounts]]
|
||||||
|
account = "innovenergy-ag"
|
||||||
|
defaultZone = "ch-dk-2"
|
||||||
|
endpoint = "https://api.exoscale.com/v1"
|
||||||
|
environment = ""
|
||||||
|
key = "EXOf67c5b528282988503ddab12"
|
||||||
|
name = "Kim"
|
||||||
|
secret = "KBFh5HvoSQcTtGYcWSm4Qn4m-WFutKe89UqsOdOL-ts"
|
|
@ -1,6 +1,7 @@
|
||||||
using System.ComponentModel.Design;
|
using System.ComponentModel.Design;
|
||||||
using System.Diagnostics.CodeAnalysis;
|
using System.Diagnostics.CodeAnalysis;
|
||||||
using System.Text.Json;
|
using System.Text.Json;
|
||||||
|
using System.Text.Json.Nodes;
|
||||||
using Flurl.Util;
|
using Flurl.Util;
|
||||||
using InnovEnergy.App.Backend.Database;
|
using InnovEnergy.App.Backend.Database;
|
||||||
using InnovEnergy.Lib.Victron.VictronVRM;
|
using InnovEnergy.Lib.Victron.VictronVRM;
|
||||||
|
@ -14,22 +15,61 @@ using Token = String;
|
||||||
[Route("api/")]
|
[Route("api/")]
|
||||||
public class Controller : ControllerBase
|
public class Controller : ControllerBase
|
||||||
{
|
{
|
||||||
[HttpPost(nameof(GetInstallation))]
|
[HttpGet(nameof(GetInstallation))]
|
||||||
[UnconditionalSuppressMessage("Trimming", "IL2026:Members annotated with 'RequiresUnreferencedCodeAttribute' require dynamic access otherwise can break functionality when trimming application code", Justification = "<Pending>")]
|
[UnconditionalSuppressMessage("Trimming", "IL2026:Members annotated with 'RequiresUnreferencedCodeAttribute' require dynamic access otherwise can break functionality when trimming application code", Justification = "<Pending>")]
|
||||||
public Object GetInstallation(String serialNumber)
|
public Object GetInstallation(UInt64 serialNumber)
|
||||||
{
|
{
|
||||||
|
var instList = Db.InstallationsAndDetails.Values.ToList();
|
||||||
foreach (var detailList in Db.InstallationsAndDetails.Values.ToList().Select((Value, Index) => new {Value, Index}))
|
foreach (var detailList in instList.Select((value, index) => new { Value = value, Index = index}))
|
||||||
{
|
{
|
||||||
if (detailList.Value.All(detail => detail.FormattedValue != serialNumber)) continue;
|
if (detailList.Value.All(detail => detail.Json["idSite"]?.GetValue<UInt64>() != serialNumber)) continue;
|
||||||
var retour = JsonSerializer.Serialize(Db.InstallationsAndDetails.Keys.ToList()[detailList.Index]);
|
var retour = Db.InstallationsAndDetails.Keys.ToList()[detailList.Index].Json;
|
||||||
retour += JsonSerializer.Serialize(detailList.Value);
|
retour["details"] = JsonSerializer.Deserialize<JsonArray>(JsonSerializer.Serialize(detailList.Value.Select(d => d.Json).ToArray()));
|
||||||
return retour;
|
return retour;
|
||||||
}
|
}
|
||||||
|
|
||||||
return new NotFoundResult();
|
return new NotFoundResult();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[HttpGet(nameof(GetInstallationList))]
|
||||||
|
public Object GetInstallationList()
|
||||||
|
{
|
||||||
|
var instList = Db.InstallationsAndDetails.Keys.ToList();
|
||||||
|
if (instList.Count == 0) return 0;
|
||||||
|
var returnJson = new Dictionary<String, Dictionary<String, String>>();
|
||||||
|
foreach (var installation in instList)
|
||||||
|
{
|
||||||
|
returnJson[installation.Name] = new Dictionary<String, String>();
|
||||||
|
returnJson[installation.Name].Add("ip", $"<a target='_blank' href=https://{Ip(installation)}> On-Device-Gui </a>");
|
||||||
|
try
|
||||||
|
{
|
||||||
|
returnJson[installation.Name].Add("idSite",
|
||||||
|
$"<a target='_blank' href=https://vrm.victronenergy.com/installation/{installation.IdSite}/dashboard> Dashboard </a>");
|
||||||
|
returnJson[installation.Name]
|
||||||
|
.Add("identifier", $"{installation.Json["identifier"]?.GetValue<String>()}");
|
||||||
|
returnJson[installation.Name].Add("machine serial number", $"{Serial(installation)}");
|
||||||
|
}
|
||||||
|
catch (Exception)
|
||||||
|
{
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return returnJson;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static String? Ip(Installation installation)
|
||||||
|
{
|
||||||
|
return Db.InstallationsAndDetails[installation].RemoteSupportIp();
|
||||||
|
}
|
||||||
|
|
||||||
|
private static String? Serial(Installation installation)
|
||||||
|
{
|
||||||
|
return Db.InstallationsAndDetails[installation].MachineSerial();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// installation Name, ip (link uf gui), idSite (vrm link), identifier , machineserial (HQ...)
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -3,8 +3,7 @@ using System.Diagnostics.CodeAnalysis;
|
||||||
using System.Reactive.Concurrency;
|
using System.Reactive.Concurrency;
|
||||||
using System.Reactive.Linq;
|
using System.Reactive.Linq;
|
||||||
using System.Reactive.Threading.Tasks;
|
using System.Reactive.Threading.Tasks;
|
||||||
using System.Text.Json;
|
using static System.Text.Json.JsonSerializer;
|
||||||
using Flurl.Util;
|
|
||||||
using InnovEnergy.Lib.Utils;
|
using InnovEnergy.Lib.Utils;
|
||||||
using InnovEnergy.Lib.Victron.VictronVRM;
|
using InnovEnergy.Lib.Victron.VictronVRM;
|
||||||
|
|
||||||
|
@ -52,10 +51,10 @@ public static partial class Db
|
||||||
[UnconditionalSuppressMessage("Trimming", "IL2026:Members annotated with 'RequiresUnreferencedCodeAttribute' require dynamic access otherwise can break functionality when trimming application code", Justification = "<Pending>")]
|
[UnconditionalSuppressMessage("Trimming", "IL2026:Members annotated with 'RequiresUnreferencedCodeAttribute' require dynamic access otherwise can break functionality when trimming application code", Justification = "<Pending>")]
|
||||||
private static async Task<Dictionary<Lib.Victron.VictronVRM.Installation, IReadOnlyList<Detail>>> UpdateInstallationsAndDetailsFromVrm(Int64 _)
|
private static async Task<Dictionary<Lib.Victron.VictronVRM.Installation, IReadOnlyList<Detail>>> UpdateInstallationsAndDetailsFromVrm(Int64 _)
|
||||||
{
|
{
|
||||||
var content = await File.ReadAllTextAsync("./token.json");
|
var fileContent = await File.ReadAllTextAsync("./token.json");
|
||||||
|
|
||||||
var acc = JsonSerializer.Deserialize<AccToken>(content)!;
|
var acc = Deserialize<AccToken>(fileContent);
|
||||||
using var user = VrmAccount.Token(acc.idUser, acc.token);
|
var user = VrmAccount.Token(acc.idUser, acc.token);
|
||||||
var installations = await user.GetInstallations();
|
var installations = await user.GetInstallations();
|
||||||
return installations
|
return installations
|
||||||
.Do(i=>i.Name.WriteLine())
|
.Do(i=>i.Name.WriteLine())
|
||||||
|
@ -65,6 +64,6 @@ public static partial class Db
|
||||||
|
|
||||||
public class AccToken
|
public class AccToken
|
||||||
{
|
{
|
||||||
public UInt64 idUser;
|
public UInt64 idUser { get; init;}
|
||||||
public String token;
|
public String token { get; init;}
|
||||||
}
|
}
|
|
@ -0,0 +1,14 @@
|
||||||
|
import requests as requests
|
||||||
|
from flask import Flask
|
||||||
|
from json2html import json2html
|
||||||
|
|
||||||
|
app = Flask(__name__)
|
||||||
|
serverUrl = "https://127.0.0.1:7087/api" #todo change me
|
||||||
|
|
||||||
|
@app.route('/')
|
||||||
|
def hello():
|
||||||
|
json = requests.get(serverUrl + '/GetInstallationList', verify=False) #TODO VERIFY
|
||||||
|
|
||||||
|
if json.content == b'0':
|
||||||
|
return "Still loading Installations"
|
||||||
|
return json2html.convert(json = json.json(), escape=False)
|
|
@ -1,3 +1,4 @@
|
||||||
|
using System.Diagnostics.CodeAnalysis;
|
||||||
using System.Text.Json.Nodes;
|
using System.Text.Json.Nodes;
|
||||||
|
|
||||||
namespace InnovEnergy.Lib.Utils;
|
namespace InnovEnergy.Lib.Utils;
|
||||||
|
|
|
@ -8,6 +8,7 @@ namespace InnovEnergy.Lib.Victron.VictronVRM;
|
||||||
|
|
||||||
public readonly partial record struct Installation(VrmAccount VrmAccount, JsonNode Json)
|
public readonly partial record struct Installation(VrmAccount VrmAccount, JsonNode Json)
|
||||||
{
|
{
|
||||||
|
|
||||||
public UInt64 IdSite => Json.GetUInt64("idSite");
|
public UInt64 IdSite => Json.GetUInt64("idSite");
|
||||||
public UnixTime Created => Json.GetUInt32("syscreated").Apply(UnixTime.FromTicks);
|
public UnixTime Created => Json.GetUInt32("syscreated").Apply(UnixTime.FromTicks);
|
||||||
|
|
||||||
|
@ -15,7 +16,7 @@ public readonly partial record struct Installation(VrmAccount VrmAccount, JsonNo
|
||||||
public String Name => Json.GetString("name");
|
public String Name => Json.GetString("name");
|
||||||
public String Notes => Json.GetString("notes");
|
public String Notes => Json.GetString("notes");
|
||||||
public String PhoneNumber => Json.GetString("phonenumber");
|
public String PhoneNumber => Json.GetString("phonenumber");
|
||||||
|
public String Identifier => Json.GetString("identifier");
|
||||||
// TODO: alternative way to handle settings? make them writeable here and have an UpdateInstallation function?
|
// TODO: alternative way to handle settings? make them writeable here and have an UpdateInstallation function?
|
||||||
// public String Name
|
// public String Name
|
||||||
// {
|
// {
|
||||||
|
|
Loading…
Reference in New Issue