8000 Develop by sky-sharma · Pull Request #34 · ClearBlade/python-iot · GitHub
[go: up one dir, main page]

Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 21 additions & 6 deletions clearblade/cloud/iot_v1/device_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,18 +50,21 @@
import base64

def convertCredentialsFormatsFromString(credentials):
# Converts public Key Format from string to object of class Public 8000 KeyFormat
for index, credential in enumerate(credentials):
if 'publicKey' in credential:
credential['publicKey']['format'] = PublicKeyFormat(credential['publicKey']['format'])
credentials[index] = DeviceCredential(credential['publicKey'], credential['expirationTime'])
if credentials is not None:
# Converts public Key Format from string to object of class PublicKeyFormat
for index, credential in enumerate(credentials):
if 'publicKey' in credential:
credential['publicKey']['format'] = PublicKeyFormat(credential['publicKey']['format'])
credentials[index] = DeviceCredential(credential['publicKey'], credential['expirationTime'])
return credentials

class Device():
"""
Data class for Clearblade Device
"""
# TODO: find a better way to construct the Device object. I dont like so much parameter in a constructor
# From google SDK docs: The field ``name`` must be empty. The server generates ``name`` from the device
# registry ``id`` and the ``parent`` field.

def __init__(self, id: str, num_id: str = None,
credentials: list = [], last_heartbeat_time: str = None, last_event_time: str = None,
Expand All @@ -73,6 +76,7 @@ def __init__(self, id: str, num_id: str = None,
log_level: str = LogLevel.NONE, meta_data: dict = {}, gateway_config : dict = {"gatewayType": GatewayType.NON_GATEWAY}) -> None:

self._id = id
self._name = ''
self._num_id = num_id
self._credentials = credentials
self._last_heartbeat_time = last_heartbeat_time
Expand Down Expand Up @@ -116,7 +120,7 @@ def from_json(json):
last_config_send_time = lastConfigSendTimeFromJson
last_error_time = lastErrorTimeFromJson

return Device(
theDevice = Device(
id=get_value(json, 'id'),
num_id=get_value(json, 'numId'),
credentials=convertCredentialsFormatsFromString(get_value(json, 'credentials')),
Expand All @@ -135,10 +139,21 @@ def from_json(json):
gateway_config=get_value(json, 'gatewayConfig')
)

#Since _name is a private attribute, we have to populate it like this
#because we don't allow "name" to be passed in the constructor

theDevice._name=get_value(json, 'name')

return theDevice

@property
def id(self):
return self._id

@property
def name(self):
return self._name

@property
def num_id(self):
return self._num_id
Expand Down
5 changes: 3 additions & 2 deletions clearblade/cloud/iot_v1/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,9 @@ def find_project_region_registry_from_parent(parent):
return project_region_registry_dict

def get_value(json_data, key):
if key in json_data:
return json_data[key]
if json_data is not None:
if key in json_data:
return json_data[key]
return None

class SingletonMetaClass(type):
Expand Down
0