|
| 1 | +/* |
| 2 | + * |
| 3 | + * Copyright (c) 2024 Project CHIP Authors |
| 4 | + * |
| 5 | + * Licensed under the Apache License, Version 2.0 (the "License"); |
| 6 | + * you may not use this file except in compliance with the License. |
| 7 | + * You may obtain a copy of the License at |
| 8 | + * |
| 9 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | + * |
| 11 | + * Unless required by applicable law or agreed to in writing, software |
| 12 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 13 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 | + * See the License for the specific language governing permissions and |
| 15 | + * limitations under the License. |
| 16 | + */ |
| 17 | + |
| 18 | +#pragma once |
| 19 | + |
| 20 | +#include <app-common/zap-generated/cluster-objects.h> |
| 21 | +#include <app/TestEventTriggerDelegate.h> |
| 22 | + |
| 23 | +/** |
| 24 | + * @brief User handler for handling the test event trigger |
| 25 | + * |
| 26 | + * @note If TestEventTrigger is enabled, it needs to be implemented in the app |
| 27 | + * |
| 28 | + * @param eventTrigger Event trigger to handle |
| 29 | + * |
| 30 | + * @retval true on success |
| 31 | + * @retval false if error happened |
| 32 | + */ |
| 33 | +bool HandleDeviceEnergyManagementTestEventTrigger(uint64_t eventTrigger); |
| 34 | + |
| 35 | +namespace chip { |
| 36 | + |
| 37 | +/* |
| 38 | + * These Test EventTrigger values can be used to produce artificial DEM forecasts |
| 39 | + * |
| 40 | + * They are sent along with the enableKey (manufacturer defined secret) |
| 41 | + * in the General Diagnostic cluster TestEventTrigger command |
| 42 | + */ |
| 43 | +enum class DeviceEnergyManagementTrigger : uint64_t |
| 44 | +{ |
| 45 | + // Simulate a fixed forecast power usage including one or more PowerAdjustmentStructs |
| 46 | + kPowerAdjustment = 0x0098'0000'0000'0000, |
| 47 | + // Clear the PowerAdjustment structs |
| 48 | + kPowerAdjustmentClear = 0x0098'0000'0000'0001, |
| 49 | + // Simulate user opt-out of Local Optimization |
| 50 | + kUserOptOutLocalOptimization = 0x0098'0000'0000'0002, |
| 51 | + // Simulate user opt-out of Grid Optimization |
| 52 | + kUserOptOutGridOptimization = 0x0098'0000'0000'0003, |
| 53 | + // Remove all user opt-out opting out |
| 54 | + kUserOptOutClearAll = 0x0098'0000'0000'0004, |
| 55 | + // Simulate a fixed forecast with EarliestStartTime earlier than startTime, and LatestEndTime greater than EndTime |
| 56 | + kStartTimeAdjustment = 0x0098'0000'0000'0005, |
| 57 | + // Clear the StartTimeAdjustment simulated forecast |
| 58 | + kStartTimeAdjustmentClear = 0x0098'0000'0000'0006, |
| 59 | + // Simulate a fixed forecast with one pausable slo with MinPauseDuration >1, MaxPauseDuration>1 and one non pausable slot |
| 60 | + kPausable = 0x0098'0000'0000'0007, |
| 61 | + // Simulate a moving time to the next forecast slot |
| 62 | + kPausableNextSlot = 0x0098'0000'0000'0008, |
| 63 | + // Clear the Pausable simulated forecast |
| 64 | + kPausableClear = 0x0098'0000'0000'0009, |
| 65 | + // Simulate a forecast power usage with at least 2 and at most 4 slots |
| 66 | + kForecastAdjustment = 0x0098'0000'0000'000A, |
| 67 | + // Simulate moving time to the next forecast slot |
| 68 | + kForecastAdjustmentNextSlot = 0x0098'0000'0000'000B, |
| 69 | + // Clear the forecast adjustment |
| 70 | + kForecastAdjustmentClear = 0x0098'0000'0000'000C, |
| 71 | + // Simulate a forecast power usage with at least 2 and at most 4 slots |
| 72 | + kConstraintBasedAdjustment = 0x0098'0000'0000'000D, |
| 73 | + // Clear the constraint based adjustment |
| 74 | + kConstraintBasedAdjustmentClear = 0x0098'0000'0000'000E, |
| 75 | + // Simulate a forecast with at least 1 slot |
| 76 | + kForecast = 0x0098'0000'0000'000F, |
| 77 | + // Clear the forecast |
| 78 | + kForecastClear = 0x0098'0000'0000'0010, |
| 79 | +}; |
| 80 | + |
| 81 | +class DeviceEnergyManagementTestEventTriggerHandler : public TestEventTriggerHandler |
| 82 | +{ |
| 83 | +public: |
| 84 | + DeviceEnergyManagementTestEventTriggerHandler() {} |
| 85 | + |
| 86 | + CHIP_ERROR HandleEventTrigger(uint64_t eventTrigger) override |
| 87 | + { |
| 88 | + if (HandleDeviceEnergyManagementTestEventTrigger(eventTrigger)) |
| 89 | + { |
| 90 | + return CHIP_NO_ERROR; |
| 91 | + } |
| 92 | + return CHIP_ERROR_INVALID_ARGUMENT; |
| 93 | + } |
| 94 | +}; |
| 95 | + |
| 96 | +} // namespace chip |
0 commit comments