Skip to content

Commit 52c9490

Browse files
authored
Merge pull request #2632 from seojune79/Aqara-WirelessRemoteSwitch-BatteryInfo
[Aqara/Wireless Remote Switch] Correcting Incorrect Battery Information
2 parents 2a14c82 + 416fdd3 commit 52c9490

File tree

1 file changed

+15
-13
lines changed
  • drivers/SmartThings/zigbee-button/src/aqara

1 file changed

+15
-13
lines changed

drivers/SmartThings/zigbee-button/src/aqara/init.lua

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -34,13 +34,13 @@ local MULTISTATE_INPUT_CLUSTER_ID = 0x0012
3434
local PRESENT_ATTRIBUTE_ID = 0x0055
3535

3636
local COMP_LIST = { "button1", "button2", "all" }
37-
local FINGERPRINTS = {
38-
["lumi.remote.b1acn02"] = { mfr = "LUMI", btn_cnt = 1 },
39-
["lumi.remote.acn003"] = { mfr = "LUMI", btn_cnt = 1 },
40-
["lumi.remote.b186acn03"] = { mfr = "LUMI", btn_cnt = 1 },
41-
["lumi.remote.b286acn03"] = { mfr = "LUMI", btn_cnt = 3 },
42-
["lumi.remote.b18ac1"] = { mfr = "LUMI", btn_cnt = 1 },
43-
["lumi.remote.b28ac1"] = { mfr = "LUMI", btn_cnt = 3 }
37+
local AQARA_REMOTE_SWITCH = {
38+
["lumi.remote.b1acn02"] = { mfr = "LUMI", btn_cnt = 1, type = "CR2032", quantity = 1 }, -- Aqara Wireless Mini Switch T1
39+
["lumi.remote.acn003"] = { mfr = "LUMI", btn_cnt = 1, type = "CR2032", quantity = 1 }, -- Aqara Wireless Remote Switch E1 (Single Rocker)
40+
["lumi.remote.b186acn03"] = { mfr = "LUMI", btn_cnt = 1, type = "CR2032", quantity = 1 }, -- Aqara Wireless Remote Switch T1 (Single Rocker)
41+
["lumi.remote.b286acn03"] = { mfr = "LUMI", btn_cnt = 3, type = "CR2032", quantity = 1 }, -- Aqara Wireless Remote Switch T1 (Double Rocker)
42+
["lumi.remote.b18ac1"] = { mfr = "LUMI", btn_cnt = 1, type = "CR2450", quantity = 1 }, -- Aqara Wireless Remote Switch H1 (Single Rocker)
43+
["lumi.remote.b28ac1"] = { mfr = "LUMI", btn_cnt = 3, type = "CR2450", quantity = 1 } -- Aqara Wireless Remote Switch H1 (Double Rocker)
4444
}
4545

4646
local configuration = {
@@ -65,7 +65,7 @@ local configuration = {
6565
local function present_value_attr_handler(driver, device, value, zb_rx)
6666
if value.value < 0xFF then
6767
local end_point = zb_rx.address_header.src_endpoint.value
68-
local btn_evt_cnt = FINGERPRINTS[device:get_model()].btn_cnt or 1
68+
local btn_evt_cnt = AQARA_REMOTE_SWITCH[device:get_model()].btn_cnt or 1
6969
local evt = capabilities.button.button.held({ state_change = true })
7070
if value.value == 1 then
7171
evt = capabilities.button.button.pushed({ state_change = true })
@@ -110,7 +110,7 @@ local function battery_level_handler(driver, device, value, zb_rx)
110110
end
111111

112112
local function mode_switching_handler(driver, device, value, zb_rx)
113-
local btn_evt_cnt = FINGERPRINTS[device:get_model()].btn_cnt or 1
113+
local btn_evt_cnt = AQARA_REMOTE_SWITCH[device:get_model()].btn_cnt or 1
114114
local allow = device.preferences[MODE_CHANGE] or false
115115
if allow then
116116
local mode = device:get_field(MODE) or 1
@@ -141,7 +141,7 @@ end
141141

142142
local is_aqara_products = function(opts, driver, device)
143143
local isAqaraProducts = false
144-
if FINGERPRINTS[device:get_model()] and FINGERPRINTS[device:get_model()].mfr == device:get_manufacturer() then
144+
if AQARA_REMOTE_SWITCH[device:get_model()] and AQARA_REMOTE_SWITCH[device:get_model()].mfr == device:get_manufacturer() then
145145
isAqaraProducts = true
146146
end
147147
return isAqaraProducts
@@ -157,9 +157,11 @@ local function device_init(driver, device)
157157
end
158158

159159
local function added_handler(self, device)
160-
local btn_evt_cnt = FINGERPRINTS[device:get_model()].btn_cnt or 1
160+
local btn_evt_cnt = AQARA_REMOTE_SWITCH[device:get_model()].btn_cnt or 1
161161
local mode = device:get_field(MODE) or 0
162162
local model = device:get_model()
163+
local type = AQARA_REMOTE_SWITCH[device:get_model()].type or "CR2032"
164+
local quantity = AQARA_REMOTE_SWITCH[device:get_model()].quantity or 1
163165

164166
if mode == 0 then
165167
if model == "lumi.remote.b18ac1" or model == "lumi.remote.b28ac1" then
@@ -175,8 +177,8 @@ local function added_handler(self, device)
175177
button_utils.emit_event_if_latest_state_missing(device, "main", capabilities.button, capabilities.button.button.NAME,
176178
capabilities.button.button.pushed({ state_change = false }))
177179
device:emit_event(capabilities.batteryLevel.battery.normal())
178-
device:emit_event(capabilities.batteryLevel.type("CR2032"))
179-
device:emit_event(capabilities.batteryLevel.quantity(1))
180+
device:emit_event(capabilities.batteryLevel.type(type))
181+
device:emit_event(capabilities.batteryLevel.quantity(quantity))
180182

181183
if btn_evt_cnt > 1 then
182184
for i = 1, btn_evt_cnt do

0 commit comments

Comments
 (0)