Skip to content

Commit

Permalink
Set setpointRange when setpoint is set (#1716)
Browse files Browse the repository at this point in the history
Signed-off-by: Hunsup Jung <[email protected]>
  • Loading branch information
HunsupJung authored Nov 15, 2024
1 parent 8107bd9 commit ce63e46
Show file tree
Hide file tree
Showing 11 changed files with 63 additions and 23 deletions.
1 change: 1 addition & 0 deletions drivers/SmartThings/matter-appliance/src/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,7 @@ local function temperature_setpoint_attr_handler(driver, device, ib, response)
local range = {
minimum = min,
maximum = max,
step = 0.1
}
-- Only emit the capability for RPC version >= 5, since unit conversion for
-- range capabilities is only supported in that case.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,7 @@ local function temperature_setpoint_attr_handler(driver, device, ib, response)
local range = {
minimum = min,
maximum = max,
step = 0.1
}

-- Only emit the capability for RPC version >= 5, since unit conversion for
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,7 @@ local function temperature_setpoint_attr_handler(driver, device, ib, response)
local range = {
minimum = min,
maximum = max,
step = 0.1
}

-- Only emit the capability for RPC version >= 5, since unit conversion for
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,7 @@ local function temperature_setpoint_attr_handler(driver, device, ib, response)
local range = {
minimum = min,
maximum = max,
step = 0.1
}

-- Only emit the capability for RPC version >= 5, since unit conversion for
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,7 @@ local function temperature_setpoint_attr_handler(driver, device, ib, response)
local range = {
minimum = min,
maximum = max,
step = 0.1
}

-- Only emit the capability for RPC version >= 5, since unit conversion for
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -505,7 +505,7 @@ test.register_message_test(
{
channel = "capability",
direction = "send",
message = mock_device:generate_test_message("main", capabilities.temperatureSetpoint.temperatureSetpointRange({value = {minimum=33.0,maximum=90.0}, unit = "C"}, {visibility = {displayed = false}}))
message = mock_device:generate_test_message("main", capabilities.temperatureSetpoint.temperatureSetpointRange({value = {minimum=33.0,maximum=90.0, step = 0.1}, unit = "C"}, {visibility = {displayed = false}}))
},
{
channel = "capability",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -548,7 +548,7 @@ test.register_message_test(
{
channel = "capability",
direction = "send",
message = mock_device:generate_test_message("main", capabilities.temperatureSetpoint.temperatureSetpointRange({value = {minimum=30.0,maximum=70.0}, unit = "C"}, {visibility = {displayed = false}}))
message = mock_device:generate_test_message("main", capabilities.temperatureSetpoint.temperatureSetpointRange({value = {minimum=30.0,maximum=70.0, step = 0.1}, unit = "C"}, {visibility = {displayed = false}}))
},
{
channel = "capability",
Expand Down Expand Up @@ -604,7 +604,7 @@ test.register_message_test(
{
channel = "capability",
direction = "send",
message = mock_device:generate_test_message("main", capabilities.temperatureSetpoint.temperatureSetpointRange({value = {minimum=27.0,maximum=80.0}, unit = "C"}, {visibility = {displayed = false}}))
message = mock_device:generate_test_message("main", capabilities.temperatureSetpoint.temperatureSetpointRange({value = {minimum=27.0,maximum=80.0, step = 0.1}, unit = "C"}, {visibility = {displayed = false}}))
},
{
channel = "capability",
Expand Down Expand Up @@ -660,7 +660,7 @@ test.register_message_test(
{
channel = "capability",
direction = "send",
message = mock_device_washer:generate_test_message("main", capabilities.temperatureSetpoint.temperatureSetpointRange({value = {minimum=15.0,maximum=50.0}, unit = "C"}, {visibility = {displayed = false}}))
message = mock_device_washer:generate_test_message("main", capabilities.temperatureSetpoint.temperatureSetpointRange({value = {minimum=15.0,maximum=50.0, step = 0.1}, unit = "C"}, {visibility = {displayed = false}}))
},
{
channel = "capability",
Expand Down Expand Up @@ -716,7 +716,7 @@ test.register_message_test(
{
channel = "capability",
direction = "send",
message = mock_device_washer:generate_test_message("main", capabilities.temperatureSetpoint.temperatureSetpointRange({value = {minimum=13.0,maximum=55.0}, unit = "C"}, {visibility = {displayed = false}}))
message = mock_device_washer:generate_test_message("main", capabilities.temperatureSetpoint.temperatureSetpointRange({value = {minimum=13.0,maximum=55.0, step = 0.1}, unit = "C"}, {visibility = {displayed = false}}))
},
{
channel = "capability",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,7 @@ test.register_message_test(
{
channel = "capability",
direction = "send",
message = mock_device:generate_test_message("tccOne", capabilities.temperatureSetpoint.temperatureSetpointRange({value = {minimum=128.0,maximum=200.0}, unit = "C"}, {visibility = {displayed = false}}))
message = mock_device:generate_test_message("tccOne", capabilities.temperatureSetpoint.temperatureSetpointRange({value = {minimum=128.0,maximum=200.0, step = 0.1}, unit = "C"}, {visibility = {displayed = false}}))
},
{
channel = "capability",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ test.register_message_test(
{
channel = "capability",
direction = "send",
message = mock_device:generate_test_message("refrigerator", capabilities.temperatureSetpoint.temperatureSetpointRange({value = {minimum=0.0,maximum=15.0}, unit = "C"}))
message = mock_device:generate_test_message("refrigerator", capabilities.temperatureSetpoint.temperatureSetpointRange({value = {minimum=0.0,maximum=15.0, step = 0.1}, unit = "C"}))
},
{
channel = "capability",
Expand Down Expand Up @@ -236,7 +236,7 @@ test.register_message_test(
{
channel = "capability",
direction = "send",
message = mock_device:generate_test_message("refrigerator", capabilities.temperatureSetpoint.temperatureSetpointRange({value = {minimum=-6.0,maximum=20.0}, unit = "C"}))
message = mock_device:generate_test_message("refrigerator", capabilities.temperatureSetpoint.temperatureSetpointRange({value = {minimum=-6.0,maximum=20.0, step = 0.1}, unit = "C"}))
},
{
channel = "capability",
Expand Down Expand Up @@ -292,7 +292,7 @@ test.register_message_test(
{
channel = "capability",
direction = "send",
message = mock_device:generate_test_message("freezer", capabilities.temperatureSetpoint.temperatureSetpointRange({value = {minimum=-22.0,maximum=-14.0}, unit = "C"}))
message = mock_device:generate_test_message("freezer", capabilities.temperatureSetpoint.temperatureSetpointRange({value = {minimum=-22.0,maximum=-14.0, step = 0.1}, unit = "C"}))
},
{
channel = "capability",
Expand Down Expand Up @@ -348,7 +348,7 @@ test.register_message_test(
{
channel = "capability",
direction = "send",
message = mock_device:generate_test_message("freezer", capabilities.temperatureSetpoint.temperatureSetpointRange({value = {minimum=-24.0,maximum=-12.0}, unit = "C"}))
message = mock_device:generate_test_message("freezer", capabilities.temperatureSetpoint.temperatureSetpointRange({value = {minimum=-24.0,maximum=-12.0, step = 0.1}, unit = "C"}))
},
{
channel = "capability",
Expand Down
26 changes: 25 additions & 1 deletion drivers/SmartThings/matter-thermostat/src/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -720,8 +720,32 @@ end

local function temp_event_handler(attribute)
return function(driver, device, ib, response)
local temp = ib.data.value / 100.0
local unit = "C"

-- Only emit the capability for RPC version >= 5, since unit conversion for
-- range capabilities is only supported in that case.
if version.rpc >= 5 then
local event
if attribute == capabilities.thermostatCoolingSetpoint.coolingSetpoint then
local range = {
minimum = device:get_field(setpoint_limit_device_field.MIN_COOL) or THERMOSTAT_MIN_TEMP_IN_C,
maximum = device:get_field(setpoint_limit_device_field.MAX_COOL) or THERMOSTAT_MAX_TEMP_IN_C,
step = 0.1
}
event = capabilities.thermostatCoolingSetpoint.coolingSetpointRange({value = range, unit = unit})
device:emit_event_for_endpoint(ib.endpoint_id, event)
elseif attribute == capabilities.thermostatHeatingSetpoint.heatingSetpoint then
local range = {
minimum = device:get_field(setpoint_limit_device_field.MIN_HEAT) or THERMOSTAT_MIN_TEMP_IN_C,
maximum = device:get_field(setpoint_limit_device_field.MAX_HEAT) or THERMOSTAT_MAX_TEMP_IN_C,
step = 0.1
}
event = capabilities.thermostatHeatingSetpoint.heatingSetpointRange({value = range, unit = unit})
device:emit_event_for_endpoint(ib.endpoint_id, event)
end
end

local temp = ib.data.value / 100.0
device:emit_event_for_endpoint(ib.endpoint_id, attribute({value = temp, unit = unit}))
end
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,18 +105,24 @@ local function configure(device)
device.id,
clusters.Thermostat.attributes.OccupiedCoolingSetpoint:build_test_report_data(mock_device, 1, 2667) --26.67 celcius
})
test.socket.capability:__expect_send(
device:generate_test_message("main", capabilities.thermostatHeatingSetpoint.heatingSetpointRange({ value = { minimum = 5.00, maximum = 40.00, step = 0.1 }, unit = "C" }))
)
test.socket.capability:__expect_send(
device:generate_test_message("main", capabilities.thermostatHeatingSetpoint.heatingSetpoint({ value = 24.44, unit = "C" }))
)
test.socket.capability:__expect_send(
device:generate_test_message("main", capabilities.thermostatCoolingSetpoint.coolingSetpointRange({ value = { minimum = 5.00, maximum = 40.00, step = 0.1 }, unit = "C" }))
)
test.socket.capability:__expect_send(
device:generate_test_message("main", capabilities.thermostatCoolingSetpoint.coolingSetpoint({ value = 26.67, unit = "C" }))
)
test.wait_for_events()
end

test.register_coroutine_test(
"Heat setpoint lower than min",
function()
configure(mock_device)
test.socket.matter:__queue_receive({
mock_device.id,
clusters.Thermostat.attributes.AbsMinHeatSetpointLimit:build_test_report_data(mock_device, 1, 1000)
Expand All @@ -128,7 +134,7 @@ test.register_coroutine_test(
test.socket.capability:__expect_send(
mock_device:generate_test_message("main", capabilities.thermostatHeatingSetpoint.heatingSetpointRange({ value = { minimum = 10.00, maximum = 32.22, step = 0.1 }, unit = "C" }))
)
configure(mock_device)
test.wait_for_events()
test.socket.capability:__queue_receive({
mock_device.id,
{ capability = "thermostatHeatingSetpoint", component = "main", command = "setHeatingSetpoint", args = { 9 } }
Expand All @@ -142,6 +148,7 @@ test.register_coroutine_test(
test.register_coroutine_test(
"Cool setpoint lower than min",
function()
configure(mock_device)
test.socket.matter:__queue_receive({
mock_device.id,
clusters.Thermostat.attributes.AbsMinCoolSetpointLimit:build_test_report_data(mock_device, 1, 1000)
Expand All @@ -151,9 +158,9 @@ test.register_coroutine_test(
clusters.Thermostat.attributes.AbsMaxCoolSetpointLimit:build_test_report_data(mock_device, 1, 3222)
})
test.socket.capability:__expect_send(
mock_device:generate_test_message("main", capabilities.thermostatCoolingSetpoint.coolingSetpointRange({ value = { minimum = 10.00, maximum = 32.22, step = 0.1 }, unit = "C" }))
mock_device:generate_test_message("main", capabilities.thermostatCoolingSetpoint.coolingSetpointRange({ value = { minimum = 10.00, maximum = 32.22, step = 0.1 }, unit = "C" }))
)
configure(mock_device)
test.wait_for_events()
test.socket.capability:__queue_receive({
mock_device.id,
{ capability = "thermostatCoolingSetpoint", component = "main", command = "setCoolingSetpoint", args = { 9 } }
Expand All @@ -167,6 +174,7 @@ test.register_coroutine_test(
test.register_coroutine_test(
"Heat setpoint higher than max",
function()
configure(mock_device)
test.socket.matter:__queue_receive({
mock_device.id,
clusters.Thermostat.attributes.AbsMinHeatSetpointLimit:build_test_report_data(mock_device, 1, 1000)
Expand All @@ -176,9 +184,9 @@ test.register_coroutine_test(
clusters.Thermostat.attributes.AbsMaxHeatSetpointLimit:build_test_report_data(mock_device, 1, 3222)
})
test.socket.capability:__expect_send(
mock_device:generate_test_message("main", capabilities.thermostatHeatingSetpoint.heatingSetpointRange({ value = { minimum = 10.00, maximum = 32.22, step = 0.1 }, unit = "C" }))
mock_device:generate_test_message("main", capabilities.thermostatHeatingSetpoint.heatingSetpointRange({ value = { minimum = 10.00, maximum = 32.22, step = 0.1 }, unit = "C" }))
)
configure(mock_device)
test.wait_for_events()
test.socket.capability:__queue_receive({
mock_device.id,
{ capability = "thermostatHeatingSetpoint", component = "main", command = "setHeatingSetpoint", args = { 33 } }
Expand All @@ -192,6 +200,7 @@ test.register_coroutine_test(
test.register_coroutine_test(
"Cool setpoint higher than max",
function()
configure(mock_device)
test.socket.matter:__queue_receive({
mock_device.id,
clusters.Thermostat.attributes.AbsMinCoolSetpointLimit:build_test_report_data(mock_device, 1, 1000)
Expand All @@ -201,9 +210,9 @@ test.register_coroutine_test(
clusters.Thermostat.attributes.AbsMaxCoolSetpointLimit:build_test_report_data(mock_device, 1, 3222)
})
test.socket.capability:__expect_send(
mock_device:generate_test_message("main", capabilities.thermostatCoolingSetpoint.coolingSetpointRange({ value = { minimum = 10.00, maximum = 32.22, step = 0.1 }, unit = "C" }))
mock_device:generate_test_message("main", capabilities.thermostatCoolingSetpoint.coolingSetpointRange({ value = { minimum = 10.00, maximum = 32.22, step = 0.1 }, unit = "C" }))
)
configure(mock_device)
test.wait_for_events()
test.socket.capability:__queue_receive({
mock_device.id,
{ capability = "thermostatCoolingSetpoint", component = "main", command = "setCoolingSetpoint", args = { 33 } }
Expand All @@ -217,11 +226,12 @@ test.register_coroutine_test(
test.register_coroutine_test(
"Heat setpoint inside deadband",
function()
configure(mock_device)
test.socket.matter:__queue_receive({
mock_device.id,
clusters.Thermostat.attributes.MinSetpointDeadBand:build_test_report_data(mock_device, 1, 16) --1.6 celcius
})
configure(mock_device)
test.wait_for_events()
test.socket.capability:__queue_receive({
mock_device.id,
{ capability = "thermostatHeatingSetpoint", component = "main", command = "setHeatingSetpoint", args = { 26 } }
Expand All @@ -235,11 +245,12 @@ test.register_coroutine_test(
test.register_coroutine_test(
"Cool setpoint inside deadband",
function()
configure(mock_device)
test.socket.matter:__queue_receive({
mock_device.id,
clusters.Thermostat.attributes.MinSetpointDeadBand:build_test_report_data(mock_device, 1, 16) --1.6 celcius
})
configure(mock_device)
test.wait_for_events()
test.socket.capability:__queue_receive({
mock_device.id,
{ capability = "thermostatCoolingSetpoint", component = "main", command = "setCoolingSetpoint", args = { 25 } }
Expand Down Expand Up @@ -285,7 +296,7 @@ test.register_message_test(
{
channel = "capability",
direction = "send",
message = mock_device:generate_test_message("main", capabilities.thermostatCoolingSetpoint.coolingSetpointRange({ value = { minimum = 10.00, maximum = 32.22, step = 0.1 }, unit = "C" }))
message = mock_device:generate_test_message("main", capabilities.thermostatCoolingSetpoint.coolingSetpointRange({ value = { minimum = 10.00, maximum = 32.22, step = 0.1 }, unit = "C" }))
}
}
)
Expand All @@ -312,7 +323,7 @@ test.register_message_test(
{
channel = "capability",
direction = "send",
message = mock_device:generate_test_message("main", capabilities.thermostatHeatingSetpoint.heatingSetpointRange({ value = { minimum = 10.00, maximum = 32.22, step = 0.1 }, unit = "C" }))
message = mock_device:generate_test_message("main", capabilities.thermostatHeatingSetpoint.heatingSetpointRange({ value = { minimum = 10.00, maximum = 32.22, step = 0.1 }, unit = "C" }))
}
}
)
Expand Down

0 comments on commit ce63e46

Please sign in to comment.