Skip to content

Commit 653030b

Browse files
Override doConfigure and driverSwitched in other subdrivers
The Aqara Cube and Eve Energy subdrivers need doConfigure and driverSwitched lifecycle event handler overrides to prevent the handlers from running in the main driver, which would result in match_profile running. Also fix nil value error in is_aqara_cube function.
1 parent 3c036b3 commit 653030b

File tree

3 files changed

+61
-34
lines changed

3 files changed

+61
-34
lines changed

drivers/SmartThings/matter-switch/src/aqara-cube/init.lua

+27-4
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,17 @@
1+
-- Copyright 2025 SmartThings
2+
--
3+
-- Licensed under the Apache License, Version 2.0 (the "License");
4+
-- you may not use this file except in compliance with the License.
5+
-- You may obtain a copy of the License at
6+
--
7+
-- http://www.apache.org/licenses/LICENSE-2.0
8+
--
9+
-- Unless required by applicable law or agreed to in writing, software
10+
-- distributed under the License is distributed on an "AS IS" BASIS,
11+
-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
-- See the License for the specific language governing permissions and
13+
-- limitations under the License.
14+
115
local capabilities = require "st.capabilities"
216
local clusters = require "st.matter.clusters"
317
local device_lib = require "st.device"
@@ -19,10 +33,11 @@ local CUBEACTION_TIMER = "__cubeAction_timer"
1933
local CUBEACTION_TIME = 3
2034

2135
local function is_aqara_cube(opts, driver, device)
22-
local name = string.format("%s", device.manufacturer_info.product_name)
23-
if device.network_type == device_lib.NETWORK_TYPE_MATTER and
24-
string.find(name, "Aqara Cube T1 Pro") then
36+
if device.network_type == device_lib.NETWORK_TYPE_MATTER then
37+
local name = string.format("%s", device.manufacturer_info.product_name)
38+
if string.find(name, "Aqara Cube T1 Pro") then
2539
return true
40+
end
2641
end
2742
return false
2843
end
@@ -186,6 +201,12 @@ local function info_changed(driver, device, event, args)
186201
end
187202
end
188203

204+
-- override do_configure to prevent it running in the main driver
205+
local function do_configure(driver, device) end
206+
207+
-- override driver_switched to prevent it running in the main driver
208+
local function driver_switched(driver, device) end
209+
189210
local function initial_press_event_handler(driver, device, ib, response)
190211
if get_field_for_endpoint(device, INITIAL_PRESS_ONLY, ib.endpoint_id) then
191212
local map = device:get_field(COMPONENT_TO_ENDPOINT_MAP_BUTTON) or {}
@@ -214,7 +235,9 @@ local aqara_cube_handler = {
214235
lifecycle_handlers = {
215236
init = device_init,
216237
added = device_added,
217-
infoChanged = info_changed
238+
infoChanged = info_changed,
239+
doConfigure = do_configure,
240+
driverSwitched = driver_switched
218241
},
219242
matter_handlers = {
220243
attr = {

drivers/SmartThings/matter-switch/src/eve-energy/init.lua

+9-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
-- Copyright 2023 SmartThings
1+
-- Copyright 2025 SmartThings
22
--
33
-- Licensed under the Apache License, Version 2.0 (the "License");
44
-- you may not use this file except in compliance with the License.
@@ -277,6 +277,12 @@ local function device_removed(driver, device)
277277
delete_poll_schedule(device)
278278
end
279279

280+
-- override do_configure to prevent it running in the main driver
281+
local function do_configure(driver, device) end
282+
283+
-- override driver_switched to prevent it running in the main driver
284+
local function driver_switched(driver, device) end
285+
280286
local function handle_refresh(self, device)
281287
requestData(device)
282288
end
@@ -368,6 +374,8 @@ local eve_energy_handler = {
368374
init = device_init,
369375
added = device_added,
370376
removed = device_removed,
377+
doConfigure = do_configure,
378+
driverSwitched = driver_switched
371379
},
372380
matter_handlers = {
373381
attr = {

drivers/SmartThings/matter-switch/src/init.lua

+25-29
Original file line numberDiff line numberDiff line change
@@ -520,9 +520,6 @@ local function assign_child_profile(device, child_ep)
520520
end
521521

522522
local function configure_buttons(device)
523-
if device.network_type == device_lib.NETWORK_TYPE_CHILD then
524-
return
525-
end
526523
local ms_eps = device:get_endpoints(clusters.Switch.ID, {feature_bitmap=clusters.Switch.types.SwitchFeature.MOMENTARY_SWITCH})
527524
local msr_eps = device:get_endpoints(clusters.Switch.ID, {feature_bitmap=clusters.Switch.types.SwitchFeature.MOMENTARY_SWITCH_RELEASE})
528525
local msl_eps = device:get_endpoints(clusters.Switch.ID, {feature_bitmap=clusters.Switch.types.SwitchFeature.MOMENTARY_SWITCH_LONG_PRESS})
@@ -689,35 +686,34 @@ local function detect_bridge(device)
689686
end
690687

691688
local function device_init(driver, device)
692-
if device.network_type ~= device_lib.NETWORK_TYPE_MATTER then
693-
return
694-
end
695-
check_field_name_updates(device)
696-
device:set_component_to_endpoint_fn(component_to_endpoint)
697-
device:set_endpoint_to_component_fn(endpoint_to_component)
698-
if device:get_field(IS_PARENT_CHILD_DEVICE) then
699-
device:set_find_child(find_child)
700-
end
701-
local main_endpoint = find_default_endpoint(device)
702-
-- ensure subscription to all endpoint attributes- including those mapped to child devices
703-
for _, ep in ipairs(device.endpoints) do
704-
if ep.endpoint_id ~= main_endpoint then
705-
local id = 0
706-
for _, dt in ipairs(ep.device_types) do
707-
id = math.max(id, dt.device_type_id)
708-
end
709-
for _, attr in pairs(device_type_attribute_map[id] or {}) do
710-
if id == GENERIC_SWITCH_ID and
711-
attr ~= clusters.PowerSource.attributes.BatPercentRemaining and
712-
attr ~= clusters.PowerSource.attributes.BatChargeLevel then
713-
device:add_subscribed_event(attr)
714-
else
715-
device:add_subscribed_attribute(attr)
689+
if device.network_type == device_lib.NETWORK_TYPE_MATTER then
690+
check_field_name_updates(device)
691+
device:set_component_to_endpoint_fn(component_to_endpoint)
692+
device:set_endpoint_to_component_fn(endpoint_to_component)
693+
if device:get_field(IS_PARENT_CHILD_DEVICE) then
694+
device:set_find_child(find_child)
695+
end
696+
local main_endpoint = find_default_endpoint(device)
697+
-- ensure subscription to all endpoint attributes- including those mapped to child devices
698+
for _, ep in ipairs(device.endpoints) do
699+
if ep.endpoint_id ~= main_endpoint then
700+
local id = 0
701+
for _, dt in ipairs(ep.device_types) do
702+
id = math.max(id, dt.device_type_id)
703+
end
704+
for _, attr in pairs(device_type_attribute_map[id] or {}) do
705+
if id == GENERIC_SWITCH_ID and
706+
attr ~= clusters.PowerSource.attributes.BatPercentRemaining and
707+
attr ~= clusters.PowerSource.attributes.BatChargeLevel then
708+
device:add_subscribed_event(attr)
709+
else
710+
device:add_subscribed_attribute(attr)
711+
end
716712
end
717713
end
718714
end
715+
device:subscribe()
719716
end
720-
device:subscribe()
721717
end
722718

723719
local function match_profile(driver, device)
@@ -1308,7 +1304,7 @@ local function info_changed(driver, device, event, args)
13081304
if device.profile.id ~= args.old_st_store.profile.id then
13091305
device:subscribe()
13101306
local button_eps = device:get_endpoints(clusters.Switch.ID, {feature_bitmap=clusters.Switch.types.SwitchFeature.MOMENTARY_SWITCH})
1311-
if #button_eps > 0 and device.network_type ~= device_lib.NETWORK_TYPE_CHILD then
1307+
if #button_eps > 0 and device.network_type == device_lib.NETWORK_TYPE_MATTER then
13121308
configure_buttons(device)
13131309
end
13141310
end

0 commit comments

Comments
 (0)