Skip to content

Commit

Permalink
Add checks for localization-configuration cluster and time-format-loc…
Browse files Browse the repository at this point in the history
…alization cluster init callback (#32747)

* Add checks for localization-configuration cluster and time-format-localization cluster

* Update src/app/clusters/time-format-localization-server/time-format-localization-server.cpp

Co-authored-by: Boris Zbarsky <bzbarsky@apple.com>

---------

Co-authored-by: Boris Zbarsky <bzbarsky@apple.com>
  • Loading branch information
wqx6 and bzbarsky-apple committed May 14, 2024
1 parent 0413783 commit e07953d
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ void emberAfLocalizationConfigurationClusterServerInitCallback(EndpointId endpoi

it->Release();

if (err == CHIP_ERROR_PERSISTED_STORAGE_VALUE_NOT_FOUND)
if (err == CHIP_ERROR_PERSISTED_STORAGE_VALUE_NOT_FOUND && validLocaleCached)
{
// If initial value is not one of the allowed values, write the valid value it.
status = ActiveLocale::Set(endpoint, validLocale);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,12 @@ class AutoReleaseIterator

TimeFormatLocalizationAttrAccess gAttrAccess;

bool HasFeature(EndpointId endpoint, Feature feature)
{
uint32_t featureMap;
return FeatureMap::Get(endpoint, &featureMap) == Status::Success ? (featureMap & to_underlying(feature)) : false;
}

CHIP_ERROR TimeFormatLocalizationAttrAccess::ReadSupportedCalendarTypes(AttributeValueEncoder & aEncoder)
{
DeviceLayer::DeviceInfoProvider * provider = DeviceLayer::GetDeviceInfoProvider();
Expand Down Expand Up @@ -202,6 +208,10 @@ Protocols::InteractionModel::Status MatterTimeFormatLocalizationClusterServerPre

void emberAfTimeFormatLocalizationClusterServerInitCallback(EndpointId endpoint)
{
if (!HasFeature(endpoint, Feature::kCalendarFormat))
{
return;
}
CalendarTypeEnum calendarType;
CalendarTypeEnum validType;
Status status = ActiveCalendarType::Get(endpoint, &calendarType);
Expand Down

0 comments on commit e07953d

Please sign in to comment.