Skip to content

Matter switch and zigbee fan switchLevel: Match default handlers behavior around small values #2125

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
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
5 changes: 4 additions & 1 deletion drivers/SmartThings/matter-switch/src/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -933,7 +933,10 @@ end

local function level_attr_handler(driver, device, ib, response)
if ib.data.value ~= nil then
local level = math.floor((ib.data.value / 254.0 * 100) + 0.5)
local level = ib.data.value
if level > 0 then
level = math.max(1, utils.round(level / 254.0 * 100))
end
device:emit_event_for_endpoint(ib.endpoint_id, capabilities.switchLevel.level(level))
if type(device.register_native_capability_attr_handler) == "function" then
device:register_native_capability_attr_handler("switchLevel", "level")
Expand Down
6 changes: 5 additions & 1 deletion drivers/SmartThings/zigbee-fan/src/fan-light/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,11 @@ local function zb_fan_control_handler(driver, device, value, zb_rx)
end

local function zb_level_handler(driver, device, value, zb_rx)
local evt = capabilities.switchLevel.level(math.floor((value.value / 254.0 * 100) + 0.5))
local level = value.value
if level > 0 then
level = math.max(1, math.floor((level / 254.0 * 100) + 0.5))
end
local evt = capabilities.switchLevel.level(level)
device:emit_component_event(device.profile.components.light, evt)
end

Expand Down