Skip to content

Commit c92c0cc

Browse files
committed
Simplify the get_device_parameters code
1 parent e7e228a commit c92c0cc

File tree

1 file changed

+4
-17
lines changed

1 file changed

+4
-17
lines changed

drivers/SmartThings/zigbee-switch/src/preferences.lua

Lines changed: 4 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ local devices = {
3131
}
3232
},
3333
AQARA_LIGHT_BULB = {
34-
MATCHING_MATRIX = { mfr = "Aqara", model = "lumi.light.acn014" },
34+
MATCHING_MATRIX = {{ mfr = "Aqara", model = "lumi.light.acn014" }},
3535
PARAMETERS = {
3636
["stse.restorePowerState"] = function(device, value)
3737
return cluster_base.write_manufacturer_specific_attribute(device, 0xFCC0,
@@ -71,26 +71,13 @@ preferences.get_device_parameters = function(zigbee_device)
7171
local model = zigbee_device:get_model()
7272

7373
for _, device in pairs(devices) do
74-
local matrix = device.MATCHING_MATRIX
75-
if not matrix then goto continue end
76-
77-
-- Single table format: { mfr = "...", model = "..." }
78-
if matrix.mfr and matrix.model then
79-
if matrix.mfr == mfr and matrix.model == model then
74+
for _, fp in ipairs(device.MATCHING_MATRIX) do
75+
if fp.mfr == mfr and fp.model == model then
8076
return device.PARAMETERS
8177
end
82-
goto continue
83-
end
84-
-- Array format: { { mfr = "...", model = "..." }, ... }
85-
if type(matrix) == "table" then
86-
for _, match in ipairs(matrix) do
87-
if match.mfr == mfr and match.model == model then
88-
return device.PARAMETERS
89-
end
90-
end
9178
end
92-
::continue::
9379
end
80+
9481
return nil
9582
end
9683

0 commit comments

Comments
 (0)