fix(hassio): Perpetual connecting (#75)
* fix(service_sse): Fixed connecting state not updating. * fix(shortcut*): Changed shortcuts to use the clean URL. * chore(plugin): Bumped version to 2.0.2
This commit is contained in:
+1
-1
@@ -1,6 +1,6 @@
|
|||||||
id = "pozzoo/hassio"
|
id = "pozzoo/hassio"
|
||||||
name = "Home Assistant"
|
name = "Home Assistant"
|
||||||
version = "2.0.1"
|
version = "2.0.2"
|
||||||
plugin_api = 4
|
plugin_api = 4
|
||||||
author = "Pozzoo"
|
author = "Pozzoo"
|
||||||
license = "MIT"
|
license = "MIT"
|
||||||
|
|||||||
@@ -39,6 +39,7 @@ local retryCount = 0
|
|||||||
local maxRetriesNotified = false
|
local maxRetriesNotified = false
|
||||||
local suspended = false
|
local suspended = false
|
||||||
local connectionRequestInFlight = false
|
local connectionRequestInFlight = false
|
||||||
|
local connectingSince = nil
|
||||||
|
|
||||||
local function getCleanToken()
|
local function getCleanToken()
|
||||||
if type(haToken) ~= "string" then return "" end
|
if type(haToken) ~= "string" then return "" end
|
||||||
@@ -214,8 +215,10 @@ end
|
|||||||
local function fetchInitialStates()
|
local function fetchInitialStates()
|
||||||
if not isConfigured() or suspended or connectionRequestInFlight then return end
|
if not isConfigured() or suspended or connectionRequestInFlight then return end
|
||||||
connectionRequestInFlight = true
|
connectionRequestInFlight = true
|
||||||
|
connectingSince = os.clock()
|
||||||
local launched = haRequest("/api/states", "GET", nil, function(res)
|
local launched = haRequest("/api/states", "GET", nil, function(res)
|
||||||
connectionRequestInFlight = false
|
connectionRequestInFlight = false
|
||||||
|
connectingSince = nil
|
||||||
|
|
||||||
if not res.body or res.body == "" then
|
if not res.body or res.body == "" then
|
||||||
noctalia.log("Empty response body from /api/states")
|
noctalia.log("Empty response body from /api/states")
|
||||||
@@ -287,6 +290,7 @@ local function fetchInitialStates()
|
|||||||
|
|
||||||
if not launched then
|
if not launched then
|
||||||
connectionRequestInFlight = false
|
connectionRequestInFlight = false
|
||||||
|
connectingSince = nil
|
||||||
status = "disconnected"
|
status = "disconnected"
|
||||||
noctalia.state.set("connection_status", status)
|
noctalia.state.set("connection_status", status)
|
||||||
syncUpdateInterval()
|
syncUpdateInterval()
|
||||||
@@ -396,6 +400,14 @@ function update()
|
|||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
|
if status == "connecting" and connectingSince and (os.clock() - connectingSince) > 15 then
|
||||||
|
connectionRequestInFlight = false
|
||||||
|
connectingSince = nil
|
||||||
|
status = "disconnected"
|
||||||
|
noctalia.state.set("connection_status", status)
|
||||||
|
syncUpdateInterval()
|
||||||
|
end
|
||||||
|
|
||||||
if status == "disconnected" then
|
if status == "disconnected" then
|
||||||
retryCount = retryCount + 1
|
retryCount = retryCount + 1
|
||||||
if retryCount >= MAX_RECONNECT_RETRIES then
|
if retryCount >= MAX_RECONNECT_RETRIES then
|
||||||
|
|||||||
@@ -14,6 +14,11 @@ local pendingTimerSeq = 0
|
|||||||
local PENDING_TIMEOUT_SECONDS = 8
|
local PENDING_TIMEOUT_SECONDS = 8
|
||||||
local render
|
local render
|
||||||
|
|
||||||
|
local function getCleanUrl()
|
||||||
|
if type(haUrl) ~= "string" then return "" end
|
||||||
|
return (haUrl:gsub("/$", ""))
|
||||||
|
end
|
||||||
|
|
||||||
local function getCleanToken()
|
local function getCleanToken()
|
||||||
if type(haToken) ~= "string" then return "" end
|
if type(haToken) ~= "string" then return "" end
|
||||||
return haToken:gsub("^%s+", ""):gsub("%s+$", "")
|
return haToken:gsub("^%s+", ""):gsub("%s+$", "")
|
||||||
@@ -116,7 +121,7 @@ function onClick()
|
|||||||
|
|
||||||
local entity = getEntity()
|
local entity = getEntity()
|
||||||
local cleanToken = getCleanToken()
|
local cleanToken = getCleanToken()
|
||||||
if not entity or not haUrl or haUrl == "" or cleanToken == "" then return end
|
if not entity or getCleanUrl() == "" or cleanToken == "" then return end
|
||||||
|
|
||||||
local eid = entity.entity_id
|
local eid = entity.entity_id
|
||||||
if pendingToggle[eid] then return end
|
if pendingToggle[eid] then return end
|
||||||
@@ -128,7 +133,7 @@ function onClick()
|
|||||||
local encoded = noctalia.json.encode({ entity_id = eid })
|
local encoded = noctalia.json.encode({ entity_id = eid })
|
||||||
|
|
||||||
noctalia.http({
|
noctalia.http({
|
||||||
url = haUrl .. "/api/services/" .. entity.domain .. "/toggle",
|
url = getCleanUrl() .. "/api/services/" .. entity.domain .. "/toggle",
|
||||||
method = "POST",
|
method = "POST",
|
||||||
headers = {
|
headers = {
|
||||||
"Authorization: Bearer " .. cleanToken,
|
"Authorization: Bearer " .. cleanToken,
|
||||||
|
|||||||
@@ -14,6 +14,11 @@ local pendingTimerSeq = 0
|
|||||||
local PENDING_TIMEOUT_SECONDS = 8
|
local PENDING_TIMEOUT_SECONDS = 8
|
||||||
local render
|
local render
|
||||||
|
|
||||||
|
local function getCleanUrl()
|
||||||
|
if type(haUrl) ~= "string" then return "" end
|
||||||
|
return (haUrl:gsub("/$", ""))
|
||||||
|
end
|
||||||
|
|
||||||
local function getCleanToken()
|
local function getCleanToken()
|
||||||
if type(haToken) ~= "string" then return "" end
|
if type(haToken) ~= "string" then return "" end
|
||||||
return haToken:gsub("^%s+", ""):gsub("%s+$", "")
|
return haToken:gsub("^%s+", ""):gsub("%s+$", "")
|
||||||
@@ -116,7 +121,7 @@ function onClick()
|
|||||||
|
|
||||||
local entity = getEntity()
|
local entity = getEntity()
|
||||||
local cleanToken = getCleanToken()
|
local cleanToken = getCleanToken()
|
||||||
if not entity or not haUrl or haUrl == "" or cleanToken == "" then return end
|
if not entity or getCleanUrl() == "" or cleanToken == "" then return end
|
||||||
|
|
||||||
local eid = entity.entity_id
|
local eid = entity.entity_id
|
||||||
if pendingToggle[eid] then return end
|
if pendingToggle[eid] then return end
|
||||||
@@ -128,7 +133,7 @@ function onClick()
|
|||||||
local encoded = noctalia.json.encode({ entity_id = eid })
|
local encoded = noctalia.json.encode({ entity_id = eid })
|
||||||
|
|
||||||
noctalia.http({
|
noctalia.http({
|
||||||
url = haUrl .. "/api/services/" .. entity.domain .. "/toggle",
|
url = getCleanUrl() .. "/api/services/" .. entity.domain .. "/toggle",
|
||||||
method = "POST",
|
method = "POST",
|
||||||
headers = {
|
headers = {
|
||||||
"Authorization: Bearer " .. cleanToken,
|
"Authorization: Bearer " .. cleanToken,
|
||||||
|
|||||||
@@ -14,6 +14,11 @@ local pendingTimerSeq = 0
|
|||||||
local PENDING_TIMEOUT_SECONDS = 8
|
local PENDING_TIMEOUT_SECONDS = 8
|
||||||
local render
|
local render
|
||||||
|
|
||||||
|
local function getCleanUrl()
|
||||||
|
if type(haUrl) ~= "string" then return "" end
|
||||||
|
return (haUrl:gsub("/$", ""))
|
||||||
|
end
|
||||||
|
|
||||||
local function getCleanToken()
|
local function getCleanToken()
|
||||||
if type(haToken) ~= "string" then return "" end
|
if type(haToken) ~= "string" then return "" end
|
||||||
return haToken:gsub("^%s+", ""):gsub("%s+$", "")
|
return haToken:gsub("^%s+", ""):gsub("%s+$", "")
|
||||||
@@ -116,7 +121,7 @@ function onClick()
|
|||||||
|
|
||||||
local entity = getEntity()
|
local entity = getEntity()
|
||||||
local cleanToken = getCleanToken()
|
local cleanToken = getCleanToken()
|
||||||
if not entity or not haUrl or haUrl == "" or cleanToken == "" then return end
|
if not entity or getCleanUrl() == "" or cleanToken == "" then return end
|
||||||
|
|
||||||
local eid = entity.entity_id
|
local eid = entity.entity_id
|
||||||
if pendingToggle[eid] then return end
|
if pendingToggle[eid] then return end
|
||||||
@@ -128,7 +133,7 @@ function onClick()
|
|||||||
local encoded = noctalia.json.encode({ entity_id = eid })
|
local encoded = noctalia.json.encode({ entity_id = eid })
|
||||||
|
|
||||||
noctalia.http({
|
noctalia.http({
|
||||||
url = haUrl .. "/api/services/" .. entity.domain .. "/toggle",
|
url = getCleanUrl() .. "/api/services/" .. entity.domain .. "/toggle",
|
||||||
method = "POST",
|
method = "POST",
|
||||||
headers = {
|
headers = {
|
||||||
"Authorization: Bearer " .. cleanToken,
|
"Authorization: Bearer " .. cleanToken,
|
||||||
|
|||||||
@@ -14,6 +14,11 @@ local pendingTimerSeq = 0
|
|||||||
local PENDING_TIMEOUT_SECONDS = 8
|
local PENDING_TIMEOUT_SECONDS = 8
|
||||||
local render
|
local render
|
||||||
|
|
||||||
|
local function getCleanUrl()
|
||||||
|
if type(haUrl) ~= "string" then return "" end
|
||||||
|
return (haUrl:gsub("/$", ""))
|
||||||
|
end
|
||||||
|
|
||||||
local function getCleanToken()
|
local function getCleanToken()
|
||||||
if type(haToken) ~= "string" then return "" end
|
if type(haToken) ~= "string" then return "" end
|
||||||
return haToken:gsub("^%s+", ""):gsub("%s+$", "")
|
return haToken:gsub("^%s+", ""):gsub("%s+$", "")
|
||||||
@@ -116,7 +121,7 @@ function onClick()
|
|||||||
|
|
||||||
local entity = getEntity()
|
local entity = getEntity()
|
||||||
local cleanToken = getCleanToken()
|
local cleanToken = getCleanToken()
|
||||||
if not entity or not haUrl or haUrl == "" or cleanToken == "" then return end
|
if not entity or getCleanUrl() == "" or cleanToken == "" then return end
|
||||||
|
|
||||||
local eid = entity.entity_id
|
local eid = entity.entity_id
|
||||||
if pendingToggle[eid] then return end
|
if pendingToggle[eid] then return end
|
||||||
@@ -128,7 +133,7 @@ function onClick()
|
|||||||
local encoded = noctalia.json.encode({ entity_id = eid })
|
local encoded = noctalia.json.encode({ entity_id = eid })
|
||||||
|
|
||||||
noctalia.http({
|
noctalia.http({
|
||||||
url = haUrl .. "/api/services/" .. entity.domain .. "/toggle",
|
url = getCleanUrl() .. "/api/services/" .. entity.domain .. "/toggle",
|
||||||
method = "POST",
|
method = "POST",
|
||||||
headers = {
|
headers = {
|
||||||
"Authorization: Bearer " .. cleanToken,
|
"Authorization: Bearer " .. cleanToken,
|
||||||
|
|||||||
Reference in New Issue
Block a user