@@ -1392,7 +1392,11 @@ local function system_mode_handler(driver, device, ib, response)
13921392 return
13931393 end
13941394
1395- local supported_modes = device :get_latest_state (device :endpoint_to_component (ib .endpoint_id ), capabilities .thermostatMode .ID , capabilities .thermostatMode .supportedThermostatModes .NAME ) or {}
1395+ local supported_modes = device :get_latest_state (
1396+ device :endpoint_to_component (ib .endpoint_id ),
1397+ capabilities .thermostatMode .ID ,
1398+ capabilities .thermostatMode .supportedThermostatModes .NAME
1399+ ) or {}
13961400 -- check that the given mode was in the supported modes list
13971401 if tbl_contains (supported_modes , THERMOSTAT_MODE_MAP [ib .data .value ].NAME ) then
13981402 device :emit_event_for_endpoint (ib .endpoint_id , THERMOSTAT_MODE_MAP [ib .data .value ]())
@@ -1538,39 +1542,59 @@ local function fan_mode_handler(driver, device, ib, response)
15381542end
15391543
15401544local function fan_mode_sequence_handler (driver , device , ib , response )
1541- local supportedFanModes , supported_fan_modes_attribute
1545+ local supported_fan_modes , supported_fan_modes_capability , supported_fan_modes_attribute
15421546 if ib .data .value == clusters .FanControl .attributes .FanModeSequence .OFF_LOW_MED_HIGH then
1543- supportedFanModes = { " off" , " low" , " medium" , " high" }
1547+ supported_fan_modes = { " off" , " low" , " medium" , " high" }
15441548 elseif ib .data .value == clusters .FanControl .attributes .FanModeSequence .OFF_LOW_HIGH then
1545- supportedFanModes = { " off" , " low" , " high" }
1549+ supported_fan_modes = { " off" , " low" , " high" }
15461550 elseif ib .data .value == clusters .FanControl .attributes .FanModeSequence .OFF_LOW_MED_HIGH_AUTO then
1547- supportedFanModes = { " off" , " low" , " medium" , " high" , " auto" }
1551+ supported_fan_modes = { " off" , " low" , " medium" , " high" , " auto" }
15481552 elseif ib .data .value == clusters .FanControl .attributes .FanModeSequence .OFF_LOW_HIGH_AUTO then
1549- supportedFanModes = { " off" , " low" , " high" , " auto" }
1553+ supported_fan_modes = { " off" , " low" , " high" , " auto" }
15501554 elseif ib .data .value == clusters .FanControl .attributes .FanModeSequence .OFF_HIGH_AUTO then
1551- supportedFanModes = { " off" , " high" , " auto" }
1555+ supported_fan_modes = { " off" , " high" , " auto" }
15521556 else
1553- supportedFanModes = { " off" , " high" }
1557+ supported_fan_modes = { " off" , " high" }
15541558 end
15551559
15561560 if device :supports_capability_by_id (capabilities .airPurifierFanMode .ID ) then
1557- supported_fan_modes_attribute = capabilities .airPurifierFanMode .supportedAirPurifierFanModes
1561+ supported_fan_modes_capability = capabilities .airPurifierFanMode
1562+ supported_fan_modes_attribute = supported_fan_modes_capability .supportedAirPurifierFanModes
15581563 elseif device :supports_capability_by_id (capabilities .airConditionerFanMode .ID ) then
1559- supported_fan_modes_attribute = capabilities .airConditionerFanMode .supportedAcFanModes
1564+ supported_fan_modes_capability = capabilities .airConditionerFanMode
1565+ supported_fan_modes_attribute = supported_fan_modes_capability .supportedAcFanModes
15601566 elseif device :supports_capability_by_id (capabilities .thermostatFanMode .ID ) then
1567+ supported_fan_modes_capability = capabilities .thermostatFanMode
15611568 supported_fan_modes_attribute = capabilities .thermostatFanMode .supportedThermostatFanModes
15621569 -- Our thermostat fan mode control is not granular enough to handle all of the supported modes
15631570 if ib .data .value >= clusters .FanControl .attributes .FanModeSequence .OFF_LOW_MED_HIGH_AUTO and
15641571 ib .data .value <= clusters .FanControl .attributes .FanModeSequence .OFF_ON_AUTO then
1565- supportedFanModes = { " auto" , " on" }
1572+ supported_fan_modes = { " auto" , " on" }
15661573 else
1567- supportedFanModes = { " on" }
1574+ supported_fan_modes = { " on" }
15681575 end
15691576 else
1570- supported_fan_modes_attribute = capabilities .fanMode .supportedFanModes
1577+ supported_fan_modes_capability = capabilities .fanMode
1578+ supported_fan_modes_attribute = supported_fan_modes_capability .supportedFanModes
1579+ end
1580+
1581+ -- remove 'off' as a supported fan mode for thermostat device types, unless the
1582+ -- device previously had 'off' as a supported fan mode to avoid breaking routines
1583+ if get_device_type (device ) == THERMOSTAT_DEVICE_TYPE_ID then
1584+ local prev_supported_fan_modes = device :get_latest_state (
1585+ device :endpoint_to_component (ib .endpoint_id ),
1586+ supported_fan_modes_capability .ID ,
1587+ supported_fan_modes_attribute .NAME
1588+ ) or {}
1589+ if not tbl_contains (prev_supported_fan_modes , " off" ) then
1590+ local _ , off_idx = tbl_contains (supported_fan_modes , " off" )
1591+ if off_idx then
1592+ table.remove (supported_fan_modes , off_idx )
1593+ end
1594+ end
15711595 end
15721596
1573- local event = supported_fan_modes_attribute (supportedFanModes , {visibility = {displayed = false }})
1597+ local event = supported_fan_modes_attribute (supported_fan_modes , {visibility = {displayed = false }})
15741598 device :emit_event_for_endpoint (ib .endpoint_id , event )
15751599end
15761600
0 commit comments