@@ -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 = {
@@ -103,6 +109,36 @@ local function battery_level_handler(driver, device, value, zb_rx)
103109 end
104110end
105111
112+ local function mode_switching_handler (driver , device , value , zb_rx )
113+ local btn_evt_cnt = FINGERPRINTS [device :get_model ()].btn_cnt or 1
114+ local allow = device .preferences [MODE_CHANGE ] or false
115+ if allow then
116+ local mode = device :get_field (MODE ) or 1
117+ mode = 3 - mode
118+ device :set_field (MODE , mode , { persist = true })
119+ device :send (cluster_base .write_manufacturer_specific_attribute (device , PRIVATE_CLUSTER_ID , PRIVATE_ATTRIBUTE_ID_E1 ,
120+ MFG_CODE , data_types .Uint8 , mode ))
121+ device :emit_event (capabilities .button .supportedButtonValues (SUPPORTED_BUTTON [mode ],
122+ { visibility = { displayed = false } }))
123+ device :emit_event (capabilities .button .numberOfButtons ({ value = 1 }))
124+ button_utils .emit_event_if_latest_state_missing (device , " main" , capabilities .button , capabilities .button .button .NAME ,
125+ capabilities .button .button .pushed ({ state_change = false }))
126+ if btn_evt_cnt > 1 then
127+ for i = 1 , btn_evt_cnt do
128+ device :emit_component_event (device .profile .components [COMP_LIST [i ]],
129+ capabilities .button .supportedButtonValues (SUPPORTED_BUTTON [mode ],
130+ { visibility = { displayed = false } }))
131+ device :emit_component_event (device .profile .components [COMP_LIST [i ]],
132+ capabilities .button .numberOfButtons ({ value = 1 }))
133+ device :emit_component_event (device .profile .components [COMP_LIST [i ]],
134+ capabilities .button .button .pushed ({ state_change = false }))
135+ button_utils .emit_event_if_latest_state_missing (device , COMP_LIST [i ], capabilities .button ,
136+ capabilities .button .button .NAME , capabilities .button .button .pushed ({ state_change = false }))
137+ end
138+ end
139+ end
140+ end
141+
106142local is_aqara_products = function (opts , driver , device )
107143 local isAqaraProducts = false
108144 if FINGERPRINTS [device :get_model ()] and FINGERPRINTS [device :get_model ()].mfr == device :get_manufacturer () then
122158
123159local function added_handler (self , device )
124160 local btn_evt_cnt = FINGERPRINTS [device :get_model ()].btn_cnt or 1
125-
126- device :emit_event (capabilities .button .supportedButtonValues ({ " pushed" , " held" , " double" },
161+ local mode = device :get_field (MODE ) or 0
162+ local model = device :get_model ()
163+
164+ if mode == 0 then
165+ if model == " lumi.remote.b18ac1" or model == " lumi.remote.b28ac1" then
166+ mode = 1
167+ else
168+ mode = 2
169+ end
170+ end
171+ device :set_field (MODE , mode , { persist = true })
172+ device :emit_event (capabilities .button .supportedButtonValues (SUPPORTED_BUTTON [mode ],
127173 { visibility = { displayed = false } }))
128174 device :emit_event (capabilities .button .numberOfButtons ({ value = 1 }))
129175 button_utils .emit_event_if_latest_state_missing (device , " main" , capabilities .button , capabilities .button .button .NAME ,
@@ -135,7 +181,7 @@ local function added_handler(self, device)
135181 if btn_evt_cnt > 1 then
136182 for i = 1 , btn_evt_cnt do
137183 device :emit_component_event (device .profile .components [COMP_LIST [i ]],
138- capabilities .button .supportedButtonValues ({ " pushed " , " held " , " double " } ,
184+ capabilities .button .supportedButtonValues (SUPPORTED_BUTTON [ mode ] ,
139185 { visibility = { displayed = false } }))
140186 device :emit_component_event (device .profile .components [COMP_LIST [i ]],
141187 capabilities .button .numberOfButtons ({ value = 1 }))
@@ -179,6 +225,9 @@ local aqara_wireless_switch_handler = {
179225 },
180226 [PowerConfiguration .ID ] = {
181227 [PowerConfiguration .attributes .BatteryVoltage .ID ] = battery_level_handler
228+ },
229+ [PRIVATE_CLUSTER_ID ] = {
230+ [PRIVATE_ATTRIBUTE_ID_ALIVE ] = mode_switching_handler
182231 }
183232 }
184233 },
0 commit comments