[Question] [Twin] Update reported properties after reconnection.
See original GitHub issueContext
- OS and version used: Windows 10
- Python version: Python 2.7.17
- pip version: pip 20.0.2
- SDK version: V2 with threads/synchronous applications.
Description of the issue:
Hi,
I have a question regarding the management of the versioning between the desired properties and the reported properties. Let’s assume that while my device/module was disconnected, I made more than one change to the desired properties. When my device/module reconnects, the listener for the patches will not see any changes (as described here). So, to change the reported properties I need to get all the document (using the get_twin()
method, for example) and check the $version
field.
But the problem is that if I made more than one change I cannot change the $version
directly to equal them (i.e. desired: $version 6
, reported: $version 2
). More than that, if it’s about adding/removing fields there’s no problem: I can check then individually; but if I made 6 changes to one field, I cannot see all the other 5 modifications to change incrementally on my reported properties. So how can I manage properties with reconnection properly? Is there any code sample for this?
Thanks in advance.
AB#7366701
Issue Analytics
- State:
- Created 3 years ago
- Comments:11 (5 by maintainers)
Top GitHub Comments
Thanks @RickBadKan for raising this issue. Since we are tracking this as a feature request in issue #599 , we are going to close this issue. We appreciate you helping make our Python SDK better!
@RickBadKan - right now, the only way I know to detect if the twin version has changed is to re-fetch the full twin and compare the $version values. If the version has changed, the only way to know what has changed is to look through it property-by-property. Another alternative is to use a json patch library such as https://pypi.org/project/jsonpatch/ to calculate the diff. I haven’t looked at this library in detail, but I assume that it properly handles setting properties to None if they are deleted in the second object.
Regarding the extra bandwidth consumed by automatically fetching the twin on reconnect, I’ve opened #599 to suggest a new feature that turns this off.