Skip to content

Commit 4e3df75

Browse files
Matter-Thermostat: Use endpoint id in limit fields
Add endpoint id to temp limit fields. Rework test cases.
1 parent de393f9 commit 4e3df75

File tree

2 files changed

+93
-44
lines changed

2 files changed

+93
-44
lines changed

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

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,14 @@ local subscribed_attributes = {
7676
}
7777
}
7878

79+
local function get_field_for_endpoint(device, field, endpoint)
80+
return device:get_field(string.format("%s_%d", field, endpoint))
81+
end
82+
83+
local function set_field_for_endpoint(device, field, endpoint, value, persist)
84+
device:set_field(string.format("%s_%d", field, endpoint), value, {persist = persist})
85+
end
86+
7987
local function find_default_endpoint(device, cluster)
8088
local res = device.MATTER_DEFAULT_ENDPOINT
8189
local eps = device:get_endpoints(cluster)
@@ -209,14 +217,14 @@ local temp_attr_handler_factory = function(minOrMax)
209217
if ib.data.value ~= nil then
210218
local temp = ib.data.value / 100.0
211219
local unit = "C"
212-
device:set_field(minOrMax, temp)
213-
local min = device:get_field(setpoint_limit_device_field.MIN_TEMP)
214-
local max = device:get_field(setpoint_limit_device_field.MAX_TEMP)
220+
set_field_for_endpoint(device, minOrMax, ib.endpoint_id, temp, false)
221+
local min = get_field_for_endpoint(device, setpoint_limit_device_field.MIN_TEMP, ib.endpoint_id)
222+
local max = get_field_for_endpoint(device, setpoint_limit_device_field.MAX_TEMP, ib.endpoint_id)
215223
if min ~= nil and max ~= nil then
216224
if min < max then
217225
device:emit_event_for_endpoint(ib.endpoint_id, capabilities.temperatureMeasurement.temperatureRange({ value = { minimum = min, maximum = max }, unit = unit }))
218-
device:set_field(setpoint_limit_device_field.MIN_TEMP, nil)
219-
device:set_field(setpoint_limit_device_field.MAX_TEMP, nil)
226+
set_field_for_endpoint(device, setpoint_limit_device_field.MIN_TEMP, ib.endpoint_id, nil, false)
227+
set_field_for_endpoint(device, setpoint_limit_device_field.MAX_TEMP, ib.endpoint_id, nil, false)
220228
else
221229
device.log.warn_with({hub_logs = true}, string.format("Device reported a min temperature %d that is not lower than the reported max temperature %d", min, max))
222230
end
@@ -414,6 +422,7 @@ local heating_setpoint_limit_handler_factory = function(minOrMax)
414422
return function(driver, device, ib, response)
415423
if ib.data.value ~= nil then
416424
local val = ib.data.value / 100.0
425+
print("setting %s to %d", minOrMax, val)
417426
device:set_field(minOrMax, val)
418427
local min = device:get_field(setpoint_limit_device_field.MIN_HEAT)
419428
local max = device:get_field(setpoint_limit_device_field.MAX_HEAT)
@@ -432,6 +441,7 @@ local cooling_setpoint_limit_handler_factory = function(minOrMax)
432441
return function(driver, device, ib, response)
433442
if ib.data.value ~= nil then
434443
local val = ib.data.value / 100.0
444+
print("setting %s to %d", minOrMax, val)
435445
device:set_field(minOrMax, val)
436446
local min = device:get_field(setpoint_limit_device_field.MIN_COOL)
437447
local max = device:get_field(setpoint_limit_device_field.MAX_COOL)

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

Lines changed: 78 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -79,45 +79,6 @@ local function test_init()
7979
read_limits:merge(clusters.TemperatureMeasurement.attributes.MaxMeasuredValue:read())
8080
test.socket.matter:__expect_send({mock_device.id, read_limits})
8181

82-
--Populate setpoint limits
83-
test.socket.matter:__queue_receive({
84-
mock_device.id,
85-
clusters.Thermostat.attributes.AbsMinHeatSetpointLimit:build_test_report_data(mock_device, 1, 1000)
86-
})
87-
test.socket.matter:__queue_receive({
88-
mock_device.id,
89-
clusters.Thermostat.attributes.AbsMaxHeatSetpointLimit:build_test_report_data(mock_device, 1, 3222)
90-
})
91-
test.socket.matter:__queue_receive({
92-
mock_device.id,
93-
clusters.Thermostat.attributes.AbsMinCoolSetpointLimit:build_test_report_data(mock_device, 1, 1000) --10.0 celcius
94-
})
95-
test.socket.matter:__queue_receive({
96-
mock_device.id,
97-
clusters.Thermostat.attributes.AbsMaxCoolSetpointLimit:build_test_report_data(mock_device, 1, 3222) --32.22 celcius
98-
})
99-
test.socket.matter:__queue_receive({
100-
mock_device.id,
101-
clusters.Thermostat.attributes.MinSetpointDeadBand:build_test_report_data(mock_device, 1, 16) --1.6 celcius
102-
})
103-
test.socket.matter:__queue_receive({
104-
mock_device.id,
105-
clusters.TemperatureMeasurement.attributes.MinMeasuredValue:build_test_report_data(mock_device, 1, 500) --5.0 celsius
106-
})
107-
test.socket.matter:__queue_receive({
108-
mock_device.id,
109-
clusters.TemperatureMeasurement.attributes.MaxMeasuredValue:build_test_report_data(mock_device, 1, 4000) --40.0 celsius
110-
})
111-
112-
test.socket.capability:__expect_send(
113-
mock_device:generate_test_message("main", capabilities.thermostatHeatingSetpoint.heatingSetpointRange({ value = { minimum = 10.00, maximum = 32.22 }, unit = "C" }))
114-
)
115-
test.socket.capability:__expect_send(
116-
mock_device:generate_test_message("main", capabilities.thermostatCoolingSetpoint.coolingSetpointRange({ value = { minimum = 10.00, maximum = 32.22 }, unit = "C" }))
117-
)
118-
test.socket.capability:__expect_send(
119-
mock_device:generate_test_message("main", capabilities.temperatureMeasurement.temperatureRange({ value = { minimum = 5.00, maximum = 40.00 }, unit = "C" }))
120-
)
12182
test.mock_device.add_test_device(mock_device)
12283
end
12384
test.set_test_init_function(test_init)
@@ -152,6 +113,10 @@ end
152113
test.register_coroutine_test(
153114
"Heat setpoint lower than min",
154115
function()
116+
test.socket.matter:__queue_receive({
117+
mock_device.id,
118+
clusters.Thermostat.attributes.AbsMinHeatSetpointLimit:build_test_report_data(mock_device, 1, 1000)
119+
})
155120
configure(mock_device)
156121
test.socket.capability:__queue_receive({
157122
mock_device.id,
@@ -166,6 +131,10 @@ test.register_coroutine_test(
166131
test.register_coroutine_test(
167132
"Cool setpoint lower than min",
168133
function()
134+
test.socket.matter:__queue_receive({
135+
mock_device.id,
136+
clusters.Thermostat.attributes.AbsMinCoolSetpointLimit:build_test_report_data(mock_device, 1, 1000)
137+
})
169138
configure(mock_device)
170139
test.socket.capability:__queue_receive({
171140
mock_device.id,
@@ -180,6 +149,10 @@ test.register_coroutine_test(
180149
test.register_coroutine_test(
181150
"Heat setpoint higher than max",
182151
function()
152+
test.socket.matter:__queue_receive({
153+
mock_device.id,
154+
clusters.Thermostat.attributes.AbsMaxHeatSetpointLimit:build_test_report_data(mock_device, 1, 3222)
155+
})
183156
configure(mock_device)
184157
test.socket.capability:__queue_receive({
185158
mock_device.id,
@@ -194,6 +167,10 @@ test.register_coroutine_test(
194167
test.register_coroutine_test(
195168
"Cool setpoint higher than max",
196169
function()
170+
test.socket.matter:__queue_receive({
171+
mock_device.id,
172+
clusters.Thermostat.attributes.AbsMaxCoolSetpointLimit:build_test_report_data(mock_device, 1, 3222)
173+
})
197174
configure(mock_device)
198175
test.socket.capability:__queue_receive({
199176
mock_device.id,
@@ -208,6 +185,10 @@ test.register_coroutine_test(
208185
test.register_coroutine_test(
209186
"Heat setpoint inside deadband",
210187
function()
188+
test.socket.matter:__queue_receive({
189+
mock_device.id,
190+
clusters.Thermostat.attributes.MinSetpointDeadBand:build_test_report_data(mock_device, 1, 16) --1.6 celcius
191+
})
211192
configure(mock_device)
212193
test.socket.capability:__queue_receive({
213194
mock_device.id,
@@ -222,6 +203,10 @@ test.register_coroutine_test(
222203
test.register_coroutine_test(
223204
"Cool setpoint inside deadband",
224205
function()
206+
test.socket.matter:__queue_receive({
207+
mock_device.id,
208+
clusters.Thermostat.attributes.MinSetpointDeadBand:build_test_report_data(mock_device, 1, 16) --1.6 celcius
209+
})
225210
configure(mock_device)
226211
test.socket.capability:__queue_receive({
227212
mock_device.id,
@@ -233,6 +218,60 @@ test.register_coroutine_test(
233218
end
234219
)
235220

221+
test.register_message_test(
222+
"Min and max heating setpoint attributes set capability constraint",
223+
{
224+
{
225+
channel = "matter",
226+
direction = "receive",
227+
message = {
228+
mock_device.id,
229+
clusters.Thermostat.attributes.AbsMinCoolSetpointLimit:build_test_report_data(mock_device, 1, 1000)
230+
}
231+
},
232+
{
233+
channel = "matter",
234+
direction = "receive",
235+
message = {
236+
mock_device.id,
237+
clusters.Thermostat.attributes.AbsMaxCoolSetpointLimit:build_test_report_data(mock_device, 1, 3222)
238+
}
239+
},
240+
{
241+
channel = "capability",
242+
direction = "send",
243+
message = mock_device:generate_test_message("main", capabilities.thermostatCoolingSetpoint.coolingSetpointRange({ value = { minimum = 10.00, maximum = 32.22 }, unit = "C" }))
244+
}
245+
}
246+
)
247+
248+
test.register_message_test(
249+
"Min and max cooling setpoint attributes set capability constraint",
250+
{
251+
{
252+
channel = "matter",
253+
direction = "receive",
254+
message = {
255+
mock_device.id,
256+
clusters.Thermostat.attributes.AbsMinHeatSetpointLimit:build_test_report_data(mock_device, 1, 1000)
257+
}
258+
},
259+
{
260+
channel = "matter",
261+
direction = "receive",
262+
message = {
263+
mock_device.id,
264+
clusters.Thermostat.attributes.AbsMaxHeatSetpointLimit:build_test_report_data(mock_device, 1, 3222)
265+
}
266+
},
267+
{
268+
channel = "capability",
269+
direction = "send",
270+
message = mock_device:generate_test_message("main", capabilities.thermostatHeatingSetpoint.heatingSetpointRange({ value = { minimum = 10.00, maximum = 32.22 }, unit = "C" }))
271+
}
272+
}
273+
)
274+
236275
test.register_message_test(
237276
"Min and max temperature attributes set capability constraint",
238277
{

0 commit comments

Comments
 (0)