|
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
|
@@ -95,6 +98,21 @@ bool IsKnownEnumValue(EnumType value)
|
95 | 98 | return (EnsureKnownEnumValue(value) != EnumType::kUnknownEnumValue);
|
96 | 99 | }
|
97 | 100 |
|
| 101 | +BootReasonType GetBootReason() { |
| 102 | + BootReasonType bootReason = BootReasonType::kUnspecified; |
| 103 | + |
| 104 | + CHIP_ERROR error = DeviceLayer::GetDiagnosticDataProvider().GetBootReason(bootReason); |
| 105 | + if (error != CHIP_NO_ERROR) |
| 106 | + { |
| 107 | + ChipLogError(Zcl, "Unable to retrieve boot reason: %" CHIP_ERROR_FORMAT, error.Format()); |
| 108 | + bootReason = BootReasonType::kUnspecified; |
| 109 | + } |
| 110 | + |
| 111 | + ChipLogProgress(Zcl, "Boot reason: %u", to_underlying(bootReason)); |
| 112 | + |
| 113 | + return bootReason; |
| 114 | +} |
| 115 | + |
98 | 116 | } // namespace
|
99 | 117 |
|
100 | 118 | #ifdef MATTER_DM_PLUGIN_LEVEL_CONTROL
|
@@ -537,35 +555,40 @@ Status OnOffServer::getOnOffValueForStartUp(chip::EndpointId endpoint, bool & on
|
537 | 555 | {
|
538 | 556 | app::DataModel::Nullable<OnOff::StartUpOnOffEnum> startUpOnOff;
|
539 | 557 | Status status = Attributes::StartUpOnOff::Get(endpoint, startUpOnOff);
|
540 |
| - if (status == Status::Success) |
| 558 | + if (status != Status::Success) |
541 | 559 | {
|
542 |
| - // Initialise updated value to 0 |
543 |
| - bool updatedOnOff = false; |
544 |
| - status = Attributes::OnOff::Get(endpoint, &updatedOnOff); |
545 |
| - if (status == Status::Success) |
546 |
| - { |
547 |
| - if (!startUpOnOff.IsNull()) |
548 |
| - { |
549 |
| - switch (startUpOnOff.Value()) |
550 |
| - { |
551 |
| - case OnOff::StartUpOnOffEnum::kOff: |
552 |
| - updatedOnOff = false; // Off |
553 |
| - break; |
554 |
| - case OnOff::StartUpOnOffEnum::kOn: |
555 |
| - updatedOnOff = true; // On |
556 |
| - break; |
557 |
| - case OnOff::StartUpOnOffEnum::kToggle: |
558 |
| - updatedOnOff = !updatedOnOff; |
559 |
| - break; |
560 |
| - default: |
561 |
| - // All other values 0x03- 0xFE are reserved - no action. |
562 |
| - break; |
563 |
| - } |
564 |
| - } |
565 |
| - onOffValueForStartUp = updatedOnOff; |
566 |
| - } |
| 560 | + return status; |
567 | 561 | }
|
568 |
| - return status; |
| 562 | + |
| 563 | + bool currentOnOff = false; |
| 564 | + status = Attributes::OnOff::Get(endpoint, ¤tOnOff); |
| 565 | + if (status != Status::Success) { |
| 566 | + return status; |
| 567 | + } |
| 568 | + |
| 569 | + if (startUpOnOff.IsNull() || GetBootReason() == BootReasonType::kSoftwareUpdateCompleted) |
| 570 | + { |
| 571 | + onOffValueForStartUp = currentOnOff; |
| 572 | + return Status::Success; |
| 573 | + } |
| 574 | + |
| 575 | + switch (startUpOnOff.Value()) |
| 576 | + { |
| 577 | + case OnOff::StartUpOnOffEnum::kOff: |
| 578 | + onOffValueForStartUp = false; // Off |
| 579 | + break; |
| 580 | + case OnOff::StartUpOnOffEnum::kOn: |
| 581 | + onOffValueForStartUp = true; // On |
| 582 | + break; |
| 583 | + case OnOff::StartUpOnOffEnum::kToggle: |
| 584 | + onOffValueForStartUp = !currentOnOff; |
| 585 | + break; |
| 586 | + default: |
| 587 | + // All other values 0x03- 0xFE are reserved - no action. |
| 588 | + break; |
| 589 | + } |
| 590 | + |
| 591 | + return Status::Success; |
569 | 592 | }
|
570 | 593 |
|
571 | 594 | bool OnOffServer::offCommand(app::CommandHandler * commandObj, const app::ConcreteCommandPath & commandPath)
|
|
0 commit comments