Home Assistant v2.0.1 (#50)

* fix(*): Added a function to remove trailing slashes from URLs.

* feat(panel): Added a home assistant icon alongsite the panel tile.

* chore(plugin): Bump the version to 2.0.1

* fix(panel): Fixed wrong glyph syntax.
This commit is contained in:
Artur
2026-07-18 19:04:23 -04:00
committed by GitHub
parent 6b54e88389
commit 9d96040309
4 changed files with 34 additions and 14 deletions
+14 -6
View File
@@ -1,6 +1,6 @@
--!nonstrict
local haUrl = noctalia.getConfig("ha_url")
local haUrlRaw = noctalia.getConfig("ha_url")
local haToken = noctalia.getConfig("ha_token")
local entityStates = {}
@@ -23,6 +23,11 @@ local searchText = ""
local monitoredEntities = {} -- current monitored list (owned here, saved to file)
local panelOpenCount = 0
local function getCleanUrl()
if type(haUrlRaw) ~= "string" then return "" end
return (haUrlRaw:gsub("/$", ""))
end
local function tr(key, subst)
return noctalia.tr("panel." .. key, subst)
end
@@ -47,13 +52,14 @@ local function getCleanToken()
end
local function haPost(path, body)
if not haUrl or haUrl == "" then return end
local url = getCleanUrl()
if not url or url == "" then return end
local cleanToken = getCleanToken()
if cleanToken == "" then return end
local encodedBody = noctalia.json.encode(body)
noctalia.http({
url = haUrl .. path,
url = url .. path,
method = "POST",
headers = {
"Authorization: Bearer " .. cleanToken,
@@ -132,7 +138,8 @@ end
local function fetchAllEntities()
if browserLoading then return end
local cleanToken = getCleanToken()
if not haUrl or haUrl == "" or cleanToken == "" then
local url = getCleanUrl()
if not url or url == "" or cleanToken == "" then
allEntities = {}
browserLoading = false
render()
@@ -143,7 +150,7 @@ local function fetchAllEntities()
render()
noctalia.http({
url = haUrl .. "/api/states",
url = url .. "/api/states",
headers = {
"Authorization: Bearer " .. cleanToken,
}
@@ -500,7 +507,7 @@ local function getOrderedIds()
end
local function buildListBody(ids)
if not haUrl or haUrl == "" or getCleanToken() == "" then
if not getCleanUrl() or getCleanUrl() == "" or getCleanToken() == "" then
return ui.label({ text = tr("not_configured"), color = "on_surface_variant" })
end
if status == "auth_failed" then
@@ -588,6 +595,7 @@ function render()
panel.render(ui.column({ flexGrow = 1, gap = 16 }, {
ui.row({ align = "center", gap = 8 }, {
ui.glyph({ name = "smart-home", size = 20, color = "primary" }),
ui.label({ text = noctalia.tr("shortcut.title"), fontSize = 16, fontWeight = "bold", color = "primary", flexGrow = 1 }),
ui.label({ text = getStatusText(), color = status == "connected" and "primary" or "on_surface_variant" }),
ui.button({ glyph = "list-search", onClick = "onOpenBrowser" }),
+1 -1
View File
@@ -1,6 +1,6 @@
id = "pozzoo/hassio"
name = "Home Assistant"
version = "2.0.0"
version = "2.0.1"
plugin_api = 4
author = "Pozzoo"
license = "MIT"
+10 -4
View File
@@ -1,10 +1,15 @@
--!nonstrict
local haUrl = noctalia.getConfig("ha_url")
local haUrlRaw = noctalia.getConfig("ha_url")
local haToken = noctalia.getConfig("ha_token")
local MANAGED_ENTITIES_FILE = "managed_entities.json"
local function getCleanUrl()
if type(haUrlRaw) ~= "string" then return "" end
return (haUrlRaw:gsub("/$", ""))
end
local function loadManagedEntities()
local dataDir, dirErr = noctalia.pluginDataDir()
if not dataDir then
@@ -49,13 +54,14 @@ local function syncUpdateInterval()
end
local function isConfigured()
return haUrl and haUrl ~= "" and getCleanToken() ~= ""
local url = getCleanUrl()
return url and url ~= "" and getCleanToken() ~= ""
end
local function haRequest(endpoint, method, body, callback)
if not isConfigured() then return false end
local url = haUrl .. endpoint
local url = getCleanUrl() .. endpoint
local cleanToken = getCleanToken()
local jsonBody
@@ -296,7 +302,7 @@ function startSSEStream()
return false
end
local url = haUrl .. "/api/stream?restrict=state_changed"
local url = getCleanUrl() .. "/api/stream?restrict=state_changed"
noctalia.log("Starting SSE stream")
currentEvent = { data = "", event = "" }
+9 -3
View File
@@ -1,6 +1,6 @@
--!nonstrict
local haUrl = noctalia.getConfig("ha_url")
local haUrlRaw = noctalia.getConfig("ha_url")
local showEntityCount = noctalia.getConfig("show_entity_count")
local status = "unconfigured"
@@ -8,6 +8,11 @@ local entityCount = 0
local render
local function getCleanUrl()
if type(haUrlRaw) ~= "string" then return "" end
return (haUrlRaw:gsub("/$", ""))
end
local function tr(key, subst)
return noctalia.tr("widget." .. key, subst)
end
@@ -83,8 +88,9 @@ function onClick()
end
function onRightClick()
if haUrl and haUrl ~= "" then
noctalia.runAsync("xdg-open " .. ("'" .. haUrl:gsub("'", "'\\''") .. "'"))
local url = getCleanUrl()
if url and url ~= "" then
noctalia.runAsync("xdg-open " .. ("'" .. url:gsub("'", "'\\''") .. "'"))
end
end