Skip to content

Commit ea07e1b

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 ea07e1b

File tree

3 files changed

+60
-30
lines changed

3 files changed

+60
-30
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

+24-25
Original file line numberDiff line numberDiff line change
@@ -689,35 +689,34 @@ local function detect_bridge(device)
689689
end
690690

691691
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)
692+
if device.network_type == device_lib.NETWORK_TYPE_MATTER then
693+
check_field_name_updates(device)
694+
device:set_component_to_endpoint_fn(component_to_endpoint)
695+
device:set_endpoint_to_component_fn(endpoint_to_component)
696+
if device:get_field(IS_PARENT_CHILD_DEVICE) then
697+
device:set_find_child(find_child)
698+
end
699+
local main_endpoint = find_default_endpoint(device)
700+
-- ensure subscription to all endpoint attributes- including those mapped to child devices
701+
for _, ep in ipairs(device.endpoints) do
702+
if ep.endpoint_id ~= main_endpoint then
703+
local id = 0
704+
for _, dt in ipairs(ep.device_types) do
705+
id = math.max(id, dt.device_type_id)
706+
end
707+
for _, attr in pairs(device_type_attribute_map[id] or {}) do
708+
if id == GENERIC_SWITCH_ID and
709+
attr ~= clusters.PowerSource.attributes.BatPercentRemaining and
710+
attr ~= clusters.PowerSource.attributes.BatChargeLevel then
711+
device:add_subscribed_event(attr)
712+
else
713+
device:add_subscribed_attribute(attr)
714+
end
716715
end
717716
end
718717
end
718+
device:subscribe()
719719
end
720-
device:subscribe()
721720
end
722721

723722
local function match_profile(driver, device)

0 commit comments

Comments
 (0)