Skip to content

Commit

Permalink
Fan Control Cluster updates for Fall 2023: TE1 (#26296)
Browse files Browse the repository at this point in the history
* Updated fan-control-server with better support for feature checking, step command handler and checks around the supported attributes in the pre-callback

* Updated fan-control-cluster.xml for TE1 for fall release and regenerated the generated code

* Ensured status was always initialised before returning, added missing break in switch case

* Update optional parameters of Step command and matched spec naming. Improved checking on Auto feature when receiving smart mode.

* Added a stop-gap fan-stub.cpp so that the existing FanControl tests pass for TE1

* removed unused variable

* fixed return after else warning

* reordered files as per restyler
  • Loading branch information
mhazley authored and pull[bot] committed Jun 9, 2023
1 parent 3371fb1 commit 389aea4
Show file tree
Hide file tree
Showing 43 changed files with 1,773 additions and 70 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3285,6 +3285,16 @@ server cluster Thermostat = 513 {

/** An interface for controlling a fan in a heating/cooling system. */
server cluster FanControl = 514 {
enum AirflowDirectionEnum : ENUM8 {
kForward = 0;
kReverse = 1;
}

enum DirectionEnum : ENUM8 {
kIncrease = 0;
kDecrease = 1;
}

enum FanModeSequenceType : ENUM8 {
kOffLowMedHigh = 0;
kOffLowHigh = 1;
Expand All @@ -3309,6 +3319,8 @@ server cluster FanControl = 514 {
kAuto = 0x2;
kRocking = 0x4;
kWind = 0x8;
kStep = 0x10;
kAirflowDirection = 0x20;
}

bitmap RockSupportMask : BITMAP8 {
Expand Down Expand Up @@ -3338,12 +3350,21 @@ server cluster FanControl = 514 {
attribute bitmap8 rockSetting = 8;
readonly attribute bitmap8 windSupport = 9;
attribute bitmap8 windSetting = 10;
attribute AirflowDirectionEnum airflowDirection = 11;
readonly attribute command_id generatedCommandList[] = 65528;
readonly attribute command_id acceptedCommandList[] = 65529;
readonly attribute event_id eventList[] = 65530;
readonly attribute attrib_id attributeList[] = 65531;
readonly attribute bitmap32 featureMap = 65532;
readonly attribute int16u clusterRevision = 65533;

request struct StepRequest {
DirectionEnum direction = 0;
optional boolean wrap = 1;
optional boolean lowestOff = 2;
}

command Step(StepRequest): DefaultSuccess = 0;
}

/** An interface for configuring the user interface of a thermostat (which may be remote from the thermostat). */
Expand Down Expand Up @@ -5330,6 +5351,7 @@ endpoint 1 {
ram attribute rockSetting default = 0x00;
ram attribute windSupport default = 0x00;
ram attribute windSetting default = 0x00;
ram attribute airflowDirection default = 0;
ram attribute featureMap default = 0x0F;
ram attribute clusterRevision default = 2;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15716,7 +15716,17 @@
"mfgCode": null,
"define": "FAN_CONTROL_CLUSTER",
"side": "client",
"enabled": 0
"enabled": 0,
"commands": [
{
"name": "Step",
"code": 0,
"mfgCode": null,
"source": "client",
"incoming": 1,
"outgoing": 0
}
]
},
{
"name": "Fan Control",
Expand Down Expand Up @@ -15902,6 +15912,22 @@
"maxInterval": 65534,
"reportableChange": 0
},
{
"name": "AirflowDirection",
"code": 11,
"mfgCode": null,
"side": "server",
"type": "AirflowDirectionEnum",
"included": 1,
"storageOption": "RAM",
"singleton": 0,
"bounded": 0,
"defaultValue": "0",
"reportable": 1,
"minInterval": 1,
"maxInterval": 65534,
"reportableChange": 0
},
{
"name": "GeneratedCommandList",
"code": 65528,
Expand Down
115 changes: 115 additions & 0 deletions examples/all-clusters-app/all-clusters-common/src/fan-stub.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
/*
*
* Copyright (c) 2023 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 <app-common/zap-generated/attributes/Accessors.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/AttributeAccessInterface.h>
#include <app/util/attribute-storage.h>
#include <lib/support/CodeUtils.h>
#include <lib/support/logging/CHIPLogging.h>

using namespace chip;
using namespace chip::app;
using namespace chip::app::Clusters;
using namespace chip::app::Clusters::FanControl::Attributes;

namespace {

/*
* TODO: This is a stop-gap solution to allow the existing fan control cluster tests to run after changes to
* the cluster objects for TE1. This should be removed once #6496 is resolved as it will likely result in a
* FanControl delegate added to the SDK.
*
* FYI... The previous implementation of the FanControl cluster set the speedCurrent/percentCurrent when it received
* speedSetting/percentSetting. The new implementation of the FanControl cluster does not do this as this should
* really be done by the application.
*/

class FanAttrAccess : public AttributeAccessInterface
{
public:
// Register for the FanControl cluster on all endpoints.
FanAttrAccess() : AttributeAccessInterface(Optional<EndpointId>::Missing(), FanControl::Id) {}

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

private:
CHIP_ERROR ReadPercentCurrent(EndpointId endpoint, AttributeValueEncoder & aEncoder);
CHIP_ERROR ReadSpeedCurrent(EndpointId endpoint, AttributeValueEncoder & aEncoder);
};

CHIP_ERROR FanAttrAccess::ReadPercentCurrent(EndpointId endpoint, AttributeValueEncoder & aEncoder)
{
// Return PercentSetting attribute value for now
DataModel::Nullable<uint8_t> percentSetting;
PercentSetting::Get(endpoint, percentSetting);
uint8_t ret = 0;
if (!percentSetting.IsNull())
{
ret = percentSetting.Value();
}

return aEncoder.Encode(ret);
}

CHIP_ERROR FanAttrAccess::ReadSpeedCurrent(EndpointId endpoint, AttributeValueEncoder & aEncoder)
{
// Return SpeedCurrent attribute value for now
DataModel::Nullable<uint8_t> speedSetting;
SpeedSetting::Get(endpoint, speedSetting);
uint8_t ret = 0;
if (!speedSetting.IsNull())
{
ret = speedSetting.Value();
}

return aEncoder.Encode(ret);
}

FanAttrAccess gAttrAccess;

CHIP_ERROR FanAttrAccess::Read(const ConcreteReadAttributePath & aPath, AttributeValueEncoder & aEncoder)
{
VerifyOrDie(aPath.mClusterId == FanControl::Id);

switch (aPath.mAttributeId)
{
case SpeedCurrent::Id:
return ReadSpeedCurrent(aPath.mEndpointId, aEncoder);
case PercentCurrent::Id:
return ReadPercentCurrent(aPath.mEndpointId, aEncoder);
default:
break;
}
return CHIP_NO_ERROR;
}
} // anonymous namespace

void emberAfFanControlClusterInitCallback(EndpointId endpoint)
{
uint32_t featureMap = 0;

featureMap |= to_underlying(FanControl::Feature::kMultiSpeed);
featureMap |= to_underlying(FanControl::Feature::kMultiSpeed);
featureMap |= to_underlying(FanControl::Feature::kAuto);

FeatureMap::Set(endpoint, featureMap);

registerAttributeAccessOverride(&gAttrAccess);
}
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 @@ -23,6 +23,7 @@ source_set("chip-all-clusters-common") {
sources = [
"${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/fan-stub.cpp",
"${chip_root}/examples/all-clusters-app/all-clusters-common/src/static-supported-modes-manager.cpp",
"AllClustersCommandDelegate.cpp",
"AppOptions.cpp",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2769,6 +2769,16 @@ server cluster Thermostat = 513 {

/** An interface for controlling a fan in a heating/cooling system. */
server cluster FanControl = 514 {
enum AirflowDirectionEnum : ENUM8 {
kForward = 0;
kReverse = 1;
}

enum DirectionEnum : ENUM8 {
kIncrease = 0;
kDecrease = 1;
}

enum FanModeSequenceType : ENUM8 {
kOffLowMedHigh = 0;
kOffLowHigh = 1;
Expand All @@ -2793,6 +2803,8 @@ server cluster FanControl = 514 {
kAuto = 0x2;
kRocking = 0x4;
kWind = 0x8;
kStep = 0x10;
kAirflowDirection = 0x20;
}

bitmap RockSupportMask : BITMAP8 {
Expand Down
12 changes: 12 additions & 0 deletions examples/chef/devices/rootnode_fan_7N2TobIlOX.matter
Original file line number Diff line number Diff line change
Expand Up @@ -1187,6 +1187,16 @@ server cluster FixedLabel = 64 {

/** An interface for controlling a fan in a heating/cooling system. */
server cluster FanControl = 514 {
enum AirflowDirectionEnum : ENUM8 {
kForward = 0;
kReverse = 1;
}

enum DirectionEnum : ENUM8 {
kIncrease = 0;
kDecrease = 1;
}

enum FanModeSequenceType : ENUM8 {
kOffLowMedHigh = 0;
kOffLowHigh = 1;
Expand All @@ -1211,6 +1221,8 @@ server cluster FanControl = 514 {
kAuto = 0x2;
kRocking = 0x4;
kWind = 0x8;
kStep = 0x10;
kAirflowDirection = 0x20;
}

bitmap RockSupportMask : BITMAP8 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1500,6 +1500,16 @@ client cluster Thermostat = 513 {

/** An interface for controlling a fan in a heating/cooling system. */
server cluster FanControl = 514 {
enum AirflowDirectionEnum : ENUM8 {
kForward = 0;
kReverse = 1;
}

enum DirectionEnum : ENUM8 {
kIncrease = 0;
kDecrease = 1;
}

enum FanModeSequenceType : ENUM8 {
kOffLowMedHigh = 0;
kOffLowHigh = 1;
Expand All @@ -1524,6 +1534,8 @@ server cluster FanControl = 514 {
kAuto = 0x2;
kRocking = 0x4;
kWind = 0x8;
kStep = 0x10;
kAirflowDirection = 0x20;
}

bitmap RockSupportMask : BITMAP8 {
Expand Down
22 changes: 22 additions & 0 deletions examples/chef/devices/rootnode_thermostat_bm3fb8dhYi.matter
Original file line number Diff line number Diff line change
Expand Up @@ -1309,6 +1309,16 @@ server cluster Thermostat = 513 {

/** An interface for controlling a fan in a heating/cooling system. */
client cluster FanControl = 514 {
enum AirflowDirectionEnum : ENUM8 {
kForward = 0;
kReverse = 1;
}

enum DirectionEnum : ENUM8 {
kIncrease = 0;
kDecrease = 1;
}

enum FanModeSequenceType : ENUM8 {
kOffLowMedHigh = 0;
kOffLowHigh = 1;
Expand All @@ -1333,6 +1343,8 @@ client cluster FanControl = 514 {
kAuto = 0x2;
kRocking = 0x4;
kWind = 0x8;
kStep = 0x10;
kAirflowDirection = 0x20;
}

bitmap RockSupportMask : BITMAP8 {
Expand Down Expand Up @@ -1362,12 +1374,22 @@ client cluster FanControl = 514 {
attribute optional bitmap8 rockSetting = 8;
readonly attribute optional bitmap8 windSupport = 9;
attribute optional bitmap8 windSetting = 10;
attribute optional AirflowDirectionEnum airflowDirection = 11;
readonly attribute command_id generatedCommandList[] = 65528;
readonly attribute command_id acceptedCommandList[] = 65529;
readonly attribute event_id eventList[] = 65530;
readonly attribute attrib_id attributeList[] = 65531;
readonly attribute bitmap32 featureMap = 65532;
readonly attribute int16u clusterRevision = 65533;

request struct StepRequest {
DirectionEnum direction = 0;
optional boolean wrap = 1;
optional boolean lowestOff = 2;
}

/** The Step command speeds up or slows down the fan, in steps. */
command Step(StepRequest): DefaultSuccess = 0;
}

/** An interface for configuring the user interface of a thermostat (which may be remote from the thermostat). */
Expand Down
Loading

0 comments on commit 389aea4

Please sign in to comment.