@@ -90,9 +90,9 @@ local function emulate_held_event(device, ep)
90
90
set_field_for_endpoint (device , START_BUTTON_PRESS , ep , nil , {persist = false })
91
91
end
92
92
93
- local buttons = {}
93
+ local button_utils = {}
94
94
95
- function buttons .build_component_map (device , main_endpoint , button_eps )
95
+ function button_utils .build_component_map (device , main_endpoint , button_eps )
96
96
-- create component mapping on the main profile button endpoints
97
97
table.sort (button_eps )
98
98
local component_map = {}
@@ -109,7 +109,7 @@ function buttons.build_component_map(device, main_endpoint, button_eps)
109
109
device :set_field (COMPONENT_TO_ENDPOINT_MAP , component_map , {persist = true })
110
110
end
111
111
112
- function buttons .build_profile (device , num_button_eps , device_supports_button_switch_combination )
112
+ function button_utils .build_profile (device , num_button_eps , device_supports_button_switch_combination )
113
113
local profile_name = string.gsub (num_button_eps .. " -button" , " 1%-" , " " ) -- remove the "1-" in a device with 1 button ep
114
114
if device_supports_button_switch_combination then
115
115
profile_name = " light-level-" .. profile_name
@@ -122,7 +122,7 @@ function buttons.build_profile(device, num_button_eps, device_supports_button_sw
122
122
end
123
123
end
124
124
125
- function buttons . configure (device )
125
+ function button_utils . configure_buttons (device )
126
126
if device .network_type == device_lib .NETWORK_TYPE_MATTER then
127
127
local ms_eps = device :get_endpoints (clusters .Switch .ID , {feature_bitmap = clusters .Switch .types .SwitchFeature .MOMENTARY_SWITCH })
128
128
local msr_eps = device :get_endpoints (clusters .Switch .ID , {feature_bitmap = clusters .Switch .types .SwitchFeature .MOMENTARY_SWITCH_RELEASE })
@@ -157,7 +157,7 @@ function buttons.configure(device)
157
157
end
158
158
end
159
159
160
- function buttons .initial_press_event_handler (driver , device , ib , response )
160
+ function button_utils .initial_press_event_handler (driver , device , ib , response )
161
161
if get_field_for_endpoint (device , SUPPORTS_MULTI_PRESS , ib .endpoint_id ) then
162
162
-- Receipt of an InitialPress event means we do not want to ignore the next MultiPressComplete event
163
163
-- or else we would potentially not create the expected button capability event
@@ -172,15 +172,15 @@ end
172
172
173
173
-- if the device distinguishes a long press event, it will always be a "held"
174
174
-- there's also a "long release" event, but this event is required to come first
175
- function buttons .long_press_event_handler (driver , device , ib , response )
175
+ function button_utils .long_press_event_handler (driver , device , ib , response )
176
176
device :emit_event_for_endpoint (ib .endpoint_id , capabilities .button .button .held ({state_change = true }))
177
177
if get_field_for_endpoint (device , SUPPORTS_MULTI_PRESS , ib .endpoint_id ) then
178
178
-- Ignore the next MultiPressComplete event if it is sent as part of this "long press" event sequence
179
179
set_field_for_endpoint (device , IGNORE_NEXT_MPC , ib .endpoint_id , true )
180
180
end
181
181
end
182
182
183
- function buttons .short_release_event_handler (driver , device , ib , response )
183
+ function button_utils .short_release_event_handler (driver , device , ib , response )
184
184
if not get_field_for_endpoint (device , SUPPORTS_MULTI_PRESS , ib .endpoint_id ) then
185
185
if get_field_for_endpoint (device , EMULATE_HELD , ib .endpoint_id ) then
186
186
emulate_held_event (device , ib .endpoint_id )
@@ -190,7 +190,7 @@ function buttons.short_release_event_handler(driver, device, ib, response)
190
190
end
191
191
end
192
192
193
- function buttons .multi_press_complete_event_handler (driver , device , ib , response )
193
+ function button_utils .multi_press_complete_event_handler (driver , device , ib , response )
194
194
-- in the case of multiple button presses
195
195
-- emit number of times, multiple presses have been completed
196
196
if ib .data and not get_field_for_endpoint (device , IGNORE_NEXT_MPC , ib .endpoint_id ) then
@@ -211,13 +211,13 @@ function buttons.multi_press_complete_event_handler(driver, device, ib, response
211
211
set_field_for_endpoint (device , IGNORE_NEXT_MPC , ib .endpoint_id , nil )
212
212
end
213
213
214
- function buttons .battery_percent_remaining_attr_handler (driver , device , ib , response )
214
+ function button_utils .battery_percent_remaining_attr_handler (driver , device , ib , response )
215
215
if ib .data .value then
216
216
device :emit_event (capabilities .battery .battery (math.floor (ib .data .value / 2.0 + 0.5 )))
217
217
end
218
218
end
219
219
220
- function buttons .battery_charge_level_attr_handler (driver , device , ib , response )
220
+ function button_utils .battery_charge_level_attr_handler (driver , device , ib , response )
221
221
if ib .data .value == clusters .PowerSource .types .BatChargeLevelEnum .OK then
222
222
device :emit_event (capabilities .batteryLevel .battery .normal ())
223
223
elseif ib .data .value == clusters .PowerSource .types .BatChargeLevelEnum .WARNING then
@@ -227,7 +227,7 @@ function buttons.battery_charge_level_attr_handler(driver, device, ib, response)
227
227
end
228
228
end
229
229
230
- function buttons .power_source_attribute_list_handler (driver , device , ib , response )
230
+ function button_utils .power_source_attribute_list_handler (driver , device , ib , response )
231
231
local profile_name = " "
232
232
local button_eps = device :get_endpoints (clusters .Switch .ID , {feature_bitmap = clusters .Switch .types .SwitchFeature .MOMENTARY_SWITCH })
233
233
for _ , attr in ipairs (ib .data .elements ) do
@@ -253,7 +253,7 @@ function buttons.power_source_attribute_list_handler(driver, device, ib, respons
253
253
end
254
254
end
255
255
256
- function buttons .max_press_handler (driver , device , ib , response )
256
+ function button_utils .max_press_handler (driver , device , ib , response )
257
257
local max = ib .data .value or 1 -- get max number of presses
258
258
device .log .debug (" Device supports " .. max .. " presses" )
259
259
-- capability only supports up to 6 presses
@@ -267,4 +267,4 @@ function buttons.max_press_handler(driver, device, ib, response)
267
267
device :emit_event_for_endpoint (ib .endpoint_id , capabilities .button .supportedButtonValues (values , {visibility = {displayed = false }}))
268
268
end
269
269
270
- return buttons
270
+ return button_utils
0 commit comments