Skip to content

Commit 093a09b

Browse files
clean up open/close handler logic
1 parent 438fbaa commit 093a09b

3 files changed

Lines changed: 17 additions & 29 deletions

File tree

drivers/SmartThings/matter-switch/src/sub_drivers/closures/closure_handlers/capability_handlers.lua

Lines changed: 15 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22
-- Licensed under the Apache License, Version 2.0
33

44
local capabilities = require "st.capabilities"
5-
local clusters = require "st.matter.clusters"
65
local closure_fields = require "sub_drivers.closures.closure_utils.fields"
6+
local clusters = require "st.matter.clusters"
77

88
clusters.ClosureControl = require "embedded_clusters.ClosureControl"
99

@@ -28,42 +28,30 @@ end
2828

2929
function ClosureCapabilityHandlers.handle_close(driver, device, cmd)
3030
local endpoint_id = device:component_to_endpoint(cmd.component)
31-
local req
32-
if #device:get_endpoints(clusters.WindowCovering.ID) > 0 then
33-
req = clusters.WindowCovering.server.commands.DownOrClose(device, endpoint_id)
34-
if device:get_field(closure_fields.REVERSE_POLARITY) then
35-
req = clusters.WindowCovering.server.commands.UpOrOpen(device, endpoint_id)
36-
end
37-
else -- ClosureControl cluster
38-
req = clusters.ClosureControl.server.commands.MoveTo(
31+
local reverse = device:get_field(closure_fields.REVERSE_POLARITY)
32+
local req = reverse and clusters.WindowCovering.server.commands.UpOrOpen(device, endpoint_id) or
33+
clusters.WindowCovering.server.commands.DownOrClose(device, endpoint_id)
34+
if #device:get_endpoints(clusters.ClosureControl.ID) > 0 then
35+
req = reverse and clusters.ClosureControl.server.commands.MoveTo(
36+
device, endpoint_id, clusters.ClosureControl.types.TargetPositionEnum.MOVE_TO_FULLY_OPEN
37+
) or clusters.ClosureControl.server.commands.MoveTo(
3938
device, endpoint_id, clusters.ClosureControl.types.TargetPositionEnum.MOVE_TO_FULLY_CLOSED
4039
)
41-
if device:get_field(closure_fields.REVERSE_POLARITY) then
42-
req = clusters.ClosureControl.server.commands.MoveTo(
43-
device, endpoint_id, clusters.ClosureControl.types.TargetPositionEnum.MOVE_TO_FULLY_OPEN
44-
)
45-
end
4640
end
4741
device:send(req)
4842
end
4943

5044
function ClosureCapabilityHandlers.handle_open(driver, device, cmd)
5145
local endpoint_id = device:component_to_endpoint(cmd.component)
52-
local req
53-
if #device:get_endpoints(clusters.WindowCovering.ID) > 0 then
54-
req = clusters.WindowCovering.server.commands.UpOrOpen(device, endpoint_id)
55-
if device:get_field(closure_fields.REVERSE_POLARITY) then
56-
req = clusters.WindowCovering.server.commands.DownOrClose(device, endpoint_id)
57-
end
58-
else -- ClosureControl cluster
59-
req = clusters.ClosureControl.server.commands.MoveTo(
46+
local reverse = device:get_field(closure_fields.REVERSE_POLARITY)
47+
local req = reverse and clusters.WindowCovering.server.commands.DownOrClose(device, endpoint_id) or
48+
clusters.WindowCovering.server.commands.UpOrOpen(device, endpoint_id)
49+
if #device:get_endpoints(clusters.ClosureControl.ID) > 0 then
50+
req = reverse and clusters.ClosureControl.server.commands.MoveTo(
51+
device, endpoint_id, clusters.ClosureControl.types.TargetPositionEnum.MOVE_TO_FULLY_CLOSED
52+
) or clusters.ClosureControl.server.commands.MoveTo(
6053
device, endpoint_id, clusters.ClosureControl.types.TargetPositionEnum.MOVE_TO_FULLY_OPEN
6154
)
62-
if device:get_field(closure_fields.REVERSE_POLARITY) then
63-
req = clusters.ClosureControl.server.commands.MoveTo(
64-
device, endpoint_id, clusters.ClosureControl.types.TargetPositionEnum.MOVE_TO_FULLY_CLOSED
65-
)
66-
end
6755
end
6856
device:send(req)
6957
end

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -319,6 +319,8 @@ function DeviceConfiguration.match_profile(driver, device)
319319
-- initialize the main device card with closure if applicable
320320
local closure_ep_ids = switch_utils.get_endpoints_by_device_type(device, fields.DEVICE_TYPE_ID.CLOSURE)
321321
if #closure_ep_ids > 0 then
322+
-- Note that Window, Barrier, and Cabinet currently all use the generic Covering profile, but will be updated to
323+
-- more specific profiles once the associated profile categories are published.
322324
local assign_closure_profile_fn_map = {
323325
[fields.closure_tag.COVERING] = ClosureDeviceConfiguration.assign_profile_for_covering_ep,
324326
[fields.closure_tag.WINDOW] = ClosureDeviceConfiguration.assign_profile_for_covering_ep,

drivers/SmartThings/matter-switch/src/test/test_matter_closure.lua

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,6 @@ local uint32 = require "st.matter.data_types.Uint32"
99

1010
clusters.ClosureControl = require "embedded_clusters.ClosureControl"
1111

12-
local WindowCovering = clusters.WindowCovering
13-
1412
local mock_device = test.mock_device.build_test_matter_device(
1513
{
1614
label = "Matter Closure",

0 commit comments

Comments
 (0)