Skip to content

Commit aeafdff

Browse files
committed
fixup! update test and fix syntax bug
1 parent 8e59891 commit aeafdff

File tree

2 files changed

+11
-7
lines changed

2 files changed

+11
-7
lines changed

drivers/SmartThings/matter-switch/src/init.lua

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -477,8 +477,10 @@ local function component_to_endpoint(device, component)
477477
end
478478

479479
local function endpoint_to_component(device, ep)
480+
print("wtf")
480481
local map = device:get_field(COMPONENT_TO_ENDPOINT_MAP) or {}
481482
for component, endpoint in pairs(map) do
483+
print("##", component, endpoint)
482484
if endpoint == ep then
483485
return component
484486
end
@@ -561,6 +563,7 @@ local function configure_buttons(device)
561563
end
562564

563565
if supportedButtonValues_event then
566+
print("@@", endpoint_to_component(device, ep))
564567
device:emit_event_for_endpoint(ep, supportedButtonValues_event)
565568
end
566569
device:emit_event_for_endpoint(ep, capabilities.button.button.pushed({state_change = false}))
@@ -1412,8 +1415,8 @@ local function device_added(driver, device)
14121415
local switch_eps = device:get_endpoints(clusters.OnOff.ID)
14131416
table.sort(switch_eps)
14141417
local electrical_tags = ""
1415-
if electrical_sensor_eps[1].power then electrical_tags = electrical_tags + "-power" end
1416-
if electrical_sensor_eps[1].energy then electrical_tags = electrical_tags + "-energy-powerConsumption" end
1418+
if electrical_sensor_eps[1].power then electrical_tags = electrical_tags .. "-power" end
1419+
if electrical_sensor_eps[1].energy then electrical_tags = electrical_tags .. "-energy-powerConsumption" end
14171420
device:set_field(profiling_data.ELECTRICAL_TOPOLOGY, {topology = clusters.PowerTopology.types.Feature.NODE_TOPOLOGY, tags_on_ep = {[switch_eps[1]] = electrical_tags}})
14181421
device:set_field(ELECTRICAL_SENSOR_EPS, nil)
14191422
end

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

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ local aqara_mock_device = test.mock_device.build_test_matter_device({
3939
{cluster_id = clusters.Basic.ID, cluster_type = "SERVER"},
4040
{cluster_id = clusters.ElectricalPowerMeasurement.ID, cluster_type = "SERVER", cluster_revision = 1, feature_map = 2 },
4141
{cluster_id = clusters.ElectricalEnergyMeasurement.ID, cluster_type = "SERVER", cluster_revision = 1, feature_map = 5 },
42-
{cluster_id = clusters.PowerTopology.ID, cluster_type = "SERVER", cluster_revision = 1, feature_map = 2 } -- NODE_TOPOLOGY
42+
{cluster_id = clusters.PowerTopology.ID, cluster_type = "SERVER", cluster_revision = 1, feature_map = 1 } -- NODE_TOPOLOGY
4343
},
4444
device_types = {
4545
{device_type_id = 0x0016, device_type_revision = 1}, -- RootNode
@@ -178,11 +178,12 @@ local function test_init()
178178
end
179179
end
180180
test.socket.matter:__expect_send({aqara_mock_device.id, subscribe_request})
181-
aqara_mock_device:set_field("__ELECTRICAL_TOPOLOGY", {topology = clusters.PowerTopology.types.Feature.NODE_TOPOLOGY, tags_on_ep = {[1] = "-power-energy-powerConsumption"}}, {persist = false}) -- since we're assuming this would have happened during device_added in this case.
181+
182+
-- Test added -> doConfigure logic
183+
test.socket.device_lifecycle:__queue_receive({ aqara_mock_device.id, "added" })
184+
test.socket.matter:__expect_send({aqara_mock_device.id, subscribe_request})
182185
test.socket.device_lifecycle:__queue_receive({ aqara_mock_device.id, "doConfigure" })
183-
test.mock_devices_api._expected_device_updates[aqara_mock_device.device_id] = "00000000-1111-2222-3333-000000000001"
184-
test.mock_devices_api._expected_device_updates[1] = {device_id = "00000000-1111-2222-3333-000000000001"}
185-
test.mock_devices_api._expected_device_updates[1].metadata = {deviceId="00000000-1111-2222-3333-000000000001", profileReference="4-button"}
186+
aqara_mock_device:expect_metadata_update({ profile = "4-button" })
186187
aqara_mock_device:expect_metadata_update({ provisioning_state = "PROVISIONED" })
187188
test.mock_device.add_test_device(aqara_mock_device)
188189
-- to test powerConsumptionReport

0 commit comments

Comments
 (0)