blob: df194f6ba8994719f92535e5b5e15d9a066d91ba [file] [log] [blame]
/*
*
* Copyright (c) 2021 Project CHIP Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
// THIS FILE IS GENERATED BY ZAP
#include "CHIPClusters.h"
#include <cstdint>
#include <app-common/zap-generated/ids/Attributes.h>
#include <app/CommandSender.h>
#include <app/InteractionModelEngine.h>
#include <app/chip-zcl-zpro-codec.h>
#include <app/util/basic-types.h>
#include <controller/CommandSenderAllocator.h>
#include <lib/core/CHIPSafeCasts.h>
#include <lib/support/BufferWriter.h>
#include <lib/support/CHIPMem.h>
#include <lib/support/CodeUtils.h>
#include <lib/support/SafeInt.h>
#include <lib/support/logging/CHIPLogging.h>
#include <system/SystemPacketBuffer.h>
#include <zap-generated/CHIPClientCallbacks.h>
namespace chip {
using namespace app::Clusters;
using namespace System;
using namespace Encoding::LittleEndian;
namespace Controller {
// TODO(#4502): onCompletion is not used by IM for now.
// TODO(#4503): length should be passed to commands when byte string is in argument list.
// TODO(#4503): Commands should take group id as an argument.
// OnOff Cluster Commands
// OnOff Cluster Attributes
CHIP_ERROR OnOffCluster::ReadAttributeOnOff(Callback::Cancelable * onSuccessCallback, Callback::Cancelable * onFailureCallback)
{
app::AttributePathParams attributePath;
attributePath.mEndpointId = mEndpoint;
attributePath.mClusterId = mClusterId;
attributePath.mFieldId = 0x00000000;
attributePath.mFlags.Set(app::AttributePathParams::Flags::kFieldIdValid);
return mDevice->SendReadAttributeRequest(attributePath, onSuccessCallback, onFailureCallback,
BasicAttributeFilter<BooleanAttributeCallback>);
}
CHIP_ERROR OnOffCluster::ReadAttributeGlobalSceneControl(Callback::Cancelable * onSuccessCallback,
Callback::Cancelable * onFailureCallback)
{
app::AttributePathParams attributePath;
attributePath.mEndpointId = mEndpoint;
attributePath.mClusterId = mClusterId;
attributePath.mFieldId = 0x00004000;
attributePath.mFlags.Set(app::AttributePathParams::Flags::kFieldIdValid);
return mDevice->SendReadAttributeRequest(attributePath, onSuccessCallback, onFailureCallback,
BasicAttributeFilter<BooleanAttributeCallback>);
}
CHIP_ERROR OnOffCluster::ReadAttributeOnTime(Callback::Cancelable * onSuccessCallback, Callback::Cancelable * onFailureCallback)
{
app::AttributePathParams attributePath;
attributePath.mEndpointId = mEndpoint;
attributePath.mClusterId = mClusterId;
attributePath.mFieldId = 0x00004001;
attributePath.mFlags.Set(app::AttributePathParams::Flags::kFieldIdValid);
return mDevice->SendReadAttributeRequest(attributePath, onSuccessCallback, onFailureCallback,
BasicAttributeFilter<Int16uAttributeCallback>);
}
CHIP_ERROR OnOffCluster::WriteAttributeOnTime(Callback::Cancelable * onSuccessCallback, Callback::Cancelable * onFailureCallback,
uint16_t value)
{
app::WriteClientHandle handle;
chip::app::AttributePathParams attributePath;
attributePath.mNodeId = mDevice->GetDeviceId();
attributePath.mEndpointId = mEndpoint;
attributePath.mClusterId = mClusterId;
attributePath.mFieldId = 0x00004001;
attributePath.mFlags.Set(chip::app::AttributePathParams::Flags::kFieldIdValid);
ReturnErrorOnFailure(app::InteractionModelEngine::GetInstance()->NewWriteClient(handle));
ReturnErrorOnFailure(handle.EncodeAttributeWritePayload(attributePath, value));
return mDevice->SendWriteAttributeRequest(std::move(handle), onSuccessCallback, onFailureCallback);
}
CHIP_ERROR OnOffCluster::ReadAttributeOffWaitTime(Callback::Cancelable * onSuccessCallback,
Callback::Cancelable * onFailureCallback)
{
app::AttributePathParams attributePath;
attributePath.mEndpointId = mEndpoint;
attributePath.mClusterId = mClusterId;
attributePath.mFieldId = 0x00004002;
attributePath.mFlags.Set(app::AttributePathParams::Flags::kFieldIdValid);
return mDevice->SendReadAttributeRequest(attributePath, onSuccessCallback, onFailureCallback,
BasicAttributeFilter<Int16uAttributeCallback>);
}
CHIP_ERROR OnOffCluster::WriteAttributeOffWaitTime(Callback::Cancelable * onSuccessCallback,
Callback::Cancelable * onFailureCallback, uint16_t value)
{
app::WriteClientHandle handle;
chip::app::AttributePathParams attributePath;
attributePath.mNodeId = mDevice->GetDeviceId();
attributePath.mEndpointId = mEndpoint;
attributePath.mClusterId = mClusterId;
attributePath.mFieldId = 0x00004002;
attributePath.mFlags.Set(chip::app::AttributePathParams::Flags::kFieldIdValid);
ReturnErrorOnFailure(app::InteractionModelEngine::GetInstance()->NewWriteClient(handle));
ReturnErrorOnFailure(handle.EncodeAttributeWritePayload(attributePath, value));
return mDevice->SendWriteAttributeRequest(std::move(handle), onSuccessCallback, onFailureCallback);
}
CHIP_ERROR OnOffCluster::ReadAttributeStartUpOnOff(Callback::Cancelable * onSuccessCallback,
Callback::Cancelable * onFailureCallback)
{
app::AttributePathParams attributePath;
attributePath.mEndpointId = mEndpoint;
attributePath.mClusterId = mClusterId;
attributePath.mFieldId = 0x00004003;
attributePath.mFlags.Set(app::AttributePathParams::Flags::kFieldIdValid);
return mDevice->SendReadAttributeRequest(attributePath, onSuccessCallback, onFailureCallback,
BasicAttributeFilter<Int8uAttributeCallback>);
}
CHIP_ERROR OnOffCluster::WriteAttributeStartUpOnOff(Callback::Cancelable * onSuccessCallback,
Callback::Cancelable * onFailureCallback, uint8_t value)
{
app::WriteClientHandle handle;
chip::app::AttributePathParams attributePath;
attributePath.mNodeId = mDevice->GetDeviceId();
attributePath.mEndpointId = mEndpoint;
attributePath.mClusterId = mClusterId;
attributePath.mFieldId = 0x00004003;
attributePath.mFlags.Set(chip::app::AttributePathParams::Flags::kFieldIdValid);
ReturnErrorOnFailure(app::InteractionModelEngine::GetInstance()->NewWriteClient(handle));
ReturnErrorOnFailure(handle.EncodeAttributeWritePayload(attributePath, value));
return mDevice->SendWriteAttributeRequest(std::move(handle), onSuccessCallback, onFailureCallback);
}
CHIP_ERROR OnOffCluster::ReadAttributeClusterRevision(Callback::Cancelable * onSuccessCallback,
Callback::Cancelable * onFailureCallback)
{
app::AttributePathParams attributePath;
attributePath.mEndpointId = mEndpoint;
attributePath.mClusterId = mClusterId;
attributePath.mFieldId = 0x0000FFFD;
attributePath.mFlags.Set(app::AttributePathParams::Flags::kFieldIdValid);
return mDevice->SendReadAttributeRequest(attributePath, onSuccessCallback, onFailureCallback,
BasicAttributeFilter<Int16uAttributeCallback>);
}
} // namespace Controller
} // namespace chip