Skip to content

Commit 9e7c9aa

Browse files
Updated Shadow sample to allow clearing properties by passing null (#379)
* Updated Shadow sample to allow clearing properties by passing null * Modification to fix clang format for Shadow sample
1 parent 15bb0b2 commit 9e7c9aa

File tree

1 file changed

+29
-7
lines changed

1 file changed

+29
-7
lines changed

samples/shadow/shadow_sync/main.cpp

+29-7
Original file line numberDiff line numberDiff line change
@@ -72,9 +72,25 @@ static void s_changeShadowValue(
7272

7373
ShadowState state;
7474
JsonObject desired;
75-
desired.WithString(shadowProperty, value);
7675
JsonObject reported;
77-
reported.WithString(shadowProperty, value);
76+
77+
if (value == "null")
78+
{
79+
JsonObject nullObject;
80+
nullObject.AsNull();
81+
desired.WithObject(shadowProperty, nullObject);
82+
reported.WithObject(shadowProperty, nullObject);
83+
}
84+
else if (value == "clear_shadow")
85+
{
86+
desired.AsNull();
87+
reported.AsNull();
88+
}
89+
else
90+
{
91+
desired.WithString(shadowProperty, value);
92+
reported.WithString(shadowProperty, value);
93+
}
7894
state.Desired = desired;
7995
state.Reported = reported;
8096

@@ -288,7 +304,6 @@ int main(int argc, char *argv[])
288304
if (event->State && event->State->View().ValueExists(shadowProperty))
289305
{
290306
JsonView objectView = event->State->View().GetJsonObject(shadowProperty);
291-
292307
if (objectView.IsNull())
293308
{
294309
fprintf(
@@ -324,10 +339,17 @@ int main(int argc, char *argv[])
324339
auto onUpdateShadowAccepted = [&](UpdateShadowResponse *response, int ioErr) {
325340
if (ioErr == AWS_OP_SUCCESS)
326341
{
327-
fprintf(
328-
stdout,
329-
"Finished updating reported shadow value to %s.\n",
330-
response->State->Reported->View().GetString(shadowProperty).c_str());
342+
if (response->State->Reported)
343+
{
344+
fprintf(
345+
stdout,
346+
"Finished updating reported shadow value to %s.\n",
347+
response->State->Reported->View().GetString(shadowProperty).c_str());
348+
}
349+
else
350+
{
351+
fprintf(stdout, "Finished clearing shadow properties\n");
352+
}
331353
fprintf(stdout, "Enter desired value:\n");
332354
}
333355
else

0 commit comments

Comments
 (0)