@@ -13,52 +13,52 @@ local OPTIONS_MASK = 0x01 -- default: The `ExecuteIfOff` option is overriden
1313local IGNORE_COMMAND_IF_OFF = 0x00 -- default: the command will not be executed if the device is off
1414
1515local function step_color_temperature_by_percent_handler (driver , device , cmd )
16- local step_percent_change = cmd .args and cmd .args .stepSize or 0
17- if step_percent_change == 0 then return end
18- local step_mode = step_percent_change > 0 and clusters .ColorControl .types .CcStepMode .DOWN or clusters .ColorControl .types .CcStepMode .UP
16+ local step_percent_change = cmd .args and cmd .args .stepSize or 0
17+ if step_percent_change == 0 then return end
18+ local step_mode = step_percent_change > 0 and clusters .ColorControl .types .CcStepMode .DOWN or clusters .ColorControl .types .CcStepMode .UP
1919
20- local color_temp_range = device :get_latest_state (" main" , capabilities .colorTemperature .ID , capabilities .colorTemperature .colorTemperatureRange .NAME );
21- local kelvin_min = device :get_field (switch_utils .KELVIN_MIN );
22- local kelvin_max = device :get_field (switch_utils .KELVIN_MAX );
20+ local color_temp_range = device :get_latest_state (" main" , capabilities .colorTemperature .ID , capabilities .colorTemperature .colorTemperatureRange .NAME );
21+ local kelvin_min = device :get_field (switch_utils .KELVIN_MIN );
22+ local kelvin_max = device :get_field (switch_utils .KELVIN_MAX );
2323
24- local min_mireds
25- local max_mireds
26- if kelvin_min and kelvin_max then
27- -- First tier: use device values if available
28- min_mireds = st_utils .round (switch_utils .MIREDS_CONVERSION_CONSTANT / kelvin_max )
29- max_mireds = st_utils .round (switch_utils .MIREDS_CONVERSION_CONSTANT / kelvin_min )
30- elseif color_temp_range then
31- -- Second tier: use color_temp_range if available
32- min_mireds = st_utils .round (switch_utils .MIREDS_CONVERSION_CONSTANT / color_temp_range . maximum )
33- max_mireds = st_utils .round (switch_utils .MIREDS_CONVERSION_CONSTANT / color_temp_range . minimum )
34- else
35- -- Third tier: use defaults
36- min_mireds = switch_utils .COLOR_TEMPERATURE_MIRED_MIN
37- max_mireds = switch_utils .COLOR_TEMPERATURE_MIRED_MAX
38- end
24+ local min_mireds
25+ local max_mireds
26+ if color_temp_range then
27+ -- First tier: use color_temp_range if available
28+ min_mireds = st_utils .round (switch_utils .MIREDS_CONVERSION_CONSTANT / color_temp_range . maximum )
29+ max_mireds = st_utils .round (switch_utils .MIREDS_CONVERSION_CONSTANT / color_temp_range . minimum )
30+ elseif kelvin_min and kelvin_max then
31+ -- Second tier: use device values if available
32+ min_mireds = st_utils .round (switch_utils .MIREDS_CONVERSION_CONSTANT / kelvin_max )
33+ max_mireds = st_utils .round (switch_utils .MIREDS_CONVERSION_CONSTANT / kelvin_min )
34+ else
35+ -- Third tier: use defaults
36+ min_mireds = switch_utils .COLOR_TEMPERATURE_MIRED_MIN
37+ max_mireds = switch_utils .COLOR_TEMPERATURE_MIRED_MAX
38+ end
3939
40- local step_size_in_mireds = st_utils .round ((max_mireds - min_mireds ) * (math.abs (step_percent_change )/ 100.0 ))
41- device :send (clusters .ColorControl .server .commands .StepColorTemperature (device , step_mode , step_size_in_mireds , TRANSITION_TIME , min_mireds , max_mireds , OPTIONS_MASK , IGNORE_COMMAND_IF_OFF ))
40+ local step_size_in_mireds = st_utils .round ((max_mireds - min_mireds ) * (math.abs (step_percent_change )/ 100.0 ))
41+ device :send (clusters .ColorControl .server .commands .StepColorTemperature (device , step_mode , step_size_in_mireds , TRANSITION_TIME , min_mireds , max_mireds , OPTIONS_MASK , IGNORE_COMMAND_IF_OFF ))
4242end
4343
4444local function step_level_handler (driver , device , cmd )
45- local step_size = st_utils .round ((cmd .args and cmd .args .stepSize or 0 )/ 100.0 * 254 )
46- if step_size == 0 then return end
47- local step_mode = step_size > 0 and clusters .Level .types .MoveStepMode .UP or clusters .Level .types .MoveStepMode .DOWN
48- device :send (clusters .Level .server .commands .Step (device , step_mode , math.abs (step_size ), TRANSITION_TIME , OPTIONS_MASK , IGNORE_COMMAND_IF_OFF ))
45+ local step_size = st_utils .round ((cmd .args and cmd .args .stepSize or 0 )/ 100.0 * 254 )
46+ if step_size == 0 then return end
47+ local step_mode = step_size > 0 and clusters .Level .types .MoveStepMode .UP or clusters .Level .types .MoveStepMode .DOWN
48+ device :send (clusters .Level .server .commands .Step (device , step_mode , math.abs (step_size ), TRANSITION_TIME , OPTIONS_MASK , IGNORE_COMMAND_IF_OFF ))
4949end
5050
5151local stateless_handlers = {
52- Name = " Zigbee Stateless Step Handlers" ,
53- capability_handlers = {
54- [capabilities .statelessColorTemperatureStep .ID ] = {
55- [capabilities .statelessColorTemperatureStep .commands .stepColorTemperatureByPercent .NAME ] = step_color_temperature_by_percent_handler ,
56- },
57- [capabilities .statelessSwitchLevelStep .ID ] = {
58- [capabilities .statelessSwitchLevelStep .commands .stepLevel .NAME ] = step_level_handler ,
59- },
52+ Name = " Zigbee Stateless Step Handlers" ,
53+ capability_handlers = {
54+ [capabilities .statelessColorTemperatureStep .ID ] = {
55+ [capabilities .statelessColorTemperatureStep .commands .stepColorTemperatureByPercent .NAME ] = step_color_temperature_by_percent_handler ,
6056 },
61- can_handle = require (" stateless_handlers.can_handle" )
57+ [capabilities .statelessSwitchLevelStep .ID ] = {
58+ [capabilities .statelessSwitchLevelStep .commands .stepLevel .NAME ] = step_level_handler ,
59+ },
60+ },
61+ can_handle = require (" stateless_handlers.can_handle" )
6262}
6363
6464return stateless_handlers
0 commit comments