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

[HVAC] Allow Thermostat delegate to supply atomic write timeout #34823

Merged
Merged
Show file tree
Hide file tree
Changes from 113 commits
Commits
Show all changes
121 commits
Select commit Hold shift + click to select a range
46d9098
Add support for Presets attributes and commands to the Thermostat clu…
nivi-apple Jul 26, 2024
5d2c740
Restyled by whitespace
restyled-commits Jul 26, 2024
f14e43e
Restyled by clang-format
restyled-commits Jul 26, 2024
dfe9f7c
Restyled by gn.
restyled-commits Jul 26, 2024
3dad3f3
Fix build error for Linux configure build of all-clusters-app
nivi-apple Jul 26, 2024
8e6db6e
Fix Darwin CI issues
nivi-apple Jul 26, 2024
362ca12
Restyled by clang-format
restyled-commits Jul 26, 2024
cb96615
More fixes
nivi-apple Jul 26, 2024
07e78e0
Restyled by clang-format
restyled-commits Jul 26, 2024
9c511bf
BUILD.gn fixes for CI
nivi-apple Jul 26, 2024
f027069
Apply suggestions from code review
nivi-apple Jul 26, 2024
a2bb5d6
Address review comments.
nivi-apple Jul 27, 2024
0147c71
Restyled by clang-format
restyled-commits Jul 27, 2024
029e9a4
Regenerate Thermostat XML from spec
hasty Jul 28, 2024
48ac309
Move atomic enum to global-enums.xml, actually
hasty Jul 26, 2024
5216415
Regenerate XML and convert thermostat-server to atomic writes
hasty Jul 28, 2024
72d114f
Merge branch 'master' into add_presets_to_Sdk
hasty Jul 29, 2024
38d14fc
Merge branch 'master' into add_presets_to_Sdk
hasty Jul 29, 2024
8511469
Pull in ACCapacityFormat typo un-fix
hasty Jul 29, 2024
dabf994
Update Test_TC_TSTAT_1_1 to know about AtomicResponse command.
bzbarsky-apple Jul 29, 2024
0212f7c
Merge branch 'master' into add_presets_to_Sdk
hasty Jul 29, 2024
90a20c1
Restyled patch
hasty Jul 29, 2024
a567de4
Merge branch 'add_presets_to_Sdk' of github.com:hasty/connectedhomeip…
hasty Jul 29, 2024
1c49a80
Merge branch 'master' into add_presets_to_Sdk
hasty Jul 29, 2024
aef165e
Fix weird merge with upstream
hasty Jul 29, 2024
9efed86
Merge branch 'add_presets_to_Sdk' of github.com:hasty/connectedhomeip…
hasty Jul 29, 2024
4c457a9
Fix emberAfIsTypeSigned not understanding temperature type
hasty Jul 29, 2024
1257477
Merge branch 'master' into add_presets_to_Sdk
hasty Jul 29, 2024
c34a9cb
Merge fixes from atomic write branch
hasty Jul 30, 2024
4665050
Merge branch 'master' into add_presets_to_Sdk
hasty Jul 30, 2024
6d2fda4
Merge branch 'add_presets_to_Sdk' of github.com:hasty/connectedhomeip…
hasty Jul 30, 2024
7acd5d4
Merge branch 'master' into add_presets_to_Sdk
hasty Jul 30, 2024
8dbabb1
Merge branch 'master' into add_presets_to_Sdk
hasty Jul 30, 2024
704c544
Relocate thermostat-manager sample code to all-clusters-common
hasty Jul 30, 2024
9d89cfe
Merge branch 'master' into add_presets_to_Sdk
hasty Jul 30, 2024
7a4f4fd
Merge branch 'add_presets_to_Sdk' of github.com:hasty/connectedhomeip…
hasty Jul 30, 2024
6de046a
Merge branch 'master' into add_presets_to_Sdk
hasty Jul 30, 2024
d67f988
Fix g++ build error on linux
hasty Jul 30, 2024
449379b
Merge branch 'add_presets_to_Sdk' of github.com:hasty/connectedhomeip…
hasty Jul 30, 2024
4c8e0a0
Fix C formatter for long int, cast whole expression
hasty Jul 30, 2024
c76e768
Merge branch 'master' into add_presets_to_Sdk
hasty Jul 30, 2024
3f40391
Merge branch 'add_presets_to_Sdk' of github.com:hasty/connectedhomeip…
hasty Jul 30, 2024
5ce2df1
Merge branch 'master' into add_presets_to_Sdk
hasty Jul 30, 2024
cf780e3
Sync cast fix with master
hasty Jul 30, 2024
af25396
Merge branch 'master' into add_presets_to_Sdk
hasty Jul 30, 2024
c80f42d
Merge branch 'add_presets_to_Sdk' of github.com:hasty/connectedhomeip…
hasty Jul 30, 2024
b4f50f6
Add thermostat-common dependency to thermostat app under linux
hasty Jul 30, 2024
51d8aaa
Merge branch 'master' into add_presets_to_Sdk
hasty Jul 30, 2024
5abc22d
Merge branch 'add_presets_to_Sdk' of github.com:hasty/connectedhomeip…
hasty Jul 30, 2024
637db40
Remove MatterPostAttributeChangeCallback from thermostat-manager, as …
hasty Jul 30, 2024
fadce3b
Merge branch 'master' into add_presets_to_Sdk
hasty Jul 30, 2024
c6e07d0
Merge branch 'add_presets_to_Sdk' of github.com:hasty/connectedhomeip…
hasty Jul 30, 2024
4b03da7
Merge branch 'master' into add_presets_to_Sdk
hasty Jul 30, 2024
0c1b853
Convert Atomic enums and structs to global
hasty Jul 30, 2024
c41d02c
Restyled patch
hasty Jul 30, 2024
924ad8f
Merge branch 'master' into add_presets_to_Sdk
hasty Jul 30, 2024
7d8df6e
Merge branch 'master' into add_presets_to_Sdk
hasty Jul 31, 2024
31ebe9d
Merge branch 'add_presets_to_Sdk' of github.com:hasty/connectedhomeip…
hasty Jul 31, 2024
2740112
Apply suggestions from code review
hasty Jul 31, 2024
dabc3a0
Regen with alchemy 0.6.1
hasty Aug 1, 2024
f08c0cf
Updates based on comments
hasty Aug 1, 2024
77c0dca
Add TC_MCORE_FS_1_3.py test implementation (#34650)
tehampson Jul 31, 2024
608d034
Fix most TC-SWTCH-2.4 remaining issues (#34677)
tcarmelveilleux Jul 31, 2024
dc312d7
Initial test script for Fabric Sync TC_MCORE_FS_1_2 (#34675)
cletnick Jul 31, 2024
ad792f1
Test automation for FabricSync ICD BridgedDeviceBasicInfoCluster (#34…
rochaferraz Jul 31, 2024
60d0429
ServiceArea test scripts (#34548)
plauric Jul 31, 2024
78dab72
Remove manual tests for Thermostat presets (#34679)
nivi-apple Jul 31, 2024
d7cadf9
Dump details about leaked ExchangeContexts before aborting (#34617)
ksperling-apple Jul 31, 2024
153c398
[TI] CC13x4_26x4 build fixes (#34682)
abiradarti Aug 1, 2024
b2e22c7
[ICD] Add missing polling function to NoWifi connectivity manager (#3…
mkardous-silabs Aug 1, 2024
12d0123
[OPSTATE] Add Q test script for CountdownTime (#34632)
rbultman Aug 1, 2024
9351279
YAML update to BRBINFO, ProductId (#34513)
rochaferraz Aug 1, 2024
08cb38b
Fix simplified Linux tv-casting-app gn build error. (#34692)
shaoltan-amazon Aug 1, 2024
ee27016
adding parallel execution to restyle-diff (#34663)
Alami-Amine Aug 1, 2024
aebaedb
Add some bits to exercise global structs/enums to Unit Testing cluste…
bzbarsky-apple Aug 1, 2024
1a7352f
[Silabs] Port platform specific Multi-Chip OTA work (#34440)
mykrupp Aug 1, 2024
eb59fc3
Add python tests for Thermostat presets feature (#34693)
nivi-apple Aug 1, 2024
5c6312b
removing unneccessary git fetch (#34698)
Alami-Amine Aug 1, 2024
687b1ac
Merge branch 'add_presets_to_Sdk' of github.com:hasty/connectedhomeip…
hasty Aug 1, 2024
6cb787b
Merge branch 'master' into add_presets_to_Sdk
hasty Aug 1, 2024
b815bbd
Restyle patch
hasty Aug 1, 2024
cf97803
Merge branch 'add_presets_to_Sdk' of github.com:hasty/connectedhomeip…
hasty Aug 1, 2024
d424a77
Regen to fix ordering of global structs
hasty Aug 1, 2024
b5410d3
Apply suggestions from code review
hasty Aug 1, 2024
353c9c1
Return correct AtomicResponse when committing or rolling back
hasty Aug 1, 2024
c58ab73
Merge branch 'master' of github.com:project-chip/connectedhomeip into…
hasty Aug 1, 2024
f0b8e7d
Merge branch 'add_presets_to_Sdk' of github.com:hasty/connectedhomeip…
hasty Aug 1, 2024
be7ca99
Patch tests for atomic write of presets
hasty Aug 2, 2024
23f3063
Fix tests to work with the new setup.
bzbarsky-apple Aug 2, 2024
ed59a01
Merge pull request #1 from bzbarsky-apple/pr-34570-fixup
hasty Aug 2, 2024
627e3f6
Merge branch 'master' of github.com:project-chip/connectedhomeip into…
hasty Aug 4, 2024
0966a01
Merge branch 'master' into add_presets_to_Sdk
hasty Aug 4, 2024
c37228c
Fix PICS values for atomic requests
hasty Aug 4, 2024
ba877a8
Remove PresetsSchedulesEditable and QueuedPreset from various places
hasty Aug 4, 2024
1106e1f
Restyled patch
hasty Aug 4, 2024
18d202a
Restyled patch, again
hasty Aug 4, 2024
18325f4
Remove PICS value for PresetsSchedulesEditable
hasty Aug 4, 2024
11eda5a
clang-tidy fixes
hasty Aug 5, 2024
0478b52
clang-tidy fixes
hasty Aug 5, 2024
9a4d415
Merge branch 'add_presets_to_Sdk' of github.com:hasty/connectedhomeip…
hasty Aug 5, 2024
12aa64f
Clear associated atomic writes when fabric is removed
hasty Aug 6, 2024
520eb2f
Add tests for fabric removal and lockout of clients outside of atomic…
hasty Aug 6, 2024
62f75c4
Merge branch 'master' of github.com:project-chip/connectedhomeip into…
hasty Aug 6, 2024
c09f01e
Python linter
hasty Aug 6, 2024
f9141fb
Restyled patch
hasty Aug 6, 2024
9fc8882
Merge branch 'master' into granbery/preset_atomic_write_fabric_index
hasty Aug 6, 2024
3d5abb5
Merge branch 'granbery/preset_atomic_write_fabric_index' of github.co…
hasty Aug 6, 2024
4c26dd4
Clear timer when fabric is removed
hasty Aug 6, 2024
2a84acb
Check for open atomic write before resetting
hasty Aug 6, 2024
98e8e2c
Merge branch 'master' into granbery/preset_atomic_write_fabric_index
hasty Aug 6, 2024
bdc747e
Revert auto delegate declaration on lines where there's no collision
hasty Aug 6, 2024
2f9a711
Allow Thermostat delegate to provide timeout for atomic requests
hasty Aug 6, 2024
1b7c152
Merge branch 'master' into granbery/preset_atomic_write_timeout
hasty Aug 6, 2024
2d72009
Apply suggestions from code review
hasty Aug 6, 2024
66525ed
Document GetAtomicWriteTimeout
hasty Aug 6, 2024
c88339c
Merge branch 'granbery/preset_atomic_write_timeout' of github.com:has…
hasty Aug 6, 2024
b3bfdba
Restyled patch
hasty Aug 7, 2024
b25d6a5
Merge branch 'master' into granbery/preset_atomic_write_timeout
hasty Aug 7, 2024
15d4c10
Merge remote-tracking branch 'upstream/master' into granbery/preset_a…
hasty Aug 8, 2024
fc9429a
Switch to enum for atomic write state
hasty Aug 8, 2024
072f0e3
Use std::optional<timeout> instead of magic zero value
hasty Aug 8, 2024
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
3 changes: 3 additions & 0 deletions examples/thermostat/linux/include/thermostat-delegate-impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,9 @@ class ThermostatDelegate : public Delegate
public:
static inline ThermostatDelegate & GetInstance() { return sInstance; }

System::Clock::Milliseconds16 GetAtomicWriteTimeout(DataModel::DecodableList<chip::AttributeId> attributeRequests,
System::Clock::Milliseconds16 timeoutRequest) override;

CHIP_ERROR GetPresetTypeAtIndex(size_t index, Structs::PresetTypeStruct::Type & presetType) override;

uint8_t GetNumberOfPresets() override;
Expand Down
38 changes: 38 additions & 0 deletions examples/thermostat/linux/thermostat-delegate-impl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,44 @@ CHIP_ERROR ThermostatDelegate::SetActivePresetHandle(const DataModel::Nullable<B
return CHIP_NO_ERROR;
}

System::Clock::Milliseconds16
ThermostatDelegate::GetAtomicWriteTimeout(DataModel::DecodableList<chip::AttributeId> attributeRequests,
hasty marked this conversation as resolved.
Show resolved Hide resolved
System::Clock::Milliseconds16 timeoutRequest)
{
auto attributeIdsIter = attributeRequests.begin();
bool requestedPresets = false, requestedSchedules = false;
while (attributeIdsIter.Next())
{
auto & attributeId = attributeIdsIter.GetValue();

switch (attributeId)
{
case Attributes::Presets::Id:
requestedPresets = true;
break;
case Attributes::Schedules::Id:
requestedSchedules = true;
break;
default:
return System::Clock::Milliseconds16(0);
}
}
if (attributeIdsIter.GetStatus() != CHIP_NO_ERROR)
{
return System::Clock::Milliseconds16(0);
}
auto timeout = System::Clock::Milliseconds16(0);
if (requestedPresets)
{
timeout += std::chrono::milliseconds(1000);
}
if (requestedSchedules)
{
timeout += std::chrono::milliseconds(3000);
woody-apple marked this conversation as resolved.
Show resolved Hide resolved
}
return std::min(timeoutRequest, timeout);
}

void ThermostatDelegate::InitializePendingPresets()
{
mNextFreeIndexInPendingPresetsList = 0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2217,6 +2217,7 @@
}; \
const EmberAfGenericClusterFunction chipFuncArrayThermostatServer[] = { \
(EmberAfGenericClusterFunction) emberAfThermostatClusterServerInitCallback, \
(EmberAfGenericClusterFunction) MatterThermostatClusterServerShutdownCallback, \
(EmberAfGenericClusterFunction) MatterThermostatClusterServerPreAttributeChangedCallback, \
}; \
const EmberAfGenericClusterFunction chipFuncArrayFanControlServer[] = { \
Expand Down Expand Up @@ -3755,7 +3756,7 @@
.attributes = ZAP_ATTRIBUTE_INDEX(616), \
.attributeCount = 26, \
.clusterSize = 72, \
.mask = ZAP_CLUSTER_MASK(SERVER) | ZAP_CLUSTER_MASK(INIT_FUNCTION) | ZAP_CLUSTER_MASK(PRE_ATTRIBUTE_CHANGED_FUNCTION), \
.mask = ZAP_CLUSTER_MASK(SERVER) | ZAP_CLUSTER_MASK(INIT_FUNCTION) | ZAP_CLUSTER_MASK(SHUTDOWN_FUNCTION) | ZAP_CLUSTER_MASK(PRE_ATTRIBUTE_CHANGED_FUNCTION), \
.functions = chipFuncArrayThermostatServer, \
.acceptedCommandList = ZAP_GENERATED_COMMANDS_INDEX( 241 ), \
.generatedCommandList = ZAP_GENERATED_COMMANDS_INDEX( 246 ), \
Expand Down
10 changes: 10 additions & 0 deletions src/app/clusters/thermostat-server/thermostat-delegate.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,16 @@ class Delegate

virtual ~Delegate() = default;

/**
* @brief Get the maximum timeout for atomically writing to a set of attributes
*
* @param[in] attributeRequests The list of attributes to write to.
* @param[out] timeoutRequest The timeout proposed by the client.
* @return The maximum allowed timeout; zero if the request is invalid.
*/
virtual System::Clock::Milliseconds16 GetAtomicWriteTimeout(DataModel::DecodableList<chip::AttributeId> attributeRequests,
hasty marked this conversation as resolved.
Show resolved Hide resolved
System::Clock::Milliseconds16 timeoutRequest) = 0;

/**
* @brief Get the preset type at a given index in the PresetTypes attribute
*
Expand Down
94 changes: 58 additions & 36 deletions src/app/clusters/thermostat-server/thermostat-server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@
#include <app/CommandHandler.h>
#include <app/ConcreteAttributePath.h>
#include <app/ConcreteCommandPath.h>
#include <app/server/Server.h>
#include <app/util/endpoint-config-api.h>
#include <lib/core/CHIPEncoding.h>
#include <platform/internal/CHIPDeviceLayerInternal.h>

Expand Down Expand Up @@ -116,8 +118,7 @@ void TimerExpiredCallback(System::Layer * systemLayer, void * callbackContext)
VerifyOrReturn(delegate != nullptr, ChipLogError(Zcl, "Delegate is null. Unable to handle timer expired"));

delegate->ClearPendingPresetList();
gThermostatAttrAccess.SetAtomicWrite(endpoint, false);
gThermostatAttrAccess.SetAtomicWriteScopedNodeId(endpoint, ScopedNodeId());
gThermostatAttrAccess.SetAtomicWrite(endpoint, ScopedNodeId(), false);
woody-apple marked this conversation as resolved.
Show resolved Hide resolved
}

/**
Expand Down Expand Up @@ -205,8 +206,7 @@ void resetAtomicWrite(Delegate * delegate, EndpointId endpoint)
delegate->ClearPendingPresetList();
}
ClearTimer(endpoint);
gThermostatAttrAccess.SetAtomicWrite(endpoint, false);
gThermostatAttrAccess.SetAtomicWriteScopedNodeId(endpoint, ScopedNodeId());
gThermostatAttrAccess.SetAtomicWrite(endpoint, ScopedNodeId(), false);
woody-apple marked this conversation as resolved.
Show resolved Hide resolved
}

/**
Expand Down Expand Up @@ -605,14 +605,16 @@ void SetDefaultDelegate(EndpointId endpoint, Delegate * delegate)
}
}

void ThermostatAttrAccess::SetAtomicWrite(EndpointId endpoint, bool inProgress)
void ThermostatAttrAccess::SetAtomicWrite(EndpointId endpoint, ScopedNodeId originatorNodeId, bool inProgress)
{
uint16_t ep =
emberAfGetClusterServerEndpointIndex(endpoint, Thermostat::Id, MATTER_DM_THERMOSTAT_CLUSTER_SERVER_ENDPOINT_COUNT);

if (ep < ArraySize(mAtomicWriteState))
if (ep < ArraySize(mAtomicWriteStates))
{
mAtomicWriteState[ep] = inProgress;
mAtomicWriteStates[ep].inProgress = inProgress;
mAtomicWriteStates[ep].endpointId = endpoint;
mAtomicWriteStates[ep].nodeId = originatorNodeId;
}
}

Expand All @@ -622,9 +624,9 @@ bool ThermostatAttrAccess::InAtomicWrite(EndpointId endpoint)
uint16_t ep =
emberAfGetClusterServerEndpointIndex(endpoint, Thermostat::Id, MATTER_DM_THERMOSTAT_CLUSTER_SERVER_ENDPOINT_COUNT);

if (ep < ArraySize(mAtomicWriteState))
if (ep < ArraySize(mAtomicWriteStates))
{
inAtomicWrite = mAtomicWriteState[ep];
inAtomicWrite = mAtomicWriteStates[ep].inProgress;
}
return inAtomicWrite;
}
Expand All @@ -649,26 +651,15 @@ bool ThermostatAttrAccess::InAtomicWrite(CommandHandler * commandObj, EndpointId
return GetAtomicWriteScopedNodeId(endpoint) == sourceNodeId;
}

void ThermostatAttrAccess::SetAtomicWriteScopedNodeId(EndpointId endpoint, ScopedNodeId originatorNodeId)
{
uint16_t ep =
emberAfGetClusterServerEndpointIndex(endpoint, Thermostat::Id, MATTER_DM_THERMOSTAT_CLUSTER_SERVER_ENDPOINT_COUNT);

if (ep < ArraySize(mAtomicWriteNodeIds))
{
mAtomicWriteNodeIds[ep] = originatorNodeId;
}
}

ScopedNodeId ThermostatAttrAccess::GetAtomicWriteScopedNodeId(EndpointId endpoint)
{
ScopedNodeId originatorNodeId = ScopedNodeId();
uint16_t ep =
emberAfGetClusterServerEndpointIndex(endpoint, Thermostat::Id, MATTER_DM_THERMOSTAT_CLUSTER_SERVER_ENDPOINT_COUNT);

if (ep < ArraySize(mAtomicWriteNodeIds))
if (ep < ArraySize(mAtomicWriteStates))
{
originatorNodeId = mAtomicWriteNodeIds[ep];
originatorNodeId = mAtomicWriteStates[ep].nodeId;
}
return originatorNodeId;
}
Expand Down Expand Up @@ -704,7 +695,7 @@ CHIP_ERROR ThermostatAttrAccess::Read(const ConcreteReadAttributePath & aPath, A
}
break;
case PresetTypes::Id: {
Delegate * delegate = GetDelegate(aPath.mEndpointId);
auto delegate = GetDelegate(aPath.mEndpointId);
VerifyOrReturnError(delegate != nullptr, CHIP_ERROR_INCORRECT_STATE, ChipLogError(Zcl, "Delegate is null"));

return aEncoder.EncodeList([delegate](const auto & encoder) -> CHIP_ERROR {
Expand All @@ -723,14 +714,14 @@ CHIP_ERROR ThermostatAttrAccess::Read(const ConcreteReadAttributePath & aPath, A
}
break;
case NumberOfPresets::Id: {
Delegate * delegate = GetDelegate(aPath.mEndpointId);
auto delegate = GetDelegate(aPath.mEndpointId);
VerifyOrReturnError(delegate != nullptr, CHIP_ERROR_INCORRECT_STATE, ChipLogError(Zcl, "Delegate is null"));

ReturnErrorOnFailure(aEncoder.Encode(delegate->GetNumberOfPresets()));
}
break;
case Presets::Id: {
Delegate * delegate = GetDelegate(aPath.mEndpointId);
auto delegate = GetDelegate(aPath.mEndpointId);
VerifyOrReturnError(delegate != nullptr, CHIP_ERROR_INCORRECT_STATE, ChipLogError(Zcl, "Delegate is null"));

auto & subjectDescriptor = aEncoder.GetSubjectDescriptor();
Expand Down Expand Up @@ -766,7 +757,7 @@ CHIP_ERROR ThermostatAttrAccess::Read(const ConcreteReadAttributePath & aPath, A
}
break;
case ActivePresetHandle::Id: {
Delegate * delegate = GetDelegate(aPath.mEndpointId);
auto delegate = GetDelegate(aPath.mEndpointId);
woody-apple marked this conversation as resolved.
Show resolved Hide resolved
VerifyOrReturnError(delegate != nullptr, CHIP_ERROR_INCORRECT_STATE, ChipLogError(Zcl, "Delegate is null"));

uint8_t buffer[kPresetHandleSize];
Expand Down Expand Up @@ -812,7 +803,7 @@ CHIP_ERROR ThermostatAttrAccess::Write(const ConcreteDataAttributePath & aPath,
{
case Presets::Id: {

Delegate * delegate = GetDelegate(endpoint);
auto delegate = GetDelegate(endpoint);
VerifyOrReturnError(delegate != nullptr, CHIP_ERROR_INCORRECT_STATE, ChipLogError(Zcl, "Delegate is null"));

// Presets are not editable, return INVALID_IN_STATE.
Expand Down Expand Up @@ -897,7 +888,7 @@ CHIP_ERROR ThermostatAttrAccess::Write(const ConcreteDataAttributePath & aPath,
return CHIP_NO_ERROR;
}

CHIP_ERROR ThermostatAttrAccess::AppendPendingPreset(Delegate * delegate, const PresetStruct::Type & preset)
CHIP_ERROR ThermostatAttrAccess::AppendPendingPreset(Thermostat::Delegate * delegate, const PresetStruct::Type & preset)
{
if (!IsValidPresetEntry(preset))
{
Expand Down Expand Up @@ -951,6 +942,23 @@ CHIP_ERROR ThermostatAttrAccess::AppendPendingPreset(Delegate * delegate, const
return delegate->AppendToPendingPresetList(preset);
}

void ThermostatAttrAccess::OnFabricRemoved(const FabricTable & fabricTable, FabricIndex fabricIndex)
{
for (size_t i = 0; i < ArraySize(mAtomicWriteStates); ++i)
{
auto atomicWriteState = mAtomicWriteStates[i];
if (atomicWriteState.inProgress && atomicWriteState.nodeId.GetFabricIndex() == fabricIndex)
{
auto delegate = GetDelegate(atomicWriteState.endpointId);
if (delegate == nullptr)
{
continue;
}
resetAtomicWrite(delegate, atomicWriteState.endpointId);
}
}
}

} // namespace Thermostat
} // namespace Clusters
} // namespace app
Expand Down Expand Up @@ -1394,8 +1402,6 @@ void handleAtomicBegin(CommandHandler * commandObj, const ConcreteCommandPath &
return;
}

auto timeout = commandData.timeout.Value();

if (!validAtomicAttributes(commandData, false))
{
commandObj->AddStatus(commandPath, imcode::InvalidCommand);
Expand All @@ -1412,13 +1418,17 @@ void handleAtomicBegin(CommandHandler * commandObj, const ConcreteCommandPath &
// needs to keep track of a pending preset list now.
delegate->InitializePendingPresets();

uint16_t maxTimeout = 5000;
timeout = std::min(timeout, maxTimeout);
System::Clock::Milliseconds16 timeout =
delegate->GetAtomicWriteTimeout(commandData.attributeRequests, System::Clock::Milliseconds16(commandData.timeout.Value()));

ScheduleTimer(endpoint, System::Clock::Milliseconds16(timeout));
gThermostatAttrAccess.SetAtomicWrite(endpoint, true);
gThermostatAttrAccess.SetAtomicWriteScopedNodeId(endpoint, GetSourceScopedNodeId(commandObj));
sendAtomicResponse(commandObj, commandPath, imcode::Success, imcode::Success, imcode::Success, MakeOptional(timeout));
if (timeout == System::Clock::Milliseconds16(0))
woody-apple marked this conversation as resolved.
Show resolved Hide resolved
{
commandObj->AddStatus(commandPath, imcode::InvalidCommand);
return;
}
ScheduleTimer(endpoint, timeout);
gThermostatAttrAccess.SetAtomicWrite(endpoint, GetSourceScopedNodeId(commandObj), true);
woody-apple marked this conversation as resolved.
Show resolved Hide resolved
sendAtomicResponse(commandObj, commandPath, imcode::Success, imcode::Success, imcode::Success, MakeOptional(timeout.count()));
}

imcode commitPresets(Delegate * delegate, EndpointId endpoint)
Expand Down Expand Up @@ -1868,5 +1878,17 @@ bool emberAfThermostatClusterSetpointRaiseLowerCallback(app::CommandHandler * co

void MatterThermostatPluginServerInitCallback()
{
Server::GetInstance().GetFabricTable().AddFabricDelegate(&gThermostatAttrAccess);
registerAttributeAccessOverride(&gThermostatAttrAccess);
}

void MatterThermostatClusterServerShutdownCallback(EndpointId endpoint)
{
ChipLogProgress(Zcl, "Shutting down thermostat server cluster on endpoint %d", endpoint);
Delegate * delegate = GetDelegate(endpoint);

if (delegate != nullptr)
{
resetAtomicWrite(delegate, endpoint);
}
}
30 changes: 15 additions & 15 deletions src/app/clusters/thermostat-server/thermostat-server.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,23 +40,14 @@ static constexpr size_t kThermostatEndpointCount =
/**
* @brief Thermostat Attribute Access Interface.
*/
class ThermostatAttrAccess : public chip::app::AttributeAccessInterface
class ThermostatAttrAccess : public chip::app::AttributeAccessInterface, public chip::FabricTable::Delegate
{
public:
ThermostatAttrAccess() : AttributeAccessInterface(Optional<chip::EndpointId>::Missing(), Thermostat::Id) {}

CHIP_ERROR Read(const ConcreteReadAttributePath & aPath, AttributeValueEncoder & aEncoder) override;
CHIP_ERROR Write(const ConcreteDataAttributePath & aPath, chip::app::AttributeValueDecoder & aDecoder) override;

/**
* @brief Sets the scoped node id of the originator that sent the last successful
* AtomicRequest of type BeginWrite for the given endpoint.
*
* @param[in] endpoint The endpoint.
* @param[in] originatorNodeId The originator scoped node id.
*/
void SetAtomicWriteScopedNodeId(EndpointId endpoint, ScopedNodeId originatorNodeId);

/**
* @brief Gets the scoped node id of the originator that sent the last successful
* AtomicRequest of type BeginWrite for the given endpoint.
Expand All @@ -68,12 +59,13 @@ class ThermostatAttrAccess : public chip::app::AttributeAccessInterface
ScopedNodeId GetAtomicWriteScopedNodeId(EndpointId endpoint);

/**
* @brief Sets whether an atomic write is in progress for the given endpoint
* @brief Sets whether an atomic write is in progress for the given endpoint and originatorNodeId
*
* @param[in] endpoint The endpoint.
* @param[in] originatorNodeId The originator scoped node id.
* @param[in] inProgress Whether or not an atomic write is in progress.
*/
void SetAtomicWrite(EndpointId endpoint, bool inProgress);
void SetAtomicWrite(EndpointId endpoint, ScopedNodeId originatorNodeId, bool inProgress);

/**
* @brief Gets whether an atomic write is in progress for the given endpoint
Expand Down Expand Up @@ -105,10 +97,18 @@ class ThermostatAttrAccess : public chip::app::AttributeAccessInterface
bool InAtomicWrite(CommandHandler * commandObj, EndpointId endpoint);

private:
CHIP_ERROR AppendPendingPreset(Delegate * delegate, const Structs::PresetStruct::Type & preset);
CHIP_ERROR AppendPendingPreset(Thermostat::Delegate * delegate, const Structs::PresetStruct::Type & preset);

void OnFabricRemoved(const FabricTable & fabricTable, FabricIndex fabricIndex) override;

struct AtomicWriteState
{
bool inProgress;
ScopedNodeId nodeId;
EndpointId endpointId;
woody-apple marked this conversation as resolved.
Show resolved Hide resolved
};

ScopedNodeId mAtomicWriteNodeIds[kThermostatEndpointCount];
bool mAtomicWriteState[kThermostatEndpointCount];
AtomicWriteState mAtomicWriteStates[kThermostatEndpointCount];
};

/**
Expand Down
1 change: 1 addition & 0 deletions src/app/common/templates/config-data.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ ClustersWithShutdownFunctions:
- Color Control
- Sample MEI
- Scenes Management
- Thermostat

ClustersWithPreAttributeChangeFunctions:
- Door Lock
Expand Down
Loading
Loading