Skip to content
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

[Aqara] Smart Wall Switch(With Neutral, No Neutral) #963

Merged
merged 3 commits into from
Nov 2, 2023
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ local PRIVATE_ATTRIBUTE_ID = 0x0009
local MFG_CODE = 0x115F

local FINGERPRINTS = {
{ mfr = "LUMI", model = "lumi.switch.n1acn1", children = 1, child_profile = "" },
{ mfr = "LUMI", model = "lumi.switch.n2acn1", children = 2, child_profile = "aqara-switch-child" },
{ mfr = "LUMI", model = "lumi.switch.n3acn1", children = 3, child_profile = "aqara-switch-child" },
{ mfr = "LUMI", model = "lumi.switch.n1acn1", children = 1, child_profile = "" },
{ mfr = "LUMI", model = "lumi.switch.n2acn1", children = 2, child_profile = "aqara-switch-child" },
{ mfr = "LUMI", model = "lumi.switch.n3acn1", children = 3, child_profile = "aqara-switch-child" },
{ mfr = "LUMI", model = "lumi.switch.b2laus01", children = 2, child_profile = "aqara-switch-child" }
}

Expand Down Expand Up @@ -70,18 +70,20 @@ local function device_added(driver, device)
end

-- for wireless button
device:emit_event(capabilities.button.supportedButtonValues({ "pushed" },
{ visibility = { displayed = false } }))
device:emit_event(capabilities.button.numberOfButtons({ value = children_amount },
{ visibility = { displayed = false } }))
device:emit_event(capabilities.button.button.pushed({ state_change = false }))

device:emit_event(capabilities.powerMeter.power({ value = 0.0, unit = "W" }))
device:emit_event(capabilities.energyMeter.energy({ value = 0.0, unit = "Wh" }))

device:send(cluster_base.write_manufacturer_specific_attribute(device,
PRIVATE_CLUSTER_ID, PRIVATE_ATTRIBUTE_ID, MFG_CODE, data_types.Uint8, 0x01)) -- private
elseif device.network_type == "DEVICE_EDGE_CHILD" then
device:emit_event(capabilities.button.numberOfButtons({ value = 1 },
{ visibility = { displayed = false } }))
end
device:emit_event(capabilities.button.supportedButtonValues({ "pushed" },
{ visibility = { displayed = false } }))
device:emit_event(capabilities.button.button.pushed({ state_change = false }))
end

local function device_init(self, device)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ local OnOff = clusters.OnOff
local AnalogInput = clusters.AnalogInput

local PRIVATE_CLUSTER_ID = 0xFCC0
local PRIVATE_ATTRIBUTE_ID = 0x0009
local MFG_CODE = 0x115F
local RESTORE_POWER_STATE_ATTRIBUTE_ID = 0x0201
local CHANGE_TO_WIRELESS_SWITCH_ATTRIBUTE_ID = 0x0200
Expand Down Expand Up @@ -61,15 +62,55 @@ local mock_child = test.mock_device.build_test_child_device({
parent_assigned_child_key = string.format("%02X", 2)
})

local mock_child2 = test.mock_device.build_test_child_device({
profile = t_utils.get_profile_definition("aqara-switch-child.yml"),
device_network_id = string.format("%04X:%02X", mock_device:get_short_address(), 3),
parent_device_id = mock_device.id,
parent_assigned_child_key = string.format("%02X", 3)
})

zigbee_test_utils.prepare_zigbee_env_info()

local function test_init()
test.mock_device.add_test_device(mock_device)
test.mock_device.add_test_device(mock_child)
test.mock_device.add_test_device(mock_child2)
end

test.set_test_init_function(test_init)

test.register_coroutine_test(
"Lifecycle - added test",
function()
test.socket.zigbee:__set_channel_ordering("relaxed")
test.socket.device_lifecycle:__queue_receive({ mock_device.id, "added" })
test.socket.capability:__expect_send(mock_device:generate_test_message("main", capabilities.button.numberOfButtons({ value = 3 },
{ visibility = { displayed = false } })))
test.socket.capability:__expect_send(mock_device:generate_test_message("main", capabilities.powerMeter.power({ value = 0.0, unit = "W" })))
test.socket.capability:__expect_send(mock_device:generate_test_message("main", capabilities.energyMeter.energy({ value = 0.0, unit = "Wh" })))
test.socket.zigbee:__expect_send({ mock_device.id,
cluster_base.write_manufacturer_specific_attribute(mock_device, PRIVATE_CLUSTER_ID, PRIVATE_ATTRIBUTE_ID, MFG_CODE,
data_types.Uint8, 1) })
test.socket.capability:__expect_send(mock_device:generate_test_message("main", capabilities.button.supportedButtonValues({ "pushed" },
{ visibility = { displayed = false } })))
test.socket.capability:__expect_send(mock_device:generate_test_message("main", capabilities.button.button.pushed({ state_change = false })))

end
)

test.register_coroutine_test(
"Lifecycle - added test",
function()
test.socket.zigbee:__set_channel_ordering("relaxed")
test.socket.device_lifecycle:__queue_receive({ mock_child.id, "added" })
test.socket.capability:__expect_send(mock_child:generate_test_message("main", capabilities.button.numberOfButtons({ value = 1 },
{ visibility = { displayed = false } })))
test.socket.capability:__expect_send(mock_child:generate_test_message("main", capabilities.button.supportedButtonValues({ "pushed" },
{ visibility = { displayed = false } })))
test.socket.capability:__expect_send(mock_child:generate_test_message("main", capabilities.button.button.pushed({ state_change = false })))
end
)

test.register_coroutine_test(
"Refresh device should read all necessary attributes",
function()
Expand Down
Loading