Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update the preset handle field in the SetActivePresetRequest c… #35105

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -1856,7 +1856,7 @@ cluster Thermostat = 513 {
}

request struct SetActivePresetRequestRequest {
octet_string<16> presetHandle = 0;
nullable octet_string<16> presetHandle = 0;
}

response struct AtomicResponse = 253 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5696,7 +5696,7 @@ cluster Thermostat = 513 {
}

request struct SetActivePresetRequestRequest {
octet_string<16> presetHandle = 0;
nullable octet_string<16> presetHandle = 0;
}

response struct AtomicResponse = 253 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4130,7 +4130,7 @@ cluster Thermostat = 513 {
}

request struct SetActivePresetRequestRequest {
octet_string<16> presetHandle = 0;
nullable octet_string<16> presetHandle = 0;
}

response struct AtomicResponse = 253 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1779,7 +1779,7 @@ cluster Thermostat = 513 {
}

request struct SetActivePresetRequestRequest {
octet_string<16> presetHandle = 0;
nullable octet_string<16> presetHandle = 0;
}

response struct AtomicResponse = 253 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2136,7 +2136,7 @@ cluster Thermostat = 513 {
}

request struct SetActivePresetRequestRequest {
octet_string<16> presetHandle = 0;
nullable octet_string<16> presetHandle = 0;
}

response struct AtomicResponse = 253 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1719,7 +1719,7 @@ cluster Thermostat = 513 {
}

request struct SetActivePresetRequestRequest {
octet_string<16> presetHandle = 0;
nullable octet_string<16> presetHandle = 0;
}

response struct AtomicResponse = 253 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1939,7 +1939,7 @@ cluster Thermostat = 513 {
}

request struct SetActivePresetRequestRequest {
octet_string<16> presetHandle = 0;
nullable octet_string<16> presetHandle = 0;
}

response struct AtomicResponse = 253 {
Expand Down
4 changes: 2 additions & 2 deletions examples/placeholder/linux/apps/app1/config.matter
Original file line number Diff line number Diff line change
Expand Up @@ -5414,7 +5414,7 @@ cluster Thermostat = 513 {
}

request struct SetActivePresetRequestRequest {
octet_string<16> presetHandle = 0;
nullable octet_string<16> presetHandle = 0;
}

response struct AtomicResponse = 253 {
Expand Down Expand Up @@ -5769,7 +5769,7 @@ cluster Thermostat = 513 {
}

request struct SetActivePresetRequestRequest {
octet_string<16> presetHandle = 0;
nullable octet_string<16> presetHandle = 0;
}

response struct AtomicResponse = 253 {
Expand Down
4 changes: 2 additions & 2 deletions examples/placeholder/linux/apps/app2/config.matter
Original file line number Diff line number Diff line change
Expand Up @@ -5371,7 +5371,7 @@ cluster Thermostat = 513 {
}

request struct SetActivePresetRequestRequest {
octet_string<16> presetHandle = 0;
nullable octet_string<16> presetHandle = 0;
}

response struct AtomicResponse = 253 {
Expand Down Expand Up @@ -5726,7 +5726,7 @@ cluster Thermostat = 513 {
}

request struct SetActivePresetRequestRequest {
octet_string<16> presetHandle = 0;
nullable octet_string<16> presetHandle = 0;
}

response struct AtomicResponse = 253 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ class ThermostatDelegate : public Delegate

CHIP_ERROR GetPresetAtIndex(size_t index, PresetStructWithOwnedMembers & preset) override;

CHIP_ERROR GetActivePresetHandle(MutableByteSpan & activePresetHandle) override;
CHIP_ERROR GetActivePresetHandle(DataModel::Nullable<MutableByteSpan> & activePresetHandle) override;

CHIP_ERROR SetActivePresetHandle(const DataModel::Nullable<ByteSpan> & newActivePresetHandle) override;

Expand Down
14 changes: 12 additions & 2 deletions examples/thermostat/linux/thermostat-delegate-impl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -117,9 +117,19 @@ CHIP_ERROR ThermostatDelegate::GetPresetAtIndex(size_t index, PresetStructWithOw
return CHIP_ERROR_PROVIDER_LIST_EXHAUSTED;
}

CHIP_ERROR ThermostatDelegate::GetActivePresetHandle(MutableByteSpan & activePresetHandle)
CHIP_ERROR ThermostatDelegate::GetActivePresetHandle(DataModel::Nullable<MutableByteSpan> & activePresetHandle)
{
return CopySpanToMutableSpan(ByteSpan(mActivePresetHandleData, mActivePresetHandleDataSize), activePresetHandle);
if (mActivePresetHandleDataSize != 0)
{
ReturnErrorOnFailure(
CopySpanToMutableSpan(ByteSpan(mActivePresetHandleData, mActivePresetHandleDataSize), activePresetHandle.Value()));
activePresetHandle.Value().reduce_size(mActivePresetHandleDataSize);
}
else
{
activePresetHandle.SetNull();
}
return CHIP_NO_ERROR;
}

CHIP_ERROR ThermostatDelegate::SetActivePresetHandle(const DataModel::Nullable<ByteSpan> & newActivePresetHandle)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2530,7 +2530,7 @@ cluster Thermostat = 513 {
}

request struct SetActivePresetRequestRequest {
octet_string<16> presetHandle = 0;
nullable octet_string<16> presetHandle = 0;
}

response struct AtomicResponse = 253 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2441,7 +2441,7 @@ cluster Thermostat = 513 {
}

request struct SetActivePresetRequestRequest {
octet_string<16> presetHandle = 0;
nullable octet_string<16> presetHandle = 0;
}

response struct AtomicResponse = 253 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2138,7 +2138,7 @@ cluster Thermostat = 513 {
}

request struct SetActivePresetRequestRequest {
octet_string<16> presetHandle = 0;
nullable octet_string<16> presetHandle = 0;
}

response struct AtomicResponse = 253 {
Expand Down
2 changes: 1 addition & 1 deletion examples/thermostat/thermostat-common/thermostat.matter
Original file line number Diff line number Diff line change
Expand Up @@ -2318,7 +2318,7 @@ cluster Thermostat = 513 {
}

request struct SetActivePresetRequestRequest {
octet_string<16> presetHandle = 0;
nullable octet_string<16> presetHandle = 0;
}

response struct AtomicResponse = 253 {
Expand Down
7 changes: 3 additions & 4 deletions src/app/clusters/thermostat-server/thermostat-delegate.h
Original file line number Diff line number Diff line change
Expand Up @@ -78,11 +78,10 @@ class Delegate
/**
* @brief Get the ActivePresetHandle attribute value.
*
* @param[out] activePresetHandle The MutableByteSpan to copy the active preset handle into. On success,
* the callee must update the length to the length of the copied data. If the value of
* the attribute is null, the callee must set the MutableByteSpan to empty.
* @param[out] activePresetHandle The nullable MutableByteSpan to copy the active preset handle into. On success,
* the size of the activePresetHandle is updated to the length of the copied data.
*/
virtual CHIP_ERROR GetActivePresetHandle(MutableByteSpan & activePresetHandle) = 0;
virtual CHIP_ERROR GetActivePresetHandle(DataModel::Nullable<MutableByteSpan> & activePresetHandle) = 0;
nivi-apple marked this conversation as resolved.
Show resolved Hide resolved

/**
* @brief Set the ActivePresetHandle attribute value.
Expand Down
25 changes: 10 additions & 15 deletions src/app/clusters/thermostat-server/thermostat-server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -761,19 +761,13 @@ CHIP_ERROR ThermostatAttrAccess::Read(const ConcreteReadAttributePath & aPath, A
VerifyOrReturnError(delegate != nullptr, CHIP_ERROR_INCORRECT_STATE, ChipLogError(Zcl, "Delegate is null"));

uint8_t buffer[kPresetHandleSize];
MutableByteSpan activePresetHandle(buffer);
MutableByteSpan activePresetHandleSpan(buffer);
auto activePresetHandle = DataModel::MakeNullable(activePresetHandleSpan);

CHIP_ERROR err = delegate->GetActivePresetHandle(activePresetHandle);
ReturnErrorOnFailure(err);

if (activePresetHandle.empty())
{
ReturnErrorOnFailure(aEncoder.EncodeNull());
}
else
{
ReturnErrorOnFailure(aEncoder.Encode(activePresetHandle));
}
ReturnErrorOnFailure(aEncoder.Encode(activePresetHandle));
}
break;
case ScheduleTypes::Id: {
Expand Down Expand Up @@ -1299,16 +1293,16 @@ bool emberAfThermostatClusterSetActivePresetRequestCallback(
return true;
}

ByteSpan newPresetHandle = commandData.presetHandle;
DataModel::Nullable<ByteSpan> newPresetHandle = commandData.presetHandle;

// If the preset handle passed in the command is not present in the Presets attribute, return INVALID_COMMAND.
if (!IsPresetHandlePresentInPresets(delegate, newPresetHandle))
if (!newPresetHandle.IsNull() && !IsPresetHandlePresentInPresets(delegate, newPresetHandle.Value()))
{
commandObj->AddStatus(commandPath, imcode::InvalidCommand);
return true;
}

CHIP_ERROR err = delegate->SetActivePresetHandle(DataModel::MakeNullable(newPresetHandle));
CHIP_ERROR err = delegate->SetActivePresetHandle(newPresetHandle);

if (err != CHIP_NO_ERROR)
{
Expand Down Expand Up @@ -1470,7 +1464,8 @@ imcode commitPresets(Delegate * delegate, EndpointId endpoint)
// attribute. If a preset is not found with the same presetHandle, return INVALID_IN_STATE. If there is no ActivePresetHandle
// attribute set, continue with other checks.
uint8_t buffer[kPresetHandleSize];
MutableByteSpan activePresetHandle(buffer);
MutableByteSpan activePresetHandleSpan(buffer);
auto activePresetHandle = DataModel::MakeNullable(activePresetHandleSpan);

err = delegate->GetActivePresetHandle(activePresetHandle);

Expand All @@ -1479,9 +1474,9 @@ imcode commitPresets(Delegate * delegate, EndpointId endpoint)
return imcode::InvalidInState;
}

if (!activePresetHandle.empty())
if (!activePresetHandle.IsNull())
{
uint8_t count = CountPresetsInPendingListWithPresetHandle(delegate, activePresetHandle);
uint8_t count = CountPresetsInPendingListWithPresetHandle(delegate, activePresetHandle.Value());
if (count == 0)
{
return imcode::InvalidInState;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -481,7 +481,7 @@ limitations under the License.

<command source="client" code="0x06" name="SetActivePresetRequest" optional="true">
<description>ID</description>
<arg id="0" name="PresetHandle" type="octet_string" length="16"/>
<arg id="0" name="PresetHandle" type="octet_string" length="16" isNullable="true"/>
</command>

<!-- Server Commands/Responses -->
Expand Down
2 changes: 1 addition & 1 deletion src/controller/data_model/controller-clusters.matter
Original file line number Diff line number Diff line change
Expand Up @@ -6994,7 +6994,7 @@ cluster Thermostat = 513 {
}

request struct SetActivePresetRequestRequest {
octet_string<16> presetHandle = 0;
nullable octet_string<16> presetHandle = 0;
}

response struct AtomicResponse = 253 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40637,16 +40637,16 @@ public void onResponse(StructType invokeStructValue) {
}}, commandId, commandArgs, timedInvokeTimeoutMs);
}

public void setActivePresetRequest(DefaultClusterCallback callback, byte[] presetHandle) {
public void setActivePresetRequest(DefaultClusterCallback callback, @Nullable byte[] presetHandle) {
setActivePresetRequest(callback, presetHandle, 0);
}

public void setActivePresetRequest(DefaultClusterCallback callback, byte[] presetHandle, int timedInvokeTimeoutMs) {
public void setActivePresetRequest(DefaultClusterCallback callback, @Nullable byte[] presetHandle, int timedInvokeTimeoutMs) {
final long commandId = 6L;

ArrayList<StructElement> elements = new ArrayList<>();
final long presetHandleFieldID = 0L;
BaseTLVType presetHandletlvValue = new ByteArrayType(presetHandle);
BaseTLVType presetHandletlvValue = presetHandle != null ? new ByteArrayType(presetHandle) : new NullType();
elements.add(new StructElement(presetHandleFieldID, presetHandletlvValue));

StructType commandArgs = new StructType(elements);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -504,7 +504,7 @@ class ThermostatCluster(private val controller: MatterController, private val en
}

suspend fun setActivePresetRequest(
presetHandle: ByteArray,
presetHandle: ByteArray?,
timedInvokeTimeout: Duration? = null,
) {
val commandId: UInt = 6u
Expand All @@ -513,7 +513,7 @@ class ThermostatCluster(private val controller: MatterController, private val en
tlvWriter.startStructure(AnonymousTag)

val TAG_PRESET_HANDLE_REQ: Int = 0
tlvWriter.put(ContextSpecificTag(TAG_PRESET_HANDLE_REQ), presetHandle)
presetHandle?.let { tlvWriter.put(ContextSpecificTag(TAG_PRESET_HANDLE_REQ), presetHandle) }
tlvWriter.endStructure()

val request: InvokeRequest =
Expand Down
4 changes: 2 additions & 2 deletions src/controller/python/chip/clusters/Objects.py

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.

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.

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

Loading