Skip to content

Commit 0ad6d58

Browse files
committed
fixup! philips-hue: Add batched command handling support
1 parent 2e719c1 commit 0ad6d58

File tree

1 file changed

+3
-5
lines changed

1 file changed

+3
-5
lines changed

drivers/SmartThings/philips-hue/src/utils/batched_command_utils.lua

+3-5
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,6 @@ end
110110
function batched_command_utils.sort_batch(driver, batch)
111111
local sorted_batch = KVCounter()
112112
local misfits = {}
113-
local to_match_table = {}
114113

115114
for _, to_inspect in ipairs(batch) do
116115
-- Check if we can handle this in a batch
@@ -152,9 +151,10 @@ function batched_command_utils.sort_batch(driver, batch)
152151
local index = #by_command + 1
153152
-- Finally, group commands with matching bridge and command name by matching arguments
154153
-- and auxilary command data.
155-
for match_idx, _ in ipairs(by_command) do
154+
for match_idx, matching_table in ipairs(by_command) do
156155
-- Grab first command, all the arguments in this table are the same so it doesn't matter.
157-
local to_match = to_match_table[match_idx]
156+
-- next is a defined function on KVCounter that uses a similar implementation as the default Lua next.
157+
local _, to_match = matching_table.next(matching_table, nil)
158158

159159
if utils.deep_table_eq(to_match.capability_command.args, to_inspect.capability_command.args) and
160160
utils.deep_table_eq(to_match.auxilary_command_data, to_inspect.auxilary_command_data) then
@@ -165,8 +165,6 @@ function batched_command_utils.sort_batch(driver, batch)
165165
end
166166
if not by_command[index] then
167167
table.insert(by_command, index, KVCounter())
168-
-- Save this off to grab it easily later
169-
to_match_table[index] = to_inspect
170168
end
171169
by_command[index][device.id] = to_inspect
172170

0 commit comments

Comments
 (0)