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:
@@ -39,6 +39,7 @@ local retryCount = 0
|
||||
local maxRetriesNotified = false
|
||||
local suspended = false
|
||||
local connectionRequestInFlight = false
|
||||
local connectingSince = nil
|
||||
|
||||
local function getCleanToken()
|
||||
if type(haToken) ~= "string" then return "" end
|
||||
@@ -214,8 +215,10 @@ end
|
||||
local function fetchInitialStates()
|
||||
if not isConfigured() or suspended or connectionRequestInFlight then return end
|
||||
connectionRequestInFlight = true
|
||||
connectingSince = os.clock()
|
||||
local launched = haRequest("/api/states", "GET", nil, function(res)
|
||||
connectionRequestInFlight = false
|
||||
connectingSince = nil
|
||||
|
||||
if not res.body or res.body == "" then
|
||||
noctalia.log("Empty response body from /api/states")
|
||||
@@ -287,6 +290,7 @@ local function fetchInitialStates()
|
||||
|
||||
if not launched then
|
||||
connectionRequestInFlight = false
|
||||
connectingSince = nil
|
||||
status = "disconnected"
|
||||
noctalia.state.set("connection_status", status)
|
||||
syncUpdateInterval()
|
||||
@@ -396,6 +400,14 @@ function update()
|
||||
return
|
||||
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
|
||||
retryCount = retryCount + 1
|
||||
if retryCount >= MAX_RECONNECT_RETRIES then
|
||||
|
||||
Reference in New Issue
Block a user