Skip to content

Commit

Permalink
Merge branch 'master' into add_presets_to_Sdk
Browse files Browse the repository at this point in the history
  • Loading branch information
hasty authored Aug 4, 2024
2 parents 627e3f6 + bbef51a commit 0966a01
Show file tree
Hide file tree
Showing 15 changed files with 782 additions and 625 deletions.
1 change: 1 addition & 0 deletions .github/workflows/tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -551,6 +551,7 @@ jobs:
scripts/run_in_python_env.sh out/venv './scripts/tests/run_python_test.py --load-from-env /tmp/test_env.yaml --script src/python_testing/TC_FAN_3_5.py'
scripts/run_in_python_env.sh out/venv './scripts/tests/run_python_test.py --load-from-env /tmp/test_env.yaml --script src/python_testing/TC_ICDM_2_1.py'
scripts/run_in_python_env.sh out/venv './scripts/tests/run_python_test.py --load-from-env /tmp/test_env.yaml --script src/python_testing/TC_ICDM_3_1.py'
scripts/run_in_python_env.sh out/venv './scripts/tests/run_python_test.py --load-from-env /tmp/test_env.yaml --script src/python_testing/TC_ICDM_3_3.py'
scripts/run_in_python_env.sh out/venv './scripts/tests/run_python_test.py --load-from-env /tmp/test_env.yaml --script src/python_testing/TC_ICDManagementCluster.py'
scripts/run_in_python_env.sh out/venv './scripts/tests/run_python_test.py --load-from-env /tmp/test_env.yaml --script src/python_testing/TC_IDM_1_2.py'
scripts/run_in_python_env.sh out/venv './scripts/tests/run_python_test.py --load-from-env /tmp/test_env.yaml --script src/python_testing/TC_IDM_1_4.py'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,38 +58,43 @@ public Set<SupportedCluster> getSupportedClusters(final Resources resources, fin
SupportedCluster cluster = new SupportedCluster();
while (reader.hasNext()) {
String name = reader.nextName();
if (name.equals(KEY_CLUSTER_ID)) {
cluster.clusterIdentifier = reader.nextInt();
} else if (name.equals(KEY_FEATURE_FLAGS)) {
cluster.features = reader.nextInt();
} else if (name.equals(KEY_OPTIONAL_COMMANDS)) {
List<Integer> commands = new ArrayList<>();
reader.beginArray();
while (reader.hasNext()) {
commands.add(reader.nextInt());
try {
if (name.equals(KEY_CLUSTER_ID)) {
cluster.clusterIdentifier = reader.nextInt();
} else if (name.equals(KEY_FEATURE_FLAGS)) {
cluster.features = reader.nextInt();
} else if (name.equals(KEY_OPTIONAL_COMMANDS)) {
List<Integer> commands = new ArrayList<>();
reader.beginArray();
while (reader.hasNext()) {
commands.add(reader.nextInt());
}
reader.endArray();
int[] commandIds = new int[commands.size()];
int i = 0;
for (Integer command : commands) {
commandIds[i++] = command;
}
cluster.optionalCommandIdentifiers = commandIds;
} else if (name.equals(KEY_OPTIONAL_ATTRIBUTES)) {
List<Integer> attributes = new ArrayList<>();
reader.beginArray();
while (reader.hasNext()) {
attributes.add(reader.nextInt());
}
reader.endArray();
int[] attributeIds = new int[attributes.size()];
int i = 0;
for (Integer command : attributes) {
attributeIds[i++] = command;
}
cluster.optionalAttributesIdentifiers = attributeIds;
} else {
reader.skipValue();
}
reader.endArray();
int[] commandIds = new int[commands.size()];
int i = 0;
for (Integer command : commands) {
commandIds[i++] = command;
}
cluster.optionalCommandIdentifiers = commandIds;
} else if (name.equals(KEY_OPTIONAL_ATTRIBUTES)) {
List<Integer> attributes = new ArrayList<>();
reader.beginArray();
while (reader.hasNext()) {
attributes.add(reader.nextInt());
}
reader.endArray();
int[] attributeIds = new int[attributes.size()];
int i = 0;
for (Integer command : attributes) {
attributeIds[i++] = command;
}
cluster.optionalAttributesIdentifiers = attributeIds;
} else {
reader.skipValue();
} catch (NumberFormatException | IllegalStateException e) {
Log.e(TAG, "Invalid number format in JSON for key: " + name, e);
reader.skipValue(); // Skip the invalid entry
}
}
supportedClusters.add(cluster);
Expand Down
39 changes: 39 additions & 0 deletions examples/tv-app/android/java/ContentAppCommandDelegate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,26 @@ Status ContentAppCommandDelegate::InvokeCommand(EndpointId epId, ClusterId clust
JniUtfString respStr(env, resp);
ChipLogProgress(Zcl, "ContentAppCommandDelegate::InvokeCommand got response %s", respStr.c_str());

Json::CharReaderBuilder readerBuilder;
std::string errors;

std::unique_ptr<Json::CharReader> testReader(readerBuilder.newCharReader());

if (!testReader->parse(respStr.c_str(), respStr.c_str() + std::strlen(respStr.c_str()), &value, &errors))
{
ChipLogError(Zcl, "Failed to parse JSON: %s\n", errors.c_str());
env->DeleteLocalRef(resp);
return chip::Protocols::InteractionModel::Status::Failure;
}

// Validate and access JSON data safely
if (!value.isObject())
{
ChipLogError(Zcl, "Invalid JSON structure: not an object");
env->DeleteLocalRef(resp);
return chip::Protocols::InteractionModel::Status::Failure;
}

Json::Reader reader;
if (!reader.parse(respStr.c_str(), value))
{
Expand Down Expand Up @@ -166,7 +186,26 @@ void ContentAppCommandDelegate::FormatResponseData(CommandHandlerInterface::Hand
{
handlerContext.SetCommandHandled();
Json::Reader reader;

Json::CharReaderBuilder readerBuilder;
std::string errors;

Json::Value value;
std::unique_ptr<Json::CharReader> testReader(readerBuilder.newCharReader());

if (!testReader->parse(response, response + std::strlen(response), &value, &errors))
{
ChipLogError(Zcl, "Failed to parse JSON: %s\n", errors.c_str());
return;
}

// Validate and access JSON data safely
if (!value.isObject())
{
ChipLogError(Zcl, "Invalid JSON structure: not an object");
return;
}

if (!reader.parse(response, value))
{
return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,10 @@ CHIP_ERROR AttrAccess::Read(const ConcreteReadAttributePath & aPath, AttributeVa
// TODO(#33223) To improve safety we could make GetEncodableLocationDescriptorStruct a private
// memeber method where we explicitly delete member method for the parameter that matches
// (LocationDescriptorStruct && aLocationDescriptor).
Structs::LocationDescriptorStruct::Type GetEncodableLocationDescriptorStruct(const LocationDescriptorStruct & aLocationDescriptor)
Globals::Structs::LocationDescriptorStruct::Type
GetEncodableLocationDescriptorStruct(const LocationDescriptorStruct & aLocationDescriptor)
{
Structs::LocationDescriptorStruct::Type locationDescriptor;
Globals::Structs::LocationDescriptorStruct::Type locationDescriptor;
// This would imply data is either not properly validated before being
// stored here or corruption has occurred.
VerifyOrDie(!aLocationDescriptor.mLocationName.empty());
Expand Down Expand Up @@ -199,7 +200,8 @@ EcosystemLocationStruct::Builder & EcosystemLocationStruct::Builder::SetFloorNum
return *this;
}

EcosystemLocationStruct::Builder & EcosystemLocationStruct::Builder::SetAreaTypeTag(std::optional<AreaTypeTag> aAreaTypeTag)
EcosystemLocationStruct::Builder &
EcosystemLocationStruct::Builder::SetAreaTypeTag(std::optional<Globals::AreaTypeTag> aAreaTypeTag)
{
VerifyOrDie(!mIsAlreadyBuilt);
mLocationDescriptor.mAreaType = aAreaTypeTag;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ struct LocationDescriptorStruct
{
std::string mLocationName;
std::optional<int16_t> mFloorNumber;
std::optional<AreaTypeTag> mAreaType;
std::optional<Globals::AreaTypeTag> mAreaType;
};

// This intentionally mirrors Structs::EcosystemLocationStruct::Type but has ownership
Expand All @@ -111,7 +111,7 @@ class EcosystemLocationStruct

Builder & SetLocationName(std::string aLocationName);
Builder & SetFloorNumber(std::optional<int16_t> aFloorNumber);
Builder & SetAreaTypeTag(std::optional<AreaTypeTag> aAreaTypeTag);
Builder & SetAreaTypeTag(std::optional<Globals::AreaTypeTag> aAreaTypeTag);
Builder & SetLocationDescriptorLastEdit(uint64_t aLocationDescriptorLastEditEpochUs);

// Upon success this object will have moved all ownership of underlying
Expand Down
74 changes: 47 additions & 27 deletions src/app/clusters/on-off-server/on-off-server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,13 +45,16 @@
#endif // MATTER_DM_PLUGIN_MODE_BASE

#include <platform/CHIPDeviceLayer.h>
#include <platform/DiagnosticDataProvider.h>
#include <platform/PlatformManager.h>

using namespace chip;
using namespace chip::app::Clusters;
using namespace chip::app::Clusters::OnOff;
using chip::Protocols::InteractionModel::Status;

using BootReasonType = GeneralDiagnostics::BootReasonEnum;

namespace {

#ifdef MATTER_DM_PLUGIN_MODE_BASE
Expand Down Expand Up @@ -95,6 +98,22 @@ bool IsKnownEnumValue(EnumType value)
return (EnsureKnownEnumValue(value) != EnumType::kUnknownEnumValue);
}

BootReasonType GetBootReason()
{
BootReasonType bootReason = BootReasonType::kUnspecified;

CHIP_ERROR error = DeviceLayer::GetDiagnosticDataProvider().GetBootReason(bootReason);
if (error != CHIP_NO_ERROR)
{
ChipLogError(Zcl, "Unable to retrieve boot reason: %" CHIP_ERROR_FORMAT, error.Format());
bootReason = BootReasonType::kUnspecified;
}

ChipLogProgress(Zcl, "Boot reason: %u", to_underlying(bootReason));

return bootReason;
}

} // namespace

#ifdef MATTER_DM_PLUGIN_LEVEL_CONTROL
Expand Down Expand Up @@ -537,35 +556,36 @@ Status OnOffServer::getOnOffValueForStartUp(chip::EndpointId endpoint, bool & on
{
app::DataModel::Nullable<OnOff::StartUpOnOffEnum> startUpOnOff;
Status status = Attributes::StartUpOnOff::Get(endpoint, startUpOnOff);
if (status == Status::Success)
VerifyOrReturnError(status == Status::Success, status);

bool currentOnOff = false;
status = Attributes::OnOff::Get(endpoint, &currentOnOff);
VerifyOrReturnError(status == Status::Success, status);

if (startUpOnOff.IsNull() || GetBootReason() == BootReasonType::kSoftwareUpdateCompleted)
{
// Initialise updated value to 0
bool updatedOnOff = false;
status = Attributes::OnOff::Get(endpoint, &updatedOnOff);
if (status == Status::Success)
{
if (!startUpOnOff.IsNull())
{
switch (startUpOnOff.Value())
{
case OnOff::StartUpOnOffEnum::kOff:
updatedOnOff = false; // Off
break;
case OnOff::StartUpOnOffEnum::kOn:
updatedOnOff = true; // On
break;
case OnOff::StartUpOnOffEnum::kToggle:
updatedOnOff = !updatedOnOff;
break;
default:
// All other values 0x03- 0xFE are reserved - no action.
break;
}
}
onOffValueForStartUp = updatedOnOff;
}
onOffValueForStartUp = currentOnOff;
return Status::Success;
}
return status;

switch (startUpOnOff.Value())
{
case OnOff::StartUpOnOffEnum::kOff:
onOffValueForStartUp = false; // Off
break;
case OnOff::StartUpOnOffEnum::kOn:
onOffValueForStartUp = true; // On
break;
case OnOff::StartUpOnOffEnum::kToggle:
onOffValueForStartUp = !currentOnOff;
break;
default:
// All other values 0x03- 0xFE are reserved - no action.
onOffValueForStartUp = currentOnOff;
break;
}

return Status::Success;
}

bool OnOffServer::offCommand(app::CommandHandler * commandObj, const app::ConcreteCommandPath & commandPath)
Expand Down
Loading

0 comments on commit 0966a01

Please sign in to comment.