-
Notifications
You must be signed in to change notification settings - Fork 2.3k
Code Driven All Devices Example App #41607
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
zaid-google
wants to merge
51
commits into
project-chip:master
Choose a base branch
from
zaid-google:new_all_devices_app
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
51 commits
Select commit
Hold shift + click to select a range
2fef989
Initial draft of all devices example app
zaid-google 4708c00
Restyled by whitespace
restyled-commits 1e0aa5e
Restyled by clang-format
restyled-commits 1f10a27
Restyled by gn
restyled-commits 5d05758
Address some review comments
zaid-google d6bf556
Merge branch 'master' into new_all_devices_app
zaid-google 050d6a7
Address more review comments
zaid-google 675bc02
Restyled by whitespace
restyled-commits 54f4933
Restyled by clang-format
restyled-commits e755f19
Restyled by gn
restyled-commits 899949a
More review comments
zaid-google 14230f4
Review comments for BUILD.gn configs
zaid-google 0debc8d
Restyled by clang-format
restyled-commits 523ed12
Restyled by gn
restyled-commits 1f52853
Add TODOs based on review comments
zaid-google cdd6d6e
Restyled by whitespace
restyled-commits 1e8876a
Restyled by clang-format
restyled-commits 794d2aa
Merge branch 'master' into new_all_devices_app
zaid-google 42517f3
Update wifi diagnostics optional atteribute set usage
zaid-google eebaef9
Remove SemanticTags function from Device
zaid-google c1c6f3a
Restyled by clang-format
restyled-commits 5164883
Make device endpoint a command line argument
zaid-google ed2caa6
Cleanup includes and remove old args.gni
zaid-google cd2c5e0
Address comments, make command line args seperate from main
zaid-google 5392dbc
Fix merge conflict
zaid-google ec9c9ba
Restyled by whitespace
restyled-commits 0b4d7cb
Restyled by clang-format
restyled-commits 1cabc92
Restyled by gn
restyled-commits 879cffd
separation of base device with single endpoint device
zaid-google 5ef1f49
Add comments, fix unregister calls, cleanup of member variables
zaid-google 09a94f2
Remove unique pointer for timer
zaid-google 5263526
Restyled by whitespace
restyled-commits 28da318
Restyled by clang-format
restyled-commits 1eee251
update comment
zaid-google ac62669
Restyled by whitespace
restyled-commits e1d7e9c
Restructure device interfaces
zaid-google b015385
Add all devices app build and basic composition test to CI
zaid-google 9afcb3b
Restyled by clang-format
restyled-commits 87e732f
Remove build variants for CI, not currently supported
zaid-google 0256f69
Fix path for all devices app in CI
zaid-google 3521dc0
Update device info provider used
zaid-google 00f9a30
Update comments
zaid-google a589afb
Restyled by whitespace
restyled-commits c6210d5
Restyled by clang-format
restyled-commits f93e4e0
Add new device info provider
zaid-google 3c9ba8f
Restyled by whitespace
restyled-commits 8f52e9f
Restyled by clang-format
restyled-commits bfa4f89
Update examples/providers/AllDevicesExampleDeviceInfoProviderImpl.cpp
andy31415 af50f13
Update examples/all-devices-app/all-devices-common/devices/boolean-st…
andy31415 d1c1b5c
Update examples/all-devices-app/all-devices-common/devices/interface/…
andy31415 d557cba
Update examples/all-devices-app/all-devices-common/devices/interface/…
andy31415 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
18 changes: 18 additions & 0 deletions
18
examples/all-devices-app/all-devices-common/devices/BUILD.gn
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,18 @@ | ||
| # Copyright (c) 2025 Project CHIP Authors | ||
| # | ||
| # Licensed under the Apache License, Version 2.0 (the "License"); | ||
| # you may not use this file except in compliance with the License. | ||
| # You may obtain a copy of the License at | ||
| # | ||
| # http://www.apache.org/licenses/LICENSE-2.0 | ||
| # | ||
| # Unless required by applicable law or agreed to in writing, software | ||
| # distributed under the License is distributed on an "AS IS" BASIS, | ||
| # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| # See the License for the specific language governing permissions and | ||
| # limitations under the License. | ||
|
|
||
| config("includes") { | ||
| # allows includes like "devices/..." | ||
| include_dirs = [ ".." ] | ||
| } |
37 changes: 37 additions & 0 deletions
37
examples/all-devices-app/all-devices-common/devices/boolean-state-sensor/BUILD.gn
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,37 @@ | ||
| # Copyright (c) 2025 Project CHIP Authors | ||
| # | ||
| # Licensed under the Apache License, Version 2.0 (the "License"); | ||
| # you may not use this file except in compliance with the License. | ||
| # You may obtain a copy of the License at | ||
| # | ||
| # http://www.apache.org/licenses/LICENSE-2.0 | ||
| # | ||
| # Unless required by applicable law or agreed to in writing, software | ||
| # distributed under the License is distributed on an "AS IS" BASIS, | ||
| # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| # See the License for the specific language governing permissions and | ||
| # limitations under the License. | ||
|
|
||
| import("//build_overrides/build.gni") | ||
| import("//build_overrides/chip.gni") | ||
|
|
||
| source_set("boolean-state-sensor") { | ||
| sources = [ | ||
| "BooleanStateSensorDevice.cpp", | ||
| "BooleanStateSensorDevice.h", | ||
| ] | ||
|
|
||
| public_deps = [ | ||
| "${chip_root}/examples/all-devices-app/all-devices-common/devices/interface:single-endpoint-device", | ||
| "${chip_root}/src/app/clusters/boolean-state-server", | ||
| "${chip_root}/src/app/clusters/identify-server", | ||
| "${chip_root}/src/data-model-providers/codedriven", | ||
| "${chip_root}/src/lib/core:error", | ||
| "${chip_root}/src/lib/support", | ||
| ] | ||
|
|
||
| public_configs = [ | ||
| "${chip_root}/examples/all-devices-app/all-devices-common/devices/:includes", | ||
| "${chip_root}/src:includes", | ||
| ] | ||
| } |
52 changes: 52 additions & 0 deletions
52
...-devices-app/all-devices-common/devices/boolean-state-sensor/BooleanStateSensorDevice.cpp
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,52 @@ | ||
| /* | ||
| * | ||
| * Copyright (c) 2025 Project CHIP Authors | ||
| * | ||
| * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| * you may not use this file except in compliance with the License. | ||
| * You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
| #include <devices/boolean-state-sensor/BooleanStateSensorDevice.h> | ||
|
|
||
| using namespace chip::app::Clusters; | ||
|
|
||
| namespace chip::app { | ||
|
|
||
| CHIP_ERROR BooleanStateSensorDevice::Register(chip::EndpointId endpoint, CodeDrivenDataModelProvider & provider, | ||
| EndpointId parentId) | ||
| { | ||
| ReturnErrorOnFailure(SingleEndpointRegistration(endpoint, provider, parentId)); | ||
|
|
||
| mIdentifyCluster.Create(IdentifyCluster::Config(endpoint, *mTimerDelegate)); | ||
| ReturnErrorOnFailure(provider.AddCluster(mIdentifyCluster.Registration())); | ||
|
|
||
| mBooleanStateCluster.Create(endpoint); | ||
| ReturnErrorOnFailure(provider.AddCluster(mBooleanStateCluster.Registration())); | ||
|
|
||
| return provider.AddEndpoint(mEndpointRegistration); | ||
| } | ||
|
|
||
| void BooleanStateSensorDevice::UnRegister(CodeDrivenDataModelProvider & provider) | ||
| { | ||
| SingleEndpointUnregistration(provider); | ||
| if (mBooleanStateCluster.IsConstructed()) | ||
| { | ||
| provider.RemoveCluster(&mBooleanStateCluster.Cluster()); | ||
| mBooleanStateCluster.Destroy(); | ||
| } | ||
| if (mIdentifyCluster.IsConstructed()) | ||
| { | ||
| provider.RemoveCluster(&mIdentifyCluster.Cluster()); | ||
| mIdentifyCluster.Destroy(); | ||
| } | ||
| } | ||
|
|
||
| } // namespace chip::app | ||
56 changes: 56 additions & 0 deletions
56
...ll-devices-app/all-devices-common/devices/boolean-state-sensor/BooleanStateSensorDevice.h
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,56 @@ | ||
| /* | ||
| * | ||
| * Copyright (c) 2025 Project CHIP Authors | ||
| * | ||
| * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| * you may not use this file except in compliance with the License. | ||
| * You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
| #pragma once | ||
|
|
||
| #include <app/clusters/boolean-state-server/boolean-state-cluster.h> | ||
| #include <app/clusters/identify-server/IdentifyCluster.h> | ||
| #include <app/reporting/ReportScheduler.h> | ||
| #include <devices/interface/SingleEndpointDevice.h> | ||
| #include <memory> | ||
|
|
||
| namespace chip { | ||
| namespace app { | ||
|
|
||
| class BooleanStateSensorDevice : public SingleEndpointDevice | ||
| { | ||
| public: | ||
| /// This is a general class for boolean state sensor devices. The device type passed here will | ||
| /// determine the type of sensor it is (contact, water leak, etc.) This is meant to be a reusable | ||
| /// class for the sensor types that share the same core functionality through the identify and | ||
| /// boolean state clusters. The caller creating a BooleanStateSensorDevice MUST ensure that the underlying | ||
| /// data for the Span of deviceTypes remains valid for the entire lifetime of the BooleanStateSensorDevice object instance. | ||
| BooleanStateSensorDevice(reporting::ReportScheduler::TimerDelegate * timerDelegate, | ||
| Span<const DataModel::DeviceTypeEntry> deviceType) : | ||
| SingleEndpointDevice(deviceType), | ||
| mTimerDelegate(timerDelegate) | ||
| {} | ||
| ~BooleanStateSensorDevice() override = default; | ||
|
|
||
| CHIP_ERROR Register(chip::EndpointId endpoint, CodeDrivenDataModelProvider & provider, | ||
| EndpointId parentId = kInvalidEndpointId) override; | ||
| void UnRegister(CodeDrivenDataModelProvider & provider) override; | ||
|
|
||
zaid-google marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| Clusters::BooleanStateCluster & BooleanState() { return mBooleanStateCluster.Cluster(); } | ||
|
|
||
| private: | ||
| reporting::ReportScheduler::TimerDelegate * mTimerDelegate; | ||
| LazyRegisteredServerCluster<Clusters::IdentifyCluster> mIdentifyCluster; | ||
| LazyRegisteredServerCluster<Clusters::BooleanStateCluster> mBooleanStateCluster; | ||
| }; | ||
|
|
||
| } // namespace app | ||
| } // namespace chip | ||
31 changes: 31 additions & 0 deletions
31
examples/all-devices-app/all-devices-common/devices/device-factory/BUILD.gn
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,31 @@ | ||
| # Copyright (c) 2025 Project CHIP Authors | ||
| # | ||
| # Licensed under the Apache License, Version 2.0 (the "License"); | ||
| # you may not use this file except in compliance with the License. | ||
| # You may obtain a copy of the License at | ||
| # | ||
| # http://www.apache.org/licenses/LICENSE-2.0 | ||
| # | ||
| # Unless required by applicable law or agreed to in writing, software | ||
| # distributed under the License is distributed on an "AS IS" BASIS, | ||
| # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| # See the License for the specific language governing permissions and | ||
| # limitations under the License. | ||
|
|
||
| import("//build_overrides/build.gni") | ||
| import("//build_overrides/chip.gni") | ||
|
|
||
| source_set("device-factory") { | ||
| sources = [ "DeviceFactory.h" ] | ||
|
|
||
| public_deps = [ | ||
| "${chip_root}/examples/all-devices-app/all-devices-common/devices/boolean-state-sensor", | ||
| "${chip_root}/src/lib/core:error", | ||
| "${chip_root}/zzz_generated/app-common/devices/", | ||
| ] | ||
|
|
||
| public_configs = [ | ||
| "${chip_root}/examples/all-devices-app/all-devices-common/devices/:includes", | ||
| "${chip_root}/src:includes", | ||
| ] | ||
| } |
83 changes: 83 additions & 0 deletions
83
examples/all-devices-app/all-devices-common/devices/device-factory/DeviceFactory.h
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,83 @@ | ||
| /* | ||
| * | ||
| * Copyright (c) 2025 Project CHIP Authors | ||
| * | ||
| * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| * you may not use this file except in compliance with the License. | ||
| * You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
|
|
||
| #pragma once | ||
|
|
||
| #include <app/TimerDelegates.h> | ||
| #include <devices/Types.h> | ||
| #include <devices/boolean-state-sensor/BooleanStateSensorDevice.h> | ||
| #include <functional> | ||
| #include <lib/core/CHIPError.h> | ||
| #include <map> | ||
|
|
||
| namespace chip::app { | ||
|
|
||
| /** | ||
| * This is a factory class made to be used to create any valid device type as part of the | ||
| * all-devices-app. This class is meant to abstract away some details of device specific code, | ||
| * and to have more generic implementation code being used in main to create a device. The keys | ||
| * in the device registry map are the command line arguments used to start the respective device. | ||
| * Create devices by fetching the instance of this class and passing in the device type argument | ||
| * i.e. DeviceFactory::GetInstance().Create(deviceTypeName) | ||
| */ | ||
| class DeviceFactory | ||
zaid-google marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| { | ||
| public: | ||
| using DeviceCreator = std::function<std::unique_ptr<DeviceInterface>()>; | ||
|
|
||
| static DeviceFactory & GetInstance() | ||
| { | ||
| static DeviceFactory instance; | ||
| return instance; | ||
| } | ||
|
|
||
| bool IsValidDevice(const std::string & deviceTypeArg) { return mRegistry.find(deviceTypeArg) != mRegistry.end(); } | ||
|
|
||
| std::unique_ptr<DeviceInterface> Create(const std::string & deviceTypeArg) | ||
| { | ||
| if (IsValidDevice(deviceTypeArg)) | ||
| { | ||
| return mRegistry.find(deviceTypeArg)->second(); | ||
| } | ||
| else | ||
| { | ||
| ChipLogError( | ||
| Support, | ||
| "INTERNAL ERROR: Invalid device type: %s. Run with the --help argument to view the list of valid device types.\n", | ||
| deviceTypeArg.c_str()); | ||
| } | ||
| return nullptr; | ||
| } | ||
|
|
||
| private: | ||
| std::map<std::string, DeviceCreator> mRegistry; | ||
| DefaultTimerDelegate timer; | ||
|
|
||
| DeviceFactory() | ||
| { | ||
| mRegistry["contact-sensor"] = [this]() { | ||
| return std::make_unique<BooleanStateSensorDevice>( | ||
| &timer, Span<const DataModel::DeviceTypeEntry>(&Device::Type::kContactSensor, 1)); | ||
| }; | ||
| mRegistry["water-leak-detector"] = [this]() { | ||
| return std::make_unique<BooleanStateSensorDevice>( | ||
| &timer, Span<const DataModel::DeviceTypeEntry>(&Device::Type::kWaterLeakDetector, 1)); | ||
| }; | ||
| } | ||
| }; | ||
|
|
||
| } // namespace chip::app | ||
55 changes: 55 additions & 0 deletions
55
examples/all-devices-app/all-devices-common/devices/interface/BUILD.gn
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,55 @@ | ||
| # Copyright (c) 2025 Project CHIP Authors | ||
| # | ||
| # Licensed under the Apache License, Version 2.0 (the "License"); | ||
| # you may not use this file except in compliance with the License. | ||
| # You may obtain a copy of the License at | ||
| # | ||
| # http://www.apache.org/licenses/LICENSE-2.0 | ||
| # | ||
| # Unless required by applicable law or agreed to in writing, software | ||
| # distributed under the License is distributed on an "AS IS" BASIS, | ||
| # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| # See the License for the specific language governing permissions and | ||
| # limitations under the License. | ||
|
|
||
| import("//build_overrides/build.gni") | ||
zaid-google marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| import("//build_overrides/chip.gni") | ||
|
|
||
| source_set("device-interface") { | ||
| sources = [ | ||
| "DeviceInterface.cpp", | ||
| "DeviceInterface.h", | ||
| ] | ||
|
|
||
| public_deps = [ | ||
| "${chip_root}/src/app/clusters/descriptor", | ||
| "${chip_root}/src/data-model-providers/codedriven", | ||
| "${chip_root}/src/lib/core:error", | ||
| "${chip_root}/src/lib/support", | ||
| ] | ||
|
|
||
| public_configs = [ | ||
| "${chip_root}/examples/all-devices-app/all-devices-common/devices/:includes", | ||
zaid-google marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| "${chip_root}/src:includes", | ||
| ] | ||
| } | ||
|
|
||
| source_set("single-endpoint-device") { | ||
| sources = [ | ||
| "SingleEndpointDevice.cpp", | ||
| "SingleEndpointDevice.h", | ||
| ] | ||
|
|
||
| public_deps = [ | ||
| ":device-interface", | ||
| "${chip_root}/src/app/clusters/descriptor", | ||
| "${chip_root}/src/data-model-providers/codedriven", | ||
| "${chip_root}/src/lib/core:error", | ||
| "${chip_root}/src/lib/support", | ||
| ] | ||
|
|
||
| public_configs = [ | ||
| "${chip_root}/examples/all-devices-app/all-devices-common/devices/:includes", | ||
| "${chip_root}/src:includes", | ||
| ] | ||
| } | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.