Skip to content

Rebuilt shadow bindings and updated shadow sample to show how to clear properties #269

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged

Conversation

TwistedTwigleg
Copy link
Contributor

Issue #, if available:

Closes #114

Description of changes:

Adjusted the code for the ShadowState class so passing None is a valid input. This allows for clearing the reported or desired properties entirely in a method similar to the V1 SDK.

This PR makes the following changes:

  • Adjusts the iotshadow.py file to allow for passing none.
    • Now the desired and reported fields are set to empty dictionaries on initialization rather than being set to None.
    • The code for sending the package check to see if desired or reported are equal to empty dictionaries instead of None.
  • Adjusted the shadow sample
    • When you type none, it will now set the property to a Python none object, clearing the property with the shadow sample name.
    • When you type clear_shadow, it will send a ShadowState with both reported and desired set to None, clearing both entirely.
    • Additional conditions added to print a message based on the status of the shadow property in the on_update_shadow_accepted function.

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

Comment on lines 1319 to 1320
self.desired_none_is_valid = kwargs.get('desired_none_is_valid')
self.reported_none_is_valid = kwargs.get('reported_none_is_valid')
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you have the new xyz_none_is_valid values defaulting to None but we should have them defaulting to False

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed!

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

misunderstanding.

I was saying that kwargs.get('desired_none_is_valid') will return None by default

but you can do: kwargs.get('desired_none_is_valid', False) to get False instead

@@ -1295,15 +1303,22 @@ class ShadowState(awsiot.ModeledClass):

Attributes:
desired (typing.Dict[str, typing.Any]): The desired shadow state (from external services and devices).
desired_none_is_valid (bool): Set to true to allow desired to be None, clearing the data if sent.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

trivial: put "desired" in backticks or quotes so it's clear we're talking about the variable

@@ -1323,10 +1338,19 @@ def from_payload(cls, payload):
def to_payload(self):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this "explicitly null" thing can go both ways. Users can send AND receive ShadowState.

We should also adjust the from_payload() function so that users can tell the difference between a "None because nothing was there" and "None because the json doc had null in it"

In my opinion, the naming scheme xyz_none_is_valid makes a little less sense when we think about data being received. maybe we should just go with something simple like xyz_is_explicitly_null and if that's true, then we just send null. We don't cross-reference it with the actual value of xyz

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That works for me - that would also make the code simpler as well.

Copy link
Contributor Author

@TwistedTwigleg TwistedTwigleg Feb 9, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I changed the name to <var>_is_nullable and added checking to from_payload 👍
(technically it should be is_nonable since null is none, but nonable not a word, so... I think nullable should work)

Comment on lines 1319 to 1320
self.desired_none_is_valid = kwargs.get('desired_none_is_valid')
self.reported_none_is_valid = kwargs.get('reported_none_is_valid')
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

misunderstanding.

I was saying that kwargs.get('desired_none_is_valid') will return None by default

but you can do: kwargs.get('desired_none_is_valid', False) to get False instead

@TwistedTwigleg TwistedTwigleg merged commit 2b9ead0 into aws:main Feb 17, 2022
@TwistedTwigleg TwistedTwigleg deleted the ShadowStateGeneratorAdjustment branch February 17, 2022 20:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Unable to Clear the "Reported" and "Desired" fields
3 participants