Skip to content

Commit 52e5174

Browse files
Override device_added and init press handler
1 parent c4fda9c commit 52e5174

File tree

2 files changed

+28
-11
lines changed

2 files changed

+28
-11
lines changed

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

+3-1
Original file line numberDiff line numberDiff line change
@@ -213,12 +213,14 @@ local function test_init()
213213
configure_buttons()
214214
test.socket.matter:__expect_send({mock_device.id, subscribe_request})
215215
test.mock_device.add_test_device(mock_device)
216+
test.socket.device_lifecycle:__queue_receive({ mock_device.id, "added" })
217+
test.socket.matter:__expect_send({mock_device.id, subscribe_request})
216218
local device_info_copy = utils.deep_copy(mock_device.raw_st_data)
217219
device_info_copy.profile.id = "12-buttons-keyboard"
218220
local device_info_json = dkjson.encode(device_info_copy)
219221
test.socket.device_lifecycle:__queue_receive({ mock_device.id, "infoChanged", device_info_json })
220-
test.socket.matter:__expect_send({mock_device.id, subscribe_request})
221222
configure_buttons()
223+
test.socket.matter:__expect_send({mock_device.id, subscribe_request})
222224
end
223225

224226
test.set_test_init_function(test_init)

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

+25-10
Original file line numberDiff line numberDiff line change
@@ -28,15 +28,14 @@ local THIRD_REALITY_MANUFACTURER_ID = 0x1407
2828
local THIRD_REALITY_MK1_PRODUCT_ID = 0x1388
2929

3030
local function is_third_reality_mk1(opts, driver, device)
31-
return true
32-
--if not device.manufacturer_info then return false end
33-
---- this sub driver does not support child devices
34-
--if device.network_type == device_lib.NETWORK_TYPE_MATTER and
35-
-- device.manufacturer_info.vendor_id == THIRD_REALITY_MANUFACTURER_ID and
36-
-- device.manufacturer_info.product_id == THIRD_REALITY_MK1_PRODUCT_ID then
37-
-- return true
38-
--end
39-
--return false
31+
if not device.manufacturer_info then return false end
32+
-- this sub driver does not support child devices
33+
if device.network_type == device_lib.NETWORK_TYPE_MATTER and
34+
device.manufacturer_info.vendor_id == THIRD_REALITY_MANUFACTURER_ID and
35+
device.manufacturer_info.product_id == THIRD_REALITY_MK1_PRODUCT_ID then
36+
return true
37+
end
38+
return false
4039
end
4140

4241
local function set_field_for_endpoint(device, field, endpoint, value, additional_params)
@@ -94,10 +93,14 @@ local function device_init(driver, device)
9493
end
9594
end
9695

96+
local function device_added(driver, device)
97+
device_init(driver, device)
98+
end
99+
97100
local function info_changed(driver, device, event, args)
98101
if device.profile.id ~= args.old_st_store.profile.id then
99-
subscribe(device)
100102
configure_buttons(device)
103+
subscribe(device)
101104
end
102105
end
103106

@@ -107,13 +110,25 @@ local function do_configure(driver, device)
107110
configure_buttons(device)
108111
end
109112

113+
local function initial_press_event_handler(driver, device, ib, response)
114+
device:emit_event_for_endpoint(ib.endpoint_id, capabilities.button.button.pushed({state_change = true}))
115+
end
116+
110117
local third_reality_mk1_handler = {
111118
NAME = "ThirdReality MK1 Handler",
112119
lifecycle_handlers = {
113120
init = device_init,
121+
added = device_added,
114122
infoChanged = info_changed,
115123
doConfigure = do_configure
116124
},
125+
matter_handlers = {
126+
event = {
127+
[clusters.Switch.ID] = {
128+
[clusters.Switch.events.InitialPress.ID] = initial_press_event_handler
129+
}
130+
}
131+
},
117132
supported_capabilities = {
118133
capabilities.button
119134
},

0 commit comments

Comments
 (0)