Skip to content

Commit cc0f3e4

Browse files
authored
Merge pull request #2176 from SmartThingsCommunity/fix/sonos-optional-reply-channel-nil-check
2 parents 0fb0427 + 130266c commit cc0f3e4

File tree

2 files changed

+9
-4
lines changed

2 files changed

+9
-4
lines changed

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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,11 @@ local _update_subscriptions_helper = function(
7878
local unique_key, bad_key_part = utils.sonos_unique_key(householdId, playerId)
7979
if not unique_key then
8080
local err_msg = string.format("Invalid Sonos Unique Key Part: %s", bad_key_part)
81-
reply_tx:send(table.pack(nil, err_msg))
81+
if reply_tx then
82+
reply_tx:send(table.pack(nil, err_msg))
83+
else
84+
log.warn(string.format("Update Subscriptions Error: %s", err_msg))
85+
end
8286
return
8387
end
8488
Router.send_message_to_player(unique_key, payload, reply_tx)

drivers/SmartThings/sonos/src/sonos_state.lua

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -183,8 +183,9 @@ end
183183
function SonosState:update_device_record_group_info(household, group, device)
184184
local player_id = device:get_field(PlayerFields.PLAYER_ID)
185185
local group_role
186-
if player_id == group.coordinatorId then
187-
if #household.groups[group.id].playerIds > 1 then
186+
if (player_id and group and group.id and group.coordinatorId) and player_id == group.coordinatorId then
187+
local player_ids_list = household.groups[group.id].playerIds or {}
188+
if #player_ids_list > 1 then
188189
group_role = "primary"
189190
else
190191
group_role = "ungrouped"
@@ -248,7 +249,7 @@ end
248249
--- @param household_id HouseholdId
249250
--- @param device SonosDevice
250251
function SonosState:update_device_record_from_state(household_id, device)
251-
local current_mapping = _STATE.device_record_map[device.id]
252+
local current_mapping = _STATE.device_record_map[device.id] or {}
252253
local household = _STATE.households:get_or_init(household_id)
253254
self:update_device_record_group_info(household, current_mapping.group, device)
254255
end

0 commit comments

Comments
 (0)