Skip to content

Commit 5d2a4d2

Browse files
committed
Remove redundant test, check cluster differently in can_handle
1 parent 5998b3f commit 5d2a4d2

2 files changed

Lines changed: 12 additions & 39 deletions

File tree

drivers/SmartThings/matter-switch/src/sub_drivers/eve_energy/can_handle.lua

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,24 @@ local device_lib = require "st.device"
55
local fields = require "switch_utils.fields"
66
local switch_utils = require "switch_utils.utils"
77

8+
local function has_cluster(device, cluster_id)
9+
for _, ep in ipairs(device.endpoints) do
10+
for _, cluster in ipairs(ep.clusters or {}) do
11+
if cluster.cluster_id == cluster_id then
12+
return true
13+
end
14+
end
15+
end
16+
return false
17+
end
18+
819
return function(opts, driver, device)
920
local EVE_PRIVATE_CLUSTER_ID = 0x130AFC01
1021
-- this sub driver loads for devices that:
1122
-- 1. Contain the Eve Private Cluster (0x130AFC01)
1223
-- 2. Do NOT have the Standard Electrical Sensor device type
1324
if device.network_type == device_lib.NETWORK_TYPE_MATTER and
14-
#device:get_endpoints(EVE_PRIVATE_CLUSTER_ID) > 0 and
25+
has_cluster(device, EVE_PRIVATE_CLUSTER_ID) and
1526
#switch_utils.get_endpoints_by_device_type(device, fields.DEVICE_TYPE_ID.ELECTRICAL_SENSOR) == 0 then
1627
return true, require("sub_drivers.eve_energy")
1728
end

drivers/SmartThings/matter-switch/src/test/test_eve_energy.lua

Lines changed: 0 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -15,28 +15,6 @@ local PRIVATE_ATTR_ID_WATT = 0x130A000A
1515
local PRIVATE_ATTR_ID_WATT_ACCUMULATED = 0x130A000B
1616
local PRIVATE_ATTR_ID_ACCUMULATED_CONTROL_POINT = 0x130A000E
1717

18-
-- Helper function to add get_endpoints method to mock devices for can_handle testing
19-
local function add_get_endpoints_to_mock(device)
20-
device.get_endpoints = function(self, cluster_id, opts)
21-
opts = opts or {}
22-
local eps = {}
23-
for _, ep in ipairs(self.endpoints) do
24-
for _, cluster in ipairs(ep.clusters or {}) do
25-
if cluster.cluster_id == cluster_id then
26-
-- Check feature_bitmap if specified
27-
if opts.feature_bitmap == nil or
28-
(cluster.feature_map and (cluster.feature_map & opts.feature_bitmap) == opts.feature_bitmap) then
29-
table.insert(eps, ep.endpoint_id)
30-
break
31-
end
32-
end
33-
end
34-
end
35-
return eps
36-
end
37-
return device
38-
end
39-
4018
local mock_device = test.mock_device.build_test_matter_device({
4119
profile = t_utils.get_profile_definition("power-energy-powerConsumption.yml"),
4220
manufacturer_info = {
@@ -75,7 +53,6 @@ local mock_device = test.mock_device.build_test_matter_device({
7553
}
7654
}
7755
})
78-
add_get_endpoints_to_mock(mock_device)
7956

8057
local mock_eve_device_using_electrical_sensor = test.mock_device.build_test_matter_device({
8158
profile = t_utils.get_profile_definition("plug-energy-powerConsumption.yml"),
@@ -135,7 +112,6 @@ local mock_eve_device_using_electrical_sensor = test.mock_device.build_test_matt
135112
}
136113
}
137114
})
138-
add_get_endpoints_to_mock(mock_eve_device_using_electrical_sensor)
139115

140116
-- Mock device without Eve Private Cluster (should not match eve_energy sub-driver)
141117
local mock_device_without_private_cluster = test.mock_device.build_test_matter_device({
@@ -170,7 +146,6 @@ local mock_device_without_private_cluster = test.mock_device.build_test_matter_d
170146
}
171147
}
172148
})
173-
add_get_endpoints_to_mock(mock_device_without_private_cluster)
174149

175150
local function test_init()
176151
local cluster_subscribe_list = {
@@ -188,7 +163,6 @@ local function test_init()
188163
end
189164
test.set_test_init_function(test_init)
190165

191-
-- Test can_handle logic
192166
test.register_coroutine_test(
193167
"Eve Energy sub-driver can_handle should return true for devices with Eve Private Cluster and no Electrical Sensor",
194168
function()
@@ -202,18 +176,6 @@ test.register_coroutine_test(
202176
}
203177
)
204178

205-
test.register_coroutine_test(
206-
"Eve Energy sub-driver can_handle should return false for devices with Electrical Sensor device type",
207-
function()
208-
local eve_energy_can_handle = require("sub_drivers.eve_energy.can_handle")
209-
local result = eve_energy_can_handle(nil, nil, mock_eve_device_using_electrical_sensor)
210-
assert(result == false, "can_handle should return false for Eve device with electrical sensor")
211-
end,
212-
{
213-
min_api_version = 17
214-
}
215-
)
216-
217179
test.register_coroutine_test(
218180
"Eve Energy sub-driver can_handle should return false for devices without Eve Private Cluster",
219181
function()

0 commit comments

Comments
 (0)