Skip to content

Commit 130266c

Browse files
committed
fix: guard against race-y nil index condition
Fix against a nil index race condition around groups by guarding against nils in certain spots related to group role introspection.
1 parent 8910fd6 commit 130266c

1 file changed

Lines changed: 4 additions & 3 deletions

File tree

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)