Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 2 additions & 12 deletions drivers/SmartThings/zigbee-window-treatment/src/aqara/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,6 @@ local APPLICATION_VERSION = "application_version"



local function window_shade_level_cmd(driver, device, command)
aqara_utils.shade_level_cmd(driver, device, command)
end

local function set_initialized_state_handler(driver, device, command)
-- update ui
device:emit_event(deviceInitialization.initializedState.initializing())
Expand All @@ -60,12 +56,6 @@ local function set_initialized_state_handler(driver, device, command)
end)
end

local function shade_level_report_legacy_handler(driver, device, value, zb_rx)
-- for version 34
aqara_utils.emit_shade_level_event(device, value)
aqara_utils.emit_shade_event(device, value)
end

local function shade_level_report_handler(driver, device, value, zb_rx)
aqara_utils.emit_shade_level_event(device, value)
aqara_utils.emit_shade_event(device, value)
Expand Down Expand Up @@ -183,7 +173,7 @@ local aqara_window_treatment_handler = {
},
capability_handlers = {
[capabilities.windowShadeLevel.ID] = {
[capabilities.windowShadeLevel.commands.setShadeLevel.NAME] = window_shade_level_cmd
[capabilities.windowShadeLevel.commands.setShadeLevel.NAME] = aqara_utils.shade_level_cmd
},
[deviceInitialization.ID] = {
[setInitializedStateCommandName] = set_initialized_state_handler
Expand All @@ -195,7 +185,7 @@ local aqara_window_treatment_handler = {
zigbee_handlers = {
attr = {
[WindowCovering.ID] = {
[WindowCovering.attributes.CurrentPositionLiftPercentage.ID] = shade_level_report_legacy_handler
[WindowCovering.attributes.CurrentPositionLiftPercentage.ID] = shade_level_report_handler -- for version 34
},
[AnalogOutput.ID] = {
[AnalogOutput.attributes.PresentValue.ID] = shade_level_report_handler
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,24 +35,6 @@ local function is_not_init(device)
initializedStateWithGuide.initializedStateWithGuide.initialized.NAME
end

local function window_shade_level_cmd(driver, device, command)
-- Cannot be controlled if not initialized
if is_not_init(device) then return end
aqara_utils.shade_level_cmd(driver, device, command)
end

local function window_shade_open_cmd(driver, device, command)
-- Cannot be controlled if not initialized
if is_not_init(device) then return end
device:send_to_component(command.component, WindowCovering.server.commands.GoToLiftPercentage(device, 100))
end

local function window_shade_close_cmd(driver, device, command)
-- Cannot be controlled if not initialized
if is_not_init(device) then return end
device:send_to_component(command.component, WindowCovering.server.commands.GoToLiftPercentage(device, 0))
end

local function set_rotate_command_handler(driver, device, command)
device:emit_event(shadeRotateState.rotateState.idle({ state_change = true, visibility = { displayed = false } })) -- update UI

Expand Down Expand Up @@ -153,13 +135,6 @@ local aqara_roller_shade_t1s_handler = {
infoChanged = device_info_changed
},
capability_handlers = {
[capabilities.windowShadeLevel.ID] = {
[capabilities.windowShadeLevel.commands.setShadeLevel.NAME] = window_shade_level_cmd
},
[capabilities.windowShade.ID] = {
[capabilities.windowShade.commands.open.NAME] = window_shade_open_cmd,
[capabilities.windowShade.commands.close.NAME] = window_shade_close_cmd
},
[shadeRotateState.ID] = {
[setRotateStateCommandName] = set_rotate_command_handler
},
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
-- Copyright 2025 SmartThings, Inc.
-- Licensed under the Apache License, Version 2.0

local capabilities = require "st.capabilities"

local axis_utils = {}

axis_utils.DEFAULT_LEVEL = 0

-- Optimistically emits the target level and the direction of travel, then sends the level to the device.
-- `send_level(device, command, level)` is the only part that differs between the AXIS Gear variants.
axis_utils.set_level = function(device, command, level, send_level)
local current_level = device:get_latest_state("main", capabilities.windowShadeLevel.ID,
capabilities.windowShadeLevel.shadeLevel.NAME) or axis_utils.DEFAULT_LEVEL
device:emit_event(capabilities.windowShadeLevel.shadeLevel(level))
-- Opening or Closing
local windowShade = capabilities.windowShade.windowShade
device:emit_event(level > current_level and windowShade.opening() or windowShade.closing())
-- Send Zigbee command
send_level(device, command, level)
end

axis_utils.build_set_level_handler = function(send_level)
return function(driver, device, command)
axis_utils.set_level(device, command, command.args.shadeLevel, send_level)
end
end

-- Resting state for a reported level
axis_utils.handle_window_shade = function(device, current_level)
local windowShade = capabilities.windowShade.windowShade
if current_level > 0 and current_level < 99 then
device:emit_event(windowShade.partially_open())
elseif current_level >= 99 then
device:emit_event(windowShade.open())
else
device:emit_event(windowShade.closed())
end
end

return axis_utils
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@


local capabilities = require "st.capabilities"
local window_shade_utils = require "window_shade_utils"
local axis_utils = require "axis.axis_utils"
local zcl_clusters = require "st.zigbee.zcl.clusters"
local utils = require "st.utils"

Expand All @@ -12,29 +12,13 @@ local Level = zcl_clusters.Level
local PowerConfiguration = zcl_clusters.PowerConfiguration
local WindowCovering = zcl_clusters.WindowCovering

local DEFAULT_LEVEL = 0


-- Commands
local function window_shade_set_level(device, command, level)
local current_level = device:get_latest_state("main", capabilities.windowShadeLevel.ID, capabilities.windowShadeLevel.shadeLevel.NAME) or DEFAULT_LEVEL
device:emit_event(capabilities.windowShadeLevel.shadeLevel(level))
-- Opening or Closing
local windowShade = capabilities.windowShade.windowShade
device:emit_event(level > current_level and windowShade.opening() or windowShade.closing())
-- Send Zigbee command
local function send_level(device, command, level)
device:send_to_component(command.component, WindowCovering.server.commands.GoToLiftPercentage(device, 100 - level))
end

local function window_shade_level_cmd_handler(driver, device, command)
local level = command.args.shadeLevel
window_shade_set_level(device, command, level)
end

local function window_shade_preset_cmd(driver, device, command)
local level = window_shade_utils.get_preset_level(device, command.component)
window_shade_set_level(device, command, level)
end
local window_shade_level_cmd_handler = axis_utils.build_set_level_handler(send_level)

local function window_shade_pause_cmd(driver, device, command)
local window_shade_state = device:get_latest_state("main", capabilities.windowShade.ID, capabilities.windowShade.windowShade.NAME) or "unknown"
Expand All @@ -56,32 +40,21 @@ local function window_shade_close_cmd(driver, device, command)
end

-- Common
local function handle_window_shade(device, current_level)
local windowShade = capabilities.windowShade.windowShade
if current_level > 0 and current_level < 99 then
device:emit_event(windowShade.partially_open())
elseif current_level >= 99 then
device:emit_event(windowShade.open())
else
device:emit_event(windowShade.closed())
end
end

local function current_position_attr_handler(driver, device, value, zb_rx)
local level = 100 - value.value
device:emit_event(capabilities.windowShadeLevel.shadeLevel(level))
handle_window_shade(device, level)
axis_utils.handle_window_shade(device, level)
end

local function level_attr_handler(driver, device, value, zb_rx)
local level = utils.round((value.value / 254.0) * 100)
local windowShade = capabilities.windowShade.windowShade
local current_level = device:get_latest_state("main", capabilities.windowShadeLevel.ID, capabilities.windowShadeLevel.shadeLevel.NAME) or DEFAULT_LEVEL
local current_level = device:get_latest_state("main", capabilities.windowShadeLevel.ID, capabilities.windowShadeLevel.shadeLevel.NAME) or axis_utils.DEFAULT_LEVEL

device:emit_event(capabilities.windowShadeLevel.shadeLevel(level))
-- If the last level equals the current reported level then it is assumed we have reached our destination.
if current_level == level then
handle_window_shade(device, current_level)
axis_utils.handle_window_shade(device, current_level)
else
device:emit_event(level > current_level and windowShade.opening() or windowShade.closing())
end
Expand All @@ -99,9 +72,6 @@ local axis_handler_version = {
[capabilities.windowShadeLevel.ID] = {
[capabilities.windowShadeLevel.commands.setShadeLevel.NAME] = window_shade_level_cmd_handler
},
[capabilities.windowShadePreset.ID] = {
[capabilities.windowShadePreset.commands.presetPosition.NAME] = window_shade_preset_cmd
},
[capabilities.windowShade.ID] = {
[capabilities.windowShade.commands.open.NAME] = window_shade_open_cmd,
[capabilities.windowShade.commands.close.NAME] = window_shade_close_cmd,
Expand Down
41 changes: 6 additions & 35 deletions drivers/SmartThings/zigbee-window-treatment/src/axis/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

local capabilities = require "st.capabilities"
local device_management = require "st.zigbee.device_management"
local window_shade_utils = require "window_shade_utils"
local axis_utils = require "axis.axis_utils"
local zcl_clusters = require "st.zigbee.zcl.clusters"
local utils = require "st.utils"

Expand All @@ -15,29 +15,14 @@ local PowerConfiguration = zcl_clusters.PowerConfiguration
local WindowCovering = zcl_clusters.WindowCovering

local SOFTWARE_VERSION = "software_version"
local DEFAULT_LEVEL = 0


-- Commands
local function window_shade_set_level(device, command, level)
local current_level = device:get_latest_state("main", capabilities.windowShadeLevel.ID, capabilities.windowShadeLevel.shadeLevel.NAME) or DEFAULT_LEVEL
device:emit_event(capabilities.windowShadeLevel.shadeLevel(level))
-- Opening or Closing
local windowShade = capabilities.windowShade.windowShade
device:emit_event(level > current_level and windowShade.opening() or windowShade.closing())
-- Send Zigbee command
local function send_level(device, command, level)
device:send_to_component(command.component, Level.server.commands.MoveToLevelWithOnOff(device, utils.round(level/100.0 * 254)))
end

local function window_shade_level_cmd_handler(driver, device, command)
local level = command.args.shadeLevel
window_shade_set_level(device, command, level)
end

local function window_shade_preset_cmd(driver, device, command)
local level = window_shade_utils.get_preset_level(device, command.component)
window_shade_set_level(device, command, level)
end
local window_shade_level_cmd_handler = axis_utils.build_set_level_handler(send_level)

local function window_shade_pause_cmd(driver, device, command)
device.thread:call_with_delay(5, function(d)
Expand All @@ -47,29 +32,18 @@ local function window_shade_pause_cmd(driver, device, command)
end

local function window_shade_open_cmd(driver, device, command)
window_shade_set_level(device, command, 100)
axis_utils.set_level(device, command, 100, send_level)
end

local function window_shade_close_cmd(driver, device, command)
window_shade_set_level(device, command, 0)
axis_utils.set_level(device, command, 0, send_level)
end

-- Common
local function handle_window_shade(device, current_level)
local windowShade = capabilities.windowShade.windowShade
if current_level > 0 and current_level < 99 then
device:emit_event(windowShade.partially_open())
elseif current_level >= 99 then
device:emit_event(windowShade.open())
else
device:emit_event(windowShade.closed())
end
end

local function level_attr_handler(driver, device, value, zb_rx)
local level = utils.round((value.value/254.0) * 100)
device:emit_event(capabilities.windowShadeLevel.shadeLevel(level))
handle_window_shade(device, level)
axis_utils.handle_window_shade(device, level)
end

local do_refresh = function(self, device)
Expand Down Expand Up @@ -110,9 +84,6 @@ local axis_handler = {
[capabilities.windowShadeLevel.ID] = {
[capabilities.windowShadeLevel.commands.setShadeLevel.NAME] = window_shade_level_cmd_handler
},
[capabilities.windowShadePreset.ID] = {
[capabilities.windowShadePreset.commands.presetPosition.NAME] = window_shade_preset_cmd
},
[capabilities.windowShade.ID] = {
[capabilities.windowShade.commands.open.NAME] = window_shade_open_cmd,
[capabilities.windowShade.commands.close.NAME] = window_shade_close_cmd,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

local capabilities = require "st.capabilities"
local zcl_clusters = require "st.zigbee.zcl.clusters"
local window_shade_utils = require "window_shade_utils"
local window_shade_defaults = require "st.zigbee.defaults.windowShade_defaults"
local device_management = require "st.zigbee.device_management"
local Level = zcl_clusters.Level
Expand All @@ -26,11 +25,6 @@ local function level_attr_handler(driver, device, value, zb_rx)
window_shade_defaults.default_current_lift_percentage_handler(driver, device, value, zb_rx)
end

local function window_shade_preset_cmd(driver, device, command)
local level = window_shade_utils.get_preset_level(device, command.component)
set_shade_level(device, level, command.component)
end

local do_refresh = function(self, device)
device:send(Level.attributes.CurrentLevel:read(device))
end
Expand All @@ -47,9 +41,6 @@ local feibit_handler = {
[capabilities.windowShadeLevel.ID] = {
[capabilities.windowShadeLevel.commands.setShadeLevel.NAME] = window_shade_level_cmd_handler
},
[capabilities.windowShadePreset.ID] = {
[capabilities.windowShadePreset.commands.presetPosition.NAME] = window_shade_preset_cmd
},
[capabilities.refresh.ID] = {
[capabilities.refresh.commands.refresh.NAME] = do_refresh,
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ local Messages = require "st.zigbee.messages"
local data_types = require "st.zigbee.data_types"
local ZigbeeConstants = require "st.zigbee.constants"
local generic_body = require "st.zigbee.generic_body"
local window_shade_utils = require "window_shade_utils"

local TUYA_CLUSTER = 0xEF00
local DP_TYPE_VALUE = "\x02"
Expand Down Expand Up @@ -150,11 +149,6 @@ local function SetShadeLevelHandler(driver, device, capability_command)
SendCommand(device, DP_ID_SET_POSITION, DP_TYPE_VALUE, string.pack(">I4", capability_command.args.shadeLevel))
end

local function PresetPositionHandler(driver, device, capability_command)
local level = window_shade_utils.get_preset_level(device, capability_command.component)
SetShadeLevelHandler(driver, device, {args = { shadeLevel = level }})
end

--------------------- Tuya Cluster Recieve Handlers --------------------

local function TuyaClusterRx(driver, device, zb_rx)
Expand Down Expand Up @@ -223,9 +217,6 @@ local hanssem_window_treatment = {
[capabilities.windowShade.commands.close.NAME] = CloseHandler,
[capabilities.windowShade.commands.pause.NAME] = PauseHandler
},
[capabilities.windowShadePreset.ID] = {
[capabilities.windowShadePreset.commands.presetPosition.NAME] = PresetPositionHandler
},
[capabilities.windowShadeLevel.ID] = {
[capabilities.windowShadeLevel.commands.setShadeLevel.NAME] = SetShadeLevelHandler
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

local capabilities = require "st.capabilities"
local zcl_clusters = require "st.zigbee.zcl.clusters"
local window_shade_utils = require "window_shade_utils"

local WindowCovering = zcl_clusters.WindowCovering

Expand Down Expand Up @@ -65,11 +64,6 @@ local function window_shade_level_cmd(driver, device, command)
set_shade_level(device, command.args.shadeLevel, command)
end

local function window_shade_preset_cmd(driver, device, command)
local level = window_shade_utils.get_preset_level(device, command.component)
set_shade_level(device, level, command)
end

local ikea_window_treatment = {
NAME = "inverted lift percentage",
zigbee_handlers = {
Expand All @@ -83,9 +77,6 @@ local ikea_window_treatment = {
[capabilities.windowShadeLevel.ID] = {
[capabilities.windowShadeLevel.commands.setShadeLevel.NAME] = window_shade_level_cmd
},
[capabilities.windowShadePreset.ID] = {
[capabilities.windowShadePreset.commands.presetPosition.NAME] = window_shade_preset_cmd
}
},
can_handle = require("invert-lift-percentage.can_handle"),
}
Expand Down
Loading
Loading