@@ -100,17 +100,13 @@ def on_get_shadow_accepted(response):
100
100
value = response .state .delta .get (shadow_property )
101
101
if value :
102
102
print (" Shadow contains delta value '{}'." .format (value ))
103
- change_shadow_value (value )
104
103
return
105
104
106
105
if response .state .reported :
107
106
value = response .state .reported .get (shadow_property )
108
107
if value :
109
108
print (" Shadow contains reported value '{}'." .format (value ))
110
109
return
111
-
112
- print (" Shadow document lacks '{}' property. Setting defaults..." .format (shadow_property ))
113
- change_shadow_value (SHADOW_VALUE_DEFAULT )
114
110
return
115
111
116
112
except Exception as e :
@@ -128,12 +124,8 @@ def on_get_shadow_rejected(error):
128
124
print ("Ignoring get_shadow_rejected message due to unexpected token." )
129
125
return
130
126
131
- if error .code == 404 :
132
- print ("Thing has no shadow document. Creating with defaults..." )
133
- change_shadow_value (SHADOW_VALUE_DEFAULT )
134
- else :
135
- exit ("Get request was rejected. code:{} message:'{}'" .format (
136
- error .code , error .message ))
127
+ if error .code != 404 :
128
+ exit ("Get request was rejected. code:{} message:'{}'" .format (error .code , error .message ))
137
129
except Exception as e :
138
130
exit (e )
139
131
@@ -193,32 +185,6 @@ def on_update_shadow_rejected(error):
193
185
exit (e )
194
186
195
187
196
- def change_shadow_value (value ):
197
- with locked_data .lock :
198
-
199
- print ("Changed local shadow value to '{}'." .format (value ))
200
- locked_data .shadow_value = value
201
-
202
- print ("Updating reported shadow value to '{}'..." .format (value ))
203
-
204
- # use a unique token so we can correlate this "request" message to
205
- # any "response" messages received on the /accepted and /rejected topics
206
- token = str (uuid4 ())
207
-
208
- # if the value is "none" then set it to a Python none object to
209
- request = iotshadow .UpdateShadowRequest (
210
- thing_name = shadow_thing_name ,
211
- state = iotshadow .ShadowState (
212
- reported = {shadow_property : value },
213
- desired = {shadow_property : value },
214
- ),
215
- client_token = token ,
216
- )
217
- future = shadow_client .publish_update_shadow (request , mqtt_qos )
218
- locked_data .request_tokens .add (token )
219
- future .add_done_callback (on_publish_update_shadow )
220
-
221
-
222
188
def update_event_received (response ):
223
189
print ("Update Event Received\n " )
224
190
print ("Current response" , response .current )
@@ -387,8 +353,6 @@ def update_shadow():
387
353
388
354
update_thing_update_future = shadow_client .publish_update_shadow (request = iotshadow .UpdateShadowRequest
389
355
(thing_name = shadow_thing_name , state = state ), qos = mqtt_qos )
390
-
391
- change_shadow_value (cmdData .input_shadow_value )
392
356
update_thing_update_future .result ()
393
357
394
358
except Exception as e :
@@ -470,6 +434,3 @@ def update_shadow():
470
434
exit (0 )
471
435
# Wait for the sample to finish
472
436
is_sample_done .wait ()
473
-
474
-
475
-
0 commit comments