From 534b87c7a13e47c1e6db336a4e3050ab3f083f5b Mon Sep 17 00:00:00 2001 From: nickolas-deboom <158304111+nickolas-deboom@users.noreply.github.com> Date: Mon, 14 Oct 2024 14:56:52 -0500 Subject: [PATCH] Prevent multiple reads of MinSetpointDeadBand (#1686) The driver currently attempts to only read MinSetpointDeadBand once during the first time device_init is called, but the MIN_SETPOINT_DEADBAND_CHECKED field is not persisted, so the read request is sent during each device init. This is contributing to a spike in InteractionQueueFull exceptions. This change ensures that the field is persisted so that the read request is only sent once. --- drivers/SmartThings/matter-thermostat/src/init.lua | 3 +-- .../src/test/test_matter_thermo_setpoint_limits.lua | 13 +++++++++++++ 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/drivers/SmartThings/matter-thermostat/src/init.lua b/drivers/SmartThings/matter-thermostat/src/init.lua index bde3914aec..0009951e36 100644 --- a/drivers/SmartThings/matter-thermostat/src/init.lua +++ b/drivers/SmartThings/matter-thermostat/src/init.lua @@ -271,7 +271,6 @@ end local function device_init(driver, device) device:subscribe() device:set_component_to_endpoint_fn(component_to_endpoint) - if not device:get_field(setpoint_limit_device_field.MIN_SETPOINT_DEADBAND_CHECKED) then local auto_eps = device:get_endpoints(clusters.Thermostat.ID, {feature_bitmap = clusters.Thermostat.types.ThermostatFeature.AUTOMODE}) --Query min setpoint deadband if needed @@ -280,7 +279,6 @@ local function device_init(driver, device) deadband_read:merge(clusters.Thermostat.attributes.MinSetpointDeadBand:read()) device:send(deadband_read) end - device:set_field(setpoint_limit_device_field.MIN_SETPOINT_DEADBAND_CHECKED, true) end end @@ -808,6 +806,7 @@ local function min_deadband_limit_handler(driver, device, ib, response) local val = ib.data.value / 10.0 log.info("Setting " .. setpoint_limit_device_field.MIN_DEADBAND .. " to " .. string.format("%s", val)) device:set_field(setpoint_limit_device_field.MIN_DEADBAND, val, { persist = true }) + device:set_field(setpoint_limit_device_field.MIN_SETPOINT_DEADBAND_CHECKED, true, {persist = true}) end local function fan_mode_handler(driver, device, ib, response) diff --git a/drivers/SmartThings/matter-thermostat/src/test/test_matter_thermo_setpoint_limits.lua b/drivers/SmartThings/matter-thermostat/src/test/test_matter_thermo_setpoint_limits.lua index 37a53fb95a..5f85dd2790 100644 --- a/drivers/SmartThings/matter-thermostat/src/test/test_matter_thermo_setpoint_limits.lua +++ b/drivers/SmartThings/matter-thermostat/src/test/test_matter_thermo_setpoint_limits.lua @@ -250,6 +250,19 @@ test.register_coroutine_test( end ) +test.register_coroutine_test( + "Set MIN_SETPOINT_DEADBAND_CHECKED flag on MinSetpointDeadBand attribute handler", + function() + test.socket.matter:__queue_receive({ + mock_device.id, + clusters.Thermostat.attributes.MinSetpointDeadBand:build_test_report_data(mock_device, 1, 16) --1.6 celcius + }) + test.wait_for_events() + local min_setpoint_deadband_checked = mock_device:get_field("MIN_SETPOINT_DEADBAND_CHECKED") + assert(min_setpoint_deadband_checked == true, "min_setpoint_deadband_checked is True") + end +) + test.register_message_test( "Min and max heating setpoint attributes set capability constraint", {