Skip to content

Commit f554da0

Browse files
committed
version gate the init event on added
1 parent b889ef9 commit f554da0

17 files changed

Lines changed: 828 additions & 1645 deletions

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

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,11 @@ function SwitchLifecycleHandlers.device_added(driver, device)
3838
device:send(clusters.OnOff.attributes.OnOff:read(device))
3939
end
4040

41-
-- call device init in case init is not called after added due to device caching
42-
SwitchLifecycleHandlers.device_init(driver, device)
41+
-- The device init event is guaranteed in FW versions 58+, so this is only needed for older hubs
42+
if version.rpc < 10 then
43+
-- call device init in case init is not called after added due to device caching
44+
SwitchLifecycleHandlers.device_init(driver, device)
45+
end
4346
end
4447

4548
function SwitchLifecycleHandlers.do_configure(driver, device)

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,6 @@ local function test_init()
130130
end
131131

132132
test.socket.device_lifecycle:__queue_receive({ aqara_mock_device.id, "added" })
133-
test.socket.matter:__expect_send({aqara_mock_device.id, subscribe_request})
134133

135134
test.socket.device_lifecycle:__queue_receive({ aqara_mock_device.id, "init" })
136135
test.socket.matter:__expect_send({aqara_mock_device.id, subscribe_request})

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

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -181,15 +181,12 @@ local function test_init()
181181

182182
-- Test added -> doConfigure logic
183183
test.socket.device_lifecycle:__queue_receive({ aqara_mock_device.id, "added" })
184-
test.socket.matter:__expect_send({aqara_mock_device.id, subscribe_request})
185184
test.socket.device_lifecycle:__queue_receive({ aqara_mock_device.id, "init" })
186185
test.socket.matter:__expect_send({aqara_mock_device.id, subscribe_request})
187186
test.socket.device_lifecycle:__queue_receive({ aqara_mock_device.id, "doConfigure" })
188187
configure_buttons()
189188
aqara_mock_device:expect_metadata_update({ profile = "4-button" })
190189
aqara_mock_device:expect_metadata_update({ provisioning_state = "PROVISIONED" })
191-
-- to test powerConsumptionReport
192-
test.timer.__create_and_queue_test_time_advance_timer(60 * 15, "interval", "create_poll_report_schedule")
193190

194191
for _, child in pairs(aqara_mock_children) do
195192
test.mock_device.add_test_device(child)

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

Lines changed: 0 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -181,8 +181,6 @@ local function test_init()
181181
subscribe_request:merge(cluster:subscribe(mock_device))
182182
end
183183
end
184-
test.socket.device_lifecycle:__queue_receive({ mock_device.id, "added" })
185-
test.socket.matter:__expect_send({ mock_device.id, subscribe_request })
186184
test.socket.matter:__expect_send({ mock_device.id, subscribe_request })
187185
end
188186
test.set_test_init_function(test_init)
@@ -195,79 +193,9 @@ local function test_init_periodic()
195193
subscribe_request:merge(cluster:subscribe(mock_device_periodic))
196194
end
197195
end
198-
test.socket.device_lifecycle:__queue_receive({ mock_device_periodic.id, "added" })
199-
test.socket.matter:__expect_send({ mock_device_periodic.id, subscribe_request })
200-
test.socket.device_lifecycle:__queue_receive({ mock_device_periodic.id, "init" })
201-
test.socket.matter:__expect_send({ mock_device_periodic.id, subscribe_request })
202196
test.socket.matter:__expect_send({ mock_device_periodic.id, subscribe_request })
203197
end
204198

205-
test.register_message_test(
206-
"On command should send the appropriate commands",
207-
{
208-
{
209-
channel = "capability",
210-
direction = "receive",
211-
message = {
212-
mock_device.id,
213-
{ capability = "switch", component = "main", command = "on", args = { } }
214-
}
215-
},
216-
{
217-
channel = "devices",
218-
direction = "send",
219-
message = {
220-
"register_native_capability_cmd_handler",
221-
{ device_uuid = mock_device.id, capability_id = "switch", capability_cmd_id = "on" }
222-
}
223-
},
224-
{
225-
channel = "matter",
226-
direction = "send",
227-
message = {
228-
mock_device.id,
229-
clusters.OnOff.server.commands.On(mock_device, 2)
230-
}
231-
}
232-
},
233-
{
234-
min_api_version = 17
235-
}
236-
)
237-
238-
test.register_message_test(
239-
"Off command should send the appropriate commands",
240-
{
241-
{
242-
channel = "capability",
243-
direction = "receive",
244-
message = {
245-
mock_device.id,
246-
{ capability = "switch", component = "main", command = "off", args = { } }
247-
}
248-
},
249-
{
250-
channel = "devices",
251-
direction = "send",
252-
message = {
253-
"register_native_capability_cmd_handler",
254-
{ device_uuid = mock_device.id, capability_id = "switch", capability_cmd_id = "off" }
255-
}
256-
},
257-
{
258-
channel = "matter",
259-
direction = "send",
260-
message = {
261-
mock_device.id,
262-
clusters.OnOff.server.commands.Off(mock_device, 2)
263-
}
264-
}
265-
},
266-
{
267-
min_api_version = 17
268-
}
269-
)
270-
271199
test.register_message_test(
272200
"Active power measurement should generate correct messages",
273201
{

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

Lines changed: 0 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -128,78 +128,10 @@ local function test_init()
128128
subscribe_request:merge(cluster:subscribe(mock_device))
129129
end
130130
end
131-
test.socket.device_lifecycle:__queue_receive({ mock_device.id, "added" })
132-
test.socket.matter:__expect_send({ mock_device.id, subscribe_request })
133131
test.socket.matter:__expect_send({ mock_device.id, subscribe_request })
134132
end
135133
test.set_test_init_function(test_init)
136134

137-
test.register_message_test(
138-
"On command should send the appropriate commands",
139-
{
140-
{
141-
channel = "capability",
142-
direction = "receive",
143-
message = {
144-
mock_device.id,
145-
{ capability = "switch", component = "main", command = "on", args = { } }
146-
}
147-
},
148-
{
149-
channel = "devices",
150-
direction = "send",
151-
message = {
152-
"register_native_capability_cmd_handler",
153-
{ device_uuid = mock_device.id, capability_id = "switch", capability_cmd_id = "on" }
154-
}
155-
},
156-
{
157-
channel = "matter",
158-
direction = "send",
159-
message = {
160-
mock_device.id,
161-
clusters.OnOff.server.commands.On(mock_device, 2)
162-
}
163-
}
164-
},
165-
{
166-
min_api_version = 17
167-
}
168-
)
169-
170-
test.register_message_test(
171-
"Off command should send the appropriate commands",
172-
{
173-
{
174-
channel = "capability",
175-
direction = "receive",
176-
message = {
177-
mock_device.id,
178-
{ capability = "switch", component = "main", command = "off", args = { } }
179-
}
180-
},
181-
{
182-
channel = "devices",
183-
direction = "send",
184-
message = {
185-
"register_native_capability_cmd_handler",
186-
{ device_uuid = mock_device.id, capability_id = "switch", capability_cmd_id = "off" }
187-
}
188-
},
189-
{
190-
channel = "matter",
191-
direction = "send",
192-
message = {
193-
mock_device.id,
194-
clusters.OnOff.server.commands.Off(mock_device, 2)
195-
}
196-
}
197-
},
198-
{
199-
min_api_version = 17
200-
}
201-
)
202-
203135
test.register_message_test(
204136
"Active power measurement should generate correct messages",
205137
{

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

Lines changed: 6 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ local mock_device = test.mock_device.build_test_matter_device({
5454
}
5555
})
5656

57-
local mock_device_electrical_sensor = test.mock_device.build_test_matter_device({
57+
local mock_eve_device_using_electrical_sensor = test.mock_device.build_test_matter_device({
5858
profile = t_utils.get_profile_definition("plug-energy-powerConsumption.yml"),
5959
manufacturer_info = {
6060
vendor_id = 0x130A,
@@ -113,30 +113,6 @@ local mock_device_electrical_sensor = test.mock_device.build_test_matter_device(
113113
}
114114
})
115115

116-
local function test_init_electrical_sensor()
117-
test.disable_startup_messages()
118-
test.mock_device.add_test_device(mock_device_electrical_sensor)
119-
local cluster_subscribe_list = {
120-
clusters.OnOff.attributes.OnOff,
121-
clusters.ElectricalEnergyMeasurement.attributes.CumulativeEnergyImported,
122-
clusters.ElectricalEnergyMeasurement.attributes.PeriodicEnergyImported,
123-
}
124-
local subscribe_request = cluster_subscribe_list[1]:subscribe(mock_device_electrical_sensor)
125-
for i, clus in ipairs(cluster_subscribe_list) do
126-
if i > 1 then subscribe_request:merge(clus:subscribe(mock_device_electrical_sensor)) end
127-
end
128-
129-
test.socket.device_lifecycle:__queue_receive({ mock_device_electrical_sensor.id, "added" })
130-
test.socket.matter:__expect_send({mock_device_electrical_sensor.id, subscribe_request})
131-
132-
test.socket.device_lifecycle:__queue_receive({ mock_device_electrical_sensor.id, "init" })
133-
test.socket.matter:__expect_send({mock_device_electrical_sensor.id, subscribe_request})
134-
135-
test.socket.device_lifecycle:__queue_receive({ mock_device_electrical_sensor.id, "doConfigure" })
136-
mock_device_electrical_sensor:expect_metadata_update({ profile = "plug-energy-powerConsumption" })
137-
mock_device_electrical_sensor:expect_metadata_update({ provisioning_state = "PROVISIONED" })
138-
end
139-
140116
local function test_init()
141117
local cluster_subscribe_list = {
142118
clusters.OnOff.attributes.OnOff,
@@ -523,7 +499,7 @@ local cumulative_report_val_39 = {
523499
test.register_coroutine_test(
524500
"Cumulative Energy measurement should generate correct messages",
525501
function()
526-
local mock_device = mock_device_electrical_sensor
502+
mock_device = mock_eve_device_using_electrical_sensor
527503

528504
test.mock_time.advance_time(901) -- move time 15 minutes past 0 (this can be assumed to be true in practice in all cases)
529505
test.socket.matter:__queue_receive(
@@ -579,7 +555,10 @@ test.register_coroutine_test(
579555
)
580556
end,
581557
{
582-
test_init = test_init_electrical_sensor,
558+
test_init = function()
559+
test.disable_startup_messages()
560+
test.mock_device.add_test_device(mock_eve_device_using_electrical_sensor)
561+
end,
583562
min_api_version = 17
584563
}
585564
)

0 commit comments

Comments
 (0)