Skip to content

Commit

Permalink
feat: Add terms-and-conditions sample app for CI testing (#36950)
Browse files Browse the repository at this point in the history
* feat: Add terms-and-conditions sample app for CI testing

Add a new sample application that demonstrates and tests the terms and
conditions feature. This app will be integrated into the CI pipeline to
prevent regressions and ensure the feature continues to work as
expected.

The sample app serves as both a reference implementation and an
automated test case for the terms and conditions functionality.

```bash
./scripts/build/build_examples.py --target linux-x64-terms-and-conditions build
```

* Update cluster configurations for app testing

- Enable switch cluster for basic app control testing
- Enable network commissioning cluster for in-app commission testing
- Disable provisional clusters as they are not required
- Disable other non-required clusters to streamline testing setup

This change focuses the cluster configuration on essential components
needed for basic app control and commissioning testing scenarios.

* refactor: Remove unused attributes from Switch cluster

Remove unused attributes from the Switch cluster to comply with the "On/Off Light"
device type specification as defined in the Matter device library v1.4. This change
removes several server-side attributes including ServerList, ClientList, PartsList,
and various internal lists that are not required for the basic On/Off Light
functionality.

* feat: Add Descriptor cluster and enable attribute reporting

Add the mandatory Descriptor cluster to endpoint 1 and enable attribute reporting
for the device. Changes include:
- Add Descriptor cluster with all required attributes (deviceTypeList, serverList, etc.)
- Enable reportable flag for multiple attributes with min/max reporting intervals
- Configure all Descriptor cluster attributes as external callbacks

This change ensures compliance with the Matter specification for the On/Off Light
device type.
  • Loading branch information
swan-amazon authored Jan 15, 2025
1 parent 72b1da7 commit 083803c
Show file tree
Hide file tree
Showing 14 changed files with 4,443 additions and 2 deletions.
1 change: 1 addition & 0 deletions docs/issue_triage.md
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,7 @@ types or functionality) as well as individual examples.
| `examples/rvc-app` | | UNMAINTAINED |
| `examples/smoke-co-alarm-app` | | UNMAINTAINED |
| `examples/temperature-measurement-app` | | UNMAINTAINED |
| `examples/terms-and-conditions-app` | James Swan | |
| `examples/thermostat` | | UNMAINTAINED |
| `examples/thread-br-app` | | UNMAINTAINED |
| `examples/tv-app` | Chris DeCenzo, Lazar Kovacic | |
Expand Down
25 changes: 25 additions & 0 deletions examples/terms-and-conditions-app/linux/.gn
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# Copyright (c) 2024 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")

# The location of the build configuration file.
buildconfig = "${build_root}/config/BUILDCONFIG.gn"

# CHIP uses angle bracket includes.
check_system_includes = true

default_args = {
import("//args.gni")
}
32 changes: 32 additions & 0 deletions examples/terms-and-conditions-app/linux/BUILD.gn
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# Copyright (c) 2024 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/chip.gni")
import("${chip_root}/build/chip/tools.gni")
import("${chip_root}/src/app/common_flags.gni")

executable("chip-terms-and-conditions-app") {
sources = [ "main.cpp" ]

deps = [
"${chip_root}/examples/platform/linux:app-main",
"${chip_root}/examples/terms-and-conditions-app/terms-and-conditions-common",
]

output_dir = root_out_dir
}

group("default") {
deps = [ ":chip-terms-and-conditions-app" ]
}
18 changes: 18 additions & 0 deletions examples/terms-and-conditions-app/linux/args.gni
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Copyright (c) 2024 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/chip.gni")
import("${chip_root}/config/standalone/args.gni")

chip_terms_and_conditions_required = true
1 change: 1 addition & 0 deletions examples/terms-and-conditions-app/linux/build_overrides
82 changes: 82 additions & 0 deletions examples/terms-and-conditions-app/linux/main.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
/*
*
* Copyright (c) 2024 Project CHIP Authors
* All rights reserved.
*
* 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 <AppMain.h>
#include <app/server/TermsAndConditionsManager.h>
#include <app/server/TermsAndConditionsProvider.h>

using namespace chip;
using namespace chip::ArgParser;

static uint16_t sTcMinRequiredVersion = 0;
static uint16_t sTcRequiredAcknowledgements = 0;

static OptionDef sTermsAndConditionsOptions[] = {
{ "tc-min-required-version", kArgumentRequired, 'm' },
{ "tc-required-acknowledgements", kArgumentRequired, 'r' },
{ nullptr },
};

static const char * const sTermsAndConditionsOptionHelp =
"-m, --tc-min-required-version <number>\n Configure the minimum required TC version.\n\n"
"-r, --tc-required-acknowledgements <number (bitfield)>\n Configure the required TC acknowledgements.\n\n";

static bool HandleOption(const char * progName, OptionSet * optSet, int id, const char * name, const char * arg)
{
switch (id)
{
case 'm':
sTcMinRequiredVersion = static_cast<uint16_t>(atoi(arg));
break;
case 'r':
sTcRequiredAcknowledgements = static_cast<uint16_t>(atoi(arg));
break;
default:
PrintArgError("%s: INTERNAL ERROR: Unhandled option: %s\n", progName, name);
return false;
}

return true;
}

static OptionSet sTermsAndConditionsCmdLineOptions = {
HandleOption,
sTermsAndConditionsOptions,
"TERMS AND CONDITIONS OPTIONS",
sTermsAndConditionsOptionHelp,
};

void ApplicationInit()
{
const app::TermsAndConditions termsAndConditions = app::TermsAndConditions(sTcRequiredAcknowledgements, sTcMinRequiredVersion);
PersistentStorageDelegate & persistentStorageDelegate = Server::GetInstance().GetPersistentStorage();
app::TermsAndConditionsManager::GetInstance()->Init(&persistentStorageDelegate, MakeOptional(termsAndConditions));
}

void ApplicationShutdown() {}

int main(int argc, char * argv[])
{
if (ChipLinuxAppInit(argc, argv, &sTermsAndConditionsCmdLineOptions) != 0)
{
return -1;
}

ChipLinuxAppMainLoop();
return 0;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# Copyright (c) 2024 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/chip.gni")

import("${chip_root}/src/app/chip_data_model.gni")

chip_data_model("terms-and-conditions-common") {
zap_file = "terms-and-conditions-app.zap"
is_server = true
}
Loading

0 comments on commit 083803c

Please sign in to comment.