Skip to content

Commit 0fb0427

Browse files
authored
Merge pull request #2173 from SmartThingsCommunity/fix/sonos-group-control-regressions
2 parents d51954b + c07bee0 commit 0fb0427

File tree

7 files changed

+214
-63
lines changed

7 files changed

+214
-63
lines changed

drivers/SmartThings/sonos/src/api/sonos_connection.lua

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -340,6 +340,7 @@ function SonosConnection.new(driver, device)
340340
self.driver.sonos:get_coordinator_for_device(self.device)
341341
local _, player_id = self.driver.sonos:get_player_for_device(self.device)
342342
self.driver.sonos:update_household_info(header.householdId, body, self.device)
343+
self.driver.sonos:update_device_record_from_state(header.householdId, self.device)
343344
local _, updated_coordinator = self.driver.sonos:get_coordinator_for_device(self.device)
344345

345346
Router.cleanup_unused_sockets(self.driver)
@@ -567,7 +568,7 @@ function SonosConnection:coordinator_running()
567568
)
568569
)
569570
end
570-
return unique_key and Router.is_connected(unique_key) and self._initialized
571+
return type(unique_key) == "string" and Router.is_connected(unique_key) and self._initialized
571572
end
572573

573574
function SonosConnection:refresh_subscriptions(maybe_reply_tx)

drivers/SmartThings/sonos/src/api/sonos_ssdp_discovery.lua

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -201,28 +201,31 @@ function SonosPersistentSsdpTask:get_player_info(reply_tx, ...)
201201
local household_id_or_mac = select(1, ...)
202202
local player_id = select(2, ...)
203203

204-
local lookup_table, lookup_key, bad_key_part
204+
local wait_table_key, lookup_table, lookup_key, bad_key_part
205205

206206
if player_id ~= nil and type(player_id) == "string" then
207+
wait_table_key = "waiting_for_unique_key"
207208
lookup_table = self.player_info_by_sonos_ids
208209
lookup_key, bad_key_part = utils.sonos_unique_key(household_id_or_mac, player_id)
209210
else
211+
wait_table_key = "waiting_for_mac_addr"
210212
lookup_table = self.player_info_by_mac_addrs
211213
lookup_key = household_id_or_mac
212214
end
213215

214216
if not lookup_key and bad_key_part then
215217
log.error(string.format("Invalid Unique Key Part: %s", bad_key_part))
216218
end
219+
217220
local maybe_existing = lookup_table[lookup_key]
218221
if maybe_existing and maybe_existing.ssdp_info.expires_at > os.time() then
219222
reply_tx:send(maybe_existing)
220223
return
221224
end
222225

223-
local waiting_for_player = self.waiting_for_unique_key[lookup_key] or {}
226+
local waiting_for_player = self[wait_table_key][lookup_key] or {}
224227
table.insert(waiting_for_player, reply_tx)
225-
self.waiting_for_unique_key[lookup_key] = waiting_for_player
228+
self[wait_table_key][lookup_key] = waiting_for_player
226229
self:refresh()
227230
end
228231

drivers/SmartThings/sonos/src/lifecycle_handlers.lua

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,7 @@ function SonosDriverLifecycleHandlers.initialize_device(driver, device)
117117
-- This is just in case both receivers are ready, so that we can prioritize
118118
-- handling the token instead of putting another request in flight.
119119
send_request = true
120+
backoff_timer:handled()
120121
backoff_timer = nil
121122
end
122123

@@ -204,12 +205,12 @@ end
204205
---@param device SonosDevice
205206
function SonosDriverLifecycleHandlers.removed(driver, device)
206207
log.trace(string.format("%s device removed", device.label))
208+
driver.sonos:remove_device_record_association(device)
207209
driver.dni_to_device_id[device.device_network_id] = nil
208210
local sonos_conn = device:get_field(PlayerFields.CONNECTION)
209211
if sonos_conn and sonos_conn:is_running() then
210212
sonos_conn:stop()
211213
end
212-
driver.sonos:remove_device_record_association(device)
213214
end
214215

215216
SonosDriverLifecycleHandlers.added = SonosDriverLifecycleHandlers.handle_initialize_lifecycle_event

drivers/SmartThings/sonos/src/sonos_driver.lua

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -490,7 +490,6 @@ function SonosDriver:handle_player_discovery_info(api_key, info, device)
490490
)
491491
end
492492

493-
---
494493
--- @cast response SonosGroupsResponseBody
495494
self.sonos:update_household_info(info.ssdp_info.household_id, response)
496495

0 commit comments

Comments
 (0)