Skip to content

Commit 7a822d1

Browse files
Move init to doConfigure
Button and switch init will eventually be moved to doConfigure in the main driver, so moving it there in the subdriver.
1 parent 6e9d71e commit 7a822d1

File tree

2 files changed

+14
-18
lines changed

2 files changed

+14
-18
lines changed

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

+2
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,9 @@ local function test_init()
210210
for i, clus in ipairs(cluster_subscribe_list) do
211211
if i > 1 then subscribe_request:merge(clus:subscribe(mock_device)) end
212212
end
213+
test.socket.device_lifecycle:__queue_receive({ mock_device.id, "doConfigure" })
213214
mock_device:expect_metadata_update({ profile = "12-button-keyboard" })
215+
mock_device:expect_metadata_update({ provisioning_state = "PROVISIONED" })
214216
configure_buttons()
215217
test.socket.matter:__expect_send({mock_device.id, subscribe_request})
216218
test.mock_device.add_test_device(mock_device)

drivers/SmartThings/matter-switch/src/third-reality-mk1/init.lua

+12-18
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,8 @@ local capabilities = require "st.capabilities"
1616
local clusters = require "st.matter.clusters"
1717
local device_lib = require "st.device"
1818

19-
local BUTTON_DEVICE_PROFILED = "__button_device_profiled"
2019
local COMPONENT_TO_ENDPOINT_MAP = "__component_to_endpoint_map"
2120
local INITIAL_PRESS_ONLY = "__initial_press_only"
22-
local SWITCH_INITIALIZED = "__switch_initialized"
2321

2422
-------------------------------------------------------------------------------------
2523
-- Third Reality MK1 specifics
@@ -92,8 +90,9 @@ local function configure_buttons(device)
9290
end
9391
end
9492

95-
local function build_button_component_map(device, button_eps)
93+
local function build_button_component_map(device)
9694
-- create component mapping on the main profile button endpoints
95+
local button_eps = device:get_endpoints(clusters.Switch.ID, {feature_bitmap=clusters.Switch.types.SwitchFeature.MOMENTARY_SWITCH})
9796
table.sort(button_eps)
9897
local component_map = {}
9998
for component_num, ep in ipairs(button_eps) do
@@ -103,33 +102,28 @@ local function build_button_component_map(device, button_eps)
103102
device:set_field(COMPONENT_TO_ENDPOINT_MAP, component_map, {persist = true})
104103
end
105104

106-
local function initialize_buttons(driver, device)
107-
local button_eps = device:get_endpoints(clusters.Switch.ID, {feature_bitmap=clusters.Switch.types.SwitchFeature.MOMENTARY_SWITCH})
108-
device:try_update_metadata({profile = "12-button-keyboard"})
109-
device:set_field(BUTTON_DEVICE_PROFILED, true)
110-
-- All button endpoints found will be added as components in the 12-button-keyboard profile.
111-
-- The resulting endpoint to component map is saved in the COMPONENT_TO_ENDPOINT_MAP field
112-
build_button_component_map(device, button_eps)
113-
configure_buttons(device)
114-
device:set_field(SWITCH_INITIALIZED, true, {persist = true})
115-
end
116-
117105
local function device_init(driver, device)
118106
if device.network_type ~= device_lib.NETWORK_TYPE_MATTER then
119107
return
120108
end
121109
device:set_component_to_endpoint_fn(component_to_endpoint)
122110
device:set_endpoint_to_component_fn(endpoint_to_component)
123-
if not device:get_field(SWITCH_INITIALIZED) then
124-
initialize_buttons(driver, device)
125-
end
126111
device:subscribe()
127112
end
128113

114+
local function do_configure(driver, device)
115+
device:try_update_metadata({profile = "12-button-keyboard"})
116+
-- All button endpoints found will be added as components in the 12-button-keyboard profile.
117+
-- The resulting endpoint to component map is saved in the COMPONENT_TO_ENDPOINT_MAP field
118+
build_button_component_map(device)
119+
configure_buttons(device)
120+
end
121+
129122
local third_reality_mk1_handler = {
130123
NAME = "Third Reality Handler",
131124
lifecycle_handlers = {
132-
init = device_init
125+
init = device_init,
126+
doConfigure = do_configure
133127
},
134128
supported_capabilities = {
135129
capabilities.button

0 commit comments

Comments
 (0)