Skip to content

Commit

Permalink
Aqara Wireless Remote Switch E1 (Single Rocker) (#1249)
Browse files Browse the repository at this point in the history
* Aqara Wireless Remote Switch E1 (Single Rocker)

* fixed formatting & comment issues

* remove unnecessary comment

* add note

---------

Co-authored-by: lelandblue <[email protected]>
  • Loading branch information
Hongming6 and lelandblue authored Mar 25, 2024
1 parent 5fafaed commit 287fb8a
Show file tree
Hide file tree
Showing 3 changed files with 68 additions and 23 deletions.
5 changes: 5 additions & 0 deletions drivers/SmartThings/zigbee-button/fingerprints.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@ zigbeeManufacturer:
manufacturer: LUMI
model: lumi.remote.b1acn02
deviceProfileName: one-button-battery
- id: "LUMI/lumi.remote.acn003"
deviceLabel: Aqara Wireless Remote Switch E1 (Single Rocker)
manufacturer: LUMI
model: lumi.remote.acn003
deviceProfileName: one-button-battery
- id: "HEIMAN/SOS-EM"
deviceLabel: HEIMAN Button
manufacturer: HEIMAN
Expand Down
23 changes: 17 additions & 6 deletions drivers/SmartThings/zigbee-button/src/aqara/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,16 @@ local capabilities = require "st.capabilities"

local PowerConfiguration = clusters.PowerConfiguration
local PRIVATE_CLUSTER_ID = 0xFCC0
local PRIVATE_ATTRIBUTE_ID = 0x0009
local PRIVATE_ATTRIBUTE_ID_T1 = 0x0009
local PRIVATE_ATTRIBUTE_ID_E1 = 0x0125
local MFG_CODE = 0x115F

local MULTISTATE_INPUT_CLUSTER_ID = 0x0012
local PRESENT_ATTRIBUTE_ID = 0x0055

local FINGERPRINTS = {
{ mfr = "LUMI", model = "lumi.remote.b1acn02" }
{ mfr = "LUMI", model = "lumi.remote.b1acn02" },
{ mfr = "LUMI", model = "lumi.remote.acn003" }
}

local configuration = {
Expand Down Expand Up @@ -79,9 +81,19 @@ local function device_init(driver, device)
end
end

local function added_handler(self, device)
device:send(cluster_base.write_manufacturer_specific_attribute(device,
PRIVATE_CLUSTER_ID, PRIVATE_ATTRIBUTE_ID, MFG_CODE, data_types.Uint8, 1))
local function added_handler(self, device)
if device:get_model() == "lumi.remote.b1acn02" then
device:send(cluster_base.write_manufacturer_specific_attribute(device,
PRIVATE_CLUSTER_ID, PRIVATE_ATTRIBUTE_ID_T1, MFG_CODE, data_types.Uint8, 1))
elseif device:get_model() == "lumi.remote.acn003" then
device:send(cluster_base.write_manufacturer_specific_attribute(device,
PRIVATE_CLUSTER_ID, PRIVATE_ATTRIBUTE_ID_E1, MFG_CODE, data_types.Uint8, 2))
end
-- when the wireless switch T1 accesses the network, the gateway sends
-- private attribute 0009 to make the device no longer distinguish
-- between the standard gateway and the aqara gateway.
-- When wireless switch E1 is connected to the network, the gateway sends
-- private attribute 0125 to enable the device to send double-click and long-press packets.
device:emit_event(capabilities.button.supportedButtonValues({"pushed","held","double"}, {visibility = { displayed = false }}))
device:emit_event(capabilities.button.numberOfButtons({value = 1}))
device:emit_event(capabilities.button.button.pushed({state_change = false}))
Expand All @@ -105,4 +117,3 @@ local aqara_wireless_switch_handler = {
}

return aqara_wireless_switch_handler

63 changes: 46 additions & 17 deletions drivers/SmartThings/zigbee-button/src/test/test_aqara_button.lua
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,22 @@ local PowerConfiguration = clusters.PowerConfiguration

local MFG_CODE = 0x115F
local PRIVATE_CLUSTER_ID = 0xFCC0
local PRIVATE_ATTRIBUTE_ID = 0x0009
local PRIVATE_ATTRIBUTE_ID_T1 = 0x0009
local PRIVATE_ATTRIBUTE_ID_E1 = 0x0125

local mock_device_e1 = test.mock_device.build_test_zigbee_device(
{
profile = t_utils.get_profile_definition("one-button-battery.yml"),
zigbee_endpoints = {
[1] = {
id = 1,
manufacturer = "LUMI",
model = "lumi.remote.acn003",
server_clusters = { 0x0001, 0x0012 }
}
}
}
)

local mock_device_t1 = test.mock_device.build_test_zigbee_device(
{
Expand All @@ -45,18 +59,36 @@ local mock_device_t1 = test.mock_device.build_test_zigbee_device(

zigbee_test_utils.prepare_zigbee_env_info()
local function test_init()
test.mock_device.add_test_device(mock_device_e1)
test.mock_device.add_test_device(mock_device_t1)
end

test.set_test_init_function(test_init)

test.register_coroutine_test(
"Handle added lifecycle",
"Handle added lifecycle -- e1",
function()
test.socket.device_lifecycle:__queue_receive({ mock_device_e1.id, "added" })

test.socket.zigbee:__expect_send({ mock_device_e1.id,
cluster_base.write_manufacturer_specific_attribute(mock_device_e1, PRIVATE_CLUSTER_ID, PRIVATE_ATTRIBUTE_ID_E1, MFG_CODE,
data_types.Uint8, 2) })


test.socket.capability:__expect_send(mock_device_e1:generate_test_message("main", capabilities.button.supportedButtonValues({"pushed","held","double"}, {visibility = { displayed = false }})))
test.socket.capability:__expect_send(mock_device_e1:generate_test_message("main", capabilities.button.numberOfButtons({value = 1})))
test.socket.capability:__expect_send(mock_device_e1:generate_test_message("main", capabilities.button.button.pushed({state_change = false})))
test.socket.capability:__expect_send(mock_device_e1:generate_test_message("main", capabilities.battery.battery(100)))
end
)

test.register_coroutine_test(
"Handle added lifecycle -- t1",
function()
test.socket.device_lifecycle:__queue_receive({ mock_device_t1.id, "added" })

test.socket.zigbee:__expect_send({ mock_device_t1.id,
cluster_base.write_manufacturer_specific_attribute(mock_device_t1, PRIVATE_CLUSTER_ID, PRIVATE_ATTRIBUTE_ID, MFG_CODE,
cluster_base.write_manufacturer_specific_attribute(mock_device_t1, PRIVATE_CLUSTER_ID, PRIVATE_ATTRIBUTE_ID_T1, MFG_CODE,
data_types.Uint8, 1) })


Expand All @@ -74,26 +106,25 @@ test.register_coroutine_test(
{ PRESENT_ATTRIBUTE_ID, data_types.Uint16.ID, 0x0001 }
}
test.socket.zigbee:__queue_receive({
mock_device_t1.id,
zigbee_test_utils.build_attribute_report(mock_device_t1, MULTISTATE_INPUT_CLUSTER_ID, attr_report_data, MFG_CODE)
mock_device_e1.id,
zigbee_test_utils.build_attribute_report(mock_device_e1, MULTISTATE_INPUT_CLUSTER_ID, attr_report_data, MFG_CODE)
})
test.socket.capability:__expect_send(mock_device_t1:generate_test_message("main",
test.socket.capability:__expect_send(mock_device_e1:generate_test_message("main",
capabilities.button.button.pushed({state_change = true})))
end
)


test.register_coroutine_test(
"Reported button should be handled: double true",
function()
local attr_report_data = {
{ PRESENT_ATTRIBUTE_ID, data_types.Uint16.ID, 0x0002 }
}
test.socket.zigbee:__queue_receive({
mock_device_t1.id,
zigbee_test_utils.build_attribute_report(mock_device_t1, MULTISTATE_INPUT_CLUSTER_ID, attr_report_data, MFG_CODE)
mock_device_e1.id,
zigbee_test_utils.build_attribute_report(mock_device_e1, MULTISTATE_INPUT_CLUSTER_ID, attr_report_data, MFG_CODE)
})
test.socket.capability:__expect_send(mock_device_t1:generate_test_message("main",
test.socket.capability:__expect_send(mock_device_e1:generate_test_message("main",
capabilities.button.button.double({state_change = true})))
end
)
Expand All @@ -105,10 +136,10 @@ test.register_coroutine_test(
{ PRESENT_ATTRIBUTE_ID, data_types.Uint16.ID, 0x0000 }
}
test.socket.zigbee:__queue_receive({
mock_device_t1.id,
zigbee_test_utils.build_attribute_report(mock_device_t1, MULTISTATE_INPUT_CLUSTER_ID, attr_report_data, MFG_CODE)
mock_device_e1.id,
zigbee_test_utils.build_attribute_report(mock_device_e1, MULTISTATE_INPUT_CLUSTER_ID, attr_report_data, MFG_CODE)
})
test.socket.capability:__expect_send(mock_device_t1:generate_test_message("main",
test.socket.capability:__expect_send(mock_device_e1:generate_test_message("main",
capabilities.button.button.held({state_change = true})))
end
)
Expand All @@ -119,16 +150,14 @@ test.register_message_test(
{
channel = "zigbee",
direction = "receive",
message = { mock_device_t1.id, PowerConfiguration.attributes.BatteryVoltage:build_test_attr_report(mock_device_t1, 30) }
message = { mock_device_e1.id, PowerConfiguration.attributes.BatteryVoltage:build_test_attr_report(mock_device_e1, 30) }
},
{
channel = "capability",
direction = "send",
message = mock_device_t1:generate_test_message("main", capabilities.battery.battery(100))
message = mock_device_e1:generate_test_message("main", capabilities.battery.battery(100))
}
}
)



test.run_registered_tests()

0 comments on commit 287fb8a

Please sign in to comment.