Skip to content

Commit 83b20b8

Browse files
tcarmelveilleuxpre-commit-ci[bot]restyled-commits
authored
Add NamedPipe support to all-devices-app (project-chip#72627)
* Add NamedPipe support to all-devices-app Changes: - Introduce common AppCommandDelegate for registering new named pipe handlers. - Addressed previous follow-up comments from project-chip#72048 in the NamedPipe handling. - Removed TogglingOccupancySensorDevice in favor of LoggingOccupancySensorDevice. - Added command line parsing and init of named pipe to all-devices app. - Added some handlers as used in Matter 1.6 SVE. - Refactored argument processing to support --trace-to and to remove duplication from all-clusters-app init (especially the CommissiableInit). Testing done: - Tested with the sending named pipe commands to occupancy sensor - Added all-devices-app as default to a Boolean State sensor cert test * Remove superfluous named-pipe arg in all-devices-app * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Restyled by gn * Address review comments * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Address review comments * Address review comments * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Fix build * Rename file * Address more review comments * Fix Darwin build * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Improved registration of clusters to reduce boilerplate * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Address minor review comments --------- Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> Co-authored-by: Restyled.io <commits@restyled.io>
1 parent 9a15b46 commit 83b20b8

25 files changed

Lines changed: 819 additions & 153 deletions

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ source_set("device-factory") {
4141
"${chip_root}/examples/all-devices-app/all-devices-common/devices/humidity-sensor/impl:increasing",
4242
"${chip_root}/examples/all-devices-app/all-devices-common/devices/light-sensor/impl:increasing",
4343
"${chip_root}/examples/all-devices-app/all-devices-common/devices/network-infrastructure-manager",
44-
"${chip_root}/examples/all-devices-app/all-devices-common/devices/occupancy-sensor/impl:toggling",
44+
"${chip_root}/examples/all-devices-app/all-devices-common/devices/occupancy-sensor/impl:logging",
4545
"${chip_root}/examples/all-devices-app/all-devices-common/devices/on-off-light",
4646
"${chip_root}/examples/all-devices-app/all-devices-common/devices/power-source/impl:decreasing",
4747
"${chip_root}/examples/all-devices-app/all-devices-common/devices/pressure-sensor/impl:increasing",

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

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
#include <devices/humidity-sensor/impl/IncreasingHumiditySensorDevice.h>
3131
#include <devices/light-sensor/impl/IncreasingLightSensorDevice.h>
3232
#include <devices/network-infrastructure-manager/NetworkInfrastructureManagerDevice.h>
33-
#include <devices/occupancy-sensor/impl/TogglingOccupancySensorDevice.h>
33+
#include <devices/occupancy-sensor/impl/LoggingOccupancySensorDevice.h>
3434
#include <devices/on-off-light/LoggingOnOffLightDevice.h>
3535
#include <devices/power-source/impl/DecreasingBatteryPowerSourceDevice.h>
3636
#include <devices/pressure-sensor/impl/IncreasingPressureSensorDevice.h>
@@ -191,7 +191,10 @@ class DeviceFactory
191191
}
192192
if constexpr (ALL_DEVICES_ENABLE_OCCUPANCY_SENSOR)
193193
{
194-
RegisterCreator("occupancy-sensor", []() { return std::make_unique<TogglingOccupancySensorDevice>(); });
194+
RegisterCreator("occupancy-sensor", [this]() {
195+
VerifyOrDie(mContext.has_value());
196+
return std::make_unique<LoggingOccupancySensorDevice>(mContext->timerDelegate);
197+
});
195198
}
196199
if constexpr (ALL_DEVICES_ENABLE_CHIME)
197200
{

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ set(ALL_DEVICES_DEVICE_SOURCES
5454
"${ALL_DEVICES_COMMON_DIR}/devices/light-sensor/impl/IncreasingLightSensorDevice.cpp"
5555
"${ALL_DEVICES_COMMON_DIR}/devices/network-infrastructure-manager/NetworkInfrastructureManagerDevice.cpp"
5656
"${ALL_DEVICES_COMMON_DIR}/devices/occupancy-sensor/OccupancySensorDevice.cpp"
57-
"${ALL_DEVICES_COMMON_DIR}/devices/occupancy-sensor/impl/TogglingOccupancySensorDevice.cpp"
57+
"${ALL_DEVICES_COMMON_DIR}/devices/occupancy-sensor/impl/LoggingOccupancySensorDevice.cpp"
5858
"${ALL_DEVICES_COMMON_DIR}/devices/on-off-light/LoggingOnOffLightDevice.cpp"
5959
"${ALL_DEVICES_COMMON_DIR}/devices/power-source/BatteryPowerSourceDevice.cpp"
6060
"${ALL_DEVICES_COMMON_DIR}/devices/power-source/impl/DecreasingBatteryPowerSourceDevice.cpp"

examples/all-devices-app/all-devices-common/devices/occupancy-sensor/impl/BUILD.gn

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,14 @@
1515
import("//build_overrides/build.gni")
1616
import("//build_overrides/chip.gni")
1717

18-
source_set("toggling") {
18+
source_set("logging") {
1919
sources = [
20-
"TogglingOccupancySensorDevice.cpp",
21-
"TogglingOccupancySensorDevice.h",
20+
"LoggingOccupancySensorDevice.cpp",
21+
"LoggingOccupancySensorDevice.h",
2222
]
2323

2424
public_deps = [
2525
"${chip_root}/examples/all-devices-app/all-devices-common/devices/occupancy-sensor",
2626
"${chip_root}/src/lib/support",
27-
"${chip_root}/src/platform",
2827
]
2928
}
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
/*
2+
*
3+
* Copyright (c) 2025 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+
#include "LoggingOccupancySensorDevice.h"
18+
#include <lib/support/BitFlags.h>
19+
#include <lib/support/CodeUtils.h>
20+
#include <lib/support/logging/CHIPLogging.h>
21+
22+
using namespace chip::app::Clusters;
23+
24+
namespace chip {
25+
namespace app {
26+
27+
LoggingOccupancySensorDevice::LoggingOccupancySensorDevice(TimerDelegate & timerDelegate) :
28+
OccupancySensorDevice(
29+
// Initialize with kInvalidEndpointId. The actual endpoint ID will be set
30+
// when Register() is called by the application with a valid endpoint ID.
31+
OccupancySensingCluster::Config(kInvalidEndpointId)
32+
.WithFeatures(BitFlags(OccupancySensing::Feature::kPassiveInfrared))
33+
.WithHoldTime(10,
34+
{
35+
.holdTimeMin = 1,
36+
.holdTimeMax = 300,
37+
.holdTimeDefault = 10,
38+
},
39+
timerDelegate)
40+
.WithDelegate(this),
41+
timerDelegate)
42+
{}
43+
44+
CHIP_ERROR LoggingOccupancySensorDevice::Register(EndpointId endpoint, CodeDrivenDataModelProvider & provider, EndpointId parentId)
45+
{
46+
return OccupancySensorDevice::Register(endpoint, provider, parentId);
47+
}
48+
49+
void LoggingOccupancySensorDevice::Unregister(CodeDrivenDataModelProvider & provider)
50+
{
51+
OccupancySensorDevice::Unregister(provider);
52+
}
53+
54+
void LoggingOccupancySensorDevice::OnOccupancyChanged(bool occupied)
55+
{
56+
ChipLogProgress(AppServer, "LoggingOccupancySensorDevice::OnOccupancyChanged: %s", occupied ? "Occupied" : "Unoccupied");
57+
}
58+
59+
void LoggingOccupancySensorDevice::OnHoldTimeChanged(uint16_t holdTime)
60+
{
61+
ChipLogProgress(AppServer, "LoggingOccupancySensorDevice::OnHoldTimeChanged: %u", holdTime);
62+
}
63+
64+
} // namespace app
65+
} // namespace chip

examples/all-devices-app/all-devices-common/devices/occupancy-sensor/impl/TogglingOccupancySensorDevice.h renamed to examples/all-devices-app/all-devices-common/devices/occupancy-sensor/impl/LoggingOccupancySensorDevice.h

Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -19,23 +19,22 @@
1919
#include <app/clusters/occupancy-sensor-server/OccupancySensingCluster.h>
2020
#include <data-model-providers/codedriven/CodeDrivenDataModelProvider.h>
2121
#include <devices/occupancy-sensor/OccupancySensorDevice.h>
22-
#include <platform/DefaultTimerDelegate.h>
22+
#include <lib/support/TimerDelegate.h>
2323

2424
namespace chip {
2525
namespace app {
2626

2727
/**
28-
* @brief An implementation of an Occupancy Sensor Device.
28+
* @brief A basic implementation of an Occupancy Sensor Device.
2929
*
30-
* This class serves as a simple example of an occupancy sensor. It emulates
31-
* occupancy state changes by toggling between "Occupied" and "Unoccupied"
32-
* states every 30 seconds using a timer.
30+
* This class serves as a simple example of an occupancy sensor. It simply
31+
* logs on occupancy or hold time changed.
3332
*/
34-
class TogglingOccupancySensorDevice : public OccupancySensorDevice, public Clusters::OccupancySensingDelegate, public TimerContext
33+
class LoggingOccupancySensorDevice : public OccupancySensorDevice, public Clusters::OccupancySensingDelegate
3534
{
3635
public:
37-
TogglingOccupancySensorDevice();
38-
~TogglingOccupancySensorDevice() override;
36+
LoggingOccupancySensorDevice(TimerDelegate & timerDelegate);
37+
~LoggingOccupancySensorDevice() override = default;
3938

4039
CHIP_ERROR Register(EndpointId endpoint, CodeDrivenDataModelProvider & provider,
4140
EndpointId parentId = kInvalidEndpointId) override;
@@ -44,12 +43,6 @@ class TogglingOccupancySensorDevice : public OccupancySensorDevice, public Clust
4443
// OccupancySensingDelegate
4544
void OnOccupancyChanged(bool occupied) override;
4645
void OnHoldTimeChanged(uint16_t holdTime) override;
47-
48-
// TimerContext
49-
void TimerFired() override;
50-
51-
private:
52-
DefaultTimerDelegate mTimerDelegate;
5346
};
5447

5548
} // namespace app

examples/all-devices-app/all-devices-common/devices/occupancy-sensor/impl/TogglingOccupancySensorDevice.cpp

Lines changed: 0 additions & 90 deletions
This file was deleted.

examples/all-devices-app/all-devices-common/devices/on-off-light/LoggingOnOffLightDevice.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,8 @@ class LoggingOnOffLightDevice : public SingleEndpointDevice
4747
EndpointId parentId = kInvalidEndpointId) override;
4848
void Unregister(CodeDrivenDataModelProvider & provider) override;
4949

50+
Clusters::OnOffLightingCluster & OnOffCluster() { return mOnOffCluster.Cluster(); }
51+
5052
private:
5153
class OnOffDelegate : public Clusters::OnOffDelegate
5254
{

examples/all-devices-app/all-devices-common/devices/root-node/RootNodeDevice.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,8 @@ class RootNodeDevice : public SingleEndpointDevice
7777
EndpointId parentId = kInvalidEndpointId) override;
7878
void Unregister(CodeDrivenDataModelProvider & provider) override;
7979

80+
Clusters::BasicInformationCluster & BasicInformation() { return mBasicInformationCluster.Cluster(); }
81+
8082
protected:
8183
Context mContext;
8284

0 commit comments

Comments
 (0)