Skip to content

Commit

Permalink
Merge pull request #1573 from SmartThingsCommunity/feature/5-button
Browse files Browse the repository at this point in the history
Matter Button: Add profile for 5-button devices
  • Loading branch information
tpmanley authored Aug 12, 2024
2 parents 4774ab8 + 62586a1 commit 9b18d70
Show file tree
Hide file tree
Showing 4 changed files with 88 additions and 73 deletions.
38 changes: 38 additions & 0 deletions drivers/SmartThings/matter-button/profiles/5-button-battery.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
name: 5-button-battery
components:
- id: main
capabilities:
- id: button
version: 1
- id: battery
version: 1
- id: firmwareUpdate
version: 1
- id: refresh
version: 1
categories:
- name: RemoteController
- id: button2
capabilities:
- id: button
version: 1
categories:
- name: RemoteController
- id: button3
capabilities:
- id: button
version: 1
categories:
- name: RemoteController
- id: button4
capabilities:
- id: button
version: 1
categories:
- name: RemoteController
- id: button5
capabilities:
- id: button
version: 1
categories:
- name: RemoteController
36 changes: 36 additions & 0 deletions drivers/SmartThings/matter-button/profiles/5-button.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
name: 5-button
components:
- id: main
capabilities:
- id: button
version: 1
- id: firmwareUpdate
version: 1
- id: refresh
version: 1
categories:
- name: RemoteController
- id: button2
capabilities:
- id: button
version: 1
categories:
- name: RemoteController
- id: button3
capabilities:
- id: button
version: 1
categories:
- name: RemoteController
- id: button4
capabilities:
- id: button
version: 1
categories:
- name: RemoteController
- id: button5
capabilities:
- id: button
version: 1
categories:
- name: RemoteController
2 changes: 1 addition & 1 deletion drivers/SmartThings/matter-button/src/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ local START_BUTTON_PRESS = "__start_button_press"
local TIMEOUT_THRESHOLD = 10 --arbitrary timeout
local HELD_THRESHOLD = 1
-- this is the number of buttons for which we have a static profile already made
local STATIC_PROFILE_SUPPORTED = {2, 4, 6, 8}
local STATIC_PROFILE_SUPPORTED = {2, 4, 5, 6, 8}

local COMPONENT_TO_ENDPOINT_MAP = "__component_to_endpoint_map"
local DEFERRED_CONFIGURE = "__DEFERRED_CONFIGURE"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,27 +40,9 @@ local mock_device = test.mock_device.build_test_matter_device(
clusters = {
{
cluster_id = clusters.Switch.ID,
feature_map = clusters.Switch.types.SwitchFeature.MOMENTARY_SWITCH | clusters.Switch.types.SwitchFeature.MOMENTARY_SWITCH_LONG_PRESS,
cluster_type = "SERVER"
},
},
},
{
endpoint_id = 5,
clusters = {
{
cluster_id = clusters.Switch.ID,
feature_map = clusters.Switch.types.SwitchFeature.MOMENTARY_SWITCH | clusters.Switch.types.SwitchFeature.MOMENTARY_SWITCH_MULTI_PRESS,
cluster_type = "SERVER"
},
},
},
{
endpoint_id = 6,
clusters = {
{
cluster_id = clusters.Switch.ID,
feature_map = clusters.Switch.types.SwitchFeature.MOMENTARY_SWITCH | clusters.Switch.types.SwitchFeature.MOMENTARY_SWITCH_MULTI_PRESS,
feature_map = clusters.Switch.types.SwitchFeature.MOMENTARY_SWITCH
| clusters.Switch.types.SwitchFeature.MOMENTARY_SWITCH_LONG_PRESS
| clusters.Switch.types.SwitchFeature.MOMENTARY_SWITCH_MULTI_PRESS,
cluster_type = "SERVER"
},
},
Expand Down Expand Up @@ -124,29 +106,9 @@ local function test_init()
parent_device_id = mock_device.id,
parent_assigned_child_key = "04"
})
test.socket.capability:__expect_send(mock_children[4]:generate_test_message("main", capabilities.button.supportedButtonValues({"pushed", "held"}, {visibility = {displayed = false}})))
test.socket.matter:__expect_send({mock_device.id, clusters.Switch.attributes.MultiPressMax:read(mock_device, 4)})
test.socket.capability:__expect_send(mock_children[4]:generate_test_message("main", button_attr.pushed({state_change = false})))

mock_device:expect_device_create({
type = "EDGE_CHILD",
label = "Matter Button 4",
profile = "button",
parent_device_id = mock_device.id,
parent_assigned_child_key = "05"
})
test.socket.matter:__expect_send({mock_device.id, clusters.Switch.attributes.MultiPressMax:read(mock_device, 5)})
test.socket.capability:__expect_send(mock_children[5]:generate_test_message("main", button_attr.pushed({state_change = false})))

mock_device:expect_device_create({
type = "EDGE_CHILD",
label = "Matter Button 5",
profile = "button",
parent_device_id = mock_device.id,
parent_assigned_child_key = "06"
})
test.socket.matter:__expect_send({mock_device.id, clusters.Switch.attributes.MultiPressMax:read(mock_device, 6)})
test.socket.capability:__expect_send(mock_children[6]:generate_test_message("main", button_attr.pushed({state_change = false})))

end

test.set_test_init_function(test_init)
Expand Down Expand Up @@ -242,27 +204,6 @@ test.register_message_test(
}
)

test.register_message_test(
"Receiving a max press attribute of 2 should emit correct event", {
{
channel = "matter",
direction = "receive",
message = {
mock_device.id,
clusters.Switch.attributes.MultiPressMax:build_test_report_data(
mock_device, 6, 2
)
},
},
{
channel = "capability",
direction = "send",
message = mock_children[6]:generate_test_message("main",
capabilities.button.supportedButtonValues({"pushed", "double"}, {visibility = {displayed = false}}))
},
}
)

test.register_message_test(
"Receiving a max press attribute of 3 should emit correct event", {
{
Expand All @@ -271,15 +212,15 @@ test.register_message_test(
message = {
mock_device.id,
clusters.Switch.attributes.MultiPressMax:build_test_report_data(
mock_device, 5, 3
mock_device, 4, 3
)
},
},
{
channel = "capability",
direction = "send",
message = mock_children[5]:generate_test_message("main",
capabilities.button.supportedButtonValues({"pushed", "double", "pushed_3x"}, {visibility = {displayed = false}}))
message = mock_children[4]:generate_test_message("main",
capabilities.button.supportedButtonValues({"pushed", "double", "held", "pushed_3x"}, {visibility = {displayed = false}}))
},
}
)
Expand Down Expand Up @@ -313,7 +254,7 @@ test.register_message_test(
message = {
mock_device.id,
clusters.Switch.events.InitialPress:build_test_event_report(
mock_device, 5, {new_position = 1}
mock_device, 4, {new_position = 1}
)
}
},
Expand All @@ -323,14 +264,14 @@ test.register_message_test(
message = {
mock_device.id,
clusters.Switch.events.MultiPressComplete:build_test_event_report(
mock_device, 5, {new_position = 1, total_number_of_presses_counted = 2, previous_position = 0}
mock_device, 4, {new_position = 1, total_number_of_presses_counted = 2, previous_position = 0}
)
}
},
{
channel = "capability",
direction = "send",
message = mock_children[5]:generate_test_message("main", button_attr.double({state_change = true}))
message = mock_children[4]:generate_test_message("main", button_attr.double({state_change = true}))
},

}
Expand All @@ -344,7 +285,7 @@ test.register_message_test(
message = {
mock_device.id,
clusters.Switch.events.InitialPress:build_test_event_report(
mock_device, 6, {new_position = 1}
mock_device, 4, {new_position = 1}
)
}
},
Expand All @@ -354,14 +295,14 @@ test.register_message_test(
message = {
mock_device.id,
clusters.Switch.events.MultiPressComplete:build_test_event_report(
mock_device, 6, {new_position = 1, total_number_of_presses_counted = 4, previous_position = 0}
mock_device, 4, {new_position = 1, total_number_of_presses_counted = 4, previous_position = 0}
)
}
},
{
channel = "capability",
direction = "send",
message = mock_children[6]:generate_test_message("main", button_attr.pushed_4x({state_change = true}))
message = mock_children[4]:generate_test_message("main", button_attr.pushed_4x({state_change = true}))
},

}
Expand Down

0 comments on commit 9b18d70

Please sign in to comment.