Skip to content

Commit ace3ccc

Browse files
[all-devices-app] Add Bridged Node Device Type (project-chip#72526)
* feat: Add Bridged Node Device Type to all-devices-app * feat: Make uniqueId injectable in BridgedNodeDevice * feat: Make nodeLabel injectable from DeviceFactory * revert: Revert local build workaround in flags.gni * fix: Revert unintended submodule changes and fix enabled_devices.gni syntax * fix: Resolve use-after-free in BridgedNodeDevice and fix GN formatting * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * fix: Make generators mandatory constructor arguments and remove fallbacks * test: Update build targets list snapshot * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * fix: Address review comments regarding target list sorting and unused lambda parameter * fix: Decouple BridgedNodeDevice UniqueID from dynamic EndpointId * fix: Rename BridgedNodeDevice members to reflect direct constructor passing * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * fix: Sort build lists alphabetically and include CodeUtils.h in BridgedNodeDevice.cpp --------- Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
1 parent fb77c38 commit ace3ccc

11 files changed

Lines changed: 184 additions & 12 deletions

File tree

examples/all-devices-app/all-devices-common/device-factory/BUILD.gn

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ source_set("device-factory") {
3333
"${chip_root}/examples/all-devices-app/all-devices-common/devices/aggregator",
3434
"${chip_root}/examples/all-devices-app/all-devices-common/devices/air-quality-sensor",
3535
"${chip_root}/examples/all-devices-app/all-devices-common/devices/boolean-state-sensor",
36+
"${chip_root}/examples/all-devices-app/all-devices-common/devices/bridged-node",
3637
"${chip_root}/examples/all-devices-app/all-devices-common/devices/chime",
3738
"${chip_root}/examples/all-devices-app/all-devices-common/devices/dimmable-light/impl:logging",
3839
"${chip_root}/examples/all-devices-app/all-devices-common/devices/fan/impl:logging",

examples/all-devices-app/all-devices-common/device-factory/DeviceFactory.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
#include <devices/aggregator/AggregatorDevice.h>
2323
#include <devices/air-quality-sensor/AirQualitySensorDevice.h>
2424
#include <devices/boolean-state-sensor/BooleanStateSensorDevice.h>
25+
#include <devices/bridged-node/BridgedNodeDevice.h>
2526
#include <devices/chime/ChimeDevice.h>
2627
#include <devices/dimmable-light/impl/LoggingDimmableLightDevice.h>
2728
#include <devices/fan/impl/LoggingFanDevice.h>
@@ -146,6 +147,17 @@ class DeviceFactory
146147
});
147148
});
148149
}
150+
if constexpr (ALL_DEVICES_ENABLE_BRIDGED_NODE)
151+
{
152+
RegisterCreator("bridged-node", [this]() {
153+
VerifyOrDie(mContext.has_value());
154+
static int sBridgedNodeCount = 0;
155+
sBridgedNodeCount++;
156+
return std::make_unique<BridgedNodeDevice>(mContext->timerDelegate,
157+
"bridged-node-unique-id-" + std::to_string(sBridgedNodeCount),
158+
"Bridged Node " + std::to_string(sBridgedNodeCount));
159+
});
160+
}
149161
if constexpr (ALL_DEVICES_ENABLE_CONTACT_SENSOR)
150162
{
151163
RegisterCreator("contact-sensor", [this]() {

examples/all-devices-app/all-devices-common/device-factory/enabled_devices.cmake

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ set(ALL_DEVICES_DEVICE_SOURCES
3838
"${ALL_DEVICES_COMMON_DIR}/devices/aggregator/AggregatorDevice.cpp"
3939
"${ALL_DEVICES_COMMON_DIR}/devices/air-quality-sensor/AirQualitySensorDevice.cpp"
4040
"${ALL_DEVICES_COMMON_DIR}/devices/boolean-state-sensor/BooleanStateSensorDevice.cpp"
41+
"${ALL_DEVICES_COMMON_DIR}/devices/bridged-node/BridgedNodeDevice.cpp"
4142
"${ALL_DEVICES_COMMON_DIR}/devices/chime/ChimeDevice.cpp"
4243
"${ALL_DEVICES_COMMON_DIR}/devices/dimmable-light/DimmableLightDevice.cpp"
4344
"${ALL_DEVICES_COMMON_DIR}/devices/dimmable-light/impl/LoggingDimmableLightDevice.cpp"
@@ -56,11 +57,11 @@ set(ALL_DEVICES_DEVICE_SOURCES
5657
"${ALL_DEVICES_COMMON_DIR}/devices/proximity-ranger/RangingTechnologyController.cpp"
5758
"${ALL_DEVICES_COMMON_DIR}/devices/proximity-ranger/impl/BleRssiRangingAdapter.cpp"
5859
"${ALL_DEVICES_COMMON_DIR}/devices/root-node/RootNodeDevice.cpp"
60+
"${ALL_DEVICES_COMMON_DIR}/devices/smoke-co-alarm/SmokeCoAlarmDevice.cpp"
5961
"${ALL_DEVICES_COMMON_DIR}/devices/soil-sensor/SoilSensorDevice.cpp"
6062
"${ALL_DEVICES_COMMON_DIR}/devices/soil-sensor/impl/IncreasingMoistureSoilSensorDevice.cpp"
6163
"${ALL_DEVICES_COMMON_DIR}/devices/speaker/SpeakerDevice.cpp"
6264
"${ALL_DEVICES_COMMON_DIR}/devices/speaker/impl/LoggingSpeakerDevice.cpp"
63-
"${ALL_DEVICES_COMMON_DIR}/devices/smoke-co-alarm/SmokeCoAlarmDevice.cpp"
6465
"${ALL_DEVICES_COMMON_DIR}/devices/temperature-sensor/TemperatureSensorDevice.cpp"
6566
"${ALL_DEVICES_COMMON_DIR}/devices/temperature-sensor/impl/IncreasingTemperatureSensorDevice.cpp"
6667
# keep-sorted: end
@@ -105,6 +106,7 @@ foreach(_key
105106
# keep-sorted: start
106107
aggregator
107108
air-quality-sensor
109+
bridged-node
108110
chime
109111
contact-sensor
110112
dimmable-light
@@ -114,8 +116,8 @@ foreach(_key
114116
on-off-light
115117
power-source
116118
proximity-ranger
117-
soil-sensor
118119
smoke-co-alarm
120+
soil-sensor
119121
speaker
120122
temperature-sensor
121123
water-leak-detector

examples/all-devices-app/all-devices-common/device-factory/enabled_devices.gni

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,10 @@ _available_devices = [
5050
"air-quality-sensor",
5151
"AIR_QUALITY_SENSOR",
5252
],
53+
[
54+
"bridged-node",
55+
"BRIDGED_NODE",
56+
],
5357
[
5458
"chime",
5559
"CHIME",
@@ -86,14 +90,14 @@ _available_devices = [
8690
"proximity-ranger",
8791
"PROXIMITY_RANGER",
8892
],
89-
[
90-
"soil-sensor",
91-
"SOIL_SENSOR",
92-
],
9393
[
9494
"smoke-co-alarm",
9595
"SMOKE_CO_ALARM",
9696
],
97+
[
98+
"soil-sensor",
99+
"SOIL_SENSOR",
100+
],
97101
[
98102
"speaker",
99103
"SPEAKER",

examples/all-devices-app/all-devices-common/device-factory/enabled_devices_config.h.in

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99

1010
#cmakedefine01 ALL_DEVICES_ENABLE_AIR_QUALITY_SENSOR
1111
#cmakedefine01 ALL_DEVICES_ENABLE_AGGREGATOR
12+
#cmakedefine01 ALL_DEVICES_ENABLE_BRIDGED_NODE
1213
#cmakedefine01 ALL_DEVICES_ENABLE_CONTACT_SENSOR
1314
#cmakedefine01 ALL_DEVICES_ENABLE_WATER_LEAK_DETECTOR
1415
#cmakedefine01 ALL_DEVICES_ENABLE_OCCUPANCY_SENSOR
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
# Copyright (c) 2026 Project CHIP Authors
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+
15+
import("//build_overrides/build.gni")
16+
import("//build_overrides/chip.gni")
17+
18+
source_set("bridged-node") {
19+
sources = [
20+
"BridgedNodeDevice.cpp",
21+
"BridgedNodeDevice.h",
22+
]
23+
24+
public_deps = [
25+
"${chip_root}/examples/all-devices-app/all-devices-common/devices/interface:single-endpoint-device",
26+
"${chip_root}/src/app/clusters/bridged-device-basic-information-server",
27+
"${chip_root}/src/data-model-providers/codedriven",
28+
"${chip_root}/src/lib/core:error",
29+
"${chip_root}/src/lib/support",
30+
"${chip_root}/zzz_generated/app-common/devices",
31+
]
32+
}
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
/*
2+
*
3+
* Copyright (c) 2026 Project CHIP Authors
4+
*
5+
* Licensed under the Apache License, Version 2.0 (the "License");
6+
* you may not use this file except in compliance with the License.
7+
* You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
18+
#include <devices/Types.h>
19+
#include <devices/bridged-node/BridgedNodeDevice.h>
20+
#include <lib/support/CodeUtils.h>
21+
#include <lib/support/logging/CHIPLogging.h>
22+
23+
#include <string>
24+
25+
using namespace chip::app::Clusters;
26+
27+
namespace chip {
28+
namespace app {
29+
30+
BridgedNodeDevice::BridgedNodeDevice(TimerDelegate & timerDelegate, std::string uniqueId, std::string nodeLabel) :
31+
SingleEndpointDevice(Span<const DataModel::DeviceTypeEntry>(&Device::Type::kBridgedNode, 1)), mTimerDelegate(timerDelegate),
32+
mUniqueId(std::move(uniqueId)), mNodeLabel(std::move(nodeLabel))
33+
{}
34+
35+
CHIP_ERROR BridgedNodeDevice::Register(EndpointId endpoint, CodeDrivenDataModelProvider & provider, EndpointId parentId)
36+
{
37+
ReturnErrorOnFailure(SingleEndpointRegistration(endpoint, provider, parentId));
38+
39+
// Create the Bridged Device Basic Information cluster.
40+
mBridgedDeviceBasicInformationCluster.Create(endpoint,
41+
BridgedDeviceBasicInformationCluster::MutableData{
42+
.reachable = true,
43+
.nodeLabel = mNodeLabel,
44+
},
45+
BridgedDeviceBasicInformationCluster::FixedData{
46+
.uniqueId = mUniqueId,
47+
},
48+
BridgedDeviceBasicInformationCluster::Context{
49+
.delegate = *this,
50+
.timerDelegate = mTimerDelegate,
51+
});
52+
53+
ReturnErrorOnFailure(provider.AddCluster(mBridgedDeviceBasicInformationCluster.Registration()));
54+
55+
return provider.AddEndpoint(mEndpointRegistration);
56+
}
57+
58+
void BridgedNodeDevice::Unregister(CodeDrivenDataModelProvider & provider)
59+
{
60+
SingleEndpointUnregistration(provider);
61+
if (mBridgedDeviceBasicInformationCluster.IsConstructed())
62+
{
63+
LogErrorOnFailure(provider.RemoveCluster(&mBridgedDeviceBasicInformationCluster.Cluster()));
64+
mBridgedDeviceBasicInformationCluster.Destroy();
65+
}
66+
}
67+
68+
} // namespace app
69+
} // namespace chip
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
/*
2+
*
3+
* Copyright (c) 2026 Project CHIP Authors
4+
*
5+
* Licensed under the Apache License, Version 2.0 (the "License");
6+
* you may not use this file except in compliance with the License.
7+
* You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
18+
#pragma once
19+
20+
#include <app/clusters/bridged-device-basic-information-server/BridgedDeviceBasicInformationCluster.h>
21+
#include <app/clusters/bridged-device-basic-information-server/BridgedDeviceBasicInformationDelegate.h>
22+
#include <data-model-providers/codedriven/CodeDrivenDataModelProvider.h>
23+
#include <devices/interface/SingleEndpointDevice.h>
24+
#include <functional>
25+
#include <lib/support/TimerDelegate.h>
26+
#include <string>
27+
28+
namespace chip {
29+
namespace app {
30+
31+
class BridgedNodeDevice : public SingleEndpointDevice, public Clusters::BridgedDeviceBasicInformationDelegate
32+
{
33+
public:
34+
BridgedNodeDevice(TimerDelegate & timerDelegate, std::string uniqueId, std::string nodeLabel);
35+
~BridgedNodeDevice() override = default;
36+
37+
CHIP_ERROR Register(chip::EndpointId endpoint, CodeDrivenDataModelProvider & provider,
38+
EndpointId parentId = kInvalidEndpointId) override;
39+
void Unregister(CodeDrivenDataModelProvider & provider) override;
40+
41+
protected:
42+
TimerDelegate & mTimerDelegate;
43+
std::string mUniqueId;
44+
std::string mNodeLabel;
45+
LazyRegisteredServerCluster<Clusters::BridgedDeviceBasicInformationCluster> mBridgedDeviceBasicInformationCluster;
46+
};
47+
48+
} // namespace app
49+
} // namespace chip

examples/all-devices-app/posix/BUILD.gn

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ executable("all-devices-app") {
2828
"${chip_root}/examples/all-devices-app/all-devices-common/device-factory",
2929
"${chip_root}/examples/all-devices-app/all-devices-common/devices/aggregator",
3030
"${chip_root}/examples/all-devices-app/all-devices-common/devices/boolean-state-sensor",
31+
"${chip_root}/examples/all-devices-app/all-devices-common/devices/bridged-node",
3132
"${chip_root}/examples/all-devices-app/all-devices-common/devices/chime",
3233
"${chip_root}/examples/all-devices-app/all-devices-common/devices/network-infrastructure-manager",
3334
"${chip_root}/examples/all-devices-app/all-devices-common/devices/occupancy-sensor",

scripts/build/build/targets.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,18 +45,19 @@
4545
_ALL_DEVICES_APP_DEVICES = [
4646
# keep-sorted: start
4747
'aggregator',
48+
'bridged-node',
4849
'chime',
4950
'contact-sensor',
5051
'dimmable-light',
5152
'fan',
5253
'occupancy-sensor',
5354
'on-off-light',
55+
'power-source',
56+
'proximity-ranger',
5457
'soil-sensor',
5558
'speaker',
5659
'temperature-sensor',
5760
'water-leak-detector',
58-
'power-source',
59-
'proximity-ranger',
6061
# keep-sorted: end
6162
]
6263

0 commit comments

Comments
 (0)