Skip to content

Commit 671071f

Browse files
committed
pr comments pt. 4
- fix tab spacing - back out driver test changes (covered by #2773) - swap `color_temp_range` and `kelvin_min, kelvin_max` checks
1 parent 7640412 commit 671071f

5 files changed

Lines changed: 48 additions & 116 deletions

File tree

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

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,11 @@
44
local capabilities = require "st.capabilities"
55

66
return function(opts, driver, device)
7-
local can_handle = device:supports_capability(capabilities.statelessColorTemperatureStep)
8-
or device:supports_capability(capabilities.statelessSwitchLevelStep)
9-
if can_handle then
10-
local subdriver = require("stateless_handlers")
11-
return true, subdriver
12-
end
13-
return false
7+
local can_handle = device:supports_capability(capabilities.statelessColorTemperatureStep)
8+
or device:supports_capability(capabilities.statelessSwitchLevelStep)
9+
if can_handle then
10+
local subdriver = require("stateless_handlers")
11+
return true, subdriver
12+
end
13+
return false
1414
end

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

Lines changed: 36 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -13,52 +13,52 @@ local OPTIONS_MASK = 0x01 -- default: The `ExecuteIfOff` option is overriden
1313
local IGNORE_COMMAND_IF_OFF = 0x00 -- default: the command will not be executed if the device is off
1414

1515
local function step_color_temperature_by_percent_handler(driver, device, cmd)
16-
local step_percent_change = cmd.args and cmd.args.stepSize or 0
17-
if step_percent_change == 0 then return end
18-
local step_mode = step_percent_change > 0 and clusters.ColorControl.types.CcStepMode.DOWN or clusters.ColorControl.types.CcStepMode.UP
16+
local step_percent_change = cmd.args and cmd.args.stepSize or 0
17+
if step_percent_change == 0 then return end
18+
local step_mode = step_percent_change > 0 and clusters.ColorControl.types.CcStepMode.DOWN or clusters.ColorControl.types.CcStepMode.UP
1919

20-
local color_temp_range = device:get_latest_state("main", capabilities.colorTemperature.ID, capabilities.colorTemperature.colorTemperatureRange.NAME);
21-
local kelvin_min = device:get_field(switch_utils.KELVIN_MIN);
22-
local kelvin_max = device:get_field(switch_utils.KELVIN_MAX);
20+
local color_temp_range = device:get_latest_state("main", capabilities.colorTemperature.ID, capabilities.colorTemperature.colorTemperatureRange.NAME);
21+
local kelvin_min = device:get_field(switch_utils.KELVIN_MIN);
22+
local kelvin_max = device:get_field(switch_utils.KELVIN_MAX);
2323

24-
local min_mireds
25-
local max_mireds
26-
if kelvin_min and kelvin_max then
27-
-- First tier: use device values if available
28-
min_mireds = st_utils.round(switch_utils.MIREDS_CONVERSION_CONSTANT / kelvin_max)
29-
max_mireds = st_utils.round(switch_utils.MIREDS_CONVERSION_CONSTANT / kelvin_min)
30-
elseif color_temp_range then
31-
-- Second tier: use color_temp_range if available
32-
min_mireds = st_utils.round(switch_utils.MIREDS_CONVERSION_CONSTANT / color_temp_range.maximum)
33-
max_mireds = st_utils.round(switch_utils.MIREDS_CONVERSION_CONSTANT / color_temp_range.minimum)
34-
else
35-
-- Third tier: use defaults
36-
min_mireds = switch_utils.COLOR_TEMPERATURE_MIRED_MIN
37-
max_mireds = switch_utils.COLOR_TEMPERATURE_MIRED_MAX
38-
end
24+
local min_mireds
25+
local max_mireds
26+
if color_temp_range then
27+
-- First tier: use color_temp_range if available
28+
min_mireds = st_utils.round(switch_utils.MIREDS_CONVERSION_CONSTANT / color_temp_range.maximum)
29+
max_mireds = st_utils.round(switch_utils.MIREDS_CONVERSION_CONSTANT / color_temp_range.minimum)
30+
elseif kelvin_min and kelvin_max then
31+
-- Second tier: use device values if available
32+
min_mireds = st_utils.round(switch_utils.MIREDS_CONVERSION_CONSTANT / kelvin_max)
33+
max_mireds = st_utils.round(switch_utils.MIREDS_CONVERSION_CONSTANT / kelvin_min)
34+
else
35+
-- Third tier: use defaults
36+
min_mireds = switch_utils.COLOR_TEMPERATURE_MIRED_MIN
37+
max_mireds = switch_utils.COLOR_TEMPERATURE_MIRED_MAX
38+
end
3939

40-
local step_size_in_mireds = st_utils.round((max_mireds - min_mireds) * (math.abs(step_percent_change)/100.0))
41-
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))
40+
local step_size_in_mireds = st_utils.round((max_mireds - min_mireds) * (math.abs(step_percent_change)/100.0))
41+
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))
4242
end
4343

4444
local function step_level_handler(driver, device, cmd)
45-
local step_size = st_utils.round((cmd.args and cmd.args.stepSize or 0)/100.0 * 254)
46-
if step_size == 0 then return end
47-
local step_mode = step_size > 0 and clusters.Level.types.MoveStepMode.UP or clusters.Level.types.MoveStepMode.DOWN
48-
device:send(clusters.Level.server.commands.Step(device, step_mode, math.abs(step_size), TRANSITION_TIME, OPTIONS_MASK, IGNORE_COMMAND_IF_OFF))
45+
local step_size = st_utils.round((cmd.args and cmd.args.stepSize or 0)/100.0 * 254)
46+
if step_size == 0 then return end
47+
local step_mode = step_size > 0 and clusters.Level.types.MoveStepMode.UP or clusters.Level.types.MoveStepMode.DOWN
48+
device:send(clusters.Level.server.commands.Step(device, step_mode, math.abs(step_size), TRANSITION_TIME, OPTIONS_MASK, IGNORE_COMMAND_IF_OFF))
4949
end
5050

5151
local stateless_handlers = {
52-
Name = "Zigbee Stateless Step Handlers",
53-
capability_handlers = {
54-
[capabilities.statelessColorTemperatureStep.ID] = {
55-
[capabilities.statelessColorTemperatureStep.commands.stepColorTemperatureByPercent.NAME] = step_color_temperature_by_percent_handler,
56-
},
57-
[capabilities.statelessSwitchLevelStep.ID] = {
58-
[capabilities.statelessSwitchLevelStep.commands.stepLevel.NAME] = step_level_handler,
59-
},
52+
Name = "Zigbee Stateless Step Handlers",
53+
capability_handlers = {
54+
[capabilities.statelessColorTemperatureStep.ID] = {
55+
[capabilities.statelessColorTemperatureStep.commands.stepColorTemperatureByPercent.NAME] = step_color_temperature_by_percent_handler,
6056
},
61-
can_handle = require("stateless_handlers.can_handle")
57+
[capabilities.statelessSwitchLevelStep.ID] = {
58+
[capabilities.statelessSwitchLevelStep.commands.stepLevel.NAME] = step_level_handler,
59+
},
60+
},
61+
can_handle = require("stateless_handlers.can_handle")
6262
}
6363

6464
return stateless_handlers

drivers/SmartThings/zigbee-switch/src/test/test_all_capability_zigbee_bulb.lua

Lines changed: 1 addition & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -348,9 +348,6 @@ test.register_message_test(
348348
ColorControl.server.commands.StepColorTemperature(mock_device, ColorControl.types.CcStepMode.UP, 467, 3, switch_utils.COLOR_TEMPERATURE_MIRED_MIN, switch_utils.COLOR_TEMPERATURE_MIRED_MAX, 0x01, 0x00)
349349
},
350350
}
351-
},
352-
{
353-
min_api_version = 20
354351
}
355352
)
356353

@@ -451,14 +448,6 @@ test.register_coroutine_test(
451448
mock_device.id,
452449
ElectricalMeasurement.attributes.ActivePower:read(mock_device)
453450
})
454-
test.socket.zigbee:__expect_send({
455-
mock_device.id,
456-
ColorControl.attributes.ColorTempPhysicalMaxMireds:read(mock_device)
457-
})
458-
test.socket.zigbee:__expect_send({
459-
mock_device.id,
460-
ColorControl.attributes.ColorTempPhysicalMinMireds:read(mock_device)
461-
})
462451
test.socket.zigbee:__expect_send({
463452
mock_device.id,
464453
OnOff.attributes.OnOff:configure_reporting(mock_device, 0, 300)
@@ -539,21 +528,13 @@ test.register_coroutine_test(
539528
mock_device.id,
540529
SimpleMetering.attributes.Divisor:read(mock_device)
541530
})
542-
test.socket.zigbee:__expect_send({
543-
mock_device.id,
544-
ColorControl.attributes.ColorTempPhysicalMaxMireds:configure_reporting(mock_device, 1, 43200, 1)
545-
})
546-
test.socket.zigbee:__expect_send({
547-
mock_device.id,
548-
ColorControl.attributes.ColorTempPhysicalMinMireds:configure_reporting(mock_device, 1, 43200, 1)
549-
})
550531
test.socket.zigbee:__expect_send({ mock_device.id, ColorControl.attributes.ColorTempPhysicalMaxMireds:read(mock_device) })
551532
test.socket.zigbee:__expect_send({ mock_device.id, ColorControl.attributes.ColorTempPhysicalMinMireds:read(mock_device) })
552533

553534
mock_device:expect_metadata_update({ provisioning_state = "PROVISIONED" })
554535
end,
555536
{
556-
min_api_version = 20
537+
min_api_version = 19
557538
}
558539
)
559540

drivers/SmartThings/zigbee-switch/src/test/test_rgbw_bulb.lua

Lines changed: 1 addition & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -82,18 +82,6 @@ test.register_coroutine_test(
8282
ColorControl.attributes.CurrentSaturation:configure_reporting(mock_device, 1, 3600, 16)
8383
}
8484
)
85-
test.socket.zigbee:__expect_send(
86-
{
87-
mock_device.id,
88-
ColorControl.attributes.ColorTempPhysicalMaxMireds:configure_reporting(mock_device, 1, 43200, 1)
89-
}
90-
)
91-
test.socket.zigbee:__expect_send(
92-
{
93-
mock_device.id,
94-
ColorControl.attributes.ColorTempPhysicalMinMireds:configure_reporting(mock_device, 1, 43200, 1)
95-
}
96-
)
9785

9886
test.socket.zigbee:__expect_send({ mock_device.id, OnOff.attributes.OnOff:read(mock_device) })
9987
test.socket.zigbee:__expect_send({ mock_device.id, Level.attributes.CurrentLevel:read(mock_device) })
@@ -103,7 +91,7 @@ test.register_coroutine_test(
10391
mock_device:expect_metadata_update({ provisioning_state = "PROVISIONED" })
10492
end,
10593
{
106-
min_api_version = 20
94+
min_api_version = 19
10795
}
10896
)
10997

@@ -376,10 +364,6 @@ test.register_message_test(
376364
ColorControl.server.commands.StepColorTemperature(mock_device, ColorControl.types.CcStepMode.UP, 467, 3, switch_utils.COLOR_TEMPERATURE_MIRED_MIN, switch_utils.COLOR_TEMPERATURE_MIRED_MAX, 0x01, 0x00)
377365
},
378366
}
379-
},
380-
{
381-
inner_block_ordering = "relaxed",
382-
min_api_version = 20
383367
}
384368
)
385369

drivers/SmartThings/zigbee-switch/src/test/test_sengled_color_temp_bulb.lua

Lines changed: 3 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,6 @@ test.register_coroutine_test(
3939
test.socket.device_lifecycle:__queue_receive({ mock_device.id, "doConfigure" })
4040
test.socket.zigbee:__set_channel_ordering("relaxed")
4141

42-
test.socket.zigbee:__expect_send({ mock_device.id, ColorControl.attributes.ColorTempPhysicalMaxMireds:read(mock_device) })
43-
test.socket.zigbee:__expect_send({ mock_device.id, ColorControl.attributes.ColorTempPhysicalMinMireds:read(mock_device) })
4442
test.socket.zigbee:__expect_send({
4543
mock_device.id,
4644
zigbee_test_utils.build_bind_request(mock_device, zigbee_test_utils.mock_hub_eui, OnOff.ID)
@@ -72,18 +70,6 @@ test.register_coroutine_test(
7270
ColorControl.attributes.ColorTemperatureMireds:configure_reporting(mock_device, 1, 3600, 16)
7371
}
7472
)
75-
test.socket.zigbee:__expect_send(
76-
{
77-
mock_device.id,
78-
ColorControl.attributes.ColorTempPhysicalMaxMireds:configure_reporting(mock_device, 1, 43200, 1)
79-
}
80-
)
81-
test.socket.zigbee:__expect_send(
82-
{
83-
mock_device.id,
84-
ColorControl.attributes.ColorTempPhysicalMinMireds:configure_reporting(mock_device, 1, 43200, 1)
85-
}
86-
)
8773

8874
test.socket.zigbee:__expect_send({ mock_device.id, OnOff.attributes.OnOff:read(mock_device) })
8975
test.socket.zigbee:__expect_send({ mock_device.id, Level.attributes.CurrentLevel:read(mock_device) })
@@ -93,7 +79,7 @@ test.register_coroutine_test(
9379
mock_device:expect_metadata_update({ provisioning_state = "PROVISIONED" })
9480
end,
9581
{
96-
min_api_version = 20
82+
min_api_version = 19
9783
}
9884
)
9985

@@ -128,27 +114,11 @@ test.register_message_test(
128114
mock_device.id,
129115
ColorControl.attributes.ColorTemperatureMireds:read(mock_device)
130116
}
131-
},
132-
{
133-
channel = "zigbee",
134-
direction = "send",
135-
message = {
136-
mock_device.id,
137-
ColorControl.attributes.ColorTempPhysicalMaxMireds:read(mock_device)
138-
}
139-
},
140-
{
141-
channel = "zigbee",
142-
direction = "send",
143-
message = {
144-
mock_device.id,
145-
ColorControl.attributes.ColorTempPhysicalMinMireds:read(mock_device)
146-
}
147117
}
148118
},
149119
{
150120
inner_block_ordering = "relaxed",
151-
min_api_version = 20
121+
min_api_version = 19
152122
}
153123
)
154124

@@ -195,10 +165,7 @@ test.register_coroutine_test(
195165
}
196166
)
197167
test.wait_for_events()
198-
end,
199-
{
200-
min_api_version = 20
201-
}
168+
end
202169
)
203170

204171
test.register_coroutine_test(

0 commit comments

Comments
 (0)