Skip to content

Commit 9f45e34

Browse files
authored
Remove extra SystemMode Read operation (#2046)
1 parent 6410f7f commit 9f45e34

File tree

4 files changed

+8
-227
lines changed

4 files changed

+8
-227
lines changed

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

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ if version.api < 10 then
4242
clusters.Thermostat.types.ThermostatSystemMode.SLEEP = 0x9
4343
end
4444

45+
local SAVED_SYSTEM_MODE_IB = "__saved_system_mode_ib"
4546
local DISALLOWED_THERMOSTAT_MODES = "__DISALLOWED_CONTROL_OPERATIONS"
4647
local OPTIONAL_THERMOSTAT_MODES_SEEN = "__OPTIONAL_THERMOSTAT_MODES_SEEN"
4748

@@ -1074,7 +1075,8 @@ end
10741075

10751076
local function system_mode_handler(driver, device, ib, response)
10761077
if device:get_field(OPTIONAL_THERMOSTAT_MODES_SEEN) == nil then -- this being nil means the sequence_of_operation_handler hasn't run.
1077-
device.log.info_with({hub_logs = true}, "In the SystemMode handler, ControlSequenceOfOperation has not run yet. Aborting.")
1078+
device.log.info_with({hub_logs = true}, "In the SystemMode handler: ControlSequenceOfOperation has not run yet. Exiting early.")
1079+
device:set_field(SAVED_SYSTEM_MODE_IB, ib)
10781080
return
10791081
end
10801082

@@ -1167,8 +1169,11 @@ local function sequence_of_operation_handler(driver, device, ib, response)
11671169
local event = capabilities.thermostatMode.supportedThermostatModes(supported_modes, {visibility = {displayed = false}})
11681170
device:emit_event_for_endpoint(ib.endpoint_id, event)
11691171

1170-
-- do an extra SystemMode read in case of out of order attribute handling
1171-
device:send(clusters.Thermostat.attributes.SystemMode:read(device))
1172+
-- will be set by the SystemMode handler if this handler hasn't run yet.
1173+
if device:get_field(SAVED_SYSTEM_MODE_IB) then
1174+
system_mode_handler(driver, device, device:get_field(SAVED_SYSTEM_MODE_IB), response)
1175+
device:set_field(SAVED_SYSTEM_MODE_IB, nil)
1176+
end
11721177
end
11731178

11741179
local function min_deadband_limit_handler(driver, device, ib, response)

drivers/SmartThings/matter-thermostat/src/test/test_matter_heat_pump.lua

Lines changed: 0 additions & 96 deletions
Original file line numberDiff line numberDiff line change
@@ -327,14 +327,6 @@ test.register_message_test(
327327
direction = "send",
328328
message = mock_device:generate_test_message("thermostatOne", capabilities.thermostatMode.supportedThermostatModes({"off", "cool", "heat"}, {visibility={displayed=false}}))
329329
},
330-
{
331-
channel = "matter",
332-
direction = "send",
333-
message = {
334-
mock_device.id,
335-
clusters.Thermostat.attributes.SystemMode:read()
336-
}
337-
},
338330
{
339331
channel = "matter",
340332
direction = "receive",
@@ -348,14 +340,6 @@ test.register_message_test(
348340
direction = "send",
349341
message = mock_device:generate_test_message("thermostatTwo", capabilities.thermostatMode.supportedThermostatModes({"off", "cool", "heat"}, {visibility={displayed=false}}))
350342
},
351-
{
352-
channel = "matter",
353-
direction = "send",
354-
message = {
355-
mock_device.id,
356-
clusters.Thermostat.attributes.SystemMode:read()
357-
}
358-
},
359343
{
360344
channel = "matter",
361345
direction = "receive",
@@ -407,14 +391,6 @@ test.register_message_test(
407391
direction = "send",
408392
message = mock_device:generate_test_message("thermostatOne", capabilities.thermostatMode.supportedThermostatModes({"off", "cool", "heat"}, {visibility={displayed=false}}))
409393
},
410-
{
411-
channel = "matter",
412-
direction = "send",
413-
message = {
414-
mock_device.id,
415-
clusters.Thermostat.attributes.SystemMode:read()
416-
}
417-
},
418394
{
419395
channel = "matter",
420396
direction = "receive",
@@ -428,14 +404,6 @@ test.register_message_test(
428404
direction = "send",
429405
message = mock_device:generate_test_message("thermostatOne", capabilities.thermostatMode.supportedThermostatModes({"off", "heat"}, {visibility={displayed=false}}))
430406
},
431-
{
432-
channel = "matter",
433-
direction = "send",
434-
message = {
435-
mock_device.id,
436-
clusters.Thermostat.attributes.SystemMode:read()
437-
}
438-
},
439407
{
440408
channel = "matter",
441409
direction = "receive",
@@ -449,14 +417,6 @@ test.register_message_test(
449417
direction = "send",
450418
message = mock_device:generate_test_message("thermostatOne", capabilities.thermostatMode.supportedThermostatModes({"off", "cool"}, {visibility={displayed=false}}))
451419
},
452-
{
453-
channel = "matter",
454-
direction = "send",
455-
message = {
456-
mock_device.id,
457-
clusters.Thermostat.attributes.SystemMode:read()
458-
}
459-
},
460420
{
461421
channel = "matter",
462422
direction = "receive",
@@ -470,14 +430,6 @@ test.register_message_test(
470430
direction = "send",
471431
message = mock_device:generate_test_message("thermostatTwo", capabilities.thermostatMode.supportedThermostatModes({"off", "cool", "heat"}, {visibility={displayed=false}}))
472432
},
473-
{
474-
channel = "matter",
475-
direction = "send",
476-
message = {
477-
mock_device.id,
478-
clusters.Thermostat.attributes.SystemMode:read()
479-
}
480-
},
481433
{
482434
channel = "matter",
483435
direction = "receive",
@@ -491,14 +443,6 @@ test.register_message_test(
491443
direction = "send",
492444
message = mock_device:generate_test_message("thermostatTwo", capabilities.thermostatMode.supportedThermostatModes({"off", "heat"}, {visibility={displayed=false}}))
493445
},
494-
{
495-
channel = "matter",
496-
direction = "send",
497-
message = {
498-
mock_device.id,
499-
clusters.Thermostat.attributes.SystemMode:read()
500-
}
501-
},
502446
{
503447
channel = "matter",
504448
direction = "receive",
@@ -512,14 +456,6 @@ test.register_message_test(
512456
direction = "send",
513457
message = mock_device:generate_test_message("thermostatTwo", capabilities.thermostatMode.supportedThermostatModes({"off", "cool"}, {visibility={displayed=false}}))
514458
},
515-
{
516-
channel = "matter",
517-
direction = "send",
518-
message = {
519-
mock_device.id,
520-
clusters.Thermostat.attributes.SystemMode:read()
521-
}
522-
},
523459
}
524460
)
525461

@@ -539,14 +475,6 @@ test.register_message_test(
539475
direction = "send",
540476
message = mock_device:generate_test_message("thermostatTwo", capabilities.thermostatMode.supportedThermostatModes({"off", "cool", "heat"}, {visibility={displayed=false}}))
541477
},
542-
{
543-
channel = "matter",
544-
direction = "send",
545-
message = {
546-
mock_device.id,
547-
clusters.Thermostat.attributes.SystemMode:read()
548-
}
549-
},
550478
{
551479
channel = "matter",
552480
direction = "receive",
@@ -560,14 +488,6 @@ test.register_message_test(
560488
direction = "send",
561489
message = mock_device:generate_test_message("thermostatOne", capabilities.thermostatMode.supportedThermostatModes({"off", "cool", "heat"}, {visibility={displayed=false}}))
562490
},
563-
{
564-
channel = "matter",
565-
direction = "send",
566-
message = {
567-
mock_device.id,
568-
clusters.Thermostat.attributes.SystemMode:read()
569-
}
570-
},
571491
{
572492
channel = "matter",
573493
direction = "receive",
@@ -623,14 +543,6 @@ test.register_message_test(
623543
direction = "send",
624544
message = mock_device_with_auto:generate_test_message("thermostatOne", capabilities.thermostatMode.supportedThermostatModes({"off", "cool", "heat", "auto"}, {visibility={displayed=false}}))
625545
},
626-
{
627-
channel = "matter",
628-
direction = "send",
629-
message = {
630-
mock_device_with_auto.id,
631-
clusters.Thermostat.attributes.SystemMode:read()
632-
}
633-
},
634546
{
635547
channel = "matter",
636548
direction = "receive",
@@ -657,14 +569,6 @@ test.register_message_test(
657569
clusters.Thermostat.server.attributes.ControlSequenceOfOperation:build_test_report_data(mock_device_with_auto, THERMOSTAT_TWO_EP, 5)
658570
}
659571
},
660-
{
661-
channel = "matter",
662-
direction = "send",
663-
message = {
664-
mock_device_with_auto.id,
665-
clusters.Thermostat.attributes.SystemMode:read()
666-
}
667-
},
668572
{
669573
channel = "capability",
670574
direction = "send",

drivers/SmartThings/matter-thermostat/src/test/test_matter_thermostat.lua

Lines changed: 0 additions & 88 deletions
Original file line numberDiff line numberDiff line change
@@ -340,14 +340,6 @@ test.register_message_test(
340340
direction = "send",
341341
message = mock_device:generate_test_message("main", capabilities.thermostatMode.supportedThermostatModes({"off", "cool", "heat"}, {visibility={displayed=false}}))
342342
},
343-
{
344-
channel = "matter",
345-
direction = "send",
346-
message = {
347-
mock_device.id,
348-
clusters.Thermostat.attributes.SystemMode:read()
349-
}
350-
},
351343
{
352344
channel = "matter",
353345
direction = "receive",
@@ -381,14 +373,6 @@ test.register_message_test(
381373
direction = "send",
382374
message = mock_device:generate_test_message("main", capabilities.thermostatMode.supportedThermostatModes({"off", "cool", "heat"}, {visibility={displayed=false}}))
383375
},
384-
{
385-
channel = "matter",
386-
direction = "send",
387-
message = {
388-
mock_device.id,
389-
clusters.Thermostat.attributes.SystemMode:read()
390-
}
391-
},
392376
{
393377
channel = "matter",
394378
direction = "receive",
@@ -402,14 +386,6 @@ test.register_message_test(
402386
direction = "send",
403387
message = mock_device:generate_test_message("main", capabilities.thermostatMode.supportedThermostatModes({"off", "heat"}, {visibility={displayed=false}}))
404388
},
405-
{
406-
channel = "matter",
407-
direction = "send",
408-
message = {
409-
mock_device.id,
410-
clusters.Thermostat.attributes.SystemMode:read()
411-
}
412-
},
413389
{
414390
channel = "matter",
415391
direction = "receive",
@@ -423,14 +399,6 @@ test.register_message_test(
423399
direction = "send",
424400
message = mock_device:generate_test_message("main", capabilities.thermostatMode.supportedThermostatModes({"off", "cool"}, {visibility={displayed=false}}))
425401
},
426-
{
427-
channel = "matter",
428-
direction = "send",
429-
message = {
430-
mock_device.id,
431-
clusters.Thermostat.attributes.SystemMode:read()
432-
}
433-
},
434402
}
435403
)
436404

@@ -450,14 +418,6 @@ test.register_message_test(
450418
direction = "send",
451419
message = mock_device_auto:generate_test_message("main", capabilities.thermostatMode.supportedThermostatModes({"off", "cool", "heat", "auto"}, {visibility={displayed=false}}))
452420
},
453-
{
454-
channel = "matter",
455-
direction = "send",
456-
message = {
457-
mock_device_auto.id,
458-
clusters.Thermostat.attributes.SystemMode:read()
459-
}
460-
},
461421
{
462422
channel = "matter",
463423
direction = "receive",
@@ -471,14 +431,6 @@ test.register_message_test(
471431
direction = "send",
472432
message = mock_device_auto:generate_test_message("main", capabilities.thermostatMode.supportedThermostatModes({"off", "heat", "auto"}, {visibility={displayed=false}}))
473433
},
474-
{
475-
channel = "matter",
476-
direction = "send",
477-
message = {
478-
mock_device_auto.id,
479-
clusters.Thermostat.attributes.SystemMode:read()
480-
}
481-
},
482434
{
483435
channel = "matter",
484436
direction = "receive",
@@ -492,14 +444,6 @@ test.register_message_test(
492444
direction = "send",
493445
message = mock_device_auto:generate_test_message("main", capabilities.thermostatMode.supportedThermostatModes({"off", "cool", "auto"}, {visibility={displayed=false}}))
494446
},
495-
{
496-
channel = "matter",
497-
direction = "send",
498-
message = {
499-
mock_device_auto.id,
500-
clusters.Thermostat.attributes.SystemMode:read()
501-
}
502-
},
503447
},
504448
{ test_init = test_init_auto }
505449
)
@@ -519,14 +463,6 @@ test.register_message_test(
519463
channel = "capability",
520464
direction = "send",
521465
message = mock_device:generate_test_message("main", capabilities.thermostatMode.supportedThermostatModes({"off", "cool", "heat"}, {visibility={displayed=false}}))
522-
},
523-
{
524-
channel = "matter",
525-
direction = "send",
526-
message = {
527-
mock_device.id,
528-
clusters.Thermostat.attributes.SystemMode:read()
529-
}
530466
},
531467
{
532468
channel = "matter",
@@ -564,14 +500,6 @@ test.register_message_test(
564500
channel = "capability",
565501
direction = "send",
566502
message = mock_device_auto:generate_test_message("main", capabilities.thermostatMode.supportedThermostatModes({"off", "cool", "heat", "auto"}, {visibility={displayed=false}}))
567-
},
568-
{
569-
channel = "matter",
570-
direction = "send",
571-
message = {
572-
mock_device_auto.id,
573-
clusters.Thermostat.attributes.SystemMode:read()
574-
}
575503
},
576504
{
577505
channel = "matter",
@@ -610,14 +538,6 @@ test.register_message_test(
610538
channel = "capability",
611539
direction = "send",
612540
message = mock_device_auto:generate_test_message("main", capabilities.thermostatMode.supportedThermostatModes({"off", "heat", "auto"}, {visibility={displayed=false}}))
613-
},
614-
{
615-
channel = "matter",
616-
direction = "send",
617-
message = {
618-
mock_device_auto.id,
619-
clusters.Thermostat.attributes.SystemMode:read()
620-
}
621541
},
622542
{
623543
channel = "matter",
@@ -639,14 +559,6 @@ test.register_message_test(
639559
channel = "capability",
640560
direction = "send",
641561
message = mock_device_auto:generate_test_message("main", capabilities.thermostatMode.supportedThermostatModes({"off", "cool", "auto"}, {visibility={displayed=false}}))
642-
},
643-
{
644-
channel = "matter",
645-
direction = "send",
646-
message = {
647-
mock_device_auto.id,
648-
clusters.Thermostat.attributes.SystemMode:read()
649-
}
650562
},
651563
{
652564
channel = "matter",

0 commit comments

Comments
 (0)