@@ -11,6 +11,12 @@ local OnOff = clusters.OnOff
1111local Level = clusters .Level
1212local ColorControl = clusters .ColorControl
1313
14+ local TRANSITION_TIME = 3
15+ local OPTIONS_MASK = 0x01
16+ local IGNORE_COMMAND_IF_OFF = 0x00
17+ local DEFAULT_MIRED_MIN = 154
18+ local DEFAULT_MIRED_MAX = 370
19+
1420local mock_device = test .mock_device .build_test_zigbee_device (
1521 { profile = t_utils .get_profile_definition (" color-temp-bulb.yml" ),
1622 fingerprinted_endpoint_id = 0x01 ,
@@ -279,4 +285,74 @@ test.register_coroutine_test(
279285 max_api_version = 19
280286 }
281287)
288+
289+ test .register_coroutine_test (
290+ " StatelessColorTemperatureStep stepColorTemperatureByPercent should trigger delayed refresh on ZLL device" ,
291+ function ()
292+ test .socket .zigbee :__set_channel_ordering (" relaxed" )
293+ test .timer .__create_and_queue_test_time_advance_timer (1 , " oneshot" )
294+ test .socket .capability :__queue_receive ({ mock_device .id , { capability = " statelessColorTemperatureStep" , component = " main" , command = " stepColorTemperatureByPercent" , args = { 20 } } })
295+ mock_device :expect_native_cmd_handler_registration (" statelessColorTemperatureStep" , " stepColorTemperatureByPercent" )
296+ test .socket .zigbee :__expect_send ({
297+ mock_device .id ,
298+ ColorControl .server .commands .StepColorTemperature (mock_device , ColorControl .types .CcStepMode .DOWN , 43 , TRANSITION_TIME , DEFAULT_MIRED_MIN , DEFAULT_MIRED_MAX , OPTIONS_MASK , IGNORE_COMMAND_IF_OFF )
299+ })
300+
301+ test .wait_for_events ()
302+ test .mock_time .advance_time (2 )
303+
304+ test .socket .zigbee :__expect_send ({ mock_device .id , OnOff .attributes .OnOff :read (mock_device ) })
305+ test .socket .zigbee :__expect_send ({ mock_device .id , Level .attributes .CurrentLevel :read (mock_device ) })
306+ test .socket .zigbee :__expect_send ({ mock_device .id , ColorControl .attributes .ColorTemperatureMireds :read (mock_device ) })
307+ test .socket .zigbee :__expect_send ({ mock_device .id , ColorControl .attributes .ColorTempPhysicalMaxMireds :read (mock_device ) })
308+ test .socket .zigbee :__expect_send ({ mock_device .id , ColorControl .attributes .ColorTempPhysicalMinMireds :read (mock_device ) })
309+ end ,
310+ {
311+ min_api_version = 20
312+ }
313+ )
314+
315+ test .register_coroutine_test (
316+ " Rapid StatelessSwitchLevelStep stepLevel commands should cancel and recreate delayed refresh timer" ,
317+ function ()
318+ test .socket .zigbee :__set_channel_ordering (" relaxed" )
319+
320+ test .socket .capability :__queue_receive ({ mock_device .id , { capability = " statelessSwitchLevelStep" , component = " main" , command = " stepLevel" , args = { 25 } } })
321+ mock_device :expect_native_cmd_handler_registration (" statelessSwitchLevelStep" , " stepLevel" )
322+ test .socket .zigbee :__expect_send ({
323+ mock_device .id ,
324+ Level .server .commands .Step (mock_device , Level .types .MoveStepMode .UP , 64 , TRANSITION_TIME , OPTIONS_MASK , IGNORE_COMMAND_IF_OFF )
325+ })
326+ test .timer .__create_and_queue_test_time_advance_timer (2 , " oneshot" )
327+
328+ test .wait_for_events ()
329+ test .mock_time .advance_time (1 )
330+
331+ -- Second step command: cancels timer #1, creates timer #2
332+ test .socket .capability :__queue_receive ({ mock_device .id , { capability = " statelessSwitchLevelStep" , component = " main" , command = " stepLevel" , args = { 25 } } })
333+ mock_device :expect_native_cmd_handler_registration (" statelessSwitchLevelStep" , " stepLevel" )
334+ test .socket .zigbee :__expect_send ({
335+ mock_device .id ,
336+ Level .server .commands .Step (mock_device , Level .types .MoveStepMode .UP , 64 , TRANSITION_TIME , OPTIONS_MASK , IGNORE_COMMAND_IF_OFF )
337+ })
338+ test .timer .__create_and_queue_test_time_advance_timer (2 , " oneshot" )
339+
340+ test .wait_for_events ()
341+ test .mock_time .advance_time (1 )
342+ -- now, nothing should happen since the first timer was cancelled and the second timer has not yet reached its 2s delay
343+
344+ test .wait_for_events ()
345+ test .mock_time .advance_time (1 )
346+
347+ test .socket .zigbee :__expect_send ({ mock_device .id , OnOff .attributes .OnOff :read (mock_device ) })
348+ test .socket .zigbee :__expect_send ({ mock_device .id , Level .attributes .CurrentLevel :read (mock_device ) })
349+ test .socket .zigbee :__expect_send ({ mock_device .id , ColorControl .attributes .ColorTemperatureMireds :read (mock_device ) })
350+ test .socket .zigbee :__expect_send ({ mock_device .id , ColorControl .attributes .ColorTempPhysicalMaxMireds :read (mock_device ) })
351+ test .socket .zigbee :__expect_send ({ mock_device .id , ColorControl .attributes .ColorTempPhysicalMinMireds :read (mock_device ) })
352+ end ,
353+ {
354+ min_api_version = 20
355+ }
356+ )
357+
282358test .run_registered_tests ()
0 commit comments