Skip to content

Commit dea95ce

Browse files
committed
make cycle tracking optional
1 parent d3afa99 commit dea95ce

File tree

4 files changed

+28
-21
lines changed
  • drivers/SmartThings

4 files changed

+28
-21
lines changed

drivers/SmartThings/matter-lock/src/new-matter-lock/init.lua

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -239,11 +239,11 @@ local function match_profile_switch(driver, device)
239239
end
240240

241241
--- Deeply compare two values.
242-
--- Handles cycles, metatables, and optional function ignoring.
242+
--- Handles metatables. Optionally handles cycles and function ignoring.
243243
---
244244
--- @param a any
245245
--- @param b any
246-
--- @param opts table|nil { ignore_functions = boolean }
246+
--- @param opts table|nil { ignore_functions = boolean, track_cycles = boolean }
247247
--- @param seen table|nil
248248
--- @return boolean
249249
local function deep_equals(a, b, opts, seen)
@@ -253,11 +253,13 @@ local function deep_equals(a, b, opts, seen)
253253
if type(a) ~= "table" then return false end -- same type but not table, thus was already compared
254254

255255
-- check for cycles in table references and preserve reference topology.
256-
seen = seen or { a_to_b = {}, b_to_a = {} }
257-
if seen.a_to_b[a] ~= nil then return seen.a_to_b[a] == b end
258-
if seen.b_to_a[b] ~= nil then return seen.b_to_a[b] == a end
259-
seen.a_to_b[a] = b
260-
seen.b_to_a[b] = a
256+
if opts and opts.track_cycles then
257+
seen = seen or { a_to_b = {}, b_to_a = {} }
258+
if seen.a_to_b[a] ~= nil then return seen.a_to_b[a] == b end
259+
if seen.b_to_a[b] ~= nil then return seen.b_to_a[b] == a end
260+
seen.a_to_b[a] = b
261+
seen.b_to_a[b] = a
262+
end
261263

262264
-- Compare keys/values from a
263265
for k, v in next, a do

drivers/SmartThings/matter-sensor/src/sub_drivers/air_quality_sensor/air_quality_sensor_utils/utils.lua

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -78,11 +78,11 @@ function AirQualitySensorUtils.set_supported_health_concern_values(device)
7878
end
7979

8080
--- Deeply compare two values.
81-
--- Handles cycles, metatables, and optional function ignoring.
81+
--- Handles metatables. Optionally handles cycles and function ignoring.
8282
---
8383
--- @param a any
8484
--- @param b any
85-
--- @param opts table|nil { ignore_functions = boolean }
85+
--- @param opts table|nil { ignore_functions = boolean, track_cycles = boolean }
8686
--- @param seen table|nil
8787
--- @return boolean
8888
function AirQualitySensorUtils.deep_equals(a, b, opts, seen)
@@ -92,11 +92,13 @@ function AirQualitySensorUtils.deep_equals(a, b, opts, seen)
9292
if type(a) ~= "table" then return false end -- same type but not table, thus was already compared
9393

9494
-- check for cycles in table references and preserve reference topology.
95-
seen = seen or { a_to_b = {}, b_to_a = {} }
96-
if seen.a_to_b[a] ~= nil then return seen.a_to_b[a] == b end
97-
if seen.b_to_a[b] ~= nil then return seen.b_to_a[b] == a end
98-
seen.a_to_b[a] = b
99-
seen.b_to_a[b] = a
95+
if opts and opts.track_cycles then
96+
seen = seen or { a_to_b = {}, b_to_a = {} }
97+
if seen.a_to_b[a] ~= nil then return seen.a_to_b[a] == b end
98+
if seen.b_to_a[b] ~= nil then return seen.b_to_a[b] == a end
99+
seen.a_to_b[a] = b
100+
seen.b_to_a[b] = a
101+
end
100102

101103
-- Compare keys/values from a
102104
for k, v in next, a do

drivers/SmartThings/matter-sensor/src/sub_drivers/air_quality_sensor/init.lua

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ function AirQualitySensorLifecycleHandlers.device_init(driver, device)
6565
device:subscribe()
6666
end
6767

68+
local st_utils = require "st.utils" --- IGNORE ---
6869
function AirQualitySensorLifecycleHandlers.info_changed(driver, device, event, args)
6970
if not aqs_utils.deep_equals(device.profile, args.old_st_store.profile, { ignore_functions = true }) then
7071
if device:get_field(fields.SUPPORTED_COMPONENT_CAPABILITIES) then

drivers/SmartThings/matter-switch/src/switch_utils/utils.lua

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -327,11 +327,11 @@ function utils.create_multi_press_values_list(size, supportsHeld)
327327
end
328328

329329
--- Deeply compare two values.
330-
--- Handles cycles, metatables, and optional function ignoring.
330+
--- Handles metatables. Optionally handles cycles and function ignoring.
331331
---
332332
--- @param a any
333333
--- @param b any
334-
--- @param opts table|nil { ignore_functions = boolean }
334+
--- @param opts table|nil { ignore_functions = boolean, track_cycles = boolean }
335335
--- @param seen table|nil
336336
--- @return boolean
337337
function utils.deep_equals(a, b, opts, seen)
@@ -341,11 +341,13 @@ function utils.deep_equals(a, b, opts, seen)
341341
if type(a) ~= "table" then return false end -- same type but not table, thus was already compared
342342

343343
-- check for cycles in table references and preserve reference topology.
344-
seen = seen or { a_to_b = {}, b_to_a = {} }
345-
if seen.a_to_b[a] ~= nil then return seen.a_to_b[a] == b end
346-
if seen.b_to_a[b] ~= nil then return seen.b_to_a[b] == a end
347-
seen.a_to_b[a] = b
348-
seen.b_to_a[b] = a
344+
if opts and opts.track_cycles then
345+
seen = seen or { a_to_b = {}, b_to_a = {} }
346+
if seen.a_to_b[a] ~= nil then return seen.a_to_b[a] == b end
347+
if seen.b_to_a[b] ~= nil then return seen.b_to_a[b] == a end
348+
seen.a_to_b[a] = b
349+
seen.b_to_a[b] = a
350+
end
349351

350352
-- Compare keys/values from a
351353
for k, v in next, a do

0 commit comments

Comments
 (0)