Skip to content

Commit 9e92a6f

Browse files
authored
Merge pull request #2125 from AldaronLau/better-match-default-handlers-behavior
Matter switch and zigbee fan switchLevel: Match default handlers behavior around small values
2 parents 25bef14 + 5da560c commit 9e92a6f

File tree

2 files changed

+10
-3
lines changed

2 files changed

+10
-3
lines changed

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

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,10 @@ end
3838

3939
function AttributeHandlers.level_control_current_level_handler(driver, device, ib, response)
4040
if ib.data.value ~= nil then
41-
local level = math.floor((ib.data.value / 254.0 * 100) + 0.5)
41+
local level = ib.data.value
42+
if level > 0 then
43+
level = math.max(1, st_utils.round(level / 254.0 * 100))
44+
end
4245
device:emit_event_for_endpoint(ib.endpoint_id, capabilities.switchLevel.level(level))
4346
if type(device.register_native_capability_attr_handler) == "function" then
4447
device:register_native_capability_attr_handler("switchLevel", "level")
@@ -535,4 +538,4 @@ function AttributeHandlers.percent_current_handler(driver, device, ib, response)
535538
device:emit_event_for_endpoint(ib.endpoint_id, capabilities.fanSpeedPercent.percent(ib.data.value))
536539
end
537540

538-
return AttributeHandlers
541+
return AttributeHandlers

drivers/SmartThings/zigbee-fan/src/fan-light/init.lua

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,11 @@ local function zb_fan_control_handler(driver, device, value, zb_rx)
7474
end
7575

7676
local function zb_level_handler(driver, device, value, zb_rx)
77-
local evt = capabilities.switchLevel.level(math.floor((value.value / 254.0 * 100) + 0.5))
77+
local level = value.value
78+
if level > 0 then
79+
level = math.max(1, math.floor((level / 254.0 * 100) + 0.5))
80+
end
81+
local evt = capabilities.switchLevel.level(level)
7882
device:emit_component_event(device.profile.components.light, evt)
7983
end
8084

0 commit comments

Comments
 (0)