Skip to content

Commit 368a6b7

Browse files
authored
update entityType to be optional (#67)
1 parent eb1b877 commit 368a6b7

3 files changed

Lines changed: 11 additions & 7 deletions

File tree

sdk/basyx/aas/adapter/json/json_serialization.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -635,7 +635,8 @@ def _entity_to_json(cls, obj: model.Entity) -> Dict[str, object]:
635635
data = cls._abstract_classes_to_json(obj)
636636
if not cls.stripped and obj.statement:
637637
data['statements'] = list(obj.statement)
638-
data['entityType'] = _generic.ENTITY_TYPES[obj.entity_type]
638+
if obj.entity_type:
639+
data['entityType'] = _generic.ENTITY_TYPES[obj.entity_type]
639640
if obj.global_asset_id:
640641
data['globalAssetId'] = obj.global_asset_id
641642
if obj.specific_asset_id:

sdk/basyx/aas/adapter/xml/xml_serialization.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -824,7 +824,8 @@ def entity_to_xml(obj: model.Entity,
824824
for statement in obj.statement:
825825
et_statements.append(submodel_element_to_xml(statement))
826826
et_entity.append(et_statements)
827-
et_entity.append(_generate_element(NS_AAS + "entityType", text=_generic.ENTITY_TYPES[obj.entity_type]))
827+
if obj.entity_type:
828+
et_entity.append(_generate_element(NS_AAS + "entityType", text=_generic.ENTITY_TYPES[obj.entity_type]))
828829
if obj.global_asset_id:
829830
et_entity.append(_generate_element(NS_AAS + "globalAssetId", text=obj.global_asset_id))
830831
if obj.specific_asset_id:

sdk/basyx/aas/model/submodel.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1088,7 +1088,7 @@ class Entity(SubmodelElement, base.UniqueIdShortNamespace):
10881088

10891089
def __init__(self,
10901090
id_short: Optional[base.NameType],
1091-
entity_type: base.EntityType,
1091+
entity_type: Optional[base.EntityType],
10921092
statement: Iterable[SubmodelElement] = (),
10931093
global_asset_id: Optional[base.Identifier] = None,
10941094
specific_asset_id: Iterable[base.SpecificAssetId] = (),
@@ -1108,7 +1108,7 @@ def __init__(self,
11081108
supplemental_semantic_id, embedded_data_specifications)
11091109
self.statement = base.NamespaceSet(self, [("id_short", True)], statement)
11101110
# assign private attributes, bypassing setters, as constraints will be checked below
1111-
self._entity_type: base.EntityType = entity_type
1111+
self._entity_type: Optional[base.EntityType] = entity_type
11121112
self._global_asset_id: Optional[base.Identifier] = global_asset_id
11131113
self._specific_asset_id: base.ConstrainedList[base.SpecificAssetId] = base.ConstrainedList(
11141114
specific_asset_id,
@@ -1120,11 +1120,11 @@ def __init__(self,
11201120
self._validate_aasd_014(entity_type, global_asset_id, bool(specific_asset_id))
11211121

11221122
@property
1123-
def entity_type(self) -> base.EntityType:
1123+
def entity_type(self) -> Optional[base.EntityType]:
11241124
return self._entity_type
11251125

11261126
@entity_type.setter
1127-
def entity_type(self, entity_type: base.EntityType) -> None:
1127+
def entity_type(self, entity_type: Optional[base.EntityType]) -> None:
11281128
self._validate_aasd_014(entity_type, self.global_asset_id, bool(self.specific_asset_id))
11291129
self._entity_type = entity_type
11301130

@@ -1167,9 +1167,11 @@ def _validate_global_asset_id(global_asset_id: Optional[base.Identifier]) -> Non
11671167
_string_constraints.check_identifier(global_asset_id)
11681168

11691169
@staticmethod
1170-
def _validate_aasd_014(entity_type: base.EntityType,
1170+
def _validate_aasd_014(entity_type: Optional[base.EntityType],
11711171
global_asset_id: Optional[base.Identifier],
11721172
specific_asset_id_nonempty: bool) -> None:
1173+
if entity_type is None:
1174+
return
11731175
if entity_type == base.EntityType.SELF_MANAGED_ENTITY and global_asset_id is None \
11741176
and not specific_asset_id_nonempty:
11751177
raise base.AASConstraintViolation(

0 commit comments

Comments
 (0)