blob: 62630d730b4355ae5a4c0d84facd5ff70f221b19 [file] [log] [blame]
/*
* Copyright (c) 2024 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.
*/
#include "BridgedDeviceBasicInformationImpl.h"
#include "BridgedDeviceManager.h"
#include <app-common/zap-generated/cluster-objects.h>
#include <app-common/zap-generated/ids/Attributes.h>
#include <app-common/zap-generated/ids/Clusters.h>
#include <app/AttributeAccessInterfaceRegistry.h>
static constexpr unsigned kBridgedDeviceBasicInformationClusterRevision = 4;
static constexpr unsigned kBridgedDeviceBasicInformationFeatureMap = 0;
using namespace ::chip;
using namespace ::chip::app;
using namespace ::chip::app::Clusters;
CHIP_ERROR BridgedDeviceBasicInformationImpl::Read(const ConcreteReadAttributePath & path, AttributeValueEncoder & encoder)
{
// Registration is done for the bridged device basic information only
VerifyOrDie(path.mClusterId == app::Clusters::BridgedDeviceBasicInformation::Id);
BridgedDevice * dev = BridgeDeviceMgr().GetDevice(path.mEndpointId);
VerifyOrReturnError(dev != nullptr, CHIP_ERROR_NOT_FOUND);
switch (path.mAttributeId)
{
case BasicInformation::Attributes::Reachable::Id:
encoder.Encode(dev->IsReachable());
break;
case BasicInformation::Attributes::NodeLabel::Id:
encoder.Encode(CharSpan::fromCharString(dev->GetName()));
break;
case BasicInformation::Attributes::ClusterRevision::Id:
encoder.Encode(kBridgedDeviceBasicInformationClusterRevision);
break;
case BasicInformation::Attributes::FeatureMap::Id:
encoder.Encode(kBridgedDeviceBasicInformationFeatureMap);
break;
default:
return CHIP_ERROR_INVALID_ARGUMENT;
}
return CHIP_NO_ERROR;
}
CHIP_ERROR BridgedDeviceBasicInformationImpl::Write(const ConcreteDataAttributePath & path, AttributeValueDecoder & decoder)
{
VerifyOrDie(path.mClusterId == app::Clusters::BridgedDeviceBasicInformation::Id);
BridgedDevice * dev = BridgeDeviceMgr().GetDevice(path.mEndpointId);
VerifyOrReturnError(dev != nullptr, CHIP_ERROR_NOT_FOUND);
if (!dev->IsReachable())
{
return CHIP_ERROR_NOT_CONNECTED;
}
ChipLogProgress(NotSpecified, "Bridged device basic information attempt to write attribute: ep=%d", path.mAttributeId);
// nothing writable right now ...
return CHIP_ERROR_INVALID_ARGUMENT;
}