Skip to content

Commit

Permalink
Updated Shadow sample to allow clearing properties by passing null (#379
Browse files Browse the repository at this point in the history
)

* Updated Shadow sample to allow clearing properties by passing null
* Modification to fix clang format for Shadow sample
  • Loading branch information
TwistedTwigleg authored Feb 17, 2022
1 parent 15bb0b2 commit 9e7c9aa
Showing 1 changed file with 29 additions and 7 deletions.
36 changes: 29 additions & 7 deletions samples/shadow/shadow_sync/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,25 @@ static void s_changeShadowValue(

ShadowState state;
JsonObject desired;
desired.WithString(shadowProperty, value);
JsonObject reported;
reported.WithString(shadowProperty, value);

if (value == "null")
{
JsonObject nullObject;
nullObject.AsNull();
desired.WithObject(shadowProperty, nullObject);
reported.WithObject(shadowProperty, nullObject);
}
else if (value == "clear_shadow")
{
desired.AsNull();
reported.AsNull();
}
else
{
desired.WithString(shadowProperty, value);
reported.WithString(shadowProperty, value);
}
state.Desired = desired;
state.Reported = reported;

Expand Down Expand Up @@ -288,7 +304,6 @@ int main(int argc, char *argv[])
if (event->State && event->State->View().ValueExists(shadowProperty))
{
JsonView objectView = event->State->View().GetJsonObject(shadowProperty);

if (objectView.IsNull())
{
fprintf(
Expand Down Expand Up @@ -324,10 +339,17 @@ int main(int argc, char *argv[])
auto onUpdateShadowAccepted = [&](UpdateShadowResponse *response, int ioErr) {
if (ioErr == AWS_OP_SUCCESS)
{
fprintf(
stdout,
"Finished updating reported shadow value to %s.\n",
response->State->Reported->View().GetString(shadowProperty).c_str());
if (response->State->Reported)
{
fprintf(
stdout,
"Finished updating reported shadow value to %s.\n",
response->State->Reported->View().GetString(shadowProperty).c_str());
}
else
{
fprintf(stdout, "Finished clearing shadow properties\n");
}
fprintf(stdout, "Enter desired value:\n");
}
else
Expand Down

0 comments on commit 9e7c9aa

Please sign in to comment.