@@ -19,11 +19,15 @@ local data_types = require "st.zigbee.data_types"
1919local capabilities = require " st.capabilities"
2020local button_utils = require " button_utils"
2121
22+ local MODE = " devicemode"
23+ local MODE_CHANGE = " stse.allowOperationModeChange"
24+ local SUPPORTED_BUTTON = { { " pushed" }, { " pushed" , " held" , " double" } }
2225
2326local PowerConfiguration = clusters .PowerConfiguration
2427local PRIVATE_CLUSTER_ID = 0xFCC0
2528local PRIVATE_ATTRIBUTE_ID_T1 = 0x0009
2629local PRIVATE_ATTRIBUTE_ID_E1 = 0x0125
30+ local PRIVATE_ATTRIBUTE_ID_ALIVE = 0x00F7
2731local MFG_CODE = 0x115F
2832
2933local MULTISTATE_INPUT_CLUSTER_ID = 0x0012
@@ -34,7 +38,9 @@ local FINGERPRINTS = {
3438 [" lumi.remote.b1acn02" ] = { mfr = " LUMI" , btn_cnt = 1 },
3539 [" lumi.remote.acn003" ] = { mfr = " LUMI" , btn_cnt = 1 },
3640 [" lumi.remote.b186acn03" ] = { mfr = " LUMI" , btn_cnt = 1 },
37- [" lumi.remote.b286acn03" ] = { mfr = " LUMI" , btn_cnt = 3 }
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 }
3844}
3945
4046local configuration = {
@@ -81,6 +87,36 @@ local function battery_level_handler(driver, device, value, zb_rx)
8187 device :emit_event (capabilities .batteryLevel .battery (batteryLevel ))
8288end
8389
90+ local function mode_switching_handler (driver , device , value , zb_rx )
91+ local btn_evt_cnt = FINGERPRINTS [device :get_model ()].btn_cnt or 1
92+ local allow = device .preferences [MODE_CHANGE ] or false
93+ if allow then
94+ local mode = device :get_field (MODE ) or 1
95+ mode = 3 - mode
96+ device :set_field (MODE , mode , { persist = true })
97+ device :send (cluster_base .write_manufacturer_specific_attribute (device , PRIVATE_CLUSTER_ID , PRIVATE_ATTRIBUTE_ID_E1 ,
98+ MFG_CODE , data_types .Uint8 , mode ))
99+ device :emit_event (capabilities .button .supportedButtonValues (SUPPORTED_BUTTON [mode ],
100+ { visibility = { displayed = false } }))
101+ device :emit_event (capabilities .button .numberOfButtons ({ value = 1 }))
102+ button_utils .emit_event_if_latest_state_missing (device , " main" , capabilities .button , capabilities .button .button .NAME ,
103+ capabilities .button .button .pushed ({ state_change = false }))
104+ if btn_evt_cnt > 1 then
105+ for i = 1 , btn_evt_cnt do
106+ device :emit_component_event (device .profile .components [COMP_LIST [i ]],
107+ capabilities .button .supportedButtonValues (SUPPORTED_BUTTON [mode ],
108+ { visibility = { displayed = false } }))
109+ device :emit_component_event (device .profile .components [COMP_LIST [i ]],
110+ capabilities .button .numberOfButtons ({ value = 1 }))
111+ device :emit_component_event (device .profile .components [COMP_LIST [i ]],
112+ capabilities .button .button .pushed ({ state_change = false }))
113+ button_utils .emit_event_if_latest_state_missing (device , COMP_LIST [i ], capabilities .button ,
114+ capabilities .button .button .NAME , capabilities .button .button .pushed ({ state_change = false }))
115+ end
116+ end
117+ end
118+ end
119+
84120local is_aqara_products = function (opts , driver , device )
85121 local isAqaraProducts = false
86122 if FINGERPRINTS [device :get_model ()] and FINGERPRINTS [device :get_model ()].mfr == device :get_manufacturer () then
100136
101137local function added_handler (self , device )
102138 local btn_evt_cnt = FINGERPRINTS [device :get_model ()].btn_cnt or 1
103-
104- device :emit_event (capabilities .button .supportedButtonValues ({ " pushed" , " held" , " double" },
139+ local mode = device :get_field (MODE ) or 0
140+ local model = device :get_model ()
141+
142+ if mode == 0 then
143+ if model == " lumi.remote.b18ac1" or model == " lumi.remote.b28ac1" then
144+ mode = 1
145+ else
146+ mode = 2
147+ end
148+ end
149+ device :set_field (MODE , mode , { persist = true })
150+ device :emit_event (capabilities .button .supportedButtonValues (SUPPORTED_BUTTON [mode ],
105151 { visibility = { displayed = false } }))
106152 device :emit_event (capabilities .button .numberOfButtons ({ value = 1 }))
107153 button_utils .emit_event_if_latest_state_missing (device , " main" , capabilities .button , capabilities .button .button .NAME ,
@@ -113,7 +159,7 @@ local function added_handler(self, device)
113159 if btn_evt_cnt > 1 then
114160 for i = 1 , btn_evt_cnt do
115161 device :emit_component_event (device .profile .components [COMP_LIST [i ]],
116- capabilities .button .supportedButtonValues ({ " pushed " , " held " , " double " } ,
162+ capabilities .button .supportedButtonValues (SUPPORTED_BUTTON [ mode ] ,
117163 { visibility = { displayed = false } }))
118164 device :emit_component_event (device .profile .components [COMP_LIST [i ]],
119165 capabilities .button .numberOfButtons ({ value = 1 }))
@@ -157,6 +203,9 @@ local aqara_wireless_switch_handler = {
157203 },
158204 [PowerConfiguration .ID ] = {
159205 [PowerConfiguration .attributes .BatteryVoltage .ID ] = battery_level_handler
206+ },
207+ [PRIVATE_CLUSTER_ID ] = {
208+ [PRIVATE_ATTRIBUTE_ID_ALIVE ] = mode_switching_handler
160209 }
161210 }
162211 },
0 commit comments