Skip to content

Commit

Permalink
stop using attribute storage for TimeSource to make the code more
Browse files Browse the repository at this point in the history
suitable for unit testing
  • Loading branch information
fessehaeve committed Apr 12, 2024
1 parent 6ff3e0a commit 85b8e13
Show file tree
Hide file tree
Showing 10 changed files with 16 additions and 82 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7590,7 +7590,7 @@ endpoint 0 {
emits event MissingTrustedTimeSource;
callback attribute UTCTime;
callback attribute granularity;
ram attribute timeSource default = 0x00;
callback attribute timeSource;
callback attribute trustedTimeSource;
callback attribute defaultNTP;
callback attribute timeZone;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4915,10 +4915,10 @@
"side": "server",
"type": "TimeSourceEnum",
"included": 1,
"storageOption": "RAM",
"storageOption": "External",
"singleton": 0,
"bounded": 0,
"defaultValue": "0x00",
"defaultValue": null,
"reportable": 1,
"minInterval": 1,
"maxInterval": 65534,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2778,7 +2778,7 @@ endpoint 0 {
emits event MissingTrustedTimeSource;
callback attribute UTCTime;
callback attribute granularity;
ram attribute timeSource default = 0x00;
callback attribute timeSource;
callback attribute trustedTimeSource;
callback attribute defaultNTP;
callback attribute timeZone;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3599,10 +3599,10 @@
"side": "server",
"type": "TimeSourceEnum",
"included": 1,
"storageOption": "RAM",
"storageOption": "External",
"singleton": 0,
"bounded": 0,
"defaultValue": "0x00",
"defaultValue": null,
"reportable": 1,
"minInterval": 1,
"maxInterval": 65534,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -378,12 +378,8 @@ void TimeSynchronizationServer::OnTimeSyncCompletionFn(TimeSourceEnum timeSource
}
return;
}
mGranularity = granularity;
Status status = TimeSource::Set(kRootEndpointId, timeSource);
if (!(status == Status::Success || status == Status::UnsupportedAttribute))
{
ChipLogError(Zcl, "Writing TimeSource failed.");
}
mGranularity = granularity;
mTimeSource = timeSource;
}

void TimeSynchronizationServer::OnFallbackNTPCompletionFn(bool timeSyncSuccessful)
Expand All @@ -392,11 +388,7 @@ void TimeSynchronizationServer::OnFallbackNTPCompletionFn(bool timeSyncSuccessfu
{
mGranularity = GranularityEnum::kMillisecondsGranularity;
// Non-matter SNTP because we know it's external and there's only one source
Status status = TimeSource::Set(kRootEndpointId, TimeSourceEnum::kNonMatterSNTP);
if (!(status == Status::Success || status == Status::UnsupportedAttribute))
{
ChipLogError(Zcl, "Writing TimeSource failed.");
}
mTimeSource = TimeSourceEnum::kNonMatterSNTP;
}
else
{
Expand Down Expand Up @@ -791,13 +783,8 @@ CHIP_ERROR TimeSynchronizationServer::SetUTCTime(EndpointId ep, uint64_t utcTime
return err;
}
GetDelegate()->UTCTimeAvailabilityChanged(utcTime);
mGranularity = static_cast<GranularityEnum>(to_underlying(granularity) - 1);
Status status = TimeSource::Set(ep, source);
if (!(status == Status::Success || status == Status::UnsupportedAttribute))
{
ChipLogError(Zcl, "Writing TimeSource failed.");
return StatusIB(status).ToChipError();
}
mGranularity = static_cast<GranularityEnum>(to_underlying(granularity) - 1);
mTimeSource = source;
return CHIP_NO_ERROR;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
#include <app/AppConfig.h>
#include <app/server/Server.h>
#include <app/util/af-types.h>
#include <app/util/config.h>
#include <credentials/FabricTable.h>
#include <lib/core/TLV.h>

Expand Down Expand Up @@ -137,6 +136,7 @@ class TimeSynchronizationServer : public FabricTable::Delegate
TimeSyncDataProvider::TimeZoneObj mTimeZoneObj{ Span<TimeSyncDataProvider::TimeZoneStore>(mTz), 0 };
TimeSyncDataProvider::DSTOffsetObj mDstOffsetObj{ DataModel::List<Structs::DSTOffsetStruct::Type>(mDst), 0 };
GranularityEnum mGranularity = GranularityEnum::kNoTimeGranularity;
TimeSourceEnum mTimeSource = TimeSourceEnum::kNone;

TimeSyncDataProvider::TimeZoneStore mTz[CHIP_CONFIG_TIME_ZONE_LIST_MAX_SIZE];
Structs::DSTOffsetStruct::Type mDst[CHIP_CONFIG_DST_OFFSET_LIST_MAX_SIZE];
Expand Down
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 @@ -382,7 +382,8 @@
"LocalTime",
"Granularity",
"TimeZoneListMaxSize",
"DSTOffsetListMaxSize"
"DSTOffsetListMaxSize",
"TimeSource"
],
"Temperature Control": ["SupportedTemperatureLevels"],
"Dishwasher Mode": [
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 @@ -380,7 +380,8 @@
"LocalTime",
"Granularity",
"TimeZoneListMaxSize",
"DSTOffsetListMaxSize"
"DSTOffsetListMaxSize",
"TimeSource"
],
"Temperature Control": ["SupportedTemperatureLevels"],
"Dishwasher Mode": [
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 85b8e13

Please sign in to comment.