-
Notifications
You must be signed in to change notification settings - Fork 222
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
Rebuilt shadow bindings and updated shadow sample to show how to clear properties #269
Conversation
…passing None as valid input
awsiot/iotshadow.py
Outdated
self.desired_none_is_valid = kwargs.get('desired_none_is_valid') | ||
self.reported_none_is_valid = kwargs.get('reported_none_is_valid') |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed!
There was a problem hiding this comment.
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
awsiot/iotshadow.py
Outdated
@@ -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. |
There was a problem hiding this comment.
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): |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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)
awsiot/iotshadow.py
Outdated
self.desired_none_is_valid = kwargs.get('desired_none_is_valid') | ||
self.reported_none_is_valid = kwargs.get('reported_none_is_valid') |
There was a problem hiding this comment.
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
…dability. Added setting _is_nullable to from_payload
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 thereported
ordesired
properties entirely in a method similar to the V1 SDK.This PR makes the following changes:
iotshadow.py
file to allow for passingnone
.desired
andreported
fields are set to empty dictionaries on initialization rather than being set toNone
.desired
orreported
are equal to empty dictionaries instead ofNone
.none
, it will now set the property to a Pythonnone
object, clearing the property with the shadow sample name.clear_shadow
, it will send a ShadowState with bothreported
anddesired
set toNone
, clearing both entirely.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.