diff --git a/apps/victron/victron.star b/apps/victron/victron.star index aba35e352..92eb5b5ac 100644 --- a/apps/victron/victron.star +++ b/apps/victron/victron.star @@ -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):