Skip to content

Commit 21d5850

Browse files
committed
pr comments pt.1
- get calues from `colorTemperature` `range` - local values for constants
1 parent 514c97c commit 21d5850

File tree

1 file changed

+8
-3
lines changed
  • drivers/SmartThings/zigbee-switch/src/stateless_handlers

1 file changed

+8
-3
lines changed

drivers/SmartThings/zigbee-switch/src/stateless_handlers/init.lua

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,12 @@
44
local capabilities = require "st.capabilities"
55
local st_utils = require "st.utils"
66
local clusters = require "st.zigbee.zcl.clusters"
7-
local constants = require "st.zigbee.constants"
7+
8+
local MIREDS_CONVERSION_CONSTANT = 1000000
9+
local COLOR_TEMPERATURE_KELVIN_MAX = 15000
10+
local COLOR_TEMPERATURE_KELVIN_MIN = 1000
11+
local COLOR_TEMPERATURE_MIRED_MAX = st_utils.round(MIREDS_CONVERSION_CONSTANT/COLOR_TEMPERATURE_KELVIN_MIN) -- 1000
12+
local COLOR_TEMPERATURE_MIRED_MIN = st_utils.round(MIREDS_CONVERSION_CONSTANT/COLOR_TEMPERATURE_KELVIN_MAX) -- 67
813

914
-- Transition Time: The time that shall be taken to perform the step change, in units of 1/10ths of a second.
1015
local TRANSITION_TIME = 3 -- default: 0.3 seconds
@@ -16,8 +21,8 @@ local function step_color_temperature_by_percent_handler(driver, device, cmd)
1621
local step_percent_change = cmd.args and cmd.args.stepSize or 0
1722
if step_percent_change == 0 then return end
1823
local step_mode = step_percent_change > 0 and (clusters.ColorControl.types.CcStepMode and clusters.ColorControl.types.CcStepMode.DOWN or 3) or (clusters.ColorControl.types.CcStepMode and clusters.ColorControl.types.CcStepMode.UP or 1)
19-
local min_mireds = device:get_field(constants.KELVIN_MIN) or constants.COLOR_TEMPERATURE_MIRED_MIN -- default min mireds
20-
local max_mireds = device:get_field(constants.KELVIN_MAX) or constants.COLOR_TEMPERATURE_MIRED_MAX -- default max mireds
24+
local min_mireds = capabilities.colorTemperature.colorTemperatureRange.minimum or COLOR_TEMPERATURE_MIRED_MIN -- default min mireds
25+
local max_mireds = capabilities.colorTemperature.colorTemperatureRange.maximum or COLOR_TEMPERATURE_MIRED_MAX -- default max mireds
2126
local step_size_in_mireds = st_utils.round((max_mireds - min_mireds) * (math.abs(step_percent_change)/100.0))
2227
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))
2328
end

0 commit comments

Comments
 (0)