Iot 918 conform to google format times binary data#24
Conversation
2. Added logic to def from_json in class DeviceState and DeviceConfig to convert times to DateTimeWithNanoseconds and binaryData to bytes if env. vars set
for time, binaryData. 2. Changed DeviceState.from_json to handle blank binaryData 3. Changed DeviceConfig.from_json to handle blank binaryData
| from .utils import get_value | ||
|
|
||
| import os | ||
| from google.api_core.datetime_helpers import DatetimeWithNanoseconds |
There was a problem hiding this comment.
I think this looks external library because when I tried to use that I got this alert,
Import "google.api_core.datetime_helpers" could not be resolvedPylancereportMissingImports
There was a problem hiding this comment.
Yes, I see. Would it make sense to add a note in the README to say IF you want that type for times, THEN you should run pip install google-api-core? See here: https://pypi.org/project/google-api-core/
I think I happened to have this already installed because I have used the Google IoTCore Python SDK before.
There was a problem hiding this comment.
We can update the dependencies inside setup.py to add this library. That should download the package when installing the sdk.
There was a problem hiding this comment.
I went ahead and added the note to the README. Does that help @ronak-ingress ?
There was a problem hiding this comment.
I just saw @rajasd27 note. I'll make changes accordingly.
| last_config_send_time = lastConfigSendTimeFromJson | ||
| last_error_time = lastErrorTimeFromJson | ||
|
|
||
| convert_binarydata_to_bytes = (False if os.environ.get("BINARYDATA_FORMAT") == None else os.environ.get("BINARYDATA_FORMAT").lower() == "bytes") |
There was a problem hiding this comment.
Not using convert_binarydata_to_bytes anywhere. Should that be used anywhere?
There was a problem hiding this comment.
Good catch. config on line 118 should be converted. I'll get to that next.
There was a problem hiding this comment.
@rajasd27 just realized I don't need to do any conversion on 'config'. I just removed the line that set convert_binarydata_to_bytes. It is not needed here.
README.rst
Outdated
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | ||
|
|
||
| - By default time parameters (e.g. **cloudUpdateTime**, **deviceAckTime**, **updateTime**) are returned as **RFC3339** strings (e.g. "2023-01-12T23:38:07.732Z"). | ||
| - To return times formatted as **DatetimeWithNanoseconds** (defined in the **google.api_core.datetime_helpers** module) as returned by the **Google IoTCore Python SDK**, set environment variable **TIME_FORMAT** to exactly **datetimewithnanoseconds**. |
There was a problem hiding this comment.
Should we just change the env variables values to true (false being the default). datetimewithnanoseconds value might be a bit too long and people might mess up writing that. We can ask Aaron/Ronak for their opinion on this.
There was a problem hiding this comment.
We'll need to change the env variable name in that case - something like ALLOW_LEGACY_TIMESTAMP & ALLOW_BYTE_ARRAYS.
There was a problem hiding this comment.
I thought about that. As we observed it seems all env. vars have to be strings. So we would have to account for "true" vs "True" vs "TRUE". That is not a big deal: I'm already converting the passed env. var to lower case anyway.
With the time format, the thing word LEGACY would confuse me: it's not like we supported that type before and we are now transitioning away from it.
And with ALLOW_BYTE_ARRAYS I would wonder where are we now allowing BYTE_ARRAYS that we didn't before? Setting that env. var ONLY changes binaryData and it changes EVERY instance of binaryData. Which is why BINARYDATA_FORMAT makes sense to me.
There was a problem hiding this comment.
Should we just change the env variables values to true (false being the default).
datetimewithnanosecondsvalue might be a bit too long and people might mess up writing that. We can ask Aaron/Ronak for their opinion on this.
Yeah I agree with that. If someone wrote wrong spelling it will also cause the issue and true false makes more sense.
There was a problem hiding this comment.
But then the env. variable names have to be long for them to make sense, no?
There was a problem hiding this comment.
But I'm fine with that - just couldn't come up with variable names that were not confusing.
| from .utils import get_value | ||
|
|
||
| import os | ||
| from google.api_core.datetime_helpers import DatetimeWithNanoseconds |
There was a problem hiding this comment.
We can update the dependencies inside setup.py to add this library. That should download the package when installing the sdk.
datetime_helpers module. Also now changed 'google.api_core' to 'proto'
in Devices.from_json
setup.py
Outdated
| version = "1.0.5" | ||
| release_status = "Development Status :: 5 - Production/Stable" | ||
| dependencies = ["httpx"] | ||
| dependencies = ["httpx", "proto.datetime_helpers"] |
There was a problem hiding this comment.
I'm not 100% sure if this would work. I think you'll need to add the exact pip package proto-plus in this case.
There was a problem hiding this comment.
OK, I'll make that change.
|
|
||
| - mostly if you change you imports from from google.cloud to clearblade.cloud everything else should work. | ||
|
|
||
| Note about types of times and binaryData |
There was a problem hiding this comment.
Should we add this Note as the 3rd point in the Quickstart section? That way people can get to know that they have the option to set this env variable along with the CLEARBLADE_CONFIGURATION.
There was a problem hiding this comment.
Got it. Added to the 'Quick Start'. Take a look.
| from .utils import get_value | ||
|
|
||
| import os | ||
| from proto.datetime_helpers import DatetimeWithNanoseconds |
There was a problem hiding this comment.
This also looks third party, got this error when executed SDK sample
ModuleNotFoundError: No module named 'proto'
* ListDevicesRequest >> _prepare_params_for_list: (#16) modified to handle gatewayListOptions following NodeJS SDK * updated device class and enums (#19) * updated send_command function to base64 encode payload (#18) * Changed 'cloud_ack_time' to 'cloud_update_time' (#20) * Iot 918 conform to google format times binary data (#24) * 1. imports incl. google.api_core.datetime_helpers 2. Added logic to def from_json in class DeviceState and DeviceConfig to convert times to DateTimeWithNanoseconds and binaryData to bytes if env. vars set * 1. Changed Device.from_json to support GCP types for time, binaryData. 2. Changed DeviceState.from_json to handle blank binaryData 3. Changed DeviceConfig.from_json to handle blank binaryData * Removed extra 'import base64' * Added note about types of times, binaryData * Cleaned up formatting * Further cleanup * Added copyright info. at top of files * Not to 'pip install google-api-core' * Removed instructions for installing datetime_helpers module. Also now changed 'google.api_core' to 'proto' * Added "proto.datetime_helpers" to dependencies * Changed 'google.api_core' to 'proto.' * Removed call to set 'convert_binarydata_to_bytes' in Devices.from_json * Changed README to reflect decision on ONE env. var * Changed module to import to proto-plus * Two env. vars -> BINARYDATA_AND_TIME_GOOGLE_FORMAT * Removed a '.' * Format improvements for README * Added note about new env. var in 'Quick Start' sec --------- Co-authored-by: rajasd27 <rajasdeshpande27@gmail.com>
* ListDevicesRequest >> _prepare_params_for_list: (#16) modified to handle gatewayListOptions following NodeJS SDK * updated device class and enums (#19) * updated send_command function to base64 encode payload (#18) * Changed 'cloud_ack_time' to 'cloud_update_time' (#20) * Iot 918 conform to google format times binary data (#24) * 1. imports incl. google.api_core.datetime_helpers 2. Added logic to def from_json in class DeviceState and DeviceConfig to convert times to DateTimeWithNanoseconds and binaryData to bytes if env. vars set * 1. Changed Device.from_json to support GCP types for time, binaryData. 2. Changed DeviceState.from_json to handle blank binaryData 3. Changed DeviceConfig.from_json to handle blank binaryData * Removed extra 'import base64' * Added note about types of times, binaryData * Cleaned up formatting * Further cleanup * Added copyright info. at top of files * Not to 'pip install google-api-core' * Removed instructions for installing datetime_helpers module. Also now changed 'google.api_core' to 'proto' * Added "proto.datetime_helpers" to dependencies * Changed 'google.api_core' to 'proto.' * Removed call to set 'convert_binarydata_to_bytes' in Devices.from_json * Changed README to reflect decision on ONE env. var * Changed module to import to proto-plus * Two env. vars -> BINARYDATA_AND_TIME_GOOGLE_FORMAT * Removed a '.' * Format improvements for README * Added note about new env. var in 'Quick Start' sec * 'config', 'state' None? (i.e. not in fieldMask?) (#26) * 'config', 'state' None? (i.e. not in fieldMask?) * Added new @Property's to address DESK-2174 --------- Co-authored-by: rajasd27 <rajasdeshpande27@gmail.com>
* ListDevicesRequest >> _prepare_params_for_list: (#16) modified to handle gatewayListOptions following NodeJS SDK * updated device class and enums (#19) * updated send_command function to base64 encode payload (#18) * Changed 'cloud_ack_time' to 'cloud_update_time' (#20) * Iot 918 conform to google format times binary data (#24) * 1. imports incl. google.api_core.datetime_helpers 2. Added logic to def from_json in class DeviceState and DeviceConfig to convert times to DateTimeWithNanoseconds and binaryData to bytes if env. vars set * 1. Changed Device.from_json to support GCP types for time, binaryData. 2. Changed DeviceState.from_json to handle blank binaryData 3. Changed DeviceConfig.from_json to handle blank binaryData * Removed extra 'import base64' * Added note about types of times, binaryData * Cleaned up formatting * Further cleanup * Added copyright info. at top of files * Not to 'pip install google-api-core' * Removed instructions for installing datetime_helpers module. Also now changed 'google.api_core' to 'proto' * Added "proto.datetime_helpers" to dependencies * Changed 'google.api_core' to 'proto.' * Removed call to set 'convert_binarydata_to_bytes' in Devices.from_json * Changed README to reflect decision on ONE env. var * Changed module to import to proto-plus * Two env. vars -> BINARYDATA_AND_TIME_GOOGLE_FORMAT * Removed a '.' * Format improvements for README * Added note about new env. var in 'Quick Start' sec * 'config', 'state' None? (i.e. not in fieldMask?) (#26) * 'config', 'state' None? (i.e. not in fieldMask?) * Added new @Property's to address DESK-2174 * Iot 994 add credential classes (#28) * Made PublicKeyFormat a child class of Enum * 1. import PublicKeyFormat from .resources 2. New dodict class for providing dot notation for dicts when read. 3. Call to dodict in credentials getter. 4. New functions for converting PublicKeyFormat to/from string. 5. Calls to PublicKeyFormat conversion functions. * Added note about how to run from source * Formatting * More formatting * Formatting * Formatting * Clearer info. on running from source * 1. Import PublicKeyCredential & DeviceCredential 2. Remove dotdict class. 3. Remove convertCredentialsFormatToString. 4. Set self._credentials=convertCredentialsFormatsToString(credentials) 5. Simplified Device class' credentials getter. 6. Changed Device class attr from 'credentials' to '_credentials' * Added code to _create_device_body to: 1. Convert DeviceCredential and PublicKeyCredential objects to dicts 2. Convert PublicKeyFormat class to string This is prior to creating device in registry. * Add PublicKeyCredential & DeviceCredential classes * Changed PublicKeyCredential constructor params: publicKeyFormat -> format publicKey -> key * 1. bug: DeviceCredential constructor calls PublicKeyCredential constructor where params were reversed. 2. Added classmethod convert_credentials_for_create_update. * 1. Removed unnecessary var from convertCredentialsFormatToString. 2. Calling convert_credentials_for_create_update in _prepare_params_body_for_update fcn * 1. Import DeviceCredential 2. Remove code for converting credentials from _create_device_body and call DeviceCredential.convert_credentials_for_create_update instead * 1. Removed the config and state conversion code from class Device. 2. In Device.from_json returned config as DeviceConfig.from_json() and state as DeviceState.from_json() 3. In DeviceState replace attr. self._update_time w/ self.updateTime and self._binary_data w/ self.binaryData 4. Added __getitem__ and get functions. * In classes PublicKeyCredential & DeviceCredential added function "get" which does the same thing as __getitem__ * Document changes from last version in UPGRADING.md * Turned ClearBlade and Google License info. into comments * Formatting changes * In 'convert_credentials_for_create_update' check for expirationTime. If it is datetime convert to ISO string * Formatting * Formatting * Formatting * Formatting * Formatting * Prefixed license info. * bug: if expirationTime type 'datetime', isoformat won't work: 'Z' suffix is left off and is needed by CB platform. Resolved by replacing isoformat with strftime. --------- Co-authored-by: rajasd27 <rajasdeshpande27@gmail.com>
* ListDevicesRequest >> _prepare_params_for_list: (#16) modified to handle gatewayListOptions following NodeJS SDK * updated device class and enums (#19) * updated send_command function to base64 encode payload (#18) * Changed 'cloud_ack_time' to 'cloud_update_time' (#20) * Iot 918 conform to google format times binary data (#24) * 1. imports incl. google.api_core.datetime_helpers 2. Added logic to def from_json in class DeviceState and DeviceConfig to convert times to DateTimeWithNanoseconds and binaryData to bytes if env. vars set * 1. Changed Device.from_json to support GCP types for time, binaryData. 2. Changed DeviceState.from_json to handle blank binaryData 3. Changed DeviceConfig.from_json to handle blank binaryData * Removed extra 'import base64' * Added note about types of times, binaryData * Cleaned up formatting * Further cleanup * Added copyright info. at top of files * Not to 'pip install google-api-core' * Removed instructions for installing datetime_helpers module. Also now changed 'google.api_core' to 'proto' * Added "proto.datetime_helpers" to dependencies * Changed 'google.api_core' to 'proto.' * Removed call to set 'convert_binarydata_to_bytes' in Devices.from_json * Changed README to reflect decision on ONE env. var * Changed module to import to proto-plus * Two env. vars -> BINARYDATA_AND_TIME_GOOGLE_FORMAT * Removed a '.' * Format improvements for README * Added note about new env. var in 'Quick Start' sec * 'config', 'state' None? (i.e. not in fieldMask?) (#26) * 'config', 'state' None? (i.e. not in fieldMask?) * Added new @Property's to address DESK-2174 * Iot 994 add credential classes (#28) * Made PublicKeyFormat a child class of Enum * 1. import PublicKeyFormat from .resources 2. New dodict class for providing dot notation for dicts when read. 3. Call to dodict in credentials getter. 4. New functions for converting PublicKeyFormat to/from string. 5. Calls to PublicKeyFormat conversion functions. * Added note about how to run from source * Formatting * More formatting * Formatting * Formatting * Clearer info. on running from source * 1. Import PublicKeyCredential & DeviceCredential 2. Remove dotdict class. 3. Remove convertCredentialsFormatToString. 4. Set self._credentials=convertCredentialsFormatsToString(credentials) 5. Simplified Device class' credentials getter. 6. Changed Device class attr from 'credentials' to '_credentials' * Added code to _create_device_body to: 1. Convert DeviceCredential and PublicKeyCredential objects to dicts 2. Convert PublicKeyFormat class to string This is prior to creating device in registry. * Add PublicKeyCredential & DeviceCredential classes * Changed PublicKeyCredential constructor params: publicKeyFormat -> format publicKey -> key * 1. bug: DeviceCredential constructor calls PublicKeyCredential constructor where params were reversed. 2. Added classmethod convert_credentials_for_create_update. * 1. Removed unnecessary var from convertCredentialsFormatToString. 2. Calling convert_credentials_for_create_update in _prepare_params_body_for_update fcn * 1. Import DeviceCredential 2. Remove code for converting credentials from _create_device_body and call DeviceCredential.convert_credentials_for_create_update instead * 1. Removed the config and state conversion code from class Device. 2. In Device.from_json returned config as DeviceConfig.from_json() and state as DeviceState.from_json() 3. In DeviceState replace attr. self._update_time w/ self.updateTime and self._binary_data w/ self.binaryData 4. Added __getitem__ and get functions. * In classes PublicKeyCredential & DeviceCredential added function "get" which does the same thing as __getitem__ * Document changes from last version in UPGRADING.md * Turned ClearBlade and Google License info. into comments * Formatting changes * In 'convert_credentials_for_create_update' check for expirationTime. If it is datetime convert to ISO string * Formatting * Formatting * Formatting * Formatting * Formatting * Prefixed license info. * bug: if expirationTime type 'datetime', isoformat won't work: 'Z' suffix is left off and is needed by CB platform. Resolved by replacing isoformat with strftime. * bug: def get_value; if json_data None throws err (#30) * bug: def get_value; if json_data None throws err * In def convertCredentials... added check for None --------- Co-authored-by: rajasd27 <rajasdeshpande27@gmail.com>
* ListDevicesRequest >> _prepare_params_for_list: (#16) modified to handle gatewayListOptions following NodeJS SDK * updated device class and enums (#19) * updated send_command function to base64 encode payload (#18) * Changed 'cloud_ack_time' to 'cloud_update_time' (#20) * Iot 918 conform to google format times binary data (#24) * 1. imports incl. google.api_core.datetime_helpers 2. Added logic to def from_json in class DeviceState and DeviceConfig to convert times to DateTimeWithNanoseconds and binaryData to bytes if env. vars set * 1. Changed Device.from_json to support GCP types for time, binaryData. 2. Changed DeviceState.from_json to handle blank binaryData 3. Changed DeviceConfig.from_json to handle blank binaryData * Removed extra 'import base64' * Added note about types of times, binaryData * Cleaned up formatting * Further cleanup * Added copyright info. at top of files * Not to 'pip install google-api-core' * Removed instructions for installing datetime_helpers module. Also now changed 'google.api_core' to 'proto' * Added "proto.datetime_helpers" to dependencies * Changed 'google.api_core' to 'proto.' * Removed call to set 'convert_binarydata_to_bytes' in Devices.from_json * Changed README to reflect decision on ONE env. var * Changed module to import to proto-plus * Two env. vars -> BINARYDATA_AND_TIME_GOOGLE_FORMAT * Removed a '.' * Format improvements for README * Added note about new env. var in 'Quick Start' sec * 'config', 'state' None? (i.e. not in fieldMask?) (#26) * 'config', 'state' None? (i.e. not in fieldMask?) * Added new @Property's to address DESK-2174 * Iot 994 add credential classes (#28) * Made PublicKeyFormat a child class of Enum * 1. import PublicKeyFormat from .resources 2. New dodict class for providing dot notation for dicts when read. 3. Call to dodict in credentials getter. 4. New functions for converting PublicKeyFormat to/from string. 5. Calls to PublicKeyFormat conversion functions. * Added note about how to run from source * Formatting * More formatting * Formatting * Formatting * Clearer info. on running from source * 1. Import PublicKeyCredential & DeviceCredential 2. Remove dotdict class. 3. Remove convertCredentialsFormatToString. 4. Set self._credentials=convertCredentialsFormatsToString(credentials) 5. Simplified Device cla 4B92 ss' credentials getter. 6. Changed Device class attr from 'credentials' to '_credentials' * Added code to _create_device_body to: 1. Convert DeviceCredential and PublicKeyCredential objects to dicts 2. Convert PublicKeyFormat class to string This is prior to creating device in registry. * Add PublicKeyCredential & DeviceCredential classes * Changed PublicKeyCredential constructor params: publicKeyFormat -> format publicKey -> key * 1. bug: DeviceCredential constructor calls PublicKeyCredential constructor where params were reversed. 2. Added classmethod convert_credentials_for_create_update. * 1. Removed unnecessary var from convertCredentialsFormatToString. 2. Calling convert_credentials_for_create_update in _prepare_params_body_for_update fcn * 1. Import DeviceCredential 2. Remove code for converting credentials from _create_device_body and call DeviceCredential.convert_credentials_for_create_update instead * 1. Removed the config and state conversion code from class Device. 2. In Device.from_json returned config as DeviceConfig.from_json() and state as DeviceState.from_json() 3. In DeviceState replace attr. self._update_time w/ self.updateTime and self._binary_data w/ self.binaryData 4. Added __getitem__ and get functions. * In classes PublicKeyCredential & DeviceCredential added function "get" which does the same thing as __getitem__ * Document changes from last version in UPGRADING.md * Turned ClearBlade and Google License info. into comments * Formatting changes * In 'convert_credentials_for_create_update' check for expirationTime. If it is datetime convert to ISO string * Formatting * Formatting * Formatting * Formatting * Formatting * Prefixed license info. * bug: if expirationTime type 'datetime', isoformat won't work: 'Z' suffix is left off and is needed by CB platform. Resolved by replacing isoformat with strftime. * bug: def get_value; if json_data None throws err (#30) * bug: def get_value; if json_data None throws err * In def convertCredentials... added check for None * Added name attribute to Device class. --------- Co-authored-by: rajasd27 <rajasdeshpande27@gmail.com> Co-authored-by: Jim Bouquet <jbouquet@clearblade.com>
* ListDevicesRequest >> _prepare_params_for_list: (#16) modified to handle gatewayListOptions following NodeJS SDK * updated device class and enums (#19) * updated send_command function to base64 encode payload (#18) * Changed 'cloud_ack_time' to 'cloud_update_time' (#20) * Iot 918 conform to google format times binary data (#24) * 1. imports incl. google.api_core.datetime_helpers 2. Added logic to def from_json in class DeviceState and DeviceConfig to convert times to DateTimeWithNanoseconds and binaryData to bytes if env. vars set * 1. Changed Device.from_json to support GCP types for time, binaryData. 2. Changed DeviceState.from_json to handle blank binaryData 3. Changed DeviceConfig.from_json to handle blank binaryData * Removed extra 'import base64' * Added note about types of times, binaryData * Cleaned up formatting * Further cleanup * Added copyright info. at top of files * Not to 'pip install google-api-core' * Removed instructions for installing datetime_helpers module. Also now changed 'google.api_core' to 'proto' * Added "proto.datetime_helpers" to dependencies * Changed 'google.api_core' to 'proto.' * Removed call to set 'convert_binarydata_to_bytes' in Devices.from_json * Changed README to reflect decision on ONE env. var * Changed module to import to proto-plus * Two env. vars -> BINARYDATA_AND_TIME_GOOGLE_FORMAT * Removed a '.' * Format improvements for README * Added note about new env. var in 'Quick Start' sec * 'config', 'state' None? (i.e. not in fieldMask?) (#26) * 'config', 'state' None? (i.e. not in fieldMask?) * Added new @Property's to address DESK-2174 * Iot 994 add credential classes (#28) * Made PublicKeyFormat a child class of Enum * 1. import PublicKeyFormat from .resources 2. New dodict class for providing dot notation for dicts when read. 3. Call to dodict in credentials getter. 4. New functions for converting PublicKeyFormat to/from string. 5. Calls to PublicKeyFormat conversion functions. * Added note about how to run from source * Formatting * More formatting * Formatting * Formatting * Clearer info. on running from source * 1. Import PublicKeyCredential & DeviceCredential 2. Remove dotdict class. 3. Remove convertCredentialsFormatToString. 4. Set self._credentials=convertCredentialsFormatsToString(credentials) 5. Simplified Device class' credentials getter. 6. Changed Device class attr from 'credentials' to '_credentials' * Added code to _create_device_body to: 1. Convert DeviceCredential and PublicKeyCredential objects to dicts 2. Convert PublicKeyFormat class to string This is prior to creating device in registry. * Add PublicKeyCredential & DeviceCredential classes * Changed PublicKeyCredential constructor params: publicKeyFormat -> format publicKey -> key * 1. bug: DeviceCredential constructor calls PublicKeyCredential constructor where params were reversed. 2. Added classmethod convert_credentials_for_create_update. * 1. Removed unnecessary var from convertCredentialsFormatToString. 2. Calling convert_credentials_for_create_update in _prepare_params_body_for_update fcn * 1. Import DeviceCredential 2. Remove code for converting credentials from _create_device_body and call DeviceCredential.convert_credentials_for_create_update instead * 1. Removed the config and state conversion code from class Device. 2. In Device.from_json returned config as DeviceConfig.from_json() and state as DeviceState.from_json() 3. In DeviceState replace attr. self._update_time w/ self.updateTime and self._binary_data w/ self.binaryData 4. Added __getitem__ and get functions. * In classes PublicKeyCredential & DeviceCredential added function "get" which does the same thing as __getitem__ * Document changes from last version in UPGRADING.md * Turned ClearBlade and Google License info. into comments * Formatting changes * In 'convert_credentials_for_create_update' check for expirationTime. If it is datetime convert to ISO string * Formatting * Formatting * Formatting * Formatting * Formatting * Prefixed license info. * bug: if expirationTime type 'datetime', isoformat won't work: 'Z' suffix is left off and is needed by CB platform. Resolved by replacing isoformat with strftime. * bug: def get_value; if json_data None throws err (#30) * bug: def get_value; if json_data None throws err * In def convertCredentials... added check for None * Added name attribute to Device class. * Added code to populate the name attribute on the device object. --------- Co-authored-by: rajasd27 <rajasdeshpande27@gmail.com> Co-authored-by: Jim Bouquet <jbouquet@clearblade.com>
* ListDevicesRequest >> _prepare_params_for_list: (#16) modified to handle gatewayListOptions following NodeJS SDK * updated device class and enums (#19) * updated send_command function to base64 encode payload (#18) * Changed 'cloud_ack_time' to 'cloud_update_time' (#20) * Iot 918 conform to google format times binary data (#24) * 1. imports incl. google.api_core.datetime_helpers 2. Added logic to def from_json in class DeviceState and DeviceConfig to convert times to DateTimeWithNanoseconds and binaryData to bytes if env. vars set * 1. Changed Device.from_json to support GCP types for time, binaryData. 2. Changed DeviceState.from_json to handle blank binaryData 3. Changed DeviceConfig.from_json to handle blank binaryData * Removed extra 'import base64' * Added note about types of times, binaryData * Cleaned up formatting * Further cleanup * Added copyright info. at top of files * Not to 'pip install google-api-core' * Removed instructions for installing datetime_helpers module. Also now changed 'google.api_core' to 'proto' * Added "proto.datetime_helpers" to dependencies * Changed 'google.api_core' to 'proto.' * Removed call to set 'convert_binarydata_to_bytes' in Devices.from_json * Changed README to reflect decision on ONE env. var * Changed module to import to proto-plus * Two env. vars -> BINARYDATA_AND_TIME_GOOGLE_FORMAT * Removed a '.' * Format improvements for README * Added note about new env. var in 'Quick Start' sec * 'config', 'state' None? (i.e. not in fieldMask?) (#26) * 'config', 'state' None? (i.e. not in fieldMask?) * Added new @Property's to address DESK-2174 * Iot 994 add credential classes (#28) * Made PublicKeyFormat a child class of Enum * 1. import PublicKeyFormat from .resources 2. New dodict class for providing dot notation for dicts when read. 3. Call to dodict in credentials getter. 4. New functions for converting PublicKeyFormat to/from string. 5. Calls to PublicKeyFormat conversion functions. * Added note about how to run from source * Formatting * More formatting * Formatting * Formatting * Clearer info. on running from source * 1. Import PublicKeyCredential & DeviceCredential 2. Remove dotdict class. 3. Remove convertCredentialsFormatToString. 4. Set self._credentials=convertCredentialsFormatsToString(credentials) 5. Simplified Device class' credentials getter. 6. Changed Device class attr from 'credentials' to '_credentials' * Added code to _create_device_body to: 1. Convert DeviceCredential and PublicKeyCredential objects to dicts 2. Convert PublicKeyFormat class to string This is prior to creating device in registry. * Add PublicKeyCredential & DeviceCredential classes * Changed PublicKeyCredential constructor params: publicKeyFormat -> format publicKey -> key * 1. bug: DeviceCredential constructor calls PublicKeyCredential constructor where params were reversed. 2. Added classmethod convert_credentials_for_create_update. * 1. Removed unnecessary var from convertCredentialsFormatToString. 2. Calling convert_credentials_for_create_update in _prepare_params_body_for_update fcn * 1. Import DeviceCredential 2. Remove code for converting credentials from _create_device_body and call DeviceCredential.convert_credentials_for_create_update instead * 1. Removed the config and state conversion code from class Device. 2. In Device.from_json returned config as DeviceConfig.from_json() and state as DeviceState.from_json() 3. In DeviceState replace attr. self._update_time w/ self.updateTime and self._binary_data w/ self.binaryData 4. Added __getitem__ and get functions. * In classes PublicKeyCredential & DeviceCredential added function "get" which does the same thing as __getitem__ * Document changes from last version in UPGRADING.md * Turned ClearBlade and Google License info. into comments * Formatting changes * In 'convert_credentials_for_create_update' check for expirationTime. If it is datetime convert to ISO string * Formatting * Formatting * Formatting * Formatting * Formatting * Prefixed license info. * bug: if expirationTime type 'datetime', isoformat won't work: 'Z' suffix is left off and is needed by CB platform. Resolved by replacing isoformat with strftime. * bug: def get_value; if json_data None throws err (#30) * bug: def get_value; if json_data None throws err * In def convertCredentials... added check for None * Added name attribute to Device class. * Added code to populate the name attribute on the device object. * Iot 1012 syskey token env vars (#35) * updated device class and enums (#19) * updated send_command function to base64 encode payload (#18) * Changed 'cloud_ack_time' to 'cloud_update_time' (#20) --------- Co-authored-by: rajasd27 <rajasdeshpande27@gmail.com> Co-authored-by: Akash Sharma <sky.sharma@gmail.com> --------- Co-authored-by: rajasd27 <rajasdeshpande27@gmail.com> Co-authored-by: Jim Bouquet <jbouquet@clearblade.com> Co-authored-by: ronak-ingress <114172748+ronak-ingress@users.noreply.github.com>
I have not created automated tests but I did run tests. If @ronak-ingress and/or @rajasd27 can run tests using the new env. vars. as per the README and using some devices you know have config and state. Running these functions in samples/clearblade would help:
get_device_async.py
get_device_configversions_list_async.py
get_device_states_list_async.py