Skip to content

Commit

Permalink
[Pump] Update pump cluster server (#19105)
Browse files Browse the repository at this point in the history
* Added checks and handling for use of optional attributes

* Restyled by whitespace

* Restyled by clang-format

* Moved check inside updateAttributeLinks and use emberAfContainsAttribute

Co-authored-by: Restyled.io <[email protected]>
  • Loading branch information
2 people authored and pull[bot] committed Feb 2, 2024
1 parent aed6bc2 commit 5d6fd6e
Showing 1 changed file with 87 additions and 41 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
*/

#include <app/util/af.h>
#include <app/util/util.h>

#include <app-common/zap-generated/attributes/Accessors.h>
#include <app-common/zap-generated/cluster-enums.h>
Expand All @@ -24,6 +25,7 @@
//#include <app/CommandHandler.h>
#include <app/ConcreteAttributePath.h>
#include <app/ConcreteCommandPath.h>
#include <app/InteractionModelEngine.h>
#include <app/util/af-event.h>
#include <app/util/attribute-storage.h>

Expand Down Expand Up @@ -72,11 +74,35 @@ static void updateAttributeLinks(EndpointId endpoint)
PumpControlMode controlMode;
PumpOperationMode operationMode;
BitFlags<PumpStatus> pumpStatus;
bool isControlModeAvailable = true;
bool isPumpStatusAvailable = true;

isControlModeAvailable = emberAfContainsAttribute(endpoint, PumpConfigurationAndControl::Id, Attributes::ControlMode::Id);
isPumpStatusAvailable = emberAfContainsAttribute(endpoint, PumpConfigurationAndControl::Id, Attributes::PumpStatus::Id);

// Get the current control- and operation modes
Attributes::ControlMode::Get(endpoint, &controlMode);
Attributes::OperationMode::Get(endpoint, &operationMode);
Attributes::PumpStatus::Get(endpoint, &pumpStatus);

if (isControlModeAvailable)
{
Attributes::ControlMode::Get(endpoint, &controlMode);
}
else
{
// If controlMode attribute is not available, then use the default value
// of the effectiveControlMode attribute as the effectiveControlMode
// if this is not suitable, the application should override this value in
// the post attribute change callback for the operation mode attribute
const EmberAfAttributeMetadata * effectiveControlModeMetaData;
effectiveControlModeMetaData = GetAttributeMetadata(
app::ConcreteAttributePath(endpoint, PumpConfigurationAndControl::Id, Attributes::EffectiveControlMode::Id));
controlMode = static_cast<PumpControlMode>(effectiveControlModeMetaData->defaultValue.defaultValue);
}

if (isPumpStatusAvailable)
{
Attributes::PumpStatus::Get(endpoint, &pumpStatus);
}

switch (operationMode)
{
Expand All @@ -93,21 +119,30 @@ static void updateAttributeLinks(EndpointId endpoint)
{
case RemoteSensorType::kFlowSensor:
Attributes::EffectiveControlMode::Set(endpoint, PumpControlMode::kConstantFlow);
pumpStatus.Set(PumpStatus::kRemoteFlow);
pumpStatus.Clear(PumpStatus::kRemotePressure);
pumpStatus.Clear(PumpStatus::kRemoteTemperature);
if (isPumpStatusAvailable)
{
pumpStatus.Set(PumpStatus::kRemoteFlow);
pumpStatus.Clear(PumpStatus::kRemotePressure);
pumpStatus.Clear(PumpStatus::kRemoteTemperature);
}
break;
case RemoteSensorType::kPressureSensor:
Attributes::EffectiveControlMode::Set(endpoint, PumpControlMode::kConstantPressure);
pumpStatus.Clear(PumpStatus::kRemoteFlow);
pumpStatus.Set(PumpStatus::kRemotePressure);
pumpStatus.Clear(PumpStatus::kRemoteTemperature);
if (isPumpStatusAvailable)
{
pumpStatus.Clear(PumpStatus::kRemoteFlow);
pumpStatus.Set(PumpStatus::kRemotePressure);
pumpStatus.Clear(PumpStatus::kRemoteTemperature);
}
break;
case RemoteSensorType::kTemperatureSensor:
Attributes::EffectiveControlMode::Set(endpoint, PumpControlMode::kConstantTemperature);
pumpStatus.Clear(PumpStatus::kRemoteFlow);
pumpStatus.Clear(PumpStatus::kRemotePressure);
pumpStatus.Set(PumpStatus::kRemoteTemperature);
if (isPumpStatusAvailable)
{
pumpStatus.Clear(PumpStatus::kRemoteFlow);
pumpStatus.Clear(PumpStatus::kRemotePressure);
pumpStatus.Set(PumpStatus::kRemoteTemperature);
}
break;
case RemoteSensorType::kNoSensor:
// The pump is controlled by a setpoint, as defined by
Expand All @@ -119,23 +154,11 @@ static void updateAttributeLinks(EndpointId endpoint)
// which would be the EffectiveControlMode is dependant on the actual
// physical pump application running "on-top" of this cluster server.
Attributes::EffectiveControlMode::Set(endpoint, controlMode);
pumpStatus.Clear(PumpStatus::kRemoteFlow);
pumpStatus.Clear(PumpStatus::kRemotePressure);
pumpStatus.Clear(PumpStatus::kRemoteTemperature);
switch (controlMode)
if (isPumpStatusAvailable)
{
case PumpControlMode::kConstantFlow:
pumpStatus.Set(PumpStatus::kRemoteFlow);
break;
case PumpControlMode::kConstantPressure:
pumpStatus.Set(PumpStatus::kRemotePressure);
break;
case PumpControlMode::kConstantTemperature:
pumpStatus.Set(PumpStatus::kRemoteTemperature);
break;
default:
// Intentionally left out
break;
pumpStatus.Clear(PumpStatus::kRemoteFlow);
pumpStatus.Clear(PumpStatus::kRemotePressure);
pumpStatus.Clear(PumpStatus::kRemoteTemperature);
}
break;
}
Expand All @@ -157,9 +180,12 @@ static void updateAttributeLinks(EndpointId endpoint)
LevelControl::Attributes::MaxLevel::Get(endpoint, &maxLevel);
LevelControl::Attributes::CurrentLevel::Set(endpoint, maxLevel);
#endif
pumpStatus.Clear(PumpStatus::kRemoteFlow);
pumpStatus.Clear(PumpStatus::kRemotePressure);
pumpStatus.Clear(PumpStatus::kRemoteTemperature);
if (isPumpStatusAvailable)
{
pumpStatus.Clear(PumpStatus::kRemoteFlow);
pumpStatus.Clear(PumpStatus::kRemotePressure);
pumpStatus.Clear(PumpStatus::kRemoteTemperature);
}
}
break;

Expand All @@ -178,9 +204,12 @@ static void updateAttributeLinks(EndpointId endpoint)
}
LevelControl::Attributes::CurrentLevel::Set(endpoint, minLevel);
#endif
pumpStatus.Clear(PumpStatus::kRemoteFlow);
pumpStatus.Clear(PumpStatus::kRemotePressure);
pumpStatus.Clear(PumpStatus::kRemoteTemperature);
if (isPumpStatusAvailable)
{
pumpStatus.Clear(PumpStatus::kRemoteFlow);
pumpStatus.Clear(PumpStatus::kRemotePressure);
pumpStatus.Clear(PumpStatus::kRemoteTemperature);
}
}
break;

Expand All @@ -193,13 +222,20 @@ static void updateAttributeLinks(EndpointId endpoint)
// Set the current ControlMode for now. Perhaps the application will set the EffectiveControlMode to something else.
Attributes::EffectiveControlMode::Set(endpoint, controlMode);
// Clear out the remote sensors from the PumpStatus flags.
pumpStatus.Clear(PumpStatus::kRemoteFlow);
pumpStatus.Clear(PumpStatus::kRemotePressure);
pumpStatus.Clear(PumpStatus::kRemoteTemperature);
if (isPumpStatusAvailable)
{
pumpStatus.Clear(PumpStatus::kRemoteFlow);
pumpStatus.Clear(PumpStatus::kRemotePressure);
pumpStatus.Clear(PumpStatus::kRemoteTemperature);
}
}
break;
}
Attributes::PumpStatus::Set(endpoint, pumpStatus);

if (isPumpStatusAvailable)
{
Attributes::PumpStatus::Set(endpoint, pumpStatus);
}
}

CHIP_ERROR PumpConfigurationAndControlAttrAccess::Read(const ConcreteReadAttributePath & aPath, AttributeValueEncoder & aEncoder)
Expand Down Expand Up @@ -287,14 +323,24 @@ void emberAfPumpConfigurationAndControlClusterServerInitCallback(EndpointId endp
emberAfDebugPrintln(
"Constant Pressure %s",
FeatureSupportedDebugString(endpoint, Attributes::MinConstPressure::Get, Attributes::MaxConstPressure::Get));
emberAfDebugPrintln("Constant Proportional Pressure %s",
emberAfDebugPrintln("PCC Server: Constant Proportional Pressure %s",
FeatureSupportedDebugString(endpoint, Attributes::MinCompPressure::Get, Attributes::MaxCompPressure::Get));
emberAfDebugPrintln("Constant Flow %s",
emberAfDebugPrintln("PCC Server: Constant Flow %s",
FeatureSupportedDebugString(endpoint, Attributes::MinConstFlow::Get, Attributes::MaxConstFlow::Get));
emberAfDebugPrintln("Constant Temperature %s",
emberAfDebugPrintln("PCC Server: Constant Temperature %s",
FeatureSupportedDebugString(endpoint, Attributes::MinConstTemp::Get, Attributes::MaxConstTemp::Get));
emberAfDebugPrintln("Constant Speed %s",
emberAfDebugPrintln("PCC Server: Constant Speed %s",
FeatureSupportedDebugString(endpoint, Attributes::MinConstSpeed::Get, Attributes::MaxConstSpeed::Get));

if (!emberAfContainsAttribute(endpoint, PumpConfigurationAndControl::Id, Attributes::ControlMode::Id))
{
emberAfDebugPrintln("PCC Server: ControlMode attribute not available");
}

if (!emberAfContainsAttribute(endpoint, PumpConfigurationAndControl::Id, Attributes::PumpStatus::Id))
{
emberAfDebugPrintln("PCC Server: PumpStatus attribute not available");
}
}

chip::Protocols::InteractionModel::Status MatterPumpConfigurationAndControlClusterServerPreAttributeChangedCallback(
Expand Down

0 comments on commit 5d6fd6e

Please sign in to comment.