Skip to content

Commit

Permalink
feat: restore onOffValue after reboot during OTA applying
Browse files Browse the repository at this point in the history
  • Loading branch information
j0tunn committed Jul 2, 2024
1 parent 005f1b4 commit 8836ee5
Showing 1 changed file with 19 additions and 1 deletion.
20 changes: 19 additions & 1 deletion src/app/clusters/on-off-server/on-off-server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,13 +45,16 @@
#endif // MATTER_DM_PLUGIN_MODE_BASE

#include <platform/CHIPDeviceLayer.h>
#include <platform/DiagnosticDataProvider.h>
#include <platform/PlatformManager.h>

using namespace chip;
using namespace chip::app::Clusters;
using namespace chip::app::Clusters::OnOff;
using chip::Protocols::InteractionModel::Status;

using BootReasonType = GeneralDiagnostics::BootReasonEnum;

namespace {

#ifdef MATTER_DM_PLUGIN_MODE_BASE
Expand Down Expand Up @@ -89,6 +92,21 @@ void UpdateModeBaseCurrentModeToOnMode(EndpointId endpoint)

#endif // MATTER_DM_PLUGIN_MODE_BASE

BootReasonType GetBootReason() {
BootReasonType bootReason = BootReasonType::kUnspecified;

CHIP_ERROR error = DeviceLayer::GetDiagnosticDataProvider().GetBootReason(bootReason);
if (error != CHIP_NO_ERROR)
{
ChipLogError(Zcl, "Unable to retrieve boot reason: %" CHIP_ERROR_FORMAT, error.Format());
bootReason = BootReasonType::kUnspecified;
}

ChipLogProgress(Zcl, "Boot reason: %u", to_underlying(bootReason));

return bootReason;
}

} // namespace

#ifdef MATTER_DM_PLUGIN_LEVEL_CONTROL
Expand Down Expand Up @@ -500,7 +518,7 @@ void OnOffServer::initOnOffServer(chip::EndpointId endpoint)

bool onOffValueForStartUp = false;
Status status = getOnOffValueForStartUp(endpoint, onOffValueForStartUp);
if (status == Status::Success)
if (status == Status::Success && GetBootReason() != BootReasonType::kSoftwareUpdateCompleted)
{
status = setOnOffValue(endpoint, onOffValueForStartUp, true);
}
Expand Down

0 comments on commit 8836ee5

Please sign in to comment.