From aca8c93a0b9fe120f5a69cea23dd05aed50054eb Mon Sep 17 00:00:00 2001 From: Aaron Carson Date: Wed, 18 Sep 2024 14:57:14 +0100 Subject: [PATCH] fix fetchEntityState --- Home Assistant Widget.js | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/Home Assistant Widget.js b/Home Assistant Widget.js index d4be0e4..acb0ec5 100644 --- a/Home Assistant Widget.js +++ b/Home Assistant Widget.js @@ -5,14 +5,15 @@ const HASS_LLAT = Keychain.get("hass_llat"); const HASS_API_URL = "https://hass-new.adhd.energy/api"; -async function fetchStates() { - var wordle_req = new Request(HASS_API_URL + "/states/sensor.aaron_wordle") - wordle_req.headers = { +async function fetchEntityState(entity_id) { + if (entity_id === undefined) { + return {"error":"entity_id is missing"} + } + let hass_req = new Request(HASS_API_URL + "/states/" + entity_id) + hass_req.headers = { "Authorization": "Bearer " + HASS_LLAT, "Content-Type": "application/json" } - console.log(wordle_req) - return await wordle_req.loadJSON(); + return await hass_req.loadJSON(); } -console.log(fetchStates().response) \ No newline at end of file