|
45 | 45 | #endif // MATTER_DM_PLUGIN_MODE_BASE
|
46 | 46 |
|
47 | 47 | #include <platform/CHIPDeviceLayer.h>
|
| 48 | +#include <platform/DiagnosticDataProvider.h> |
48 | 49 | #include <platform/PlatformManager.h>
|
49 | 50 |
|
50 | 51 | using namespace chip;
|
51 | 52 | using namespace chip::app::Clusters;
|
52 | 53 | using namespace chip::app::Clusters::OnOff;
|
53 | 54 | using chip::Protocols::InteractionModel::Status;
|
54 | 55 |
|
| 56 | +using BootReasonType = GeneralDiagnostics::BootReasonEnum; |
| 57 | + |
55 | 58 | namespace {
|
56 | 59 |
|
57 | 60 | #ifdef MATTER_DM_PLUGIN_MODE_BASE
|
@@ -89,6 +92,21 @@ void UpdateModeBaseCurrentModeToOnMode(EndpointId endpoint)
|
89 | 92 |
|
90 | 93 | #endif // MATTER_DM_PLUGIN_MODE_BASE
|
91 | 94 |
|
| 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 | + |
92 | 110 | } // namespace
|
93 | 111 |
|
94 | 112 | #ifdef MATTER_DM_PLUGIN_LEVEL_CONTROL
|
@@ -541,35 +559,40 @@ Status OnOffServer::getOnOffValueForStartUp(chip::EndpointId endpoint, bool & on
|
541 | 559 | {
|
542 | 560 | app::DataModel::Nullable<OnOff::StartUpOnOffEnum> startUpOnOff;
|
543 | 561 | Status status = Attributes::StartUpOnOff::Get(endpoint, startUpOnOff);
|
544 |
| - if (status == Status::Success) |
| 562 | + if (status != Status::Success) |
545 | 563 | {
|
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; |
571 | 565 | }
|
572 |
| - return status; |
| 566 | + |
| 567 | + bool currentOnOff = false; |
| 568 | + status = Attributes::OnOff::Get(endpoint, ¤tOnOff); |
| 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; |
573 | 596 | }
|
574 | 597 |
|
575 | 598 | bool OnOffServer::offCommand(app::CommandHandler * commandObj, const app::ConcreteCommandPath & commandPath)
|
|
0 commit comments