1- -- Copyright 2022 SmartThings
2- --
3- -- Licensed under the Apache License, Version 2.0 (the "License");
4- -- you may not use this file except in compliance with the License.
5- -- You may obtain a copy of the License at
6- --
7- -- http://www.apache.org/licenses/LICENSE-2.0
8- --
9- -- Unless required by applicable law or agreed to in writing, software
10- -- distributed under the License is distributed on an "AS IS" BASIS,
11- -- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12- -- See the License for the specific language governing permissions and
13- -- limitations under the License.
1+ -- Copyright © 2026 SmartThings, Inc.
2+ -- Licensed under the Apache License, Version 2.0
143
15- local test = require " integration_test"
164local capabilities = require " st.capabilities"
17- local t_utils = require " integration_test.utils"
185local clusters = require " st.matter.clusters"
6+ local st_utils = require " st.utils"
7+ local t_utils = require " integration_test.utils"
8+ local test = require " integration_test"
199
2010local mock_device = test .mock_device .build_test_matter_device ({
2111 profile = t_utils .get_profile_definition (" media-speaker.yml" ),
@@ -56,6 +46,8 @@ local function test_init()
5646 test .socket .device_lifecycle :__queue_receive ({ mock_device .id , " init" })
5747 local subscribe_request = clusters .OnOff .attributes .OnOff :subscribe (mock_device )
5848 subscribe_request :merge (clusters .LevelControl .attributes .CurrentLevel :subscribe (mock_device ))
49+ subscribe_request :merge (clusters .LevelControl .attributes .MinLevel :subscribe (mock_device ))
50+ subscribe_request :merge (clusters .LevelControl .attributes .MaxLevel :subscribe (mock_device ))
5951 test .socket .matter :__expect_send ({mock_device .id , subscribe_request })
6052
6153 test .socket .device_lifecycle :__queue_receive ({ mock_device .id , " doConfigure" })
@@ -181,7 +173,7 @@ test.register_message_test(
181173 direction = " send" ,
182174 message = {
183175 mock_device .id ,
184- clusters .LevelControl .server .commands .MoveToLevelWithOnOff (mock_device , 10 , math.floor (20 / 100.0 * 254 ), 0 , 0 , 0 )
176+ clusters .LevelControl .server .commands .MoveToLevelWithOnOff (mock_device , 10 , st_utils . round (20 / 100.0 * 254 ), 0 , 0 , 0 )
185177 }
186178 },
187179 {
@@ -208,6 +200,57 @@ test.register_message_test(
208200 }
209201)
210202
203+ test .register_message_test (
204+ " Set volume command should send the appropriate commands with given MinLevel and MaxLevel attribute values" ,
205+ {
206+ {
207+ channel = " matter" ,
208+ direction = " receive" ,
209+ message = {
210+ mock_device .id ,
211+ clusters .LevelControl .attributes .MinLevel :build_test_report_data (mock_device , 1 , 50 )
212+ }
213+ },
214+ {
215+ channel = " matter" ,
216+ direction = " receive" ,
217+ message = {
218+ mock_device .id ,
219+ clusters .LevelControl .attributes .MaxLevel :build_test_report_data (mock_device , 1 , 200 )
220+ }
221+ },
222+ {
223+ channel = " capability" ,
224+ direction = " receive" ,
225+ message = {
226+ mock_device .id ,
227+ { capability = " audioVolume" , component = " main" , command = " setVolume" , args = { 60 } }
228+ }
229+ },
230+ {
231+ channel = " matter" ,
232+ direction = " send" ,
233+ message = {
234+ mock_device .id ,
235+ clusters .LevelControl .server .commands .MoveToLevelWithOnOff (mock_device , 10 , st_utils .round ((60 * (200 - 50 ) / 100.0 ) + 50 ), 0 , 0 , 0 ) -- 140
236+ }
237+ },
238+ {
239+ channel = " matter" ,
240+ direction = " receive" ,
241+ message = {
242+ mock_device .id ,
243+ clusters .LevelControl .attributes .CurrentLevel :build_test_report_data (mock_device , 10 , 110 )
244+ }
245+ },
246+ {
247+ channel = " capability" ,
248+ direction = " send" ,
249+ message = mock_device :generate_test_message (" main" , capabilities .audioVolume .volume (st_utils .round (((110 - 50 ) * 100 ) / (200 - 50 )))) -- 40%
250+ }
251+ }
252+ )
253+
211254test .register_message_test (
212255 " Volume up/down command should send the appropriate commands" ,
213256 {
@@ -224,7 +267,7 @@ test.register_message_test(
224267 direction = " send" ,
225268 message = {
226269 mock_device .id ,
227- clusters .LevelControl .server .commands .MoveToLevelWithOnOff (mock_device , 10 , math.floor (20 / 100.0 * 254 ), 0 , 0 , 0 )
270+ clusters .LevelControl .server .commands .MoveToLevelWithOnOff (mock_device , 10 , st_utils . round (20 / 100.0 * 254 ), 0 , 0 , 0 )
228271 }
229272 },
230273 {
@@ -262,7 +305,7 @@ test.register_message_test(
262305 direction = " send" ,
263306 message = {
264307 mock_device .id ,
265- clusters .LevelControl .server .commands .MoveToLevelWithOnOff (mock_device , 10 , math.floor (25 / 100.0 * 254 ), 0 , 0 , 0 )
308+ clusters .LevelControl .server .commands .MoveToLevelWithOnOff (mock_device , 10 , st_utils . round (25 / 100.0 * 254 ), 0 , 0 , 0 )
266309 }
267310 },
268311 {
@@ -300,7 +343,7 @@ test.register_message_test(
300343 direction = " send" ,
301344 message = {
302345 mock_device .id ,
303- clusters .LevelControl .server .commands .MoveToLevelWithOnOff (mock_device , 10 , math.floor (20 / 100.0 * 254 ), 0 , 0 , 0 )
346+ clusters .LevelControl .server .commands .MoveToLevelWithOnOff (mock_device , 10 , st_utils . round (20 / 100.0 * 254 ), 0 , 0 , 0 )
304347 }
305348 },
306349 {
@@ -330,6 +373,8 @@ test.register_message_test(
330373local function refresh_commands (dev )
331374 local req = clusters .OnOff .attributes .OnOff :read (dev )
332375 req :merge (clusters .LevelControl .attributes .CurrentLevel :read (dev ))
376+ req :merge (clusters .LevelControl .attributes .MinLevel :read (dev ))
377+ req :merge (clusters .LevelControl .attributes .MaxLevel :read (dev ))
333378 return req
334379end
335380
0 commit comments