Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
7cc490d
Add a setpoint_bounds.lua script and load it
matthewdehaven Apr 15, 2024
135be3d
Add beginning of setpoint_bounds object and return in
matthewdehaven Apr 15, 2024
4922eb3
Create a factory method for setpoint capabilities handler
matthewdehaven Apr 15, 2024
b34ca14
Add a placeholder zwave thermostat capabilites report handler
matthewdehaven Apr 15, 2024
347f2ed
Add arguments to setpoint capabilites report handler
matthewdehaven Apr 15, 2024
9898d71
Request setpoint capabilites from capatible zwave thermostats
matthewdehaven Apr 15, 2024
d5b4ff7
Fix typo: double "capabilities"
matthewdehaven Apr 15, 2024
1abcbc0
Use V3 Thermostat Setpoint Command
matthewdehaven Apr 16, 2024
6f527cd
Update test case to expect Capabilities Get command send
matthewdehaven Apr 16, 2024
396352f
Add send for Cooling Setpoint Capabilities Get
matthewdehaven Apr 16, 2024
fa70e87
Add start of setpoint capability report test
matthewdehaven Apr 16, 2024
70a8b46
Add a fake return value for heating setpoint min/max
matthewdehaven Apr 16, 2024
4dac851
Emit placeholder event for setpoint report
matthewdehaven Apr 16, 2024
98605a4
Convert F to C
matthewdehaven Apr 16, 2024
9c06c75
Use variables instead of hardcoded values
matthewdehaven Apr 16, 2024
50ac147
Implement setpoint report conversion
matthewdehaven Apr 16, 2024
c8edfc3
Remove a FIXME
matthewdehaven Apr 16, 2024
9560b63
Adjust fixme comment
matthewdehaven Apr 16, 2024
293fc38
Delete unused file
matthewdehaven Apr 16, 2024
84dcf20
Remove reference to unused file
matthewdehaven Apr 16, 2024
6e192f1
Utitlize implicit serialization magic
matthewdehaven Apr 22, 2024
77b55fc
Remove a fixme comment
matthewdehaven Apr 22, 2024
9c431bf
Improve specificity of test name
matthewdehaven Apr 22, 2024
4895aa2
Add heating Fahrenheit test
matthewdehaven Apr 22, 2024
c53b335
Copy heating tests to create cooling test
matthewdehaven Apr 22, 2024
96cee46
heating -> cooling in copied test
matthewdehaven Apr 22, 2024
7836502
Support cooling setpoint range report
matthewdehaven Apr 22, 2024
2a0e188
Rename min/max temp variables
matthewdehaven Apr 22, 2024
56df5e7
Explicitly check for cooling setpoint
matthewdehaven Apr 22, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 47 additions & 0 deletions drivers/SmartThings/zwave-thermostat/src/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,20 @@ 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 function device_supports_thermostat_setpoint(device)
return (
(
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)
)
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
Expand All @@ -37,6 +48,10 @@ 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(ThermostatSetpointV3:CapabilitiesGet({setpoint_type = ThermostatSetpoint.setpoint_type.HEATING_1}))
device:send(ThermostatSetpointV3:CapabilitiesGet({setpoint_type = ThermostatSetpoint.setpoint_type.COOLING_1}))
end
device:refresh()
end

Expand Down Expand Up @@ -87,6 +102,33 @@ local function set_setpoint_factory(setpoint_type)
end
end

local function setpoint_capabilites_report(driver, device, cmd)
local args = cmd.args
local min_temp = args.min_value
local max_temp = args.max_value

local scale = 'C'
if args.scale1 == ThermostatSetpoint.scale.FAHRENHEIT then
scale = 'F'
end

local capability_constructor = nil
if args.setpoint_type == ThermostatSetpoint.setpoint_type.HEATING_1 then
capability_constructor = capabilities.thermostatHeatingSetpoint.heatingSetpointRange
elseif args.setpoint_type == ThermostatSetpoint.setpoint_type.COOLING_1 then
capability_constructor = capabilities.thermostatCoolingSetpoint.coolingSetpointRange
end

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 = {
supported_capabilities = {
capabilities.temperatureAlarm,
Expand All @@ -109,6 +151,11 @@ local driver_template = {
[capabilities.thermostatHeatingSetpoint.commands.setHeatingSetpoint.NAME] = set_setpoint_factory(ThermostatSetpoint.setpoint_type.HEATING_1)
}
},
zwave_handlers = {
[cc.THERMOSTAT_SETPOINT] = {
[ThermostatSetpoint.CAPABILITIES_REPORT] = setpoint_capabilites_report
}
},
lifecycle_handlers = {
added = device_added
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -140,6 +141,22 @@ 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})
)
},
{
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)
},
{
Expand Down Expand Up @@ -379,6 +396,138 @@ 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_message_test(
"Thermostat cooling 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.COOLING_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.thermostatCoolingSetpoint.coolingSetpointRange(
{
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.COOLING_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.thermostatCoolingSetpoint.coolingSetpointRange(
{
unit = 'F',
value = {minimum = 44.9, maximum = 80.9}
}
)
)
}
}
)

test.register_coroutine_test(
"Setting the thermostat fan mode should generate the appropriate commands",
function()
Expand Down