From 6430fe5e1f90c7c5ffe946818acbe834d027cec0 Mon Sep 17 00:00:00 2001 From: Noah Beard Date: Wed, 20 Apr 2022 11:56:24 -0400 Subject: [PATCH 1/2] Added ClientToken to ShadowDeltaUpdated --- awsiot/iotshadow.py | 9 +++++++-- samples/shadow.py | 3 ++- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/awsiot/iotshadow.py b/awsiot/iotshadow.py index a6c28ef7..61b3c6ca 100644 --- a/awsiot/iotshadow.py +++ b/awsiot/iotshadow.py @@ -1187,21 +1187,24 @@ class ShadowDeltaUpdatedEvent(awsiot.ModeledClass): All attributes are None by default, and may be set by keyword in the constructor. Keyword Args: + client_token (str): An opaque token used to correlate requests and responses. Present only if a client token was used in the request. metadata (typing.Dict[str, typing.Any]): Timestamps for the shadow properties that were updated. state (typing.Dict[str, typing.Any]): Shadow properties that were updated. timestamp (datetime.datetime): The time the event was generated by AWS IoT. version (int): The current version of the document for the device's shadow. Attributes: + client_token (str): An opaque token used to correlate requests and responses. Present only if a client token was used in the request. metadata (typing.Dict[str, typing.Any]): Timestamps for the shadow properties that were updated. state (typing.Dict[str, typing.Any]): Shadow properties that were updated. timestamp (datetime.datetime): The time the event was generated by AWS IoT. version (int): The current version of the document for the device's shadow. """ - __slots__ = ['metadata', 'state', 'timestamp', 'version'] + __slots__ = ['client_token', 'metadata', 'state', 'timestamp', 'version'] def __init__(self, *args, **kwargs): + self.client_token = kwargs.get('client_token') self.metadata = kwargs.get('metadata') self.state = kwargs.get('state') self.timestamp = kwargs.get('timestamp') @@ -1215,6 +1218,9 @@ def __init__(self, *args, **kwargs): def from_payload(cls, payload): # type: (typing.Dict[str, typing.Any]) -> ShadowDeltaUpdatedEvent new = cls() + val = payload.get('clientToken') + if val is not None: + new.client_token = val val = payload.get('metadata') if val is not None: new.metadata = val @@ -1711,4 +1717,3 @@ def __init__(self, *args, **kwargs): # for backwards compatibility, read any arguments that used to be accepted by position for key, val in zip(['thing_name'], args): setattr(self, key, val) - diff --git a/samples/shadow.py b/samples/shadow.py index 9e0f9bf8..b7549ed7 100644 --- a/samples/shadow.py +++ b/samples/shadow.py @@ -154,7 +154,8 @@ def on_shadow_delta_updated(delta): return else: print(" Delta reports that desired value is '{}'. Changing local value...".format(value)) - change_shadow_value(value) + if (delta.client_token is not None): + print (" ClientToken is: " + delta.client_token) else: print(" Delta did not report a change in '{}'".format(shadow_property)) From 4c87fd109a7aaaaca729eba26f4ee7a4da5cf07a Mon Sep 17 00:00:00 2001 From: Noah Beard Date: Wed, 20 Apr 2022 13:08:12 -0400 Subject: [PATCH 2/2] Add back changing shadow value that was accidentally removed --- samples/shadow.py | 1 + 1 file changed, 1 insertion(+) diff --git a/samples/shadow.py b/samples/shadow.py index b7549ed7..2b390361 100644 --- a/samples/shadow.py +++ b/samples/shadow.py @@ -156,6 +156,7 @@ def on_shadow_delta_updated(delta): print(" Delta reports that desired value is '{}'. Changing local value...".format(value)) if (delta.client_token is not None): print (" ClientToken is: " + delta.client_token) + change_shadow_value(value) else: print(" Delta did not report a change in '{}'".format(shadow_property))