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:
+14
-6
@@ -1,6 +1,6 @@
|
|||||||
--!nonstrict
|
--!nonstrict
|
||||||
|
|
||||||
local haUrl = noctalia.getConfig("ha_url")
|
local haUrlRaw = noctalia.getConfig("ha_url")
|
||||||
local haToken = noctalia.getConfig("ha_token")
|
local haToken = noctalia.getConfig("ha_token")
|
||||||
|
|
||||||
local entityStates = {}
|
local entityStates = {}
|
||||||
@@ -23,6 +23,11 @@ local searchText = ""
|
|||||||
local monitoredEntities = {} -- current monitored list (owned here, saved to file)
|
local monitoredEntities = {} -- current monitored list (owned here, saved to file)
|
||||||
local panelOpenCount = 0
|
local panelOpenCount = 0
|
||||||
|
|
||||||
|
local function getCleanUrl()
|
||||||
|
if type(haUrlRaw) ~= "string" then return "" end
|
||||||
|
return (haUrlRaw:gsub("/$", ""))
|
||||||
|
end
|
||||||
|
|
||||||
local function tr(key, subst)
|
local function tr(key, subst)
|
||||||
return noctalia.tr("panel." .. key, subst)
|
return noctalia.tr("panel." .. key, subst)
|
||||||
end
|
end
|
||||||
@@ -47,13 +52,14 @@ local function getCleanToken()
|
|||||||
end
|
end
|
||||||
|
|
||||||
local function haPost(path, body)
|
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()
|
local cleanToken = getCleanToken()
|
||||||
if cleanToken == "" then return end
|
if cleanToken == "" then return end
|
||||||
local encodedBody = noctalia.json.encode(body)
|
local encodedBody = noctalia.json.encode(body)
|
||||||
|
|
||||||
noctalia.http({
|
noctalia.http({
|
||||||
url = haUrl .. path,
|
url = url .. path,
|
||||||
method = "POST",
|
method = "POST",
|
||||||
headers = {
|
headers = {
|
||||||
"Authorization: Bearer " .. cleanToken,
|
"Authorization: Bearer " .. cleanToken,
|
||||||
@@ -132,7 +138,8 @@ end
|
|||||||
local function fetchAllEntities()
|
local function fetchAllEntities()
|
||||||
if browserLoading then return end
|
if browserLoading then return end
|
||||||
local cleanToken = getCleanToken()
|
local cleanToken = getCleanToken()
|
||||||
if not haUrl or haUrl == "" or cleanToken == "" then
|
local url = getCleanUrl()
|
||||||
|
if not url or url == "" or cleanToken == "" then
|
||||||
allEntities = {}
|
allEntities = {}
|
||||||
browserLoading = false
|
browserLoading = false
|
||||||
render()
|
render()
|
||||||
@@ -143,7 +150,7 @@ local function fetchAllEntities()
|
|||||||
render()
|
render()
|
||||||
|
|
||||||
noctalia.http({
|
noctalia.http({
|
||||||
url = haUrl .. "/api/states",
|
url = url .. "/api/states",
|
||||||
headers = {
|
headers = {
|
||||||
"Authorization: Bearer " .. cleanToken,
|
"Authorization: Bearer " .. cleanToken,
|
||||||
}
|
}
|
||||||
@@ -500,7 +507,7 @@ local function getOrderedIds()
|
|||||||
end
|
end
|
||||||
|
|
||||||
local function buildListBody(ids)
|
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" })
|
return ui.label({ text = tr("not_configured"), color = "on_surface_variant" })
|
||||||
end
|
end
|
||||||
if status == "auth_failed" then
|
if status == "auth_failed" then
|
||||||
@@ -588,6 +595,7 @@ function render()
|
|||||||
|
|
||||||
panel.render(ui.column({ flexGrow = 1, gap = 16 }, {
|
panel.render(ui.column({ flexGrow = 1, gap = 16 }, {
|
||||||
ui.row({ align = "center", gap = 8 }, {
|
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 = 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.label({ text = getStatusText(), color = status == "connected" and "primary" or "on_surface_variant" }),
|
||||||
ui.button({ glyph = "list-search", onClick = "onOpenBrowser" }),
|
ui.button({ glyph = "list-search", onClick = "onOpenBrowser" }),
|
||||||
|
|||||||
+1
-1
@@ -1,6 +1,6 @@
|
|||||||
id = "pozzoo/hassio"
|
id = "pozzoo/hassio"
|
||||||
name = "Home Assistant"
|
name = "Home Assistant"
|
||||||
version = "2.0.0"
|
version = "2.0.1"
|
||||||
plugin_api = 4
|
plugin_api = 4
|
||||||
author = "Pozzoo"
|
author = "Pozzoo"
|
||||||
license = "MIT"
|
license = "MIT"
|
||||||
|
|||||||
+10
-4
@@ -1,10 +1,15 @@
|
|||||||
--!nonstrict
|
--!nonstrict
|
||||||
|
|
||||||
local haUrl = noctalia.getConfig("ha_url")
|
local haUrlRaw = noctalia.getConfig("ha_url")
|
||||||
local haToken = noctalia.getConfig("ha_token")
|
local haToken = noctalia.getConfig("ha_token")
|
||||||
|
|
||||||
local MANAGED_ENTITIES_FILE = "managed_entities.json"
|
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 function loadManagedEntities()
|
||||||
local dataDir, dirErr = noctalia.pluginDataDir()
|
local dataDir, dirErr = noctalia.pluginDataDir()
|
||||||
if not dataDir then
|
if not dataDir then
|
||||||
@@ -49,13 +54,14 @@ local function syncUpdateInterval()
|
|||||||
end
|
end
|
||||||
|
|
||||||
local function isConfigured()
|
local function isConfigured()
|
||||||
return haUrl and haUrl ~= "" and getCleanToken() ~= ""
|
local url = getCleanUrl()
|
||||||
|
return url and url ~= "" and getCleanToken() ~= ""
|
||||||
end
|
end
|
||||||
|
|
||||||
local function haRequest(endpoint, method, body, callback)
|
local function haRequest(endpoint, method, body, callback)
|
||||||
if not isConfigured() then return false end
|
if not isConfigured() then return false end
|
||||||
|
|
||||||
local url = haUrl .. endpoint
|
local url = getCleanUrl() .. endpoint
|
||||||
local cleanToken = getCleanToken()
|
local cleanToken = getCleanToken()
|
||||||
|
|
||||||
local jsonBody
|
local jsonBody
|
||||||
@@ -296,7 +302,7 @@ function startSSEStream()
|
|||||||
return false
|
return false
|
||||||
end
|
end
|
||||||
|
|
||||||
local url = haUrl .. "/api/stream?restrict=state_changed"
|
local url = getCleanUrl() .. "/api/stream?restrict=state_changed"
|
||||||
|
|
||||||
noctalia.log("Starting SSE stream")
|
noctalia.log("Starting SSE stream")
|
||||||
currentEvent = { data = "", event = "" }
|
currentEvent = { data = "", event = "" }
|
||||||
|
|||||||
+9
-3
@@ -1,6 +1,6 @@
|
|||||||
--!nonstrict
|
--!nonstrict
|
||||||
|
|
||||||
local haUrl = noctalia.getConfig("ha_url")
|
local haUrlRaw = noctalia.getConfig("ha_url")
|
||||||
local showEntityCount = noctalia.getConfig("show_entity_count")
|
local showEntityCount = noctalia.getConfig("show_entity_count")
|
||||||
|
|
||||||
local status = "unconfigured"
|
local status = "unconfigured"
|
||||||
@@ -8,6 +8,11 @@ local entityCount = 0
|
|||||||
|
|
||||||
local render
|
local render
|
||||||
|
|
||||||
|
local function getCleanUrl()
|
||||||
|
if type(haUrlRaw) ~= "string" then return "" end
|
||||||
|
return (haUrlRaw:gsub("/$", ""))
|
||||||
|
end
|
||||||
|
|
||||||
local function tr(key, subst)
|
local function tr(key, subst)
|
||||||
return noctalia.tr("widget." .. key, subst)
|
return noctalia.tr("widget." .. key, subst)
|
||||||
end
|
end
|
||||||
@@ -83,8 +88,9 @@ function onClick()
|
|||||||
end
|
end
|
||||||
|
|
||||||
function onRightClick()
|
function onRightClick()
|
||||||
if haUrl and haUrl ~= "" then
|
local url = getCleanUrl()
|
||||||
noctalia.runAsync("xdg-open " .. ("'" .. haUrl:gsub("'", "'\\''") .. "'"))
|
if url and url ~= "" then
|
||||||
|
noctalia.runAsync("xdg-open " .. ("'" .. url:gsub("'", "'\\''") .. "'"))
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user