Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 7ebc1c0

Browse files
committedJul 3, 2024·
feat: restore onOffValue after reboot during OTA applying
1 parent 005f1b4 commit 7ebc1c0

File tree

1 file changed

+50
-27
lines changed

1 file changed

+50
-27
lines changed
 

‎src/app/clusters/on-off-server/on-off-server.cpp

+50-27
Original file line numberDiff line numberDiff line change
@@ -45,13 +45,16 @@
4545
#endif // MATTER_DM_PLUGIN_MODE_BASE
4646

4747
#include <platform/CHIPDeviceLayer.h>
48+
#include <platform/DiagnosticDataProvider.h>
4849
#include <platform/PlatformManager.h>
4950

5051
using namespace chip;
5152
using namespace chip::app::Clusters;
5253
using namespace chip::app::Clusters::OnOff;
5354
using chip::Protocols::InteractionModel::Status;
5455

56+
using BootReasonType = GeneralDiagnostics::BootReasonEnum;
57+
5558
namespace {
5659

5760
#ifdef MATTER_DM_PLUGIN_MODE_BASE
@@ -89,6 +92,21 @@ void UpdateModeBaseCurrentModeToOnMode(EndpointId endpoint)
8992

9093
#endif // MATTER_DM_PLUGIN_MODE_BASE
9194

95+
BootReasonType GetBootReason() {
96+
BootReasonType bootReason = BootReasonType::kUnspecified;
97+
98+
CHIP_ERROR error = DeviceLayer::GetDiagnosticDataProvider().GetBootReason(bootReason);
99+
if (error != CHIP_NO_ERROR)
100+
{
101+
ChipLogError(Zcl, "Unable to retrieve boot reason: %" CHIP_ERROR_FORMAT, error.Format());
102+
bootReason = BootReasonType::kUnspecified;
103+
}
104+
105+
ChipLogProgress(Zcl, "Boot reason: %u", to_underlying(bootReason));
106+
107+
return bootReason;
108+
}
109+
92110
} // namespace
93111

94112
#ifdef MATTER_DM_PLUGIN_LEVEL_CONTROL
@@ -541,35 +559,40 @@ Status OnOffServer::getOnOffValueForStartUp(chip::EndpointId endpoint, bool & on
541559
{
542560
app::DataModel::Nullable<OnOff::StartUpOnOffEnum> startUpOnOff;
543561
Status status = Attributes::StartUpOnOff::Get(endpoint, startUpOnOff);
544-
if (status == Status::Success)
562+
if (status != Status::Success)
545563
{
546-
// Initialise updated value to 0
547-
bool updatedOnOff = false;
548-
status = Attributes::OnOff::Get(endpoint, &updatedOnOff);
549-
if (status == Status::Success)
550-
{
551-
if (!startUpOnOff.IsNull())
552-
{
553-
switch (startUpOnOff.Value())
554-
{
555-
case OnOff::StartUpOnOffEnum::kOff:
556-
updatedOnOff = false; // Off
557-
break;
558-
case OnOff::StartUpOnOffEnum::kOn:
559-
updatedOnOff = true; // On
560-
break;
561-
case OnOff::StartUpOnOffEnum::kToggle:
562-
updatedOnOff = !updatedOnOff;
563-
break;
564-
default:
565-
// All other values 0x03- 0xFE are reserved - no action.
566-
break;
567-
}
568-
}
569-
onOffValueForStartUp = updatedOnOff;
570-
}
564+
return status;
571565
}
572-
return status;
566+
567+
bool currentOnOff = false;
568+
status = Attributes::OnOff::Get(endpoint, &currentOnOff);
569+
if (status != Status::Success) {
570+
return status;
571+
}
572+
573+
if (startUpOnOff.IsNull() || GetBootReason() == BootReasonType::kSoftwareUpdateCompleted)
574+
{
575+
onOffValueForStartUp = currentOnOff;
576+
return Status::Success;
577+
}
578+
579+
switch (startUpOnOff.Value())
580+
{
581+
case OnOff::StartUpOnOffEnum::kOff:
582+
onOffValueForStartUp = false; // Off
583+
break;
584+
case OnOff::StartUpOnOffEnum::kOn:
585+
onOffValueForStartUp = true; // On
586+
break;
587+
case OnOff::StartUpOnOffEnum::kToggle:
588+
onOffValueForStartUp = !currentOnOff;
589+
break;
590+
default:
591+
// All other values 0x03- 0xFE are reserved - no action.
592+
break;
593+
}
594+
595+
return Status::Success;
573596
}
574597

575598
bool OnOffServer::offCommand(app::CommandHandler * commandObj, const app::ConcreteCommandPath & commandPath)

0 commit comments

Comments
 (0)
Please sign in to comment.