Skip to content

Commit

Permalink
Update air quality api (#28707)
Browse files Browse the repository at this point in the history
* Added an air quality cluster instance class that manages the attributes via the AttributeAccessInterface. Marke these attributes as being manage via the AttributeAccessInterface.

* Regenerated auto gen code

* Added the instantiation of the Air Quality cluter in the all-clusters-app.

* Added method to get the current setting of the AirQuality attribute.

* Restyled by whitespace

* Restyled by clang-format

* Restyled by prettier-json

---------

Co-authored-by: Restyled.io <[email protected]>
  • Loading branch information
hicklin and restyled-commits authored Aug 22, 2023
1 parent 925914d commit cbc3865
Show file tree
Hide file tree
Showing 15 changed files with 254 additions and 42 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2046,7 +2046,7 @@ endpoint 1 {
}

server cluster AirQuality {
ram attribute airQuality default = 0;
callback attribute airQuality default = 0;
callback attribute generatedCommandList;
callback attribute acceptedCommandList;
callback attribute eventList;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6772,7 +6772,7 @@ endpoint 1 {
}

server cluster AirQuality {
ram attribute airQuality default = 0;
callback attribute airQuality default = 0;
callback attribute generatedCommandList;
callback attribute acceptedCommandList;
callback attribute attributeList;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#pragma once

#include <app/clusters/air-quality-server/air-quality-server.h>

namespace chip {
namespace app {
namespace Clusters {
namespace AirQuality {

void Shutdown();

} // namespace AirQuality
} // namespace Clusters
} // namespace app
} // namespace chip
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#include <air-quality-instance.h>

using namespace chip::app::Clusters;
using namespace chip::app::Clusters::AirQuality;

Instance * gAirQualityCluster = nullptr;

void AirQuality::Shutdown()
{
if (gAirQualityCluster != nullptr)
{
delete gAirQualityCluster;
gAirQualityCluster = nullptr;
}
}

void emberAfAirQualityClusterInitCallback(chip::EndpointId endpointId)
{
VerifyOrDie(endpointId == 1); // this cluster is only enabled for endpoint 1.
VerifyOrDie(gAirQualityCluster == nullptr);
chip::BitMask<Feature, uint32_t> airQualityFeatures(Feature::kModerate, Feature::kFair, Feature::kVeryPoor,
Feature::kExtremelyPoor);
gAirQualityCluster = new Instance(1, airQualityFeatures.Raw());
gAirQualityCluster->Init();
}
1 change: 1 addition & 0 deletions examples/all-clusters-app/linux/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import("${chip_root}/src/platform/device.gni")

source_set("chip-all-clusters-common") {
sources = [
"${chip_root}/examples/all-clusters-app/all-clusters-common/src/air-quality-instance.cpp",
"${chip_root}/examples/all-clusters-app/all-clusters-common/src/binding-handler.cpp",
"${chip_root}/examples/all-clusters-app/all-clusters-common/src/bridged-actions-stub.cpp",
"${chip_root}/examples/all-clusters-app/all-clusters-common/src/dishwasher-alarm-stub.cpp",
Expand Down
2 changes: 2 additions & 0 deletions examples/all-clusters-app/linux/main-common.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

#include "AllClustersCommandDelegate.h"
#include "WindowCoveringManager.h"
#include "air-quality-instance.h"
#include "dishwasher-mode.h"
#include "include/tv-callbacks.h"
#include "laundry-washer-controls-delegate-impl.h"
Expand Down Expand Up @@ -196,6 +197,7 @@ void ApplicationShutdown()
Clusters::RvcRunMode::Shutdown();
Clusters::RefrigeratorAndTemperatureControlledCabinetMode::Shutdown();

Clusters::AirQuality::Shutdown();
Clusters::OperationalState::Shutdown();
Clusters::RvcOperationalState::Shutdown();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1994,7 +1994,7 @@ endpoint 2 {
}

server cluster AirQuality {
ram attribute airQuality default = 0;
callback attribute airQuality default = 0;
callback attribute generatedCommandList;
callback attribute acceptedCommandList;
callback attribute eventList;
Expand Down
5 changes: 5 additions & 0 deletions src/app/chip_data_model.gni
Original file line number Diff line number Diff line change
Expand Up @@ -301,6 +301,11 @@ template("chip_data_model") {
"${_app_root}/clusters/${cluster}/SmokeCOTestEventTriggerDelegate.cpp",
"${_app_root}/clusters/${cluster}/SmokeCOTestEventTriggerDelegate.h",
]
} else if (cluster == "air-quality-server") {
sources += [
"${_app_root}/clusters/${cluster}/${cluster}.cpp",
"${_app_root}/clusters/${cluster}/${cluster}.h",
]
} else {
sources += [ "${_app_root}/clusters/${cluster}/${cluster}.cpp" ]
}
Expand Down
120 changes: 120 additions & 0 deletions src/app/clusters/air-quality-server/air-quality-server.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
/*
*
* Copyright (c) 2023 Project CHIP Authors
* All rights reserved.
*
* 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 "app-common/zap-generated/ids/Clusters.h"
#include <app-common/zap-generated/attributes/Accessors.h>
#include <app/clusters/air-quality-server/air-quality-server.h>
#include <app/reporting/reporting.h>
#include <app/util/attribute-storage.h>

using namespace chip;
using namespace chip::app;
using namespace chip::app::Clusters;
using chip::Protocols::InteractionModel::Status;

namespace chip {
namespace app {
namespace Clusters {
namespace AirQuality {

Instance::Instance(EndpointId aEndpointId, uint32_t aFeature) :
AttributeAccessInterface(Optional<EndpointId>(aEndpointId), Id), mEndpointId(aEndpointId), mFeature(aFeature)
{}

Instance::~Instance()
{
unregisterAttributeAccessOverride(this);
}

CHIP_ERROR Instance::Init()
{
// Check if the cluster has been selected in zap
VerifyOrDie(emberAfContainsServer(mEndpointId, Id) == true);

VerifyOrReturnError(registerAttributeAccessOverride(this), CHIP_ERROR_INCORRECT_STATE);

return CHIP_NO_ERROR;
}

bool Instance::HasFeature(AirQualityEnum aFeature) const
{
return mFeature & to_underlying(aFeature);
}

Protocols::InteractionModel::Status Instance::UpdateAirQuality(AirQualityEnum aNewAirQuality)
{
// Check that the value in is valid according to the enabled features.
switch (aNewAirQuality)
{
case AirQualityEnum::kFair: {
if (!HasFeature(AirQualityEnum::kFair))
{
return Protocols::InteractionModel::Status::ConstraintError;
}
}
break;
case AirQualityEnum::kModerate: {
if (!HasFeature(AirQualityEnum::kModerate))
{
return Protocols::InteractionModel::Status::ConstraintError;
}
}
break;
case AirQualityEnum::kPoor: {
if (!HasFeature(AirQualityEnum::kPoor))
{
return Protocols::InteractionModel::Status::ConstraintError;
}
}
break;
case AirQualityEnum::kExtremelyPoor: {
if (!HasFeature(AirQualityEnum::kExtremelyPoor))
{
return Protocols::InteractionModel::Status::ConstraintError;
}
}
break;
default:
break;
}

mAirQuality = aNewAirQuality;
MatterReportingAttributeChangeCallback(ConcreteAttributePath(mEndpointId, Id, Attributes::AirQuality::Id));
return Protocols::InteractionModel::Status::Success;
}

AirQualityEnum Instance::GetAirQuality()
{
return mAirQuality;
}

CHIP_ERROR Instance::Read(const ConcreteReadAttributePath & aPath, AttributeValueEncoder & aEncoder)
{
switch (aPath.mAttributeId)
{
case Attributes::AirQuality::Id:
ReturnErrorOnFailure(aEncoder.Encode(mAirQuality));
break;
}
return CHIP_NO_ERROR;
}

} // namespace AirQuality
} // namespace Clusters
} // namespace app
} // namespace chip
78 changes: 78 additions & 0 deletions src/app/clusters/air-quality-server/air-quality-server.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
/*
*
* Copyright (c) 2023 Project CHIP Authors
* All rights reserved.
*
* 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.
*/

#pragma once

#include <app/AttributeAccessInterface.h>

namespace chip {
namespace app {
namespace Clusters {
namespace AirQuality {

class Instance : public AttributeAccessInterface
{
public:
/**
* Creates an air quality cluster instance. The Init() function needs to be called for this instance to be registered and
* called by the interaction model at the appropriate times.
* @param aEndpointId The endpoint on which this cluster exists. This must match the zap configuration.
* @param aFeature The bitmask value that identifies which features are supported by this instance.
*/
Instance(EndpointId aEndpointId, uint32_t eFeature);

~Instance() override;

/**
* Initialises the air quality cluster instance
* @return Returns an error if an air quality cluster has not been enabled in zap for the given endpoint ID or
* if the AttributeHandler registration fails.
*/
CHIP_ERROR Init();

/**
* Returns true if the feature is supported.
* @param feature the feature to check.
*/
bool HasFeature(AirQualityEnum) const;

/**
* Sets the AirQuality attribute.
* @param aNewAirQuality The value to which the AirQuality attribute is to be set.
* @return Returns a ConstraintError if the aNewAirQuality value is not valid. Returns Success otherwise.
*/
Protocols::InteractionModel::Status UpdateAirQuality(AirQualityEnum aNewAirQuality);

/**
* @return The current AirQuality enum.
*/
AirQualityEnum GetAirQuality();

private:
EndpointId mEndpointId;
AirQualityEnum mAirQuality = AirQualityEnum::kUnknown;
uint32_t mFeature;

// AttributeAccessInterface
CHIP_ERROR Read(const ConcreteReadAttributePath & aPath, AttributeValueEncoder & aEncoder) override;
};

} // namespace AirQuality
} // namespace Clusters
} // namespace app
} // namespace chip
3 changes: 2 additions & 1 deletion src/app/zap-templates/zcl/zcl-with-test-extensions.json
Original file line number Diff line number Diff line change
Expand Up @@ -378,7 +378,8 @@
"LastChangedTime",
"ReplacementProductList",
"FeatureMap"
]
],
"Air Quality": ["AirQuality", "FeatureMap"]
},
"defaultReportingPolicy": "mandatory",
"ZCLDataTypes": ["ARRAY", "BITMAP", "ENUM", "NUMBER", "STRING", "STRUCT"],
Expand Down
3 changes: 2 additions & 1 deletion src/app/zap-templates/zcl/zcl.json
Original file line number Diff line number Diff line change
Expand Up @@ -376,7 +376,8 @@
"LastChangedTime",
"ReplacementProductList",
"FeatureMap"
]
],
"Air Quality": ["AirQuality", "FeatureMap"]
},
"defaultReportingPolicy": "mandatory",
"ZCLDataTypes": ["ARRAY", "BITMAP", "ENUM", "NUMBER", "STRING", "STRUCT"],
Expand Down
2 changes: 1 addition & 1 deletion src/app/zap_cluster_list.json
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@
"ServerDirectories": {
"ACCESS_CONTROL_CLUSTER": ["access-control-server"],
"ACCOUNT_LOGIN_CLUSTER": ["account-login-server"],
"ACTIONS_CLUSTER": [],
"ACTIONS_CLUSTER": ["air-quality-server"],
"ACTIVATED_CARBON_FILTER_MONITORING_CLUSTER": [
"resource-monitoring-server"
],
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit cbc3865

Please sign in to comment.