Skip to content

Commit

Permalink
final edits
Browse files Browse the repository at this point in the history
  • Loading branch information
Jonathan Desrochers authored and Jonathan Desrochers committed Nov 6, 2024
1 parent fb06991 commit 91fabc0
Showing 1 changed file with 31 additions and 19 deletions.
50 changes: 31 additions & 19 deletions apps/victron/victron.star
Original file line number Diff line number Diff line change
Expand Up @@ -9,39 +9,51 @@ load("http.star", "http")
load("render.star", "render")
load("schema.star", "schema")

VRM_TOKEN = "1"
VRM_URL_USER = "https://vrmapi.victronenergy.com/v2/users/me"
VRM_URL_INSTALLATIONS = "https://vrmapi.victronenergy.com/v2/users/%s/installations"
VRM_URL_DIAG = "https://vrmapi.victronenergy.com/v2/installations/%s/diagnostics"

def main(config):
token = config.get("token", VRM_TOKEN)
installationIndex = config.get("installation_index", 0)
token = config.get("token")
if not "token" in config:
# dummy data if no token provided
installation_name = "Installation"
parsed_diag = {
"SOCRaw": 100,
"SOC": "100 %",
"PVPRaw": 100,
"PVP": "100%",
"DCRaw": 100,
"DC": "100%",
}

user = vrm_api(VRM_URL_USER, token, 600)
else:
installationIndex = config.get("installation_index", 0)

user = vrm_api(VRM_URL_USER, token, 600)

if (user["success"] != True):
fail("failed to check for user %s" % user)
if (user["success"] != True):
fail("failed to check for user %s" % user)

user_id = str(user["user"]["id"])
user_id = str(user["user"]["id"])

if (int(user_id) < 0):
fail("failed to get user id %s" % user_id)
if (int(user_id) < 0):
fail("failed to get user id %s" % user_id)

installations = vrm_api(VRM_URL_INSTALLATIONS % user_id, token, 600)
installations = vrm_api(VRM_URL_INSTALLATIONS % user_id, token, 600)

if (installations["success"] != True):
fail("failed to check for installations %s" % installations)
if (installations["success"] != True):
fail("failed to check for installations %s" % installations)

installation = installations["records"][installationIndex]
installation_id = installation["idSite"]
installation_name = installation["name"]
installation = installations["records"][installationIndex]
installation_id = installation["idSite"]
installation_name = installation["name"]

diag = vrm_api(VRM_URL_DIAG % str(int(installation_id)), token, 0)
if (diag["success"] != True):
fail("failed to check for diagnostics %s" % diag)
diag = vrm_api(VRM_URL_DIAG % str(int(installation_id)), token, 0)
if (diag["success"] != True):
fail("failed to check for diagnostics %s" % diag)

parsed_diag = parse_diag(diag)
parsed_diag = parse_diag(diag)

#print(parsed_diag)
if (float(parsed_diag["SOCRaw"]) > 50):
Expand Down

0 comments on commit 91fabc0

Please sign in to comment.