-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: get digital twin with properties
- Loading branch information
1 parent
baf24b6
commit c515e56
Showing
19 changed files
with
569 additions
and
60 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
from uuid import UUID | ||
from jarvis_sdk.utils import timestamp_to_date | ||
from jarvis_sdk.model.property import Property | ||
|
||
class DigitalTwinCore: | ||
def deserialize(message): | ||
if message is None: | ||
return None | ||
|
||
return DigitalTwinCore( | ||
str(UUID(bytes=message.id)), | ||
str(UUID(bytes=message.tenant_id)), | ||
message.kind, | ||
message.state | ||
) | ||
|
||
def __init__(self, id, tenant_id, kind, state): | ||
self.id = id | ||
self.tenantId = tenant_id | ||
self.kind = kind | ||
self.state = state | ||
|
||
def __str__(self): | ||
return ( | ||
"Digital Twin: " + self.id + "\n" | ||
"Tenant: " + self.tenantId | ||
) | ||
|
||
class DigitalTwin(DigitalTwinCore): | ||
def deserialize(message): | ||
if message is None: | ||
return None | ||
|
||
create_time = None | ||
if message.create_time: | ||
create_time = timestamp_to_date(message.create_time) | ||
properties = list(map(lambda x: Property.deserialize(x), message.properties)) | ||
|
||
dt_core = DigitalTwinCore.deserialize(message.digital_twin) | ||
return DigitalTwin( | ||
dt_core.id, | ||
dt_core.tenantId, | ||
dt_core.kind, | ||
dt_core.state, | ||
properties, | ||
create_time | ||
) | ||
|
||
def __init__(self, id, tenant_id, kind, state, properties = [], create_time = None): | ||
super().__init__(id, tenant_id, kind, state) | ||
self.createTime = create_time | ||
self.properties = properties | ||
|
||
def __str__(self): | ||
properties_string = "" | ||
for property in self.properties: | ||
properties_string = properties_string + str(property) + "\n" | ||
|
||
return ( | ||
super().__str__() + "\n\n" | ||
"Properties:\n" + properties_string | ||
).strip() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
from jarvis_sdk.indykite.identity.v1beta1.model_pb2 import PostalAddress as PostalAddressPb | ||
from google.protobuf.json_format import MessageToDict | ||
|
||
class PostalAddress: | ||
def deserialize(message): | ||
if not message.Is(PostalAddressPb.DESCRIPTOR): | ||
return None | ||
|
||
dict = MessageToDict(message) | ||
return PostalAddress( | ||
dict.get('addressType', ''), | ||
dict.get('addressCountry', ''), | ||
dict.get('addressCountryCode', ''), | ||
dict.get('addressLocality', ''), | ||
dict.get('addressRegion', ''), | ||
dict.get('postOfficeBoxNumber', ''), | ||
dict.get('postalCode', ''), | ||
dict.get('streetAddress', ''), | ||
dict.get('formatted', '') | ||
) | ||
|
||
def __init__(self, addressType, addressCountry, addressCountryCode, addressLocality, addressRegion, postOfficeBoxNumber, postalCode, streetAddress, formatted): | ||
self.addressType = addressType | ||
self.addressCountry = addressCountry | ||
self.addressCountryCode = addressCountryCode | ||
self.addressLocality = addressLocality | ||
self.addressRegion = addressRegion | ||
self.postOfficeBoxNumber = postOfficeBoxNumber | ||
self.postalCode = postalCode | ||
self.streetAddress = streetAddress | ||
self.formatted = formatted | ||
|
||
def __str__(self): | ||
if self.formatted: | ||
return self.formatted | ||
else: | ||
return '<Postal Address object>' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
from google.protobuf.json_format import MessageToDict | ||
from jarvis_sdk.utils.message_to_value import object_to_value | ||
|
||
class Property: | ||
def deserialize(message): | ||
dict = MessageToDict(message) | ||
value = None | ||
if ('referenceValue' in dict): | ||
value = dict['referenceValue'] | ||
elif ('objectValue' in dict): | ||
value = object_to_value(message.object_value) | ||
return Property(dict['id'], dict['definition']['property'], dict['meta'], value) | ||
|
||
def __init__(self, id, property, meta, value): | ||
self.id = id | ||
self.property = property | ||
self.meta = meta | ||
self.value = value | ||
|
||
def __str__(self): | ||
return ( | ||
"Property: " + self.property + "\n" | ||
"ID: " + self.id + "\n" | ||
"Value: " + str(self.value) + "\n" | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
from jarvis_sdk.indykite.identity.v1beta1.model_pb2 import ProviderType | ||
|
||
class ProviderInfo: | ||
def deserialize(message): | ||
return ProviderInfo(message.type, message.issuer) | ||
|
||
def __init__(self, type, issuer): | ||
self.type = ProviderType.Name(type) | ||
self.issuer = issuer | ||
|
||
def __str__(self): | ||
return ( | ||
"Type: " + self.type + "\n" | ||
"Issuer: " + self.issuer | ||
) |
Oops, something went wrong.