Skip to content

Commit 52f9266

Browse files
authored
[Chef] Add a mode select sample chef app (#71520)
* Add chef-supported-modes-manager * ZAp and matter files for mode select chef app * Compile debug * Compile fix * Compile fix * Compile fix * Compile fix * Add default value for current mode * Add mode select test * Test debug * Gemini comment * Undo unintentional submodule bumps * Change to more realistic mode options * Set StandardNamespace to NULL * Update test to check NULL for standard namespace * Update default current mode * Fix tests
1 parent 70641c9 commit 52f9266

9 files changed

Lines changed: 4417 additions & 0 deletions

File tree

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
/*
2+
*
3+
* Copyright (c) 2026 Project CHIP Authors
4+
* All rights reserved.
5+
*
6+
* Licensed under the Apache License, Version 2.0 (the "License");
7+
* you may not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*/
18+
19+
#include "chef-supported-modes-manager.h"
20+
21+
#if MATTER_DM_MODE_SELECT_CLUSTER_SERVER_ENDPOINT_COUNT > 0
22+
23+
using namespace chip;
24+
using namespace chip::app::Clusters::ModeSelect;
25+
using namespace chip::app::Clusters::ModeSelect::Chef;
26+
27+
CHIP_ERROR ChefSupportedModesManager::AddModeOptionsProvider(EndpointId endpoint, ModeOptionsProvider optionsProvider)
28+
{
29+
if (mModeOptionsPerEndpoint.count(endpoint) > 0)
30+
{
31+
return CHIP_ERROR_ENDPOINT_EXISTS;
32+
}
33+
mModeOptionsPerEndpoint[endpoint] = optionsProvider;
34+
return CHIP_NO_ERROR;
35+
}
36+
37+
SupportedModesManager::ModeOptionsProvider ChefSupportedModesManager::getModeOptionsProvider(EndpointId endpointId) const
38+
{
39+
auto it = mModeOptionsPerEndpoint.find(endpointId);
40+
if (it == mModeOptionsPerEndpoint.end())
41+
{
42+
return ModeOptionsProvider();
43+
}
44+
return it->second;
45+
}
46+
47+
Protocols::InteractionModel::Status ChefSupportedModesManager::getModeOptionByMode(EndpointId endpointId, uint8_t mode,
48+
const ModeOptionStructType ** dataPtr) const
49+
{
50+
SupportedModesManager::ModeOptionsProvider provider = getModeOptionsProvider(endpointId);
51+
if (provider.begin() == nullptr || provider.end() == nullptr)
52+
{
53+
return Protocols::InteractionModel::Status::NotFound;
54+
}
55+
56+
for (const auto & option : provider)
57+
{
58+
if (option.mode == mode)
59+
{
60+
*dataPtr = &option;
61+
return Protocols::InteractionModel::Status::Success;
62+
}
63+
}
64+
return Protocols::InteractionModel::Status::NotFound;
65+
}
66+
67+
#endif // MATTER_DM_MODE_SELECT_CLUSTER_SERVER_ENDPOINT_COUNT
Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
/*
2+
*
3+
* Copyright (c) 2026 Project CHIP Authors
4+
* All rights reserved.
5+
*
6+
* Licensed under the Apache License, Version 2.0 (the "License");
7+
* you may not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*/
18+
19+
#pragma once
20+
21+
#include <app/clusters/mode-select-server/supported-modes-manager.h>
22+
#include <app/data-model/List.h>
23+
#include <app/util/config.h>
24+
#include <lib/core/CHIPError.h>
25+
#include <lib/support/Span.h>
26+
#include <map>
27+
28+
#if MATTER_DM_MODE_SELECT_CLUSTER_SERVER_ENDPOINT_COUNT > 0
29+
30+
namespace chip {
31+
namespace app {
32+
namespace Clusters {
33+
namespace ModeSelect {
34+
namespace Chef {
35+
36+
using chip::operator""_span;
37+
38+
static const Structs::SemanticTagStruct::Type kDefaultSemanticTagForModes[] = { { .mfgCode = static_cast<chip::VendorId>(0xFFF1),
39+
.value = 0 } };
40+
41+
static const Structs::ModeOptionStruct::Type kDefaultModeOptions[] = {
42+
{
43+
.label = "3.5s"_span,
44+
.mode = 35,
45+
.semanticTags = chip::app::DataModel::List<const Structs::SemanticTagStruct::Type>(kDefaultSemanticTagForModes),
46+
},
47+
{
48+
.label = "4s"_span,
49+
.mode = 40,
50+
.semanticTags = chip::app::DataModel::List<const Structs::SemanticTagStruct::Type>(kDefaultSemanticTagForModes),
51+
},
52+
{
53+
.label = "5s"_span,
54+
.mode = 50,
55+
.semanticTags = chip::app::DataModel::List<const Structs::SemanticTagStruct::Type>(kDefaultSemanticTagForModes),
56+
}
57+
};
58+
59+
class ChefSupportedModesManager : public SupportedModesManager
60+
{
61+
using ModeOptionStructType = Structs::ModeOptionStruct::Type;
62+
63+
public:
64+
CHIP_ERROR AddModeOptionsProvider(EndpointId endpoint, ModeOptionsProvider optionsProvider);
65+
66+
ModeOptionsProvider getModeOptionsProvider(EndpointId endpointId) const override;
67+
68+
Protocols::InteractionModel::Status getModeOptionByMode(EndpointId endpointId, uint8_t mode,
69+
const ModeOptionStructType ** dataPtr) const override;
70+
71+
~ChefSupportedModesManager() override {}
72+
73+
private:
74+
std::map<EndpointId, ModeOptionsProvider> mModeOptionsPerEndpoint;
75+
};
76+
77+
} // namespace Chef
78+
} // namespace ModeSelect
79+
} // namespace Clusters
80+
} // namespace app
81+
} // namespace chip
82+
83+
#endif // MATTER_DM_MODE_SELECT_CLUSTER_SERVER_ENDPOINT_COUNT

examples/chef/common/stubs.cpp

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,10 @@ const Clusters::Descriptor::Structs::SemanticTagStruct::Type kEp2TagList[] = { P
199199
#include "microwave-oven-control/chef-microwave-oven-control.h"
200200
#endif // MATTER_DM_PLUGIN_MICROWAVE_OVEN_CONTROL_SERVER
201201

202+
#if MATTER_DM_MODE_SELECT_CLUSTER_SERVER_ENDPOINT_COUNT > 0
203+
#include "clusters/mode-select/chef-supported-modes-manager.h"
204+
#endif
205+
202206
#if MATTER_DM_LAUNDRY_DRYER_CONTROLS_CLUSTER_SERVER_ENDPOINT_COUNT > 0
203207
#include "laundry-dryer-controls/chef-laundry-dryer-controls-delegate.h"
204208
#endif // #if MATTER_DM_LAUNDRY_DRYER_CONTROLS_CLUSTER_SERVER_ENDPOINT_COUNT
@@ -757,6 +761,23 @@ void ChimeInit()
757761
#endif // #if MATTER_DM_CHIME_CLUSTER_SERVER_ENDPOINT_COUNT
758762
}
759763

764+
void InitModeSelect()
765+
{
766+
#if MATTER_DM_MODE_SELECT_CLUSTER_SERVER_ENDPOINT_COUNT > 0
767+
if (DeviceTypes::EndpointHasDeviceType(1, Device::kModeSelectDeviceTypeId))
768+
{
769+
using namespace chip::app::Clusters::ModeSelect;
770+
using namespace chip::app::Clusters::ModeSelect::Chef;
771+
static ChefSupportedModesManager supportedModesManager;
772+
static SupportedModesManager::ModeOptionsProvider modeOptions(
773+
kDefaultModeOptions, kDefaultModeOptions + (sizeof(kDefaultModeOptions) / sizeof(kDefaultModeOptions[0])));
774+
VerifyOrDieWithMsg(supportedModesManager.AddModeOptionsProvider(1, modeOptions) == CHIP_NO_ERROR, Zcl,
775+
"InitModeSelect: Failed to AddModeOptionsProvider");
776+
setSupportedModesManager(&supportedModesManager);
777+
}
778+
#endif // MATTER_DM_MODE_SELECT_CLUSTER_SERVER_ENDPOINT_COUNT
779+
}
780+
760781
void ApplicationInit()
761782
{
762783
ChipLogProgress(NotSpecified, "Chef Application Init !!!");
@@ -768,6 +789,7 @@ void ApplicationInit()
768789
CastingvideoplayerContentappInit();
769790
WaterHeaterInit();
770791
ChimeInit();
792+
InitModeSelect();
771793

772794
#ifdef MATTER_DM_PLUGIN_PUMP_CONFIGURATION_AND_CONTROL_SERVER
773795
#ifdef MATTER_DM_PLUGIN_ON_OFF_SERVER

0 commit comments

Comments
 (0)