From 7cc490d22887078580c1ab353231bc20a6b24612 Mon Sep 17 00:00:00 2001 From: Matthew DeHaven Date: Mon, 15 Apr 2024 10:15:23 -0500 Subject: [PATCH 01/29] Add a setpoint_bounds.lua script and load it This file is intended to contain code for dynamically retrieving setpoint constraints from zwave thermostats. The initial contents are copied from a zigbee bulb color bounds script with a similar purpose. --- .../SmartThings/zwave-thermostat/src/init.lua | 1 + .../zwave-thermostat/src/setpoint_bounds.lua | 49 +++++++++++++++++++ 2 files changed, 50 insertions(+) create mode 100644 drivers/SmartThings/zwave-thermostat/src/setpoint_bounds.lua diff --git a/drivers/SmartThings/zwave-thermostat/src/init.lua b/drivers/SmartThings/zwave-thermostat/src/init.lua index 22ad3cdf43..1f7c4d51c1 100755 --- a/drivers/SmartThings/zwave-thermostat/src/init.lua +++ b/drivers/SmartThings/zwave-thermostat/src/init.lua @@ -27,6 +27,7 @@ local ThermostatMode = (require "st.zwave.CommandClass.ThermostatMode")({version local ThermostatSetpoint = (require "st.zwave.CommandClass.ThermostatSetpoint")({version=1}) local constants = require "st.zwave.constants" local utils = require "st.utils" +local SetpointBounds = require "setpoint_bounds" local function device_added(driver, device) if device:supports_capability_by_id(capabilities.thermostatMode.ID) and diff --git a/drivers/SmartThings/zwave-thermostat/src/setpoint_bounds.lua b/drivers/SmartThings/zwave-thermostat/src/setpoint_bounds.lua new file mode 100644 index 0000000000..13268abaf7 --- /dev/null +++ b/drivers/SmartThings/zwave-thermostat/src/setpoint_bounds.lua @@ -0,0 +1,49 @@ +local capabilities = require "st.capabilities" +local clusters = require "st.zigbee.zcl.clusters" +local ColorControl = clusters.ColorControl +local utils = require "st.utils" + +local color_bounds = {} + +local SANITY_CHECK_MIN_KELVIN = 1 +local SANITY_CHECK_MAX_KELVIN = 30000 +color_bounds.BOUND_RECEIVED = "colorTemp_bound_received" +color_bounds.MIN = "_MIN" +color_bounds.MAX = "_MAX" + +color_bounds.mired_to_kelvin = function(value) + local CONVERSION_CONSTANT = 1000000 + if value == 0 then value = 1 end -- shouldn't happen, but has + -- we divide inside the rounding and multiply outside of it because we expect these + -- bounds to be multiples of 100 + return utils.round((CONVERSION_CONSTANT / value) / 100) * 100 +end + +color_bounds.mired_bounds_handler_factory = function(minOrMax) + return function(self, device, value, zb_rx) + local endpoint_id = zb_rx.address_header.src_endpoint.value + local temp_in_kelvin = color_bounds.mired_to_kelvin(value.value) + if temp_in_kelvin > SANITY_CHECK_MIN_KELVIN and temp_in_kelvin < SANITY_CHECK_MAX_KELVIN then + device:set_field(color_bounds.BOUND_RECEIVED..minOrMax, temp_in_kelvin) + else + device.log.warn("Device reported a min or max color temp value outside of reasonable bounds: "..temp_in_kelvin..'K') + end + + local min = device:get_field(color_bounds.BOUND_RECEIVED..color_bounds.MIN) + local max = device:get_field(color_bounds.BOUND_RECEIVED..color_bounds.MAX) + if min ~= nil and max ~= nil and min < max then + device:emit_event_for_endpoint(endpoint_id, capabilities.colorTemperature.colorTemperatureRange({ value = {minimum = min, maximum = max}})) + device:set_field(color_bounds.BOUND_RECEIVED..color_bounds.MAX, nil) + device:set_field(color_bounds.BOUND_RECEIVED..color_bounds.MIN, nil) + end + end +end + +color_bounds.check_bounds_if_applicable = function(device) + if device:supports_capability(capabilities.colorTemperature) then + device:send(ColorControl.attributes.ColorTempPhysicalMaxMireds:read(device)) + device:send(ColorControl.attributes.ColorTempPhysicalMinMireds:read(device)) + end +end + +return color_bounds From 135be3dbf5d021106d5a1288839d8690130d1356 Mon Sep 17 00:00:00 2001 From: Matthew DeHaven Date: Mon, 15 Apr 2024 10:21:31 -0500 Subject: [PATCH 02/29] Add beginning of setpoint_bounds object and return in --- .../SmartThings/zwave-thermostat/src/setpoint_bounds.lua | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/drivers/SmartThings/zwave-thermostat/src/setpoint_bounds.lua b/drivers/SmartThings/zwave-thermostat/src/setpoint_bounds.lua index 13268abaf7..16b462e7df 100644 --- a/drivers/SmartThings/zwave-thermostat/src/setpoint_bounds.lua +++ b/drivers/SmartThings/zwave-thermostat/src/setpoint_bounds.lua @@ -3,6 +3,11 @@ local clusters = require "st.zigbee.zcl.clusters" local ColorControl = clusters.ColorControl local utils = require "st.utils" +local setpoint_bounds = {} + +setpoint_bounds.HEATING = "_HEATING" +setpoint_bounds.COOLING = "_COOLING" + local color_bounds = {} local SANITY_CHECK_MIN_KELVIN = 1 @@ -46,4 +51,4 @@ color_bounds.check_bounds_if_applicable = function(device) end end -return color_bounds +return setpoint_bounds From 4922eb3775c60063b8dca893551fb3a19c30801a Mon Sep 17 00:00:00 2001 From: Matthew DeHaven Date: Mon, 15 Apr 2024 12:05:55 -0500 Subject: [PATCH 03/29] Create a factory method for setpoint capabilities handler --- .../SmartThings/zwave-thermostat/src/setpoint_bounds.lua | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/drivers/SmartThings/zwave-thermostat/src/setpoint_bounds.lua b/drivers/SmartThings/zwave-thermostat/src/setpoint_bounds.lua index 16b462e7df..b249120c74 100644 --- a/drivers/SmartThings/zwave-thermostat/src/setpoint_bounds.lua +++ b/drivers/SmartThings/zwave-thermostat/src/setpoint_bounds.lua @@ -8,6 +8,12 @@ local setpoint_bounds = {} setpoint_bounds.HEATING = "_HEATING" setpoint_bounds.COOLING = "_COOLING" +setpoint_bounds.setpoint_capabilites_report_handler_factory = function(coolingOrHeating) + return function(self, device, value) + print("setpoint_capabilites_report_handler_factory: Device reported a "..coolingOrHeating.." setpoint of"..value) + end +end + local color_bounds = {} local SANITY_CHECK_MIN_KELVIN = 1 From b34ca14421c1e086520446d1a09c98821f2df117 Mon Sep 17 00:00:00 2001 From: Matthew DeHaven Date: Mon, 15 Apr 2024 13:30:03 -0500 Subject: [PATCH 04/29] Add a placeholder zwave thermostat capabilites report handler --- drivers/SmartThings/zwave-thermostat/src/init.lua | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/drivers/SmartThings/zwave-thermostat/src/init.lua b/drivers/SmartThings/zwave-thermostat/src/init.lua index 1f7c4d51c1..9093ab1c34 100755 --- a/drivers/SmartThings/zwave-thermostat/src/init.lua +++ b/drivers/SmartThings/zwave-thermostat/src/init.lua @@ -110,6 +110,13 @@ local driver_template = { [capabilities.thermostatHeatingSetpoint.commands.setHeatingSetpoint.NAME] = set_setpoint_factory(ThermostatSetpoint.setpoint_type.HEATING_1) } }, + zwave_handlers = { + [cc.THERMOSTAT_SETPOINT] = { + [ThermostatSetpoint.CAPABILITIES_REPORT] = function() + print("Running ThermostatSetpoint.CAPABILITIES_REPORT handler") + end + } + }, lifecycle_handlers = { added = device_added }, From 347f2ed0b3d7648e1bf7f650a4c2d8407445f62c Mon Sep 17 00:00:00 2001 From: Matthew DeHaven Date: Mon, 15 Apr 2024 13:34:56 -0500 Subject: [PATCH 05/29] Add arguments to setpoint capabilites report handler --- drivers/SmartThings/zwave-thermostat/src/init.lua | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/drivers/SmartThings/zwave-thermostat/src/init.lua b/drivers/SmartThings/zwave-thermostat/src/init.lua index 9093ab1c34..cd75a44a60 100755 --- a/drivers/SmartThings/zwave-thermostat/src/init.lua +++ b/drivers/SmartThings/zwave-thermostat/src/init.lua @@ -88,6 +88,10 @@ local function set_setpoint_factory(setpoint_type) end end +local function setpoint_capabilites_report(driver, device, cmd) + print("Running setpoint_capabilites_report handler") +end + local driver_template = { supported_capabilities = { capabilities.temperatureAlarm, @@ -112,9 +116,7 @@ local driver_template = { }, zwave_handlers = { [cc.THERMOSTAT_SETPOINT] = { - [ThermostatSetpoint.CAPABILITIES_REPORT] = function() - print("Running ThermostatSetpoint.CAPABILITIES_REPORT handler") - end + [ThermostatSetpoint.CAPABILITIES_REPORT] = setpoint_capabilites_report } }, lifecycle_handlers = { From 9898d71c7ceff7f214756e75e9c0dd57a6f36327 Mon Sep 17 00:00:00 2001 From: Matthew DeHaven Date: Mon, 15 Apr 2024 13:49:43 -0500 Subject: [PATCH 06/29] Request setpoint capabilites from capatible zwave thermostats --- drivers/SmartThings/zwave-thermostat/src/init.lua | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/drivers/SmartThings/zwave-thermostat/src/init.lua b/drivers/SmartThings/zwave-thermostat/src/init.lua index cd75a44a60..d0ab8a3571 100755 --- a/drivers/SmartThings/zwave-thermostat/src/init.lua +++ b/drivers/SmartThings/zwave-thermostat/src/init.lua @@ -29,6 +29,16 @@ local constants = require "st.zwave.constants" local utils = require "st.utils" local SetpointBounds = require "setpoint_bounds" +local function device_supports_thermostat_setpoint(device) + return ( + ( + device:supports_capability_by_id(capabilities.capabilities.thermostatCoolingSetpoint.ID) or + device:supports_capability_by_id(capabilities.capabilities.thermostatHeatingSetpoint.ID) + ) and + device:is_cc_supported(cc.THERMOSTAT_SETPOINT) + ) +end + local function device_added(driver, device) if device:supports_capability_by_id(capabilities.thermostatMode.ID) and device:is_cc_supported(cc.THERMOSTAT_MODE) then @@ -38,6 +48,9 @@ local function device_added(driver, device) device:is_cc_supported(cc.THERMOSTAT_FAN_MODE) then device:send(ThermostatFanMode:SupportedGet({})) end + if device_supports_thermostat_setpoint(device) then + device:send(ThermostatSetpoint:CapabilitiesGet({})) + end device:refresh() end From d5b4ff733f3108034bd462fc7308dc849bd5a9ce Mon Sep 17 00:00:00 2001 From: Matthew DeHaven Date: Mon, 15 Apr 2024 15:44:52 -0500 Subject: [PATCH 07/29] Fix typo: double "capabilities" --- drivers/SmartThings/zwave-thermostat/src/init.lua | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/drivers/SmartThings/zwave-thermostat/src/init.lua b/drivers/SmartThings/zwave-thermostat/src/init.lua index d0ab8a3571..d9966de162 100755 --- a/drivers/SmartThings/zwave-thermostat/src/init.lua +++ b/drivers/SmartThings/zwave-thermostat/src/init.lua @@ -32,8 +32,8 @@ local SetpointBounds = require "setpoint_bounds" local function device_supports_thermostat_setpoint(device) return ( ( - device:supports_capability_by_id(capabilities.capabilities.thermostatCoolingSetpoint.ID) or - device:supports_capability_by_id(capabilities.capabilities.thermostatHeatingSetpoint.ID) + device:supports_capability_by_id(capabilities.thermostatCoolingSetpoint.ID) or + device:supports_capability_by_id(capabilities.thermostatHeatingSetpoint.ID) ) and device:is_cc_supported(cc.THERMOSTAT_SETPOINT) ) From 1abcbc058ccdda515ae2303f02a1906b703de74d Mon Sep 17 00:00:00 2001 From: Matthew DeHaven Date: Tue, 16 Apr 2024 11:56:11 -0500 Subject: [PATCH 08/29] Use V3 Thermostat Setpoint Command --- drivers/SmartThings/zwave-thermostat/src/init.lua | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/drivers/SmartThings/zwave-thermostat/src/init.lua b/drivers/SmartThings/zwave-thermostat/src/init.lua index d9966de162..62f05bfb73 100755 --- a/drivers/SmartThings/zwave-thermostat/src/init.lua +++ b/drivers/SmartThings/zwave-thermostat/src/init.lua @@ -25,6 +25,7 @@ local ThermostatFanMode = (require "st.zwave.CommandClass.ThermostatFanMode")({v local ThermostatMode = (require "st.zwave.CommandClass.ThermostatMode")({version=2}) --- @type st.zwave.CommandClass.ThermostatSetpoint local ThermostatSetpoint = (require "st.zwave.CommandClass.ThermostatSetpoint")({version=1}) +local ThermostatSetpointV3 = (require "st.zwave.CommandClass.ThermostatSetpoint")({version=3}) local constants = require "st.zwave.constants" local utils = require "st.utils" local SetpointBounds = require "setpoint_bounds" @@ -49,7 +50,7 @@ local function device_added(driver, device) device:send(ThermostatFanMode:SupportedGet({})) end if device_supports_thermostat_setpoint(device) then - device:send(ThermostatSetpoint:CapabilitiesGet({})) + device:send(ThermostatSetpointV3:CapabilitiesGet({setpoint_type = ThermostatSetpoint.setpoint_type.HEATING_1})) end device:refresh() end From 6f527cd4359f3df46c9a2cb885ecbfea0d41fb76 Mon Sep 17 00:00:00 2001 From: Matthew DeHaven Date: Tue, 16 Apr 2024 13:05:11 -0500 Subject: [PATCH 09/29] Update test case to expect Capabilities Get command send --- .../zwave-thermostat/src/test/test_zwave_thermostat.lua | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/drivers/SmartThings/zwave-thermostat/src/test/test_zwave_thermostat.lua b/drivers/SmartThings/zwave-thermostat/src/test/test_zwave_thermostat.lua index f57f7cc6cf..3514313bf7 100644 --- a/drivers/SmartThings/zwave-thermostat/src/test/test_zwave_thermostat.lua +++ b/drivers/SmartThings/zwave-thermostat/src/test/test_zwave_thermostat.lua @@ -19,6 +19,7 @@ local Battery = (require "st.zwave.CommandClass.Battery")({ version = 1 }) local SensorMultilevel = (require "st.zwave.CommandClass.SensorMultilevel")({ version = 5 }) local ThermostatMode = (require "st.zwave.CommandClass.ThermostatMode")({ version = 2 }) local ThermostatSetpoint = (require "st.zwave.CommandClass.ThermostatSetpoint")({ version = 1 }) +local ThermostatSetpointV3 = (require "st.zwave.CommandClass.ThermostatSetpoint")({ version = 3 }) local ThermostatOperatingState = (require "st.zwave.CommandClass.ThermostatOperatingState")({ version = 1 }) local ThermostatFanMode = (require "st.zwave.CommandClass.ThermostatFanMode")({ version = 3 }) local zw = require "st.zwave" @@ -140,6 +141,14 @@ test.register_message_test( ThermostatFanMode:SupportedGet({}) ) }, + { + channel = "zwave", + direction = "send", + message = zw_test_utilities.zwave_test_build_send_command( + mock_device, + ThermostatSetpointV3:CapabilitiesGet({setpoint_type = ThermostatSetpoint.setpoint_type.HEATING_1}) + ) + }, table.unpack(refresh_commands) }, { From 396352f5a822b8ae4acd92b1447b9251e293eaa8 Mon Sep 17 00:00:00 2001 From: Matthew DeHaven Date: Tue, 16 Apr 2024 13:08:21 -0500 Subject: [PATCH 10/29] Add send for Cooling Setpoint Capabilities Get --- drivers/SmartThings/zwave-thermostat/src/init.lua | 1 + .../zwave-thermostat/src/test/test_zwave_thermostat.lua | 8 ++++++++ 2 files changed, 9 insertions(+) diff --git a/drivers/SmartThings/zwave-thermostat/src/init.lua b/drivers/SmartThings/zwave-thermostat/src/init.lua index 62f05bfb73..1d182283de 100755 --- a/drivers/SmartThings/zwave-thermostat/src/init.lua +++ b/drivers/SmartThings/zwave-thermostat/src/init.lua @@ -51,6 +51,7 @@ local function device_added(driver, device) end if device_supports_thermostat_setpoint(device) then device:send(ThermostatSetpointV3:CapabilitiesGet({setpoint_type = ThermostatSetpoint.setpoint_type.HEATING_1})) + device:send(ThermostatSetpointV3:CapabilitiesGet({setpoint_type = ThermostatSetpoint.setpoint_type.COOLING_1})) end device:refresh() end diff --git a/drivers/SmartThings/zwave-thermostat/src/test/test_zwave_thermostat.lua b/drivers/SmartThings/zwave-thermostat/src/test/test_zwave_thermostat.lua index 3514313bf7..86dac7327e 100644 --- a/drivers/SmartThings/zwave-thermostat/src/test/test_zwave_thermostat.lua +++ b/drivers/SmartThings/zwave-thermostat/src/test/test_zwave_thermostat.lua @@ -149,6 +149,14 @@ test.register_message_test( ThermostatSetpointV3:CapabilitiesGet({setpoint_type = ThermostatSetpoint.setpoint_type.HEATING_1}) ) }, + { + channel = "zwave", + direction = "send", + message = zw_test_utilities.zwave_test_build_send_command( + mock_device, + ThermostatSetpointV3:CapabilitiesGet({setpoint_type = ThermostatSetpoint.setpoint_type.COOLING_1}) + ) + }, table.unpack(refresh_commands) }, { From fa70e878743b832060888aecf18cf54adf81bd23 Mon Sep 17 00:00:00 2001 From: Matthew DeHaven Date: Tue, 16 Apr 2024 14:25:39 -0500 Subject: [PATCH 11/29] Add start of setpoint capability report test --- .../src/test/test_zwave_thermostat.lua | 33 +++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/drivers/SmartThings/zwave-thermostat/src/test/test_zwave_thermostat.lua b/drivers/SmartThings/zwave-thermostat/src/test/test_zwave_thermostat.lua index 86dac7327e..de2853bd73 100644 --- a/drivers/SmartThings/zwave-thermostat/src/test/test_zwave_thermostat.lua +++ b/drivers/SmartThings/zwave-thermostat/src/test/test_zwave_thermostat.lua @@ -396,6 +396,39 @@ test.register_message_test( } ) +test.register_message_test( + "Thermostat heating setpoint capability reports should be handled. ", + { + { + channel = "zwave", + direction = "receive", + message = { + mock_device.id, + zw_test_utilities.zwave_test_build_receive_command( + ThermostatSetpointV3:CapabilitiesReport( + { + setpoint_type = ThermostatSetpoint.setpoint_type.HEATING_1, + size1 = 2, + scale1 = ThermostatSetpoint.scale.CELSIUS, + precision1 = 1, + min_value = 0, + size2 = 2, + scale2 = ThermostatSetpoint.scale.CELSIUS, + precision2 = 1, + max_value = 1 + } + ) + ) + } + }, + { + channel = "capability", + direction = "send", + message = mock_device:generate_test_message("main", capabilities.thermostatOperatingState.thermostatOperatingState.heating()) + } + } +) + test.register_coroutine_test( "Setting the thermostat fan mode should generate the appropriate commands", function() From 70a8b46f6a50c921e979f12383c9a4ab3793136d Mon Sep 17 00:00:00 2001 From: Matthew DeHaven Date: Tue, 16 Apr 2024 15:49:32 -0500 Subject: [PATCH 12/29] Add a fake return value for heating setpoint min/max --- .../zwave-thermostat/src/test/test_zwave_thermostat.lua | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/drivers/SmartThings/zwave-thermostat/src/test/test_zwave_thermostat.lua b/drivers/SmartThings/zwave-thermostat/src/test/test_zwave_thermostat.lua index de2853bd73..6158343cd5 100644 --- a/drivers/SmartThings/zwave-thermostat/src/test/test_zwave_thermostat.lua +++ b/drivers/SmartThings/zwave-thermostat/src/test/test_zwave_thermostat.lua @@ -424,7 +424,14 @@ test.register_message_test( { channel = "capability", direction = "send", - message = mock_device:generate_test_message("main", capabilities.thermostatOperatingState.thermostatOperatingState.heating()) + message = mock_device:generate_test_message("main", + capabilities.thermostatHeatingSetpoint.heatingSetpointRange( + { + unit = 'F', + value = {minimum = 40, maximum = 80} + } + ) + ) } } ) From 4dac851e96cc6996d98b2c61a88cbb064d5171f4 Mon Sep 17 00:00:00 2001 From: Matthew DeHaven Date: Tue, 16 Apr 2024 16:17:43 -0500 Subject: [PATCH 13/29] Emit placeholder event for setpoint report --- .../SmartThings/zwave-thermostat/src/init.lua | 26 ++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/drivers/SmartThings/zwave-thermostat/src/init.lua b/drivers/SmartThings/zwave-thermostat/src/init.lua index 1d182283de..e3d65d9ac5 100755 --- a/drivers/SmartThings/zwave-thermostat/src/init.lua +++ b/drivers/SmartThings/zwave-thermostat/src/init.lua @@ -104,7 +104,31 @@ local function set_setpoint_factory(setpoint_type) end local function setpoint_capabilites_report(driver, device, cmd) - print("Running setpoint_capabilites_report handler") + local function concrete_setpoint_temperature(precision, size, value) + --- MADFIXME + return value + end + local function celsius_setpoint_temperature(precision, size, value, scale) + local concrete_temperature = concrete_setpoint_temperature(precision, size, value) + if (scale == ThermostatSetpoint.scale.FAHRENHEIT) then + return utils.f_to_c(concrete_temperature) + else + return concrete_temperature + end + end + local args = cmd.args + --- MADFIXME - Verify scale1 is associated with min_value and scale2 is associated with max_value + local min_temp_c = celsius_setpoint_temperature(args.precision1, args.size1, args.min_value, args.scale1) + local max_temp_c = celsius_setpoint_temperature(args.precision2, args.size2, args.max_value, args.scale2) + + -- MADFIXME - Send the capability message + device:emit_event_for_endpoint(cmd.src_channel, capabilities.thermostatHeatingSetpoint.heatingSetpointRange( + { + -- MAXFIXME - Should be 'C' + unit = 'F', + value = {minimum = 40, maximum = 80} + } + )) end local driver_template = { From 98605a46f17eedbe2fb9a26536a21c46308f75a4 Mon Sep 17 00:00:00 2001 From: Matthew DeHaven Date: Tue, 16 Apr 2024 16:18:42 -0500 Subject: [PATCH 14/29] Convert F to C --- drivers/SmartThings/zwave-thermostat/src/init.lua | 2 +- .../zwave-thermostat/src/test/test_zwave_thermostat.lua | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/drivers/SmartThings/zwave-thermostat/src/init.lua b/drivers/SmartThings/zwave-thermostat/src/init.lua index e3d65d9ac5..1924331d1e 100755 --- a/drivers/SmartThings/zwave-thermostat/src/init.lua +++ b/drivers/SmartThings/zwave-thermostat/src/init.lua @@ -125,7 +125,7 @@ local function setpoint_capabilites_report(driver, device, cmd) device:emit_event_for_endpoint(cmd.src_channel, capabilities.thermostatHeatingSetpoint.heatingSetpointRange( { -- MAXFIXME - Should be 'C' - unit = 'F', + unit = 'C', value = {minimum = 40, maximum = 80} } )) diff --git a/drivers/SmartThings/zwave-thermostat/src/test/test_zwave_thermostat.lua b/drivers/SmartThings/zwave-thermostat/src/test/test_zwave_thermostat.lua index 6158343cd5..4a185ab919 100644 --- a/drivers/SmartThings/zwave-thermostat/src/test/test_zwave_thermostat.lua +++ b/drivers/SmartThings/zwave-thermostat/src/test/test_zwave_thermostat.lua @@ -427,7 +427,7 @@ test.register_message_test( message = mock_device:generate_test_message("main", capabilities.thermostatHeatingSetpoint.heatingSetpointRange( { - unit = 'F', + unit = 'C', value = {minimum = 40, maximum = 80} } ) From 9c06c7563de4fe3545178317613b933393c68e83 Mon Sep 17 00:00:00 2001 From: Matthew DeHaven Date: Tue, 16 Apr 2024 16:23:47 -0500 Subject: [PATCH 15/29] Use variables instead of hardcoded values --- drivers/SmartThings/zwave-thermostat/src/init.lua | 6 ++---- .../zwave-thermostat/src/test/test_zwave_thermostat.lua | 2 +- 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/drivers/SmartThings/zwave-thermostat/src/init.lua b/drivers/SmartThings/zwave-thermostat/src/init.lua index 1924331d1e..3910c7f29d 100755 --- a/drivers/SmartThings/zwave-thermostat/src/init.lua +++ b/drivers/SmartThings/zwave-thermostat/src/init.lua @@ -105,7 +105,7 @@ end local function setpoint_capabilites_report(driver, device, cmd) local function concrete_setpoint_temperature(precision, size, value) - --- MADFIXME + --- MADFIXME -- Perform the actual conversion return value end local function celsius_setpoint_temperature(precision, size, value, scale) @@ -121,12 +121,10 @@ local function setpoint_capabilites_report(driver, device, cmd) local min_temp_c = celsius_setpoint_temperature(args.precision1, args.size1, args.min_value, args.scale1) local max_temp_c = celsius_setpoint_temperature(args.precision2, args.size2, args.max_value, args.scale2) - -- MADFIXME - Send the capability message device:emit_event_for_endpoint(cmd.src_channel, capabilities.thermostatHeatingSetpoint.heatingSetpointRange( { - -- MAXFIXME - Should be 'C' unit = 'C', - value = {minimum = 40, maximum = 80} + value = {minimum = min_temp_c, maximum = max_temp_c} } )) end diff --git a/drivers/SmartThings/zwave-thermostat/src/test/test_zwave_thermostat.lua b/drivers/SmartThings/zwave-thermostat/src/test/test_zwave_thermostat.lua index 4a185ab919..07e2f21a6d 100644 --- a/drivers/SmartThings/zwave-thermostat/src/test/test_zwave_thermostat.lua +++ b/drivers/SmartThings/zwave-thermostat/src/test/test_zwave_thermostat.lua @@ -428,7 +428,7 @@ test.register_message_test( capabilities.thermostatHeatingSetpoint.heatingSetpointRange( { unit = 'C', - value = {minimum = 40, maximum = 80} + value = {minimum = 0.0, maximum = 1.0} } ) ) From 50ac147fa450f48e6e6a83e0c131e2a1d4a4768d Mon Sep 17 00:00:00 2001 From: Matthew DeHaven Date: Tue, 16 Apr 2024 16:34:33 -0500 Subject: [PATCH 16/29] Implement setpoint report conversion --- drivers/SmartThings/zwave-thermostat/src/init.lua | 13 +++++++------ .../src/test/test_zwave_thermostat.lua | 12 ++++++------ 2 files changed, 13 insertions(+), 12 deletions(-) diff --git a/drivers/SmartThings/zwave-thermostat/src/init.lua b/drivers/SmartThings/zwave-thermostat/src/init.lua index 3910c7f29d..aa6ed337ce 100755 --- a/drivers/SmartThings/zwave-thermostat/src/init.lua +++ b/drivers/SmartThings/zwave-thermostat/src/init.lua @@ -104,12 +104,13 @@ local function set_setpoint_factory(setpoint_type) end local function setpoint_capabilites_report(driver, device, cmd) - local function concrete_setpoint_temperature(precision, size, value) + local function concrete_setpoint_temperature(precision, value) --- MADFIXME -- Perform the actual conversion - return value + local result = value / (10 ^ precision) + return result end - local function celsius_setpoint_temperature(precision, size, value, scale) - local concrete_temperature = concrete_setpoint_temperature(precision, size, value) + local function celsius_setpoint_temperature(precision, value, scale) + local concrete_temperature = concrete_setpoint_temperature(precision, value) if (scale == ThermostatSetpoint.scale.FAHRENHEIT) then return utils.f_to_c(concrete_temperature) else @@ -118,8 +119,8 @@ local function setpoint_capabilites_report(driver, device, cmd) end local args = cmd.args --- MADFIXME - Verify scale1 is associated with min_value and scale2 is associated with max_value - local min_temp_c = celsius_setpoint_temperature(args.precision1, args.size1, args.min_value, args.scale1) - local max_temp_c = celsius_setpoint_temperature(args.precision2, args.size2, args.max_value, args.scale2) + local min_temp_c = celsius_setpoint_temperature(args.precision1, args.min_value, args.scale1) + local max_temp_c = celsius_setpoint_temperature(args.precision2, args.max_value, args.scale2) device:emit_event_for_endpoint(cmd.src_channel, capabilities.thermostatHeatingSetpoint.heatingSetpointRange( { diff --git a/drivers/SmartThings/zwave-thermostat/src/test/test_zwave_thermostat.lua b/drivers/SmartThings/zwave-thermostat/src/test/test_zwave_thermostat.lua index 07e2f21a6d..f880b73a25 100644 --- a/drivers/SmartThings/zwave-thermostat/src/test/test_zwave_thermostat.lua +++ b/drivers/SmartThings/zwave-thermostat/src/test/test_zwave_thermostat.lua @@ -408,14 +408,14 @@ test.register_message_test( ThermostatSetpointV3:CapabilitiesReport( { setpoint_type = ThermostatSetpoint.setpoint_type.HEATING_1, - size1 = 2, + size1 = 4, scale1 = ThermostatSetpoint.scale.CELSIUS, - precision1 = 1, - min_value = 0, - size2 = 2, + precision1 = 2, + min_value = 722, + size2 = 4, scale2 = ThermostatSetpoint.scale.CELSIUS, precision2 = 1, - max_value = 1 + max_value = 272 } ) ) @@ -428,7 +428,7 @@ test.register_message_test( capabilities.thermostatHeatingSetpoint.heatingSetpointRange( { unit = 'C', - value = {minimum = 0.0, maximum = 1.0} + value = {minimum = 7.22, maximum = 27.2} } ) ) From c8edfc33aa622b7cb4f57418055f8c8989e0ba92 Mon Sep 17 00:00:00 2001 From: Matthew DeHaven Date: Tue, 16 Apr 2024 16:34:57 -0500 Subject: [PATCH 17/29] Remove a FIXME --- drivers/SmartThings/zwave-thermostat/src/init.lua | 1 - 1 file changed, 1 deletion(-) diff --git a/drivers/SmartThings/zwave-thermostat/src/init.lua b/drivers/SmartThings/zwave-thermostat/src/init.lua index aa6ed337ce..d8347cf45d 100755 --- a/drivers/SmartThings/zwave-thermostat/src/init.lua +++ b/drivers/SmartThings/zwave-thermostat/src/init.lua @@ -105,7 +105,6 @@ end local function setpoint_capabilites_report(driver, device, cmd) local function concrete_setpoint_temperature(precision, value) - --- MADFIXME -- Perform the actual conversion local result = value / (10 ^ precision) return result end From 9560b63371a54d25860360337ef17d3dd30b4993 Mon Sep 17 00:00:00 2001 From: Matthew DeHaven Date: Tue, 16 Apr 2024 16:42:20 -0500 Subject: [PATCH 18/29] Adjust fixme comment --- drivers/SmartThings/zwave-thermostat/src/init.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/SmartThings/zwave-thermostat/src/init.lua b/drivers/SmartThings/zwave-thermostat/src/init.lua index d8347cf45d..4e35ed78ec 100755 --- a/drivers/SmartThings/zwave-thermostat/src/init.lua +++ b/drivers/SmartThings/zwave-thermostat/src/init.lua @@ -117,7 +117,7 @@ local function setpoint_capabilites_report(driver, device, cmd) end end local args = cmd.args - --- MADFIXME - Verify scale1 is associated with min_value and scale2 is associated with max_value + --- FIXME - MAD - Verify scale1 is associated with min_value and scale2 is associated with max_value local min_temp_c = celsius_setpoint_temperature(args.precision1, args.min_value, args.scale1) local max_temp_c = celsius_setpoint_temperature(args.precision2, args.max_value, args.scale2) From 293fc3825545f897f6292d51b75f64b35052fcc1 Mon Sep 17 00:00:00 2001 From: Matthew DeHaven Date: Tue, 16 Apr 2024 16:44:37 -0500 Subject: [PATCH 19/29] Delete unused file --- .../zwave-thermostat/src/setpoint_bounds.lua | 60 ------------------- 1 file changed, 60 deletions(-) delete mode 100644 drivers/SmartThings/zwave-thermostat/src/setpoint_bounds.lua diff --git a/drivers/SmartThings/zwave-thermostat/src/setpoint_bounds.lua b/drivers/SmartThings/zwave-thermostat/src/setpoint_bounds.lua deleted file mode 100644 index b249120c74..0000000000 --- a/drivers/SmartThings/zwave-thermostat/src/setpoint_bounds.lua +++ /dev/null @@ -1,60 +0,0 @@ -local capabilities = require "st.capabilities" -local clusters = require "st.zigbee.zcl.clusters" -local ColorControl = clusters.ColorControl -local utils = require "st.utils" - -local setpoint_bounds = {} - -setpoint_bounds.HEATING = "_HEATING" -setpoint_bounds.COOLING = "_COOLING" - -setpoint_bounds.setpoint_capabilites_report_handler_factory = function(coolingOrHeating) - return function(self, device, value) - print("setpoint_capabilites_report_handler_factory: Device reported a "..coolingOrHeating.." setpoint of"..value) - end -end - -local color_bounds = {} - -local SANITY_CHECK_MIN_KELVIN = 1 -local SANITY_CHECK_MAX_KELVIN = 30000 -color_bounds.BOUND_RECEIVED = "colorTemp_bound_received" -color_bounds.MIN = "_MIN" -color_bounds.MAX = "_MAX" - -color_bounds.mired_to_kelvin = function(value) - local CONVERSION_CONSTANT = 1000000 - if value == 0 then value = 1 end -- shouldn't happen, but has - -- we divide inside the rounding and multiply outside of it because we expect these - -- bounds to be multiples of 100 - return utils.round((CONVERSION_CONSTANT / value) / 100) * 100 -end - -color_bounds.mired_bounds_handler_factory = function(minOrMax) - return function(self, device, value, zb_rx) - local endpoint_id = zb_rx.address_header.src_endpoint.value - local temp_in_kelvin = color_bounds.mired_to_kelvin(value.value) - if temp_in_kelvin > SANITY_CHECK_MIN_KELVIN and temp_in_kelvin < SANITY_CHECK_MAX_KELVIN then - device:set_field(color_bounds.BOUND_RECEIVED..minOrMax, temp_in_kelvin) - else - device.log.warn("Device reported a min or max color temp value outside of reasonable bounds: "..temp_in_kelvin..'K') - end - - local min = device:get_field(color_bounds.BOUND_RECEIVED..color_bounds.MIN) - local max = device:get_field(color_bounds.BOUND_RECEIVED..color_bounds.MAX) - if min ~= nil and max ~= nil and min < max then - device:emit_event_for_endpoint(endpoint_id, capabilities.colorTemperature.colorTemperatureRange({ value = {minimum = min, maximum = max}})) - device:set_field(color_bounds.BOUND_RECEIVED..color_bounds.MAX, nil) - device:set_field(color_bounds.BOUND_RECEIVED..color_bounds.MIN, nil) - end - end -end - -color_bounds.check_bounds_if_applicable = function(device) - if device:supports_capability(capabilities.colorTemperature) then - device:send(ColorControl.attributes.ColorTempPhysicalMaxMireds:read(device)) - device:send(ColorControl.attributes.ColorTempPhysicalMinMireds:read(device)) - end -end - -return setpoint_bounds From 84dcf2002f6fd1e156d83f1d7727f4d41e207199 Mon Sep 17 00:00:00 2001 From: Matthew DeHaven Date: Tue, 16 Apr 2024 16:45:20 -0500 Subject: [PATCH 20/29] Remove reference to unused file --- drivers/SmartThings/zwave-thermostat/src/init.lua | 1 - 1 file changed, 1 deletion(-) diff --git a/drivers/SmartThings/zwave-thermostat/src/init.lua b/drivers/SmartThings/zwave-thermostat/src/init.lua index 4e35ed78ec..c545bd530e 100755 --- a/drivers/SmartThings/zwave-thermostat/src/init.lua +++ b/drivers/SmartThings/zwave-thermostat/src/init.lua @@ -28,7 +28,6 @@ local ThermostatSetpoint = (require "st.zwave.CommandClass.ThermostatSetpoint")( local ThermostatSetpointV3 = (require "st.zwave.CommandClass.ThermostatSetpoint")({version=3}) local constants = require "st.zwave.constants" local utils = require "st.utils" -local SetpointBounds = require "setpoint_bounds" local function device_supports_thermostat_setpoint(device) return ( From 6e192f16b1b9d1f54dd32ca5336752447310cdd8 Mon Sep 17 00:00:00 2001 From: Matthew DeHaven Date: Mon, 22 Apr 2024 10:54:44 -0500 Subject: [PATCH 21/29] Utitlize implicit serialization magic Do not explicitly use scale and precision. Rely on existing conversion utilities behind the scenes. --- .../SmartThings/zwave-thermostat/src/init.lua | 16 ++-------------- .../src/test/test_zwave_thermostat.lua | 8 ++------ 2 files changed, 4 insertions(+), 20 deletions(-) diff --git a/drivers/SmartThings/zwave-thermostat/src/init.lua b/drivers/SmartThings/zwave-thermostat/src/init.lua index c545bd530e..9287eeec79 100755 --- a/drivers/SmartThings/zwave-thermostat/src/init.lua +++ b/drivers/SmartThings/zwave-thermostat/src/init.lua @@ -103,22 +103,10 @@ local function set_setpoint_factory(setpoint_type) end local function setpoint_capabilites_report(driver, device, cmd) - local function concrete_setpoint_temperature(precision, value) - local result = value / (10 ^ precision) - return result - end - local function celsius_setpoint_temperature(precision, value, scale) - local concrete_temperature = concrete_setpoint_temperature(precision, value) - if (scale == ThermostatSetpoint.scale.FAHRENHEIT) then - return utils.f_to_c(concrete_temperature) - else - return concrete_temperature - end - end local args = cmd.args --- FIXME - MAD - Verify scale1 is associated with min_value and scale2 is associated with max_value - local min_temp_c = celsius_setpoint_temperature(args.precision1, args.min_value, args.scale1) - local max_temp_c = celsius_setpoint_temperature(args.precision2, args.max_value, args.scale2) + local min_temp_c = args.min_value + local max_temp_c = args.max_value device:emit_event_for_endpoint(cmd.src_channel, capabilities.thermostatHeatingSetpoint.heatingSetpointRange( { diff --git a/drivers/SmartThings/zwave-thermostat/src/test/test_zwave_thermostat.lua b/drivers/SmartThings/zwave-thermostat/src/test/test_zwave_thermostat.lua index f880b73a25..c75ae66aef 100644 --- a/drivers/SmartThings/zwave-thermostat/src/test/test_zwave_thermostat.lua +++ b/drivers/SmartThings/zwave-thermostat/src/test/test_zwave_thermostat.lua @@ -408,14 +408,10 @@ test.register_message_test( ThermostatSetpointV3:CapabilitiesReport( { setpoint_type = ThermostatSetpoint.setpoint_type.HEATING_1, - size1 = 4, scale1 = ThermostatSetpoint.scale.CELSIUS, - precision1 = 2, - min_value = 722, - size2 = 4, + min_value = 7.22, scale2 = ThermostatSetpoint.scale.CELSIUS, - precision2 = 1, - max_value = 272 + max_value = 27.2 } ) ) From 77b55fc7b5e2aef9696e83a72156d47b077696ff Mon Sep 17 00:00:00 2001 From: Matthew DeHaven Date: Mon, 22 Apr 2024 10:56:15 -0500 Subject: [PATCH 22/29] Remove a fixme comment --- drivers/SmartThings/zwave-thermostat/src/init.lua | 1 - 1 file changed, 1 deletion(-) diff --git a/drivers/SmartThings/zwave-thermostat/src/init.lua b/drivers/SmartThings/zwave-thermostat/src/init.lua index 9287eeec79..576716f8eb 100755 --- a/drivers/SmartThings/zwave-thermostat/src/init.lua +++ b/drivers/SmartThings/zwave-thermostat/src/init.lua @@ -104,7 +104,6 @@ end local function setpoint_capabilites_report(driver, device, cmd) local args = cmd.args - --- FIXME - MAD - Verify scale1 is associated with min_value and scale2 is associated with max_value local min_temp_c = args.min_value local max_temp_c = args.max_value From 9c431bf92c0c4105c4eca10078dfb98ca2f056a9 Mon Sep 17 00:00:00 2001 From: Matthew DeHaven Date: Mon, 22 Apr 2024 12:02:42 -0500 Subject: [PATCH 23/29] Improve specificity of test name --- .../zwave-thermostat/src/test/test_zwave_thermostat.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/SmartThings/zwave-thermostat/src/test/test_zwave_thermostat.lua b/drivers/SmartThings/zwave-thermostat/src/test/test_zwave_thermostat.lua index c75ae66aef..d45529422e 100644 --- a/drivers/SmartThings/zwave-thermostat/src/test/test_zwave_thermostat.lua +++ b/drivers/SmartThings/zwave-thermostat/src/test/test_zwave_thermostat.lua @@ -397,7 +397,7 @@ test.register_message_test( ) test.register_message_test( - "Thermostat heating setpoint capability reports should be handled. ", + "Thermostat heating setpoint capability reports should be sent to the capabilities channel.", { { channel = "zwave", From 4895aa2b7a1a24869c90255a3c1fe7e0acdc07a7 Mon Sep 17 00:00:00 2001 From: Matthew DeHaven Date: Mon, 22 Apr 2024 12:19:12 -0500 Subject: [PATCH 24/29] Add heating Fahrenheit test and fix an issue identified by this new test --- .../SmartThings/zwave-thermostat/src/init.lua | 7 ++++- .../src/test/test_zwave_thermostat.lua | 30 +++++++++++++++++++ 2 files changed, 36 insertions(+), 1 deletion(-) diff --git a/drivers/SmartThings/zwave-thermostat/src/init.lua b/drivers/SmartThings/zwave-thermostat/src/init.lua index 576716f8eb..3037621260 100755 --- a/drivers/SmartThings/zwave-thermostat/src/init.lua +++ b/drivers/SmartThings/zwave-thermostat/src/init.lua @@ -107,9 +107,14 @@ local function setpoint_capabilites_report(driver, device, cmd) local min_temp_c = args.min_value local max_temp_c = args.max_value + local scale = 'C' + if args.scale1 == ThermostatSetpoint.scale.FAHRENHEIT then + scale = 'F' + end + device:emit_event_for_endpoint(cmd.src_channel, capabilities.thermostatHeatingSetpoint.heatingSetpointRange( { - unit = 'C', + unit = scale, value = {minimum = min_temp_c, maximum = max_temp_c} } )) diff --git a/drivers/SmartThings/zwave-thermostat/src/test/test_zwave_thermostat.lua b/drivers/SmartThings/zwave-thermostat/src/test/test_zwave_thermostat.lua index d45529422e..356a176cc5 100644 --- a/drivers/SmartThings/zwave-thermostat/src/test/test_zwave_thermostat.lua +++ b/drivers/SmartThings/zwave-thermostat/src/test/test_zwave_thermostat.lua @@ -428,6 +428,36 @@ test.register_message_test( } ) ) + }, + { + channel = "zwave", + direction = "receive", + message = { + mock_device.id, + zw_test_utilities.zwave_test_build_receive_command( + ThermostatSetpointV3:CapabilitiesReport( + { + setpoint_type = ThermostatSetpoint.setpoint_type.HEATING_1, + scale1 = ThermostatSetpoint.scale.FAHRENHEIT, + min_value = 44.9, + scale2 = ThermostatSetpoint.scale.FAHRENHEIT, + max_value = 80.9 + } + ) + ) + } + }, + { + channel = "capability", + direction = "send", + message = mock_device:generate_test_message("main", + capabilities.thermostatHeatingSetpoint.heatingSetpointRange( + { + unit = 'F', + value = {minimum = 44.9, maximum = 80.9} + } + ) + ) } } ) From c53b335c5cab894300d26d6ba9ca447bb1f0a408 Mon Sep 17 00:00:00 2001 From: Matthew DeHaven Date: Mon, 22 Apr 2024 12:24:29 -0500 Subject: [PATCH 25/29] Copy heating tests to create cooling test --- .../src/test/test_zwave_thermostat.lua | 66 +++++++++++++++++++ 1 file changed, 66 insertions(+) diff --git a/drivers/SmartThings/zwave-thermostat/src/test/test_zwave_thermostat.lua b/drivers/SmartThings/zwave-thermostat/src/test/test_zwave_thermostat.lua index 356a176cc5..e63ae50c0d 100644 --- a/drivers/SmartThings/zwave-thermostat/src/test/test_zwave_thermostat.lua +++ b/drivers/SmartThings/zwave-thermostat/src/test/test_zwave_thermostat.lua @@ -462,6 +462,72 @@ test.register_message_test( } ) +test.register_message_test( + "Thermostat heating setpoint capability reports should be sent to the capabilities channel.", + { + { + channel = "zwave", + direction = "receive", + message = { + mock_device.id, + zw_test_utilities.zwave_test_build_receive_command( + ThermostatSetpointV3:CapabilitiesReport( + { + setpoint_type = ThermostatSetpoint.setpoint_type.HEATING_1, + scale1 = ThermostatSetpoint.scale.CELSIUS, + min_value = 7.22, + scale2 = ThermostatSetpoint.scale.CELSIUS, + max_value = 27.2 + } + ) + ) + } + }, + { + channel = "capability", + direction = "send", + message = mock_device:generate_test_message("main", + capabilities.thermostatHeatingSetpoint.heatingSetpointRange( + { + unit = 'C', + value = {minimum = 7.22, maximum = 27.2} + } + ) + ) + }, + { + channel = "zwave", + direction = "receive", + message = { + mock_device.id, + zw_test_utilities.zwave_test_build_receive_command( + ThermostatSetpointV3:CapabilitiesReport( + { + setpoint_type = ThermostatSetpoint.setpoint_type.HEATING_1, + scale1 = ThermostatSetpoint.scale.FAHRENHEIT, + min_value = 44.9, + scale2 = ThermostatSetpoint.scale.FAHRENHEIT, + max_value = 80.9 + } + ) + ) + } + }, + { + channel = "capability", + direction = "send", + message = mock_device:generate_test_message("main", + capabilities.thermostatHeatingSetpoint.heatingSetpointRange( + { + unit = 'F', + value = {minimum = 44.9, maximum = 80.9} + } + ) + ) + } + } +) + test.register_coroutine_test( "Setting the thermostat fan mode should generate the appropriate commands", function() From 96cee461f9a4a1cfc76ed115d8ea686e9f22e315 Mon Sep 17 00:00:00 2001 From: Matthew DeHaven Date: Mon, 22 Apr 2024 12:24:39 -0500 Subject: [PATCH 26/29] heating -> cooling in copied test --- .../src/test/test_zwave_thermostat.lua | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/drivers/SmartThings/zwave-thermostat/src/test/test_zwave_thermostat.lua b/drivers/SmartThings/zwave-thermostat/src/test/test_zwave_thermostat.lua index e63ae50c0d..189c5b4c7b 100644 --- a/drivers/SmartThings/zwave-thermostat/src/test/test_zwave_thermostat.lua +++ b/drivers/SmartThings/zwave-thermostat/src/test/test_zwave_thermostat.lua @@ -463,7 +463,7 @@ test.register_message_test( ) test.register_message_test( - "Thermostat heating setpoint capability reports should be sent to the capabilities channel.", + "Thermostat cooling setpoint capability reports should be sent to the capabilities channel.", { { channel = "zwave", @@ -473,7 +473,7 @@ test.register_message_test( zw_test_utilities.zwave_test_build_receive_command( ThermostatSetpointV3:CapabilitiesReport( { - setpoint_type = ThermostatSetpoint.setpoint_type.HEATING_1, + setpoint_type = ThermostatSetpoint.setpoint_type.COOLING_1, scale1 = ThermostatSetpoint.scale.CELSIUS, min_value = 7.22, scale2 = ThermostatSetpoint.scale.CELSIUS, @@ -487,7 +487,7 @@ test.register_message_test( channel = "capability", direction = "send", message = mock_device:generate_test_message("main", - capabilities.thermostatHeatingSetpoint.heatingSetpointRange( + capabilities.thermostatCoolingSetpoint.coolingSetpointRange( { unit = 'C', value = {minimum = 7.22, maximum = 27.2} @@ -503,7 +503,7 @@ test.register_message_test( zw_test_utilities.zwave_test_build_receive_command( ThermostatSetpointV3:CapabilitiesReport( { - setpoint_type = ThermostatSetpoint.setpoint_type.HEATING_1, + setpoint_type = ThermostatSetpoint.setpoint_type.COOLING_1, scale1 = ThermostatSetpoint.scale.FAHRENHEIT, min_value = 44.9, scale2 = ThermostatSetpoint.scale.FAHRENHEIT, @@ -517,7 +517,7 @@ test.register_message_test( channel = "capability", direction = "send", message = mock_device:generate_test_message("main", - capabilities.thermostatHeatingSetpoint.heatingSetpointRange( + capabilities.thermostatCoolingSetpoint.coolingSetpointRange( { unit = 'F', value = {minimum = 44.9, maximum = 80.9} From 78365023e1555f791573ed40cd65ebc7d5f90a87 Mon Sep 17 00:00:00 2001 From: Matthew DeHaven Date: Mon, 22 Apr 2024 12:31:08 -0500 Subject: [PATCH 27/29] Support cooling setpoint range report --- drivers/SmartThings/zwave-thermostat/src/init.lua | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/drivers/SmartThings/zwave-thermostat/src/init.lua b/drivers/SmartThings/zwave-thermostat/src/init.lua index 3037621260..f663617f5f 100755 --- a/drivers/SmartThings/zwave-thermostat/src/init.lua +++ b/drivers/SmartThings/zwave-thermostat/src/init.lua @@ -112,7 +112,14 @@ local function setpoint_capabilites_report(driver, device, cmd) scale = 'F' end - device:emit_event_for_endpoint(cmd.src_channel, capabilities.thermostatHeatingSetpoint.heatingSetpointRange( + local capability_constructor = nil + if args.setpoint_type == ThermostatSetpoint.setpoint_type.HEATING_1 then + capability_constructor = capabilities.thermostatHeatingSetpoint.heatingSetpointRange + else + capability_constructor = capabilities.thermostatCoolingSetpoint.coolingSetpointRange + end + + device:emit_event_for_endpoint(cmd.src_channel, capability_constructor( { unit = scale, value = {minimum = min_temp_c, maximum = max_temp_c} From 2a0e18807a0369f7b47a5270d6cf38d850aaba7a Mon Sep 17 00:00:00 2001 From: Matthew DeHaven Date: Mon, 22 Apr 2024 13:47:30 -0500 Subject: [PATCH 28/29] Rename min/max temp variables They are not guaranteed to be in celsius --- drivers/SmartThings/zwave-thermostat/src/init.lua | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/drivers/SmartThings/zwave-thermostat/src/init.lua b/drivers/SmartThings/zwave-thermostat/src/init.lua index f663617f5f..f4ace98595 100755 --- a/drivers/SmartThings/zwave-thermostat/src/init.lua +++ b/drivers/SmartThings/zwave-thermostat/src/init.lua @@ -104,8 +104,8 @@ end local function setpoint_capabilites_report(driver, device, cmd) local args = cmd.args - local min_temp_c = args.min_value - local max_temp_c = args.max_value + local min_temp = args.min_value + local max_temp = args.max_value local scale = 'C' if args.scale1 == ThermostatSetpoint.scale.FAHRENHEIT then @@ -122,7 +122,7 @@ local function setpoint_capabilites_report(driver, device, cmd) device:emit_event_for_endpoint(cmd.src_channel, capability_constructor( { unit = scale, - value = {minimum = min_temp_c, maximum = max_temp_c} + value = {minimum = min_temp, maximum = max_temp} } )) end From 56df5e76ace24ea589351e600811088d1d8287e8 Mon Sep 17 00:00:00 2001 From: Matthew DeHaven Date: Mon, 22 Apr 2024 13:51:08 -0500 Subject: [PATCH 29/29] Explicitly check for cooling setpoint To account for the case a different controller on the network inquires about an unsupported setpoint --- .../SmartThings/zwave-thermostat/src/init.lua | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/drivers/SmartThings/zwave-thermostat/src/init.lua b/drivers/SmartThings/zwave-thermostat/src/init.lua index f4ace98595..ed3e1d6c0f 100755 --- a/drivers/SmartThings/zwave-thermostat/src/init.lua +++ b/drivers/SmartThings/zwave-thermostat/src/init.lua @@ -115,16 +115,18 @@ local function setpoint_capabilites_report(driver, device, cmd) local capability_constructor = nil if args.setpoint_type == ThermostatSetpoint.setpoint_type.HEATING_1 then capability_constructor = capabilities.thermostatHeatingSetpoint.heatingSetpointRange - else + elseif args.setpoint_type == ThermostatSetpoint.setpoint_type.COOLING_1 then capability_constructor = capabilities.thermostatCoolingSetpoint.coolingSetpointRange end - device:emit_event_for_endpoint(cmd.src_channel, capability_constructor( - { - unit = scale, - value = {minimum = min_temp, maximum = max_temp} - } - )) + if capability_constructor then + device:emit_event_for_endpoint(cmd.src_channel, capability_constructor( + { + unit = scale, + value = {minimum = min_temp, maximum = max_temp} + } + )) + end end local driver_template = {