Skip to content

Commit

Permalink
Addressing review feedback
Browse files Browse the repository at this point in the history
* Add embedded preferences for preset tilt value
* Update profile selection logic
* Minor test case changes
  • Loading branch information
nickolas-deboom committed Dec 17, 2024
1 parent 8264136 commit d5424d3
Show file tree
Hide file tree
Showing 6 changed files with 67 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,11 @@ components:
preferences:
- preferenceId: presetPosition
explicit: true
- name: "presetTiltPosition"
title: "Preset tilt position"
description: "Set the window shade preset tilt position"
preferenceType: integer
definition:
minimum: 0
maximum: 100
default: 50
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,12 @@ components:
categories:
- name: Blind
preferences:
- preferenceId: presetPosition
explicit: true
- name: "presetTiltPosition"
title: "Preset tilt position"
description: "Set the window shade preset tilt position"
required: false
preferenceType: integer
definition:
minimum: 0
maximum: 100
default: 50
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,12 @@ components:
categories:
- name: Blind
preferences:
- preferenceId: presetPosition
explicit: true
- name: "presetTiltPosition"
title: "Preset tilt position"
description: "Set the window shade preset tilt position"
required: false
preferenceType: integer
definition:
minimum: 0
maximum: 100
default: 50
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,12 @@ components:
preferences:
- preferenceId: presetPosition
explicit: true
- name: "presetTiltPosition"
title: "Preset tilt position"
description: "Set the window shade preset tilt position"
required: false
preferenceType: integer
definition:
minimum: 0
maximum: 100
default: 50
39 changes: 24 additions & 15 deletions drivers/SmartThings/matter-window-covering/src/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -40,21 +40,19 @@ local function component_to_endpoint(device, component_name)
end

local function match_profile(device)
local profile_name = "window-covering"
local lift_eps = device:get_endpoints(clusters.WindowCovering.ID, {feature_bitmap = clusters.WindowCovering.types.Feature.LIFT})
local tilt_eps = device:get_endpoints(clusters.WindowCovering.ID, {feature_bitmap = clusters.WindowCovering.types.Feature.TILT})
local battery_eps = device:get_endpoints(clusters.PowerSource.ID, {feature_bitmap = clusters.PowerSource.types.PowerSourceFeature.BATTERY})
local profile_name = "window-covering"
if #tilt_eps > 0 then
if #lift_eps > 0 then
profile_name = profile_name .. "-tilt"
else
profile_name = profile_name .. "-tilt-only"
profile_name = profile_name .. "-tilt"
if #lift_eps == 0 then
profile_name = profile_name .. "-only"
end
end
local battery_eps = device:get_endpoints(clusters.PowerSource.ID,
{feature_bitmap = clusters.PowerSource.types.PowerSourceFeature.BATTERY})

if #battery_eps > 0 then
profile_name = "window-covering-battery"
profile_name = profile_name .. "-battery"
end
device:try_update_metadata({profile = profile_name})
device:set_field(PROFILE_MATCHED, 1)
Expand Down Expand Up @@ -90,13 +88,24 @@ local function device_removed(driver, device) log.info("device removed") end
-- capability handlers
local function handle_preset(driver, device, cmd)
local endpoint_id = device:component_to_endpoint(cmd.component)
local lift_value = 100 - device.preferences.presetPosition
local hundredths_lift_percent = lift_value * 100
local req = clusters.WindowCovering.server.commands.GoToLiftPercentage(
device, endpoint_id, hundredths_lift_percent
)

device:send(req)
local lift_eps = device:get_endpoints(clusters.WindowCovering.ID, {feature_bitmap = clusters.WindowCovering.types.Feature.LIFT})
local tilt_eps = device:get_endpoints(clusters.WindowCovering.ID, {feature_bitmap = clusters.WindowCovering.types.Feature.TILT})
if #lift_eps > 0 then
local lift_value = 100 - device.preferences.presetPosition
local hundredths_lift_percent = lift_value * 100
local req = clusters.WindowCovering.server.commands.GoToLiftPercentage(
device, endpoint_id, hundredths_lift_percent
)
device:send(req)
end
if #tilt_eps > 0 then
local tilt_value = 100 - device.preferences.presetTiltPosition
local hundredths_tilt_percent = tilt_value * 100
local req = clusters.WindowCovering.server.commands.GoToTiltPercentage(
device, endpoint_id, hundredths_tilt_percent
)
device:send(req)
end
end

-- close covering
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ local mock_device = test.mock_device.build_test_matter_device(
cluster_id = clusters.WindowCovering.ID,
cluster_type = "SERVER",
cluster_revision = 1,
feature_map = 0,
feature_map = 3,
},
{cluster_id = clusters.LevelControl.ID, cluster_type = "SERVER"},
{cluster_id = clusters.PowerSource.ID, cluster_type = "SERVER", feature_map = 0x0002}
Expand Down Expand Up @@ -73,7 +73,7 @@ local mock_device_switch_to_battery = test.mock_device.build_test_matter_device(
cluster_id = clusters.WindowCovering.ID,
cluster_type = "SERVER",
cluster_revision = 1,
feature_map = 0,
feature_map = 1,
},
{cluster_id = clusters.LevelControl.ID, cluster_type = "SERVER"},
{cluster_id = clusters.PowerSource.ID, cluster_type = "SERVER", feature_map = 0x0002}
Expand Down Expand Up @@ -105,7 +105,7 @@ local mock_device_mains_powered = test.mock_device.build_test_matter_device(
cluster_id = clusters.WindowCovering.ID,
cluster_type = "SERVER",
cluster_revision = 1,
feature_map = 0,
feature_map = 1,
},
{cluster_id = clusters.LevelControl.ID, cluster_type = "SERVER"},
{cluster_id = clusters.PowerSource.ID, cluster_type = "SERVER", feature_map = 0x0001}
Expand Down Expand Up @@ -136,7 +136,7 @@ local function test_init()
end
test.socket.matter:__expect_send({mock_device.id, subscribe_request})
test.mock_device.add_test_device(mock_device)
mock_device:expect_metadata_update({ profile = "window-covering-battery" })
mock_device:expect_metadata_update({ profile = "window-covering-tilt-battery" })
end

local function test_init_switch_to_battery()
Expand Down Expand Up @@ -780,6 +780,9 @@ test.register_coroutine_test("Handle windowcoveringPreset", function()
test.socket.matter:__expect_send(
{mock_device.id, WindowCovering.server.commands.GoToLiftPercentage(mock_device, 10, 7000)}
)
test.socket.matter:__expect_send(
{mock_device.id, WindowCovering.server.commands.GoToTiltPercentage(mock_device, 10, 5000)}
)
end)

test.register_coroutine_test(
Expand All @@ -801,7 +804,7 @@ test.register_coroutine_test(
function()
test.socket.device_lifecycle:__queue_receive(mock_device:generate_info_changed({}))
mock_device:expect_metadata_update({
profile = "window-covering-battery",
profile = "window-covering-tilt-battery",
})
end
)
Expand Down

0 comments on commit d5424d3

Please sign in to comment.