|
| 1 | +/** |
| 2 | + * |
| 3 | + * Copyright (c) 2023 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 | + * @file Cross-platform API to handle cluster-specific logic for the valve configuration and control cluster on a single endpoint. |
| 19 | + */ |
| 20 | + |
| 21 | +#include "valve-configuration-and-control-cluster-logic.h" |
| 22 | +#include <lib/core/CHIPError.h> |
| 23 | + |
| 24 | +namespace chip { |
| 25 | +namespace app { |
| 26 | +namespace Clusters { |
| 27 | +namespace ValveConfigurationAndControl { |
| 28 | + |
| 29 | +CHIP_ERROR ClusterLogic::Init(const ClusterConformance & conformance, const ClusterState & initialState) |
| 30 | +{ |
| 31 | + if (!conformance.Valid()) |
| 32 | + { |
| 33 | + return CHIP_ERROR_INVALID_DEVICE_DESCRIPTOR; |
| 34 | + } |
| 35 | + mConformance = conformance; |
| 36 | + mState = initialState; |
| 37 | + mInitialized = true; |
| 38 | + return CHIP_NO_ERROR; |
| 39 | +} |
| 40 | + |
| 41 | +// All Get functions: |
| 42 | +// Return CHIP_ERROR_INVALID_STATE if the class has not been initialized. |
| 43 | +// Return CHIP_ERROR_UNSUPPORTED_CHIP_FEATURE if the attribute is not supported by the conformance. |
| 44 | +// Return CHIP_NO_ERROR and set the parameter value otherwise |
| 45 | +CHIP_ERROR ClusterLogic::GetOpenDuration(DataModel::Nullable<uint32_t> * openDuration) |
| 46 | +{ |
| 47 | + VerifyOrReturnError(mInitialized, CHIP_ERROR_INCORRECT_STATE); |
| 48 | + *openDuration = mState.openDuration; |
| 49 | + return CHIP_NO_ERROR; |
| 50 | +} |
| 51 | +CHIP_ERROR ClusterLogic::GetDefaultOpenDuration(DataModel::Nullable<uint32_t> * defaultOpenDuration) |
| 52 | +{ |
| 53 | + VerifyOrReturnError(mInitialized, CHIP_ERROR_INCORRECT_STATE); |
| 54 | + *defaultOpenDuration = mState.openDuration; |
| 55 | + return CHIP_NO_ERROR; |
| 56 | +} |
| 57 | +CHIP_ERROR ClusterLogic::GetAutoCloseTime(DataModel::Nullable<uint64_t> * autoCloseTime) |
| 58 | +{ |
| 59 | + VerifyOrReturnError(mInitialized, CHIP_ERROR_INCORRECT_STATE); |
| 60 | + VerifyOrReturnError(mConformance.HasFeature(Feature::kTimeSync), CHIP_ERROR_UNSUPPORTED_CHIP_FEATURE); |
| 61 | + *autoCloseTime = mState.autoCloseTime; |
| 62 | + return CHIP_NO_ERROR; |
| 63 | +} |
| 64 | +CHIP_ERROR ClusterLogic::GetRemainingDuration(DataModel::Nullable<uint32_t> * remainingDuration) |
| 65 | +{ |
| 66 | + VerifyOrReturnError(mInitialized, CHIP_ERROR_INCORRECT_STATE); |
| 67 | + *remainingDuration = mState.remainingDuration; |
| 68 | + return CHIP_NO_ERROR; |
| 69 | +} |
| 70 | +CHIP_ERROR ClusterLogic::GetCurrentState(DataModel::Nullable<ValveStateEnum> * currentState) |
| 71 | +{ |
| 72 | + VerifyOrReturnError(mInitialized, CHIP_ERROR_INCORRECT_STATE); |
| 73 | + *currentState = mState.currentState; |
| 74 | + return CHIP_NO_ERROR; |
| 75 | +} |
| 76 | +CHIP_ERROR ClusterLogic::GetTargetState(DataModel::Nullable<ValveStateEnum> * targetState) |
| 77 | +{ |
| 78 | + VerifyOrReturnError(mInitialized, CHIP_ERROR_INCORRECT_STATE); |
| 79 | + *targetState = mState.targetState; |
| 80 | + return CHIP_NO_ERROR; |
| 81 | +} |
| 82 | +CHIP_ERROR ClusterLogic::GetCurrentLevel(DataModel::Nullable<uint8_t> * currentLevel) |
| 83 | +{ |
| 84 | + VerifyOrReturnError(mInitialized, CHIP_ERROR_INCORRECT_STATE); |
| 85 | + VerifyOrReturnError(mConformance.HasFeature(Feature::kLevel), CHIP_ERROR_UNSUPPORTED_CHIP_FEATURE); |
| 86 | + *currentLevel = mState.currentLevel; |
| 87 | + return CHIP_NO_ERROR; |
| 88 | +} |
| 89 | +CHIP_ERROR ClusterLogic::GetTargetLevel(DataModel::Nullable<uint8_t> * targetLevel) |
| 90 | +{ |
| 91 | + VerifyOrReturnError(mInitialized, CHIP_ERROR_INCORRECT_STATE); |
| 92 | + VerifyOrReturnError(mConformance.HasFeature(Feature::kLevel), CHIP_ERROR_UNSUPPORTED_CHIP_FEATURE); |
| 93 | + *targetLevel = mState.targetLevel; |
| 94 | + return CHIP_NO_ERROR; |
| 95 | +} |
| 96 | +CHIP_ERROR ClusterLogic::GetDefaultOpenLevel(uint8_t * defaultOpenLevel) |
| 97 | +{ |
| 98 | + VerifyOrReturnError(mInitialized, CHIP_ERROR_INCORRECT_STATE); |
| 99 | + VerifyOrReturnError(mConformance.HasFeature(Feature::kLevel), CHIP_ERROR_UNSUPPORTED_CHIP_FEATURE); |
| 100 | + VerifyOrReturnError(mConformance.supportsDefaultOpenLevel, CHIP_ERROR_UNSUPPORTED_CHIP_FEATURE); |
| 101 | + *defaultOpenLevel = mState.defaultOpenLevel; |
| 102 | + return CHIP_NO_ERROR; |
| 103 | +} |
| 104 | +CHIP_ERROR ClusterLogic::GetValveFault(BitMask<ValveFaultBitmap> * valveFault) |
| 105 | +{ |
| 106 | + VerifyOrReturnError(mInitialized, CHIP_ERROR_INCORRECT_STATE); |
| 107 | + VerifyOrReturnError(mConformance.supportsValveFault, CHIP_ERROR_UNSUPPORTED_CHIP_FEATURE); |
| 108 | + *valveFault = mState.valveFault; |
| 109 | + return CHIP_NO_ERROR; |
| 110 | +} |
| 111 | +CHIP_ERROR ClusterLogic::GetLevelStep(uint8_t * levelStep) |
| 112 | +{ |
| 113 | + VerifyOrReturnError(mInitialized, CHIP_ERROR_INCORRECT_STATE); |
| 114 | + VerifyOrReturnError(mConformance.HasFeature(Feature::kLevel), CHIP_ERROR_UNSUPPORTED_CHIP_FEATURE); |
| 115 | + VerifyOrReturnError(mConformance.supportsLevelStep, CHIP_ERROR_UNSUPPORTED_CHIP_FEATURE); |
| 116 | + *levelStep = mState.levelStep; |
| 117 | + return CHIP_NO_ERROR; |
| 118 | +} |
| 119 | + |
| 120 | +} // namespace ValveConfigurationAndControl |
| 121 | +} // namespace Clusters |
| 122 | +} // namespace app |
| 123 | +} // namespace chip |
0 commit comments