Skip to content

Commit b8b7068

Browse files
Exclude off from fanMode capability for Thermostats (#2673)
Exclude the off mode from the supportedFanModes attribute of the fanMode capability for Thermostats.
1 parent 9b50583 commit b8b7068

File tree

1 file changed

+22
-12
lines changed

1 file changed

+22
-12
lines changed

drivers/SmartThings/matter-thermostat/src/thermostat_handlers/attribute_handlers.lua

Lines changed: 22 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,11 @@ function AttributeHandlers.system_mode_handler(driver, device, ib, response)
4848
return
4949
end
5050

51-
local supported_modes = device:get_latest_state(device:endpoint_to_component(ib.endpoint_id), capabilities.thermostatMode.ID, capabilities.thermostatMode.supportedThermostatModes.NAME) or {}
51+
local supported_modes = device:get_latest_state(
52+
device:endpoint_to_component(ib.endpoint_id),
53+
capabilities.thermostatMode.ID,
54+
capabilities.thermostatMode.supportedThermostatModes.NAME
55+
) or {}
5256
-- check that the given mode was in the supported modes list
5357
if thermostat_utils.tbl_contains(supported_modes, fields.THERMOSTAT_MODE_MAP[ib.data.value].NAME) then
5458
device:emit_event_for_endpoint(ib.endpoint_id, fields.THERMOSTAT_MODE_MAP[ib.data.value]())
@@ -325,19 +329,19 @@ function AttributeHandlers.fan_mode_handler(driver, device, ib, response)
325329
end
326330

327331
function AttributeHandlers.fan_mode_sequence_handler(driver, device, ib, response)
328-
local supportedFanModes, supported_fan_modes_attribute
332+
local supported_fan_modes, supported_fan_modes_attribute
329333
if ib.data.value == clusters.FanControl.attributes.FanModeSequence.OFF_LOW_MED_HIGH then
330-
supportedFanModes = { "off", "low", "medium", "high" }
334+
supported_fan_modes = { "off", "low", "medium", "high" }
331335
elseif ib.data.value == clusters.FanControl.attributes.FanModeSequence.OFF_LOW_HIGH then
332-
supportedFanModes = { "off", "low", "high" }
336+
supported_fan_modes = { "off", "low", "high" }
333337
elseif ib.data.value == clusters.FanControl.attributes.FanModeSequence.OFF_LOW_MED_HIGH_AUTO then
334-
supportedFanModes = { "off", "low", "medium", "high", "auto" }
338+
supported_fan_modes = { "off", "low", "medium", "high", "auto" }
335339
elseif ib.data.value == clusters.FanControl.attributes.FanModeSequence.OFF_LOW_HIGH_AUTO then
336-
supportedFanModes = { "off", "low", "high", "auto" }
340+
supported_fan_modes = { "off", "low", "high", "auto" }
337341
elseif ib.data.value == clusters.FanControl.attributes.FanModeSequence.OFF_HIGH_AUTO then
338-
supportedFanModes = { "off", "high", "auto" }
342+
supported_fan_modes = { "off", "high", "auto" }
339343
else
340-
supportedFanModes = { "off", "high" }
344+
supported_fan_modes = { "off", "high" }
341345
end
342346

343347
if device:supports_capability_by_id(capabilities.airPurifierFanMode.ID) then
@@ -349,16 +353,22 @@ function AttributeHandlers.fan_mode_sequence_handler(driver, device, ib, respons
349353
-- Our thermostat fan mode control is not granular enough to handle all of the supported modes
350354
if ib.data.value >= clusters.FanControl.attributes.FanModeSequence.OFF_LOW_MED_HIGH_AUTO and
351355
ib.data.value <= clusters.FanControl.attributes.FanModeSequence.OFF_ON_AUTO then
352-
supportedFanModes = { "auto", "on" }
356+
supported_fan_modes = { "auto", "on" }
353357
else
354-
supportedFanModes = { "on" }
358+
supported_fan_modes = { "on" }
355359
end
356360
else
357361
supported_fan_modes_attribute = capabilities.fanMode.supportedFanModes
358362
end
359363

360-
local event = supported_fan_modes_attribute(supportedFanModes, {visibility = {displayed = false}})
361-
device:emit_event_for_endpoint(ib.endpoint_id, event)
364+
-- remove 'off' as a supported fan mode for thermostat device types
365+
if thermostat_utils.get_device_type(device) == fields.THERMOSTAT_DEVICE_TYPE_ID and
366+
device:supports_capability_by_id(capabilities.fanMode.ID) then
367+
-- per the definitions set above, the first index always contains "off"
368+
table.remove(supported_fan_modes, 1)
369+
end
370+
371+
device:emit_event_for_endpoint(ib.endpoint_id, supported_fan_modes_attribute(supported_fan_modes, {visibility = {displayed = false}}))
362372
end
363373

364374
function AttributeHandlers.percent_current_handler(driver, device, ib, response)

0 commit comments

Comments
 (0)