-
Notifications
You must be signed in to change notification settings - Fork 522
Matter Switch: Include Ikea subdriver support for knob capability #2678
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
hcarter-775
wants to merge
4
commits into
main
Choose a base branch
from
feature/knob
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 2 commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,24 @@ | ||
| name: Knob | ||
| status: proposed | ||
| attributes: | ||
| rotateAmount: | ||
| schema: | ||
| $ref: RelativeStep | ||
| heldRotateAmount: | ||
| schema: | ||
| $ref: RelativeStep | ||
| supportedAttributes: | ||
| schema: | ||
| type: object | ||
| additionalProperties: false | ||
| properties: | ||
| value: | ||
| type: array | ||
| items: | ||
| type: string | ||
| enum: | ||
| - rotateAmount | ||
| - heldRotateAmount | ||
| commands: {} | ||
| id: knob | ||
| version: 1 | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
39 changes: 39 additions & 0 deletions
39
.../SmartThings/matter-switch/src/sub_drivers/ikea_scroll/scroll_handlers/event_handlers.lua
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,39 @@ | ||
| -- Copyright © 2025 SmartThings, Inc. | ||
| -- Licensed under the Apache License, Version 2.0 | ||
|
|
||
| local st_utils = require "st.utils" | ||
| local capabilities = require "st.capabilities" | ||
| local switch_utils = require "switch_utils.utils" | ||
| local generic_event_handlers = require "switch_handlers.event_handlers" | ||
| local scroll_fields = require "sub_drivers.ikea_scroll.scroll_utils.fields" | ||
|
|
||
| local IkeaScrollEventHandlers = {} | ||
|
|
||
| local function rotate_amount_event_helper(device, endpoint_id, num_presses_to_handle) | ||
| -- to cut down on checks, we can assume that if the endpoint is not in ENDPOINTS_UP_SCROLL, it is in ENDPOINTS_DOWN_SCROLL | ||
| local scroll_direction = switch_utils.tbl_contains(scroll_fields.ENDPOINTS_UP_SCROLL, endpoint_id) and 1 or -1 | ||
| local scroll_amount = st_utils.clamp_value(scroll_direction * scroll_fields.PER_SCROLL_EVENT_ROTATION * num_presses_to_handle, -100, 100) | ||
| device:emit_event_for_endpoint(endpoint_id, capabilities.knob.rotateAmount(scroll_amount, {state_change = true})) | ||
| end | ||
|
|
||
| function IkeaScrollEventHandlers.initial_press_handler(driver, device, ib, response) | ||
| -- use the generic handler logic for the push endpoints. Else, use custom logic. | ||
| if switch_utils.tbl_contains(ib.endpoint_id, scroll_fields.ENDPOINTS_PUSH) then | ||
| generic_event_handlers.initial_press_handler(driver, device. ib, response) | ||
| else | ||
| device:set_field(scroll_fields.LATEST_NUMBER_OF_PRESSES_COUNTED, 1) | ||
| rotate_amount_event_helper(device, ib.endpoint_id, 1) | ||
| end | ||
| end | ||
|
|
||
| -- Used by ENDPOINTS_UP_SCROLL and ENDPOINTS_DOWN_SCROLL, not ENDPOINTS_PUSH | ||
| function IkeaScrollEventHandlers.multi_press_ongoing_handler(driver, device, ib, response) | ||
| local cur_num_presses_counted = ib.data and ib.data.elements and ib.data.elements.current_number_of_presses_counted.value or 0 | ||
| local num_presses_to_handle = cur_num_presses_counted - (device:get_field(scroll_fields.LATEST_NUMBER_OF_PRESSES_COUNTED) or 0) | ||
| if num_presses_to_handle > 0 then | ||
| device:set_field(scroll_fields.LATEST_NUMBER_OF_PRESSES_COUNTED, cur_num_presses_counted) | ||
| rotate_amount_event_helper(device, ib.endpoint_id, num_presses_to_handle) | ||
| end | ||
| end | ||
|
|
||
| return IkeaScrollEventHandlers |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
29 changes: 25 additions & 4 deletions
29
drivers/SmartThings/matter-switch/src/sub_drivers/ikea_scroll/scroll_utils/fields.lua
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,21 +1,42 @@ | ||
| -- Copyright © 2025 SmartThings, Inc. | ||
| -- Licensed under the Apache License, Version 2.0 | ||
|
|
||
| local st_utils = require "st.utils" | ||
| local clusters = require "st.matter.clusters" | ||
|
|
||
| local IkeaScrollFields = {} | ||
|
|
||
| -- PowerSource supported on Root Node | ||
| IkeaScrollFields.ENDPOINT_POWER_SOURCE = 0 | ||
|
|
||
| -- Switch Endpoints used for basic press functionality | ||
| IkeaScrollFields.ENDPOINTS_PRESS = {3, 6, 9} | ||
| -- Generic Switch Endpoints used for basic push functionality | ||
| IkeaScrollFields.ENDPOINTS_PUSH = {3, 6, 9} | ||
|
|
||
| -- Required Events for the ENDPOINTS_PRESS. | ||
| -- Generic Switch Endpoints used for Up Scroll functionality | ||
| IkeaScrollFields.ENDPOINTS_UP_SCROLL = {1, 4, 7} | ||
|
|
||
| -- Generic Switch Endpoints used for Down Scroll functionality | ||
| IkeaScrollFields.ENDPOINTS_DOWN_SCROLL = {2, 5, 8} | ||
|
|
||
| IkeaScrollFields.MAX_SCROLL_PRESSES = 18 | ||
| IkeaScrollFields.PER_SCROLL_EVENT_ROTATION = st_utils.round(1 / IkeaScrollFields.MAX_SCROLL_PRESSES * 100) | ||
|
|
||
| IkeaScrollFields.LATEST_NUMBER_OF_PRESSES_COUNTED = "__latest_number_of_presses_counted" | ||
|
|
||
| -- Required Events for the ENDPOINTS_PUSH. | ||
| IkeaScrollFields.switch_press_subscribed_events = { | ||
| clusters.Switch.events.InitialPress.ID, | ||
| clusters.Switch.events.MultiPressComplete.ID, | ||
| clusters.Switch.events.LongPress.ID, | ||
| } | ||
|
|
||
| return IkeaScrollFields | ||
| -- Required Events for the ENDPOINTS_UP_SCROLL and ENDPOINTS_DOWN_SCROLL. Adds a | ||
| -- MultiPressOngoing subscription to handle step functionality in real-time, and | ||
| -- removes MultiPressComplete subscription due to the real-time handling | ||
| IkeaScrollFields.switch_scroll_subscribed_events = { | ||
| clusters.Switch.events.InitialPress.ID, | ||
| clusters.Switch.events.MultiPressOngoing.ID, | ||
| } | ||
|
|
||
|
|
||
| return IkeaScrollFields |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -201,7 +201,8 @@ end | |
|
|
||
| --- An extension of the library function endpoint_to_component, used to support a mapping scheme | ||
| --- that optionally includes cluster and attribute ids so that multiple components can be mapped | ||
| --- to a single endpoint. | ||
| --- to a single endpoint. This extension also handles the case that multiple endpoints map to the | ||
| --- same component | ||
| --- | ||
| --- @param device any a Matter device object | ||
| --- @param ep_info number|table either an ep_id or a table { endpoint_id, optional(cluster_id), optional(attribute_id) } | ||
|
|
@@ -214,10 +215,19 @@ function utils.endpoint_to_component(device, ep_info) | |
| for component, map_info in pairs(device:get_field(fields.COMPONENT_TO_ENDPOINT_MAP) or {}) do | ||
| if type(map_info) == "number" and map_info == ep_info.endpoint_id then | ||
| return component | ||
| elseif type(map_info) == "table" and map_info.endpoint_id == ep_info.endpoint_id | ||
| and (not map_info.cluster_id or (map_info.cluster_id == ep_info.cluster_id | ||
| and (not map_info.attribute_ids or utils.tbl_contains(map_info.attribute_ids, ep_info.attribute_id)))) then | ||
| return component | ||
| elseif type(map_info) == "table" then | ||
| if type(map_info.endpoint_id) == "number" then | ||
| map_info = {map_info} | ||
| end | ||
| for _, ep_map_info in ipairs(map_info) do | ||
| if type(ep_map_info) == "number" and ep_map_info == ep_info.endpoint_id then | ||
| return component | ||
| elseif type(ep_map_info) == "table" and ep_map_info.endpoint_id == ep_info.endpoint_id | ||
| and (not ep_map_info.cluster_id or (ep_map_info.cluster_id == ep_info.cluster_id | ||
| and (not ep_map_info.attribute_ids or utils.tbl_contains(ep_map_info.attribute_ids, ep_info.attribute_id)))) then | ||
| return component | ||
| end | ||
| end | ||
|
Comment on lines
+218
to
+230
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The logic here is a little hard to follow. I'm not quite understanding why this change is needed to support multiple endpoints mapping to the same component? Wouldn't the table layout of map_info be the same? does the old code not actually work for this case? |
||
| end | ||
| end | ||
| return "main" | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.