Skip to content

Commit caad0fb

Browse files
committed
Address review comments
1 parent f1aacf6 commit caad0fb

File tree

7 files changed

+55
-54
lines changed

7 files changed

+55
-54
lines changed

examples/oven-app/oven-app-common/include/CookSurfaceEndpoint.h

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,15 +40,19 @@ class CookSurfaceEndpoint
4040
CHIP_ERROR Init();
4141

4242
/**
43-
* @brief Returns the current On/Off state.
43+
* @brief Gets the current On/Off state from server.
44+
* @param state Reference to store the current On/Off state.
45+
* @return Returns Status::Success on success, or an error code on failure.
4446
*/
4547

46-
bool GetOnOffState();
48+
chip::Protocols::InteractionModel::Status GetOnOffState(bool &state);
4749

4850
/**
4951
* @brief Set On/Off state for the CookSurface.
52+
* @param state Desired On/Off state.
53+
* @return Returns Status::Success on success, or an error code on failure.
5054
*/
51-
void SetOnOffState(bool state);
55+
chip::Protocols::InteractionModel::Status SetOnOffState(bool state);
5256

5357
EndpointId GetEndpointId() const { return mEndpointId; }
5458

examples/oven-app/oven-app-common/include/CookTopEndpoint.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,11 @@ class CookTopEndpoint
3939
CHIP_ERROR Init();
4040

4141
/**
42-
* @brief Handle the "off" command for the cooktop.
42+
* @brief Set On/Off state for the CookSurface.
43+
* @param state Desired On/Off state.
44+
* @return Returns Status::Success on success, or an error code on failure.
4345
*/
44-
void SetOnOffState(bool state);
46+
chip::Protocols::InteractionModel::Status SetOnOffState(bool state);
4547

4648
private:
4749
bool currentOnOffState = false;

examples/oven-app/oven-app-common/include/OvenEndpoint.h

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,13 @@ class OvenModeDelegate : public ModeBase::Delegate
5757
CHIP_ERROR GetModeValueByIndex(uint8_t modeIndex, uint8_t & value) override;
5858
CHIP_ERROR GetModeTagsByIndex(uint8_t modeIndex, DataModel::List<detail::Structs::ModeTagStruct::Type> & tags) override;
5959

60-
// Public helper to query support status without exposing internal tables
61-
static bool IsSupportedMode(uint8_t mode);
60+
/**
61+
* @brief Checks if the provided mode is supported.
62+
*
63+
* @param mode The mode to check.
64+
* @return true if the mode is supported, false otherwise.
65+
*/
66+
bool IsSupportedMode(uint8_t mode);
6267

6368
private:
6469
EndpointId mEndpointId;

examples/oven-app/oven-app-common/src/CookSurfaceEndpoint.cpp

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -26,24 +26,22 @@ using namespace chip::app::Clusters::CookSurface;
2626

2727
CHIP_ERROR CookSurfaceEndpoint::Init()
2828
{
29-
bool state = false;
30-
OnOffServer::Instance().getOnOffValue(mEndpointId, &state);
3129
return CHIP_NO_ERROR;
3230
}
3331

34-
bool CookSurfaceEndpoint::GetOnOffState()
32+
chip::Protocols::InteractionModel::Status CookSurfaceEndpoint::GetOnOffState(bool &state)
3533
{
36-
bool state = false;
37-
OnOffServer::Instance().getOnOffValue(mEndpointId, &state);
38-
return state;
34+
auto status = OnOffServer::Instance().getOnOffValue(mEndpointId, &state);
35+
VerifyOrReturnValue(status == Protocols::InteractionModel::Status::Success, status,
36+
ChipLogError(AppServer, "ERR: reading on/off %x", to_underlying(status)));
37+
return status;
3938
}
4039

41-
void CookSurfaceEndpoint::SetOnOffState(bool state)
40+
chip::Protocols::InteractionModel::Status CookSurfaceEndpoint::SetOnOffState(bool state)
4241
{
4342
CommandId commandId = state ? OnOff::Commands::On::Id : OnOff::Commands::Off::Id;
4443
auto status = OnOffServer::Instance().setOnOffValue(mEndpointId, commandId, false);
45-
if (status != Protocols::InteractionModel::Status::Success)
46-
{
47-
ChipLogError(AppServer, "ERR: updating on/off %x", to_underlying(status));
48-
}
44+
VerifyOrReturnValue(status == Protocols::InteractionModel::Status::Success, status,
45+
ChipLogError(AppServer, "ERR: updating on/off %x", to_underlying(status)));
46+
return status;
4947
}

examples/oven-app/oven-app-common/src/CookTopEndpoint.cpp

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,11 @@ CHIP_ERROR CookTopEndpoint::Init()
2727
return CHIP_NO_ERROR;
2828
}
2929

30-
void CookTopEndpoint::SetOnOffState(bool state)
30+
chip::Protocols::InteractionModel::Status CookTopEndpoint::SetOnOffState(bool state)
3131
{
3232
CommandId commandId = state ? OnOff::Commands::On::Id : OnOff::Commands::Off::Id;
3333
auto status = OnOffServer::Instance().setOnOffValue(mEndpointId, commandId, false);
34-
if (status == chip::Protocols::InteractionModel::Status::Success)
35-
{
36-
currentOnOffState = state;
37-
}
38-
return;
34+
VerifyOrReturnValue(status == Protocols::InteractionModel::Status::Success, status,
35+
ChipLogError(AppServer, "ERR: updating on/off %x", to_underlying(status)));
36+
return status;
3937
}

examples/oven-app/silabs/include/OvenManager.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,8 @@ class OvenManager
5656
kState_OffCompleted,
5757
kState_OnInitiated,
5858
kState_OnCompleted,
59+
kState_ActionInProgress,
60+
kState_NoAction,
5961
} State;
6062

6163
bool InitiateAction(int32_t aActor, Action_t aAction, uint8_t * aValue);

examples/oven-app/silabs/src/OvenManager.cpp

Lines changed: 22 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -57,21 +57,6 @@ void OvenManager::Init()
5757

5858
VerifyOrReturn(mCookTopEndpoint.Init() == CHIP_NO_ERROR, ChipLogError(AppServer, "CookTopEndpoint Init failed"));
5959

60-
// Initialize TemperatureControl cluster numeric temperature attributes for endpoint 2 (silent on failure)
61-
{
62-
Status tcStatus = TemperatureControl::Attributes::TemperatureSetpoint::Set(kTemperatureControlledCabinetEndpoint2, 0);
63-
VerifyOrReturn(tcStatus == Status::Success, ChipLogError(AppServer, "Endpoint2 TemperatureSetpoint init failed"));
64-
65-
tcStatus = TemperatureControl::Attributes::MinTemperature::Set(kTemperatureControlledCabinetEndpoint2, 0);
66-
VerifyOrReturn(tcStatus == Status::Success, ChipLogError(AppServer, "Endpoint2 MinTemperature init failed"));
67-
68-
tcStatus = TemperatureControl::Attributes::MaxTemperature::Set(kTemperatureControlledCabinetEndpoint2, 30000);
69-
VerifyOrReturn(tcStatus == Status::Success, ChipLogError(AppServer, "Endpoint2 MaxTemperature init failed"));
70-
71-
tcStatus = TemperatureControl::Attributes::Step::Set(kTemperatureControlledCabinetEndpoint2, 500);
72-
VerifyOrReturn(tcStatus == Status::Success, ChipLogError(AppServer, "Endpoint2 Step init failed"));
73-
}
74-
7560
// Register the shared TemperatureLevelsDelegate for all the cooksurface endpoints
7661
TemperatureControl::SetInstance(&mTemperatureControlDelegate);
7762

@@ -167,35 +152,42 @@ CHIP_ERROR OvenManager::SetTemperatureControlledCabinetInitialState(EndpointId t
167152

168153
void OvenManager::TempCtrlAttributeChangeHandler(EndpointId endpointId, AttributeId attributeId, uint8_t * value, uint16_t size)
169154
{
170-
if (endpointId == kTemperatureControlledCabinetEndpoint2)
155+
switch (endpointId)
171156
{
157+
case kTemperatureControlledCabinetEndpoint:
172158
// TODO: Update the LCD with the new Temperature Control attribute value
159+
break;
160+
default:
161+
break;
173162
}
174-
return;
175163
}
176164

177165
void OvenManager::OnOffAttributeChangeHandler(EndpointId endpointId, AttributeId attributeId, uint8_t * value, uint16_t size)
178166
{
179-
if (endpointId == kCookTopEndpoint3)
167+
switch (endpointId)
180168
{
169+
case kCookTopEndpoint3:
181170
InitiateAction(AppEvent::kEventType_Oven, *value ? OvenManager::ON_ACTION : OvenManager::OFF_ACTION, value);
182-
183171
// Update CookSurface states accordingly
184-
mCookSurfaceEndpoint4.SetOnOffState(*value);
185-
mCookSurfaceEndpoint5.SetOnOffState(*value);
186-
}
187-
else if (endpointId == kCookSurfaceEndpoint4 || endpointId == kCookSurfaceEndpoint5)
188-
{
172+
mCookSurfaceEndpoint1.SetOnOffState(*value);
173+
mCookSurfaceEndpoint2.SetOnOffState(*value);
174+
break;
175+
case kCookSurfaceEndpoint1:
176+
case kCookSurfaceEndpoint2:
189177
// Handle On/Off attribute changes for the cook surface endpoints
190-
bool cookSurfaceEndpoint4State = mCookSurfaceEndpoint4.GetOnOffState();
191-
bool cookSurfaceEndpoint5State = mCookSurfaceEndpoint5.GetOnOffState();
192-
// Check if both cooksurfaces are off. If yes, turn off the cooktop (call cooktop.TurnOffCookTop)
193-
if (cookSurfaceEndpoint4State == false && cookSurfaceEndpoint5State == false)
194178
{
195-
mCookTopEndpoint3.SetOnOffState(false);
179+
bool cookSurfaceEndpoint1State = mCookSurfaceEndpoint1.GetOnOffState();
180+
bool cookSurfaceEndpoint2State = mCookSurfaceEndpoint2.GetOnOffState();
181+
// Check if both cooksurfaces are off. If yes, turn off the cooktop (call cooktop.TurnOffCookTop)
182+
if (cookSurfaceEndpoint1State == false && cookSurfaceEndpoint2State == false)
183+
{
184+
mCookTopEndpoint3.SetOnOffState(false);
185+
}
196186
}
187+
break;
188+
default:
189+
break;
197190
}
198-
return;
199191
}
200192

201193
void OvenManager::OvenModeAttributeChangeHandler(chip::EndpointId endpointId, chip::AttributeId attributeId, uint8_t * value,

0 commit comments

Comments
 (0)