Skip to content

Commit 429845c

Browse files
committed
fix up logic
1 parent 987716d commit 429845c

File tree

2 files changed

+5
-3
lines changed

2 files changed

+5
-3
lines changed

drivers/SmartThings/matter-switch/src/switch_handlers/capability_handlers.lua

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ function CapabilityHandlers.handle_step_level(driver, device, cmd)
5454
if step_size == 0 then return end
5555
local endpoint_id = device:component_to_endpoint(cmd.component)
5656
local step_mode = step_size > 0 and clusters.LevelControl.types.StepMode.UP or clusters.LevelControl.types.StepMode.DOWN
57+
print("Stepping level by ", math.abs(step_size))
5758
device:send(clusters.LevelControl.server.commands.Step(device, endpoint_id, step_mode, math.abs(step_size), fields.TRANSITION_TIME, fields.OPTIONS_MASK, fields.OPTIONS_OVERRIDE))
5859
end
5960

@@ -130,7 +131,8 @@ function CapabilityHandlers.handle_step_color_temperature_by_percent(driver, dev
130131
local step_mode = step_percent_change > 0 and (clusters.ColorControl.types.StepModeEnum and clusters.ColorControl.types.StepModeEnum.DOWN or 3) or (clusters.ColorControl.types.StepModeEnum and clusters.ColorControl.types.StepModeEnum.UP or 1)
131132
local min_mireds = switch_utils.get_field_for_endpoint(device, fields.COLOR_TEMP_BOUND_RECEIVED_MIRED..fields.COLOR_TEMP_MIN, endpoint_id) or fields.COLOR_TEMPERATURE_MIRED_MIN -- default min mireds
132133
local max_mireds = switch_utils.get_field_for_endpoint(device, fields.COLOR_TEMP_BOUND_RECEIVED_MIRED..fields.COLOR_TEMP_MAX, endpoint_id) or fields.COLOR_TEMPERATURE_MIRED_MAX -- default max mireds
133-
local step_size_in_mireds = (max_mireds - min_mireds) * st_utils.round((math.abs(step_percent_change)/100))
134+
local step_size_in_mireds = st_utils.round((max_mireds - min_mireds) * (math.abs(step_percent_change)/100.0))
135+
print("Stepping color temperature by ", step_size_in_mireds, " mireds", " with max mireds of ", max_mireds, " and min mireds of ", min_mireds)
134136
device:send(clusters.ColorControl.server.commands.StepColorTemperature(device, endpoint_id, step_mode, step_size_in_mireds, fields.TRANSITION_TIME, min_mireds, max_mireds, fields.OPTIONS_MASK, fields.OPTIONS_OVERRIDE))
135137
end
136138

drivers/SmartThings/matter-switch/src/switch_utils/fields.lua

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,8 @@ SwitchFields.MIRED_KELVIN_CONVERSION_CONSTANT = 1000000
2727
-- These values are a "sanity check" to check that values we are getting are reasonable
2828
local COLOR_TEMPERATURE_KELVIN_MAX = 15000
2929
local COLOR_TEMPERATURE_KELVIN_MIN = 1000
30-
SwitchFields.COLOR_TEMPERATURE_MIRED_MAX = SwitchFields.MIRED_KELVIN_CONVERSION_CONSTANT/COLOR_TEMPERATURE_KELVIN_MIN
31-
SwitchFields.COLOR_TEMPERATURE_MIRED_MIN = SwitchFields.MIRED_KELVIN_CONVERSION_CONSTANT/COLOR_TEMPERATURE_KELVIN_MAX
30+
SwitchFields.COLOR_TEMPERATURE_MIRED_MAX = math.floor(SwitchFields.MIRED_KELVIN_CONVERSION_CONSTANT/COLOR_TEMPERATURE_KELVIN_MIN)
31+
SwitchFields.COLOR_TEMPERATURE_MIRED_MIN = math.floor(SwitchFields.MIRED_KELVIN_CONVERSION_CONSTANT/COLOR_TEMPERATURE_KELVIN_MAX)
3232

3333
SwitchFields.SWITCH_LEVEL_LIGHTING_MIN = 1
3434
SwitchFields.CURRENT_HUESAT_ATTR_MIN = 0

0 commit comments

Comments
 (0)