Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 7 additions & 4 deletions drivers/SmartThings/sonos/src/api/sonos_connection.lua
Original file line number Diff line number Diff line change
Expand Up @@ -547,6 +547,8 @@ function SonosConnection.new(driver, device)
self.on_close = function(_)
log.debug(string.format("OnClose for %s", device_name))
if self._initialized then
self._initialized = false
log.debug(string.format("Marking %s as offline due to websocket closure", device_name))
self.device:offline()
end
if self._keepalive then
Expand All @@ -566,10 +568,10 @@ function SonosConnection:is_running()
string.format(
"%s all connections running? %s",
self.device.label,
st_utils.stringify_table({ coordinator = self_running, mine = self_running })
st_utils.stringify_table({ coordinator = coord_running, mine = self_running })
)
)
return self_running and coord_running
return self_running and coord_running and self._initialized
end

--- Whether or not the connection has a live websocket connection
Expand All @@ -586,7 +588,7 @@ function SonosConnection:self_running()
)
)
end
return type(unique_key) == "string" and Router.is_connected(unique_key) and self._initialized
return type(unique_key) == "string" and Router.is_connected(unique_key)
end

--- Whether or not the connection has a live websocket connection to its coordinator
Expand Down Expand Up @@ -685,7 +687,7 @@ function SonosConnection:start()
end

if not self:coordinator_running() then
--TODO this is not infallible
--TODO this is not infallible, but is checked below
_open_coordinator_socket(self, household_id, player_id, api_key)
end

Expand All @@ -700,6 +702,7 @@ function SonosConnection:start()
and coordinator_unique_key
and Router.is_connected(coordinator_unique_key)
then
log.debug(string.format("Marking %s as online since all websockets connected", self.device.label))
self.device:online()
self._initialized = true
self._keepalive = true
Expand Down
4 changes: 2 additions & 2 deletions drivers/SmartThings/sonos/src/api/sonos_websocket_router.lua
Original file line number Diff line number Diff line change
Expand Up @@ -233,11 +233,11 @@ end
---@return string?
function SonosWebSocketRouter.register_listener_for_socket(listener, unique_key_for_socket)
if listener and listener.device and listener.device.label then
log.debug(
log.debug(string.format(
"Registering SonosConnection for device %s as listener for player %s websocket",
listener.device.label,
unique_key_for_socket
)
))
end
local ws = websockets[unique_key_for_socket]

Expand Down
Loading