Skip to content

Commit b98548e

Browse files
Rename button-utils file
Renaming buttons.lua to button-utils.lua to align with the changes coming in #2142.
1 parent 5a7bd97 commit b98548e

File tree

3 files changed

+29
-29
lines changed

3 files changed

+29
-29
lines changed

drivers/SmartThings/matter-switch/src/buttons.lua renamed to drivers/SmartThings/matter-switch/src/button-utils.lua

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -90,9 +90,9 @@ local function emulate_held_event(device, ep)
9090
set_field_for_endpoint(device, START_BUTTON_PRESS, ep, nil, {persist = false})
9191
end
9292

93-
local buttons = {}
93+
local button_utils = {}
9494

95-
function buttons.build_component_map(device, main_endpoint, button_eps)
95+
function button_utils.build_component_map(device, main_endpoint, button_eps)
9696
-- create component mapping on the main profile button endpoints
9797
table.sort(button_eps)
9898
local component_map = {}
@@ -109,7 +109,7 @@ function buttons.build_component_map(device, main_endpoint, button_eps)
109109
device:set_field(COMPONENT_TO_ENDPOINT_MAP, component_map, {persist = true})
110110
end
111111

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)
113113
local profile_name = string.gsub(num_button_eps .. "-button", "1%-", "") -- remove the "1-" in a device with 1 button ep
114114
if device_supports_button_switch_combination then
115115
profile_name = "light-level-" .. profile_name
@@ -122,7 +122,7 @@ function buttons.build_profile(device, num_button_eps, device_supports_button_sw
122122
end
123123
end
124124

125-
function buttons.configure(device)
125+
function button_utils.configure_buttons(device)
126126
if device.network_type == device_lib.NETWORK_TYPE_MATTER then
127127
local ms_eps = device:get_endpoints(clusters.Switch.ID, {feature_bitmap=clusters.Switch.types.SwitchFeature.MOMENTARY_SWITCH})
128128
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)
157157
end
158158
end
159159

160-
function buttons.initial_press_event_handler(driver, device, ib, response)
160+
function button_utils.initial_press_event_handler(driver, device, ib, response)
161161
if get_field_for_endpoint(device, SUPPORTS_MULTI_PRESS, ib.endpoint_id) then
162162
-- Receipt of an InitialPress event means we do not want to ignore the next MultiPressComplete event
163163
-- or else we would potentially not create the expected button capability event
@@ -172,15 +172,15 @@ end
172172

173173
-- if the device distinguishes a long press event, it will always be a "held"
174174
-- 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)
176176
device:emit_event_for_endpoint(ib.endpoint_id, capabilities.button.button.held({state_change = true}))
177177
if get_field_for_endpoint(device, SUPPORTS_MULTI_PRESS, ib.endpoint_id) then
178178
-- Ignore the next MultiPressComplete event if it is sent as part of this "long press" event sequence
179179
set_field_for_endpoint(device, IGNORE_NEXT_MPC, ib.endpoint_id, true)
180180
end
181181
end
182182

183-
function buttons.short_release_event_handler(driver, device, ib, response)
183+
function button_utils.short_release_event_handler(driver, device, ib, response)
184184
if not get_field_for_endpoint(device, SUPPORTS_MULTI_PRESS, ib.endpoint_id) then
185185
if get_field_for_endpoint(device, EMULATE_HELD, ib.endpoint_id) then
186186
emulate_held_event(device, ib.endpoint_id)
@@ -190,7 +190,7 @@ function buttons.short_release_event_handler(driver, device, ib, response)
190190
end
191191
end
192192

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)
194194
-- in the case of multiple button presses
195195
-- emit number of times, multiple presses have been completed
196196
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
211211
set_field_for_endpoint(device, IGNORE_NEXT_MPC, ib.endpoint_id, nil)
212212
end
213213

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)
215215
if ib.data.value then
216216
device:emit_event(capabilities.battery.battery(math.floor(ib.data.value / 2.0 + 0.5)))
217217
end
218218
end
219219

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)
221221
if ib.data.value == clusters.PowerSource.types.BatChargeLevelEnum.OK then
222222
device:emit_event(capabilities.batteryLevel.battery.normal())
223223
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)
227227
end
228228
end
229229

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)
231231
local profile_name = ""
232232
local button_eps = device:get_endpoints(clusters.Switch.ID, {feature_bitmap=clusters.Switch.types.SwitchFeature.MOMENTARY_SWITCH})
233233
for _, attr in ipairs(ib.data.elements) do
@@ -253,7 +253,7 @@ function buttons.power_source_attribute_list_handler(driver, device, ib, respons
253253
end
254254
end
255255

256-
function buttons.max_press_handler(driver, device, ib, response)
256+
function button_utils.max_press_handler(driver, device, ib, response)
257257
local max = ib.data.value or 1 --get max number of presses
258258
device.log.debug("Device supports "..max.." presses")
259259
-- capability only supports up to 6 presses
@@ -267,4 +267,4 @@ function buttons.max_press_handler(driver, device, ib, response)
267267
device:emit_event_for_endpoint(ib.endpoint_id, capabilities.button.supportedButtonValues(values, {visibility = {displayed = false}}))
268268
end
269269

270-
return buttons
270+
return button_utils

drivers/SmartThings/matter-switch/src/init.lua

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ local clusters = require "st.matter.clusters"
1919
local im = require "st.matter.interaction_model"
2020
local MatterDriver = require "st.matter.driver"
2121
local utils = require "st.utils"
22-
local buttons = require "buttons"
22+
local buttons_utils = require "button-utils"
2323
local device_lib = require "st.device"
2424
local embedded_cluster_utils = require "embedded-cluster-utils"
2525
local version = require "version"
@@ -544,11 +544,11 @@ local function initialize_buttons_and_switches(driver, device, main_endpoint)
544544
local profile_found = false
545545
local button_eps = device:get_endpoints(clusters.Switch.ID, {feature_bitmap=clusters.Switch.types.SwitchFeature.MOMENTARY_SWITCH})
546546
if tbl_contains(STATIC_BUTTON_PROFILE_SUPPORTED, #button_eps) then
547-
buttons.build_profile(device, #button_eps, device_type_supports_button_switch_combination(device, main_endpoint))
547+
buttons_utils.build_profile(device, #button_eps, device_type_supports_button_switch_combination(device, main_endpoint))
548548
-- All button endpoints found will be added as additional components in the profile containing the main_endpoint.
549549
-- The resulting endpoint to component map is saved in the COMPONENT_TO_ENDPOINT_MAP field
550-
buttons.build_component_map(device, main_endpoint, button_eps)
551-
buttons.configure(device)
550+
buttons_utils.build_component_map(device, main_endpoint, button_eps)
551+
buttons_utils.configure_buttons(device)
552552
profile_found = true
553553
end
554554

@@ -1082,7 +1082,7 @@ local function info_changed(driver, device, event, args)
10821082
device:subscribe()
10831083
local button_eps = device:get_endpoints(clusters.Switch.ID, {feature_bitmap=clusters.Switch.types.SwitchFeature.MOMENTARY_SWITCH})
10841084
if #button_eps > 0 and device.network_type == device_lib.NETWORK_TYPE_MATTER then
1085-
buttons.configure(device)
1085+
buttons_utils.configure_buttons(device)
10861086
end
10871087
end
10881088
end
@@ -1257,12 +1257,12 @@ local matter_driver_template = {
12571257
[clusters.ValveConfigurationAndControl.attributes.CurrentLevel.ID] = valve_level_attr_handler
12581258
},
12591259
[clusters.PowerSource.ID] = {
1260-
[clusters.PowerSource.attributes.AttributeList.ID] = buttons.power_source_attribute_list_handler,
1261-
[clusters.PowerSource.attributes.BatChargeLevel.ID] = buttons.battery_charge_level_attr_handler,
1262-
[clusters.PowerSource.attributes.BatPercentRemaining.ID] = buttons.battery_percent_remaining_attr_handler,
1260+
[clusters.PowerSource.attributes.AttributeList.ID] = buttons_utils.power_source_attribute_list_handler,
1261+
[clusters.PowerSource.attributes.BatChargeLevel.ID] = buttons_utils.battery_charge_level_attr_handler,
1262+
[clusters.PowerSource.attributes.BatPercentRemaining.ID] = buttons_utils.battery_percent_remaining_attr_handler,
12631263
},
12641264
[clusters.Switch.ID] = {
1265-
[clusters.Switch.attributes.MultiPressMax.ID] = buttons.max_press_handler
1265+
[clusters.Switch.attributes.MultiPressMax.ID] = buttons_utils.max_press_handler
12661266
},
12671267
[clusters.RelativeHumidityMeasurement.ID] = {
12681268
[clusters.RelativeHumidityMeasurement.attributes.MeasuredValue.ID] = humidity_attr_handler
@@ -1280,10 +1280,10 @@ local matter_driver_template = {
12801280
},
12811281
event = {
12821282
[clusters.Switch.ID] = {
1283-
[clusters.Switch.events.InitialPress.ID] = buttons.initial_press_event_handler,
1284-
[clusters.Switch.events.LongPress.ID] = buttons.long_press_event_handler,
1285-
[clusters.Switch.events.ShortRelease.ID] = buttons.short_release_event_handler,
1286-
[clusters.Switch.events.MultiPressComplete.ID] = buttons.multi_press_complete_event_handler
1283+
[clusters.Switch.events.InitialPress.ID] = buttons_utils.initial_press_event_handler,
1284+
[clusters.Switch.events.LongPress.ID] = buttons_utils.long_press_event_handler,
1285+
[clusters.Switch.events.ShortRelease.ID] = buttons_utils.short_release_event_handler,
1286+
[clusters.Switch.events.MultiPressComplete.ID] = buttons_utils.multi_press_complete_event_handler
12871287
}
12881288
},
12891289
fallback = matter_handler,

drivers/SmartThings/matter-switch/src/inovelli-vtm31-sn/init.lua

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414

1515
local cluster_base = require "st.matter.cluster_base"
1616
local clusters = require "st.matter.clusters"
17-
local buttons = require "buttons"
17+
local button_utils = require "button-utils"
1818
local data_types = require "st.matter.data_types"
1919
local device_lib = require "st.device"
2020
local log = require "log"
@@ -131,7 +131,7 @@ local function initialize_vtm31_sn(driver, device)
131131
current_component_number = current_component_number + 1
132132
end
133133
device:set_field(COMPONENT_TO_ENDPOINT_MAP, component_map, {persist = true})
134-
buttons.configure(device)
134+
button_utils.configure_buttons(device)
135135
-- Create a child device for direct control of the LED Notification Bar.
136136
local name = string.format("%s Notification Bar", device.label)
137137
driver:try_create_device(
@@ -220,7 +220,7 @@ local function info_changed(driver, device, event, args)
220220
end
221221
if device.profile.id ~= args.old_st_store.profile.id then
222222
device:subscribe()
223-
buttons.configure(device)
223+
button_utils.configure_buttons(device)
224224
end
225225
end
226226

0 commit comments

Comments
 (0)