in src/modules/sitewise/sync-connector-lambda/importer.py [0:0]
def create_update_entity(create, workspace_id, entity):
if entity.get("entity_id") == '$ROOT': return
if create:
component_properties_key = "properties"
else:
component_properties_key = "propertyUpdates"
component = { "sitewiseData": {
"componentTypeId": entity.get("component_id"),
component_properties_key : {
"sitewiseAssetId": {
"value": { "stringValue": entity.get("asset_id") }
}
} } }
entity_prop = { "entityId" : entity.get("entity_id"),
"entityName" : entity.get("entity_name"),
"workspaceId" : workspace_id,
"description" : "Imported from SiteWise:" + str(entity.get("description"))}
if create:
if entity.get("parent_id") is not None and entity.get("parent_id") != '$ROOT':
entity_prop["parentEntityId"] = entity.get("parent_id")
resp = iottwinmaker_client.create_entity(
**entity_prop,
components = component
)
else:
if entity.get("parent_id") is not None and entity.get("parent_id") != '$ROOT':
entity_prop["parentEntityUpdate"] = {
"updateType" : "UPDATE",
"parentEntityId": entity.get("parent_id")}
resp = iottwinmaker_client.update_entity(
**entity_prop,
componentUpdates = component
)
## Ensure that the entity is created/updated and in active status
## before proceeding, as this entity may be a parent to some child.
api_report(resp)
#entity_created_id = resp.get('entityId')
wait_over(iottwinmaker_client.get_entity,
{"entityId":entity.get('entity_id'),
#{"entityId":entity_created_id,
"workspaceId":workspace_id},
'status.state', 'ACTIVE')
return resp