From d5424d31248d3d81549e817624f8905565ec15da Mon Sep 17 00:00:00 2001 From: Nick DeBoom Date: Tue, 17 Dec 2024 15:17:13 -0600 Subject: [PATCH] Addressing review feedback * Add embedded preferences for preset tilt value * Update profile selection logic * Minor test case changes --- .../profiles/window-covering-tilt-battery.yml | 8 ++++ .../window-covering-tilt-only-battery.yml | 11 +++++- .../profiles/window-covering-tilt-only.yml | 11 +++++- .../profiles/window-covering-tilt.yml | 9 +++++ .../matter-window-covering/src/init.lua | 39 ++++++++++++------- .../src/test/test_matter_window_covering.lua | 13 ++++--- 6 files changed, 67 insertions(+), 24 deletions(-) diff --git a/drivers/SmartThings/matter-window-covering/profiles/window-covering-tilt-battery.yml b/drivers/SmartThings/matter-window-covering/profiles/window-covering-tilt-battery.yml index 7a39456b52..ae8bb0aa5d 100644 --- a/drivers/SmartThings/matter-window-covering/profiles/window-covering-tilt-battery.yml +++ b/drivers/SmartThings/matter-window-covering/profiles/window-covering-tilt-battery.yml @@ -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 diff --git a/drivers/SmartThings/matter-window-covering/profiles/window-covering-tilt-only-battery.yml b/drivers/SmartThings/matter-window-covering/profiles/window-covering-tilt-only-battery.yml index e8dc16d688..831583efdf 100644 --- a/drivers/SmartThings/matter-window-covering/profiles/window-covering-tilt-only-battery.yml +++ b/drivers/SmartThings/matter-window-covering/profiles/window-covering-tilt-only-battery.yml @@ -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 diff --git a/drivers/SmartThings/matter-window-covering/profiles/window-covering-tilt-only.yml b/drivers/SmartThings/matter-window-covering/profiles/window-covering-tilt-only.yml index 861ffbe47e..be2c56beb6 100644 --- a/drivers/SmartThings/matter-window-covering/profiles/window-covering-tilt-only.yml +++ b/drivers/SmartThings/matter-window-covering/profiles/window-covering-tilt-only.yml @@ -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 diff --git a/drivers/SmartThings/matter-window-covering/profiles/window-covering-tilt.yml b/drivers/SmartThings/matter-window-covering/profiles/window-covering-tilt.yml index 6ed5bfac82..de2c8c03f8 100644 --- a/drivers/SmartThings/matter-window-covering/profiles/window-covering-tilt.yml +++ b/drivers/SmartThings/matter-window-covering/profiles/window-covering-tilt.yml @@ -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 diff --git a/drivers/SmartThings/matter-window-covering/src/init.lua b/drivers/SmartThings/matter-window-covering/src/init.lua index bbcdaa1f6d..015ca01a8b 100644 --- a/drivers/SmartThings/matter-window-covering/src/init.lua +++ b/drivers/SmartThings/matter-window-covering/src/init.lua @@ -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) @@ -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 diff --git a/drivers/SmartThings/matter-window-covering/src/test/test_matter_window_covering.lua b/drivers/SmartThings/matter-window-covering/src/test/test_matter_window_covering.lua index e09731ff41..30553b5cbd 100644 --- a/drivers/SmartThings/matter-window-covering/src/test/test_matter_window_covering.lua +++ b/drivers/SmartThings/matter-window-covering/src/test/test_matter_window_covering.lua @@ -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} @@ -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} @@ -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} @@ -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() @@ -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( @@ -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 )