@@ -16,10 +16,8 @@ local capabilities = require "st.capabilities"
16
16
local clusters = require " st.matter.clusters"
17
17
local device_lib = require " st.device"
18
18
19
- local BUTTON_DEVICE_PROFILED = " __button_device_profiled"
20
19
local COMPONENT_TO_ENDPOINT_MAP = " __component_to_endpoint_map"
21
20
local INITIAL_PRESS_ONLY = " __initial_press_only"
22
- local SWITCH_INITIALIZED = " __switch_initialized"
23
21
24
22
---- ---------------------------------------------------------------------------------
25
23
-- Third Reality MK1 specifics
@@ -92,8 +90,9 @@ local function configure_buttons(device)
92
90
end
93
91
end
94
92
95
- local function build_button_component_map (device , button_eps )
93
+ local function build_button_component_map (device )
96
94
-- 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 })
97
96
table.sort (button_eps )
98
97
local component_map = {}
99
98
for component_num , ep in ipairs (button_eps ) do
@@ -103,33 +102,28 @@ local function build_button_component_map(device, button_eps)
103
102
device :set_field (COMPONENT_TO_ENDPOINT_MAP , component_map , {persist = true })
104
103
end
105
104
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
-
117
105
local function device_init (driver , device )
118
106
if device .network_type ~= device_lib .NETWORK_TYPE_MATTER then
119
107
return
120
108
end
121
109
device :set_component_to_endpoint_fn (component_to_endpoint )
122
110
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
126
111
device :subscribe ()
127
112
end
128
113
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
+
129
122
local third_reality_mk1_handler = {
130
123
NAME = " Third Reality Handler" ,
131
124
lifecycle_handlers = {
132
- init = device_init
125
+ init = device_init ,
126
+ doConfigure = do_configure
133
127
},
134
128
supported_capabilities = {
135
129
capabilities .button
0 commit comments