Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unable to add SubmodelElementCollection to SubmodelElementList #233

Open
s-heppner opened this issue Feb 12, 2024 · 9 comments
Open

Unable to add SubmodelElementCollection to SubmodelElementList #233

s-heppner opened this issue Feb 12, 2024 · 9 comments
Labels
question Further information is requested

Comments

@s-heppner
Copy link
Contributor

s-heppner commented Feb 12, 2024

I have this classes for it (e.g. QosFlowStatus) which inherit from e.g. SubmodelElementCollection class:

class QosFlowStatus(SubmodelElementCollection):                      
    def __init__(
        self, 
        qfi, 
        qos_profile, 
        alternative_qos_profiles, 
        rrm_parameters, 
        id_short: NameType | None, 
        value: Iterable[SubmodelElement] = ..., 
        display_name: MultiLanguageNameType | None = None, 
        category: NameType | None = None, 
        description: MultiLanguageTextType | None = None, 
        parent: UniqueIdShortNamespace | None = None, 
        semantic_id: Reference | None = None, qualifier: Iterable[Qualifier] = ..., 
        extension: Iterable[Extension] = ..., 
        supplemental_semantic_id: Iterable[Reference] = ..., 
        embedded_data_specifications: Iterable[EmbeddedDataSpecification] = ...
    ):

When I try to add this collection to QosFlowStatusList:

class QosFlowStatusList(SubmodelElementList):
    def __init__(
        self,  
        id_short: NameType | None, 
        type_value_list_element: type, 
        value: Iterable = ..., 
        semantic_id_list_element: Reference | None = None, 
        value_type_list_element: DataTypeDefXsd | None = None, 
        order_relevant: bool = True, 
        display_name: MultiLanguageNameType | None = None, 
        category: NameType | None = None, 
        description: MultiLanguageTextType | None = None, 
        parent: UniqueIdShortNamespace | None = None, 
        semantic_id: Reference | None = None, 
        qualifier: Iterable[Qualifier] = ..., 
        extension: Iterable[Extension] = ..., 
        supplemental_semantic_id: Iterable[Reference] = ..., 
        embedded_data_specifications: Iterable[EmbeddedDataSpecification] = ...
    ):

And I obtain this error (which I don´t understand):

---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
Cell In[4], [line 275](vscode-notebook-cell:?execution_count=4&line=275)
    [273](vscode-notebook-cell:?execution_count=4&line=273)                 print(elemento_ref_2._type_value_list_element)
    [274](vscode-notebook-cell:?execution_count=4&line=274)                 qos_flow_list=QosFlowStatusList(elemento_ref_2.id_short, elemento_ref_2._type_value_list_element, elemento_ref_2._value, elemento_ref_2._semantic_id_list_element, elemento_ref_2._value_type_list_element, elemento_ref_2._order_relevant, elemento_ref_2.display_name, elemento_ref_2.category, elemento_ref_2.description, elemento_ref_2.parent, elemento_ref_2.semantic_id, elemento_ref_2.qualifier, elemento_ref_2.extension, elemento_ref_2.supplemental_semantic_id, elemento_ref_2.embedded_data_specifications)
--> [275](vscode-notebook-cell:?execution_count=4&line=275)                 qos_flow_list.value.add(qos_flow)
    [277](vscode-notebook-cell:?execution_count=4&line=277)     pdu_session=PDUSessionStatus(ip_address,qos_flow_list, elemento_ref.id_short, elemento_ref.value, elemento_ref.display_name, elemento_ref.category, elemento_ref.description, elemento_ref.parent, elemento_ref.semantic_id, elemento_ref.qualifier, elemento_ref.extension, elemento_ref.supplemental_semantic_id, elemento_ref.embedded_data_specifications)
    [279](vscode-notebook-cell:?execution_count=4&line=279) pdu_session_list=PDUSessionStatusList(elemento_contenido.id_short, elemento_contenido._type_value_list_element, elemento_contenido._value, elemento_contenido._semantic_id_list_element, elemento_contenido._value_type_list_element, elemento_contenido._order_relevant, elemento_contenido.display_name, elemento_contenido.category, elemento_contenido.description, elemento_contenido.parent, elemento_contenido.semantic_id, elemento_contenido.qualifier, elemento_contenido.extension, elemento_contenido.supplemental_semantic_id, elemento_contenido.embedded_data_specifications)

File [c:\Users\uwicore\anaconda3\Lib\site-packages\basyx\aas\model\base.py:2082](file:///C:/Users/uwicore/anaconda3/Lib/site-packages/basyx/aas/model/base.py:2082), in OrderedNamespaceSet.add(self, element)
   [2081](file:///C:/Users/uwicore/anaconda3/Lib/site-packages/basyx/aas/model/base.py:2081) def add(self, element: _NSO):
-> [2082](file:///C:/Users/uwicore/anaconda3/Lib/site-packages/basyx/aas/model/base.py:2082)     super().add(element)
   [2083](file:///C:/Users/uwicore/anaconda3/Lib/site-packages/basyx/aas/model/base.py:2083)     self._order.append(element)

File [c:\Users\uwicore\anaconda3\Lib\site-packages\basyx\aas\model\base.py:1884](file:///C:/Users/uwicore/anaconda3/Lib/site-packages/basyx/aas/model/base.py:1884), in NamespaceSet.add(self, element)
   [1881](file:///C:/Users/uwicore/anaconda3/Lib/site-packages/basyx/aas/model/base.py:1881)     raise ValueError("Object has already a parent; it cannot belong to two namespaces.")
   [1882](file:///C:/Users/uwicore/anaconda3/Lib/site-packages/basyx/aas/model/base.py:1882)     # TODO remove from current parent instead (allow moving)?
-> [1884](file:///C:/Users/uwicore/anaconda3/Lib/site-packages/basyx/aas/model/base.py:1884) self._execute_item_id_set_hook(element)
   [1885](file:///C:/Users/uwicore/anaconda3/Lib/site-packages/basyx/aas/model/base.py:1885) self._validate_namespace_constraints(element)
   [1886](file:///C:/Users/uwicore/anaconda3/Lib/site-packages/basyx/aas/model/base.py:1886) self._execute_item_add_hook(element)

File [c:\Users\uwicore\anaconda3\Lib\site-packages\basyx\aas\model\base.py:1921](file:///C:/Users/uwicore/anaconda3/Lib/site-packages/basyx/aas/model/base.py:1921), in NamespaceSet._execute_item_id_set_hook(self, element)
   [1919](file:///C:/Users/uwicore/anaconda3/Lib/site-packages/basyx/aas/model/base.py:1919) def _execute_item_id_set_hook(self, element: _NSO):
   [1920](file:///C:/Users/uwicore/anaconda3/Lib/site-packages/basyx/aas/model/base.py:1920)     if self._item_id_set_hook is not None:
-> [1921](file:///C:/Users/uwicore/anaconda3/Lib/site-packages/basyx/aas/model/base.py:1921)         self._item_id_set_hook(element)
...
    [624](file:///C:/Users/uwicore/anaconda3/Lib/site-packages/basyx/aas/model/base.py:624)     else:

File <frozen _collections_abc>:1030, in index(self, value, start, stop)

Then I have tried to add this qos_flow to a very simple list like that:

my_list = SubmodelElementList(
    id_short="lista_1",
    type_value_list_element=SubmodelElementCollection,
    value_type_list_element=None  # Set to None for SubmodelElementCollection
)
# Creating new SubmodelElement instances (replace SubmodelElement with the actual class)
new_element1 = SubmodelElementCollection(id_short=None)
new_element2 = SubmodelElementCollection(id_short=None)

# Adding elements to the SubmodelElementList
my_list.value.add(new_element1)
my_list.value.add(new_element2)

So now I check attributes of qos_flow and try to add to this simple list:

qos_flow.id_short

generated_submodel_list_hack_4ecbd1f2c73f11ee8000f057a6e54ba0

Now I try to add this qos_flow:

my_list.value.add(qos_flow)
---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
Cell In[8], [line 1](vscode-notebook-cell:?execution_count=8&line=1)
----> [1](vscode-notebook-cell:?execution_count=8&line=1) my_list.value.add(qos_flow)

File [c:\Users\uwicore\anaconda3\Lib\site-packages\basyx\aas\model\base.py:2082](file:///C:/Users/uwicore/anaconda3/Lib/site-packages/basyx/aas/model/base.py:2082), in OrderedNamespaceSet.add(self, element)
   [2081](file:///C:/Users/uwicore/anaconda3/Lib/site-packages/basyx/aas/model/base.py:2081) def add(self, element: _NSO):
-> [2082](file:///C:/Users/uwicore/anaconda3/Lib/site-packages/basyx/aas/model/base.py:2082)     super().add(element)
   [2083](file:///C:/Users/uwicore/anaconda3/Lib/site-packages/basyx/aas/model/base.py:2083)     self._order.append(element)

File [c:\Users\uwicore\anaconda3\Lib\site-packages\basyx\aas\model\base.py:1881](file:///C:/Users/uwicore/anaconda3/Lib/site-packages/basyx/aas/model/base.py:1881), in NamespaceSet.add(self, element)
   [1879](file:///C:/Users/uwicore/anaconda3/Lib/site-packages/basyx/aas/model/base.py:1879) def add(self, element: _NSO):
   [1880](file:///C:/Users/uwicore/anaconda3/Lib/site-packages/basyx/aas/model/base.py:1880)     if element.parent is not None and element.parent is not self.parent:
-> [1881](file:///C:/Users/uwicore/anaconda3/Lib/site-packages/basyx/aas/model/base.py:1881)         raise ValueError("Object has already a parent; it cannot belong to two namespaces.")
   [1882](file:///C:/Users/uwicore/anaconda3/Lib/site-packages/basyx/aas/model/base.py:1882)         # TODO remove from current parent instead (allow moving)?
   [1884](file:///C:/Users/uwicore/anaconda3/Lib/site-packages/basyx/aas/model/base.py:1884)     self._execute_item_id_set_hook(element)

ValueError: Object has already a parent; it cannot belong to two namespaces.

So, I try this:

qos_flow.parent=None
my_list.value.add(qos_flow)
---------------------------------------------------------------------------
AASConstraintViolation                    Traceback (most recent call last)
Cell In[9], [line 2](vscode-notebook-cell:?execution_count=9&line=2)
      [1](vscode-notebook-cell:?execution_count=9&line=1) qos_flow.parent=None
----> [2](vscode-notebook-cell:?execution_count=9&line=2) my_list.value.add(qos_flow)

File [c:\Users\uwicore\anaconda3\Lib\site-packages\basyx\aas\model\base.py:2082](file:///C:/Users/uwicore/anaconda3/Lib/site-packages/basyx/aas/model/base.py:2082), in OrderedNamespaceSet.add(self, element)
   [2081](file:///C:/Users/uwicore/anaconda3/Lib/site-packages/basyx/aas/model/base.py:2081) def add(self, element: _NSO):
-> [2082](file:///C:/Users/uwicore/anaconda3/Lib/site-packages/basyx/aas/model/base.py:2082)     super().add(element)
   [2083](file:///C:/Users/uwicore/anaconda3/Lib/site-packages/basyx/aas/model/base.py:2083)     self._order.append(element)

File [c:\Users\uwicore\anaconda3\Lib\site-packages\basyx\aas\model\base.py:1884](file:///C:/Users/uwicore/anaconda3/Lib/site-packages/basyx/aas/model/base.py:1884), in NamespaceSet.add(self, element)
   [1881](file:///C:/Users/uwicore/anaconda3/Lib/site-packages/basyx/aas/model/base.py:1881)     raise ValueError("Object has already a parent; it cannot belong to two namespaces.")
   [1882](file:///C:/Users/uwicore/anaconda3/Lib/site-packages/basyx/aas/model/base.py:1882)     # TODO remove from current parent instead (allow moving)?
-> [1884](file:///C:/Users/uwicore/anaconda3/Lib/site-packages/basyx/aas/model/base.py:1884) self._execute_item_id_set_hook(element)
   [1885](file:///C:/Users/uwicore/anaconda3/Lib/site-packages/basyx/aas/model/base.py:1885) self._validate_namespace_constraints(element)
   [1886](file:///C:/Users/uwicore/anaconda3/Lib/site-packages/basyx/aas/model/base.py:1886) self._execute_item_add_hook(element)

File [c:\Users\uwicore\anaconda3\Lib\site-packages\basyx\aas\model\base.py:1921](file:///C:/Users/uwicore/anaconda3/Lib/site-packages/basyx/aas/model/base.py:1921), in NamespaceSet._execute_item_id_set_hook(self, element)
   [1919](file:///C:/Users/uwicore/anaconda3/Lib/site-packages/basyx/aas/model/base.py:1919) def _execute_item_id_set_hook(self, element: _NSO):
   [1920](file:///C:/Users/uwicore/anaconda3/Lib/site-packages/basyx/aas/model/base.py:1920)     if self._item_id_set_hook is not None:
-> [1921](file:///C:/Users/uwicore/anaconda3/Lib/site-packages/basyx/aas/model/base.py:1921)         self._item_id_set_hook(element)

File [c:\Users\uwicore\anaconda3\Lib\site-packages\basyx\aas\model\submodel.py:739](file:///C:/Users/uwicore/anaconda3/Lib/site-packages/basyx/aas/model/submodel.py:739), in SubmodelElementList._generate_id_short(self, new)
    [737](file:///C:/Users/uwicore/anaconda3/Lib/site-packages/basyx/aas/model/submodel.py:737) def _generate_id_short(self, new: _SE) -> None:
...
    [742](file:///C:/Users/uwicore/anaconda3/Lib/site-packages/basyx/aas/model/submodel.py:742)     # have an id_short. The alternative would be making SubmodelElementList a special kind of base.Namespace without
    [743](file:///C:/Users/uwicore/anaconda3/Lib/site-packages/basyx/aas/model/submodel.py:743)     # a unique attribute for child-elements (which contradicts the definition of a Namespace).
    [744](file:///C:/Users/uwicore/anaconda3/Lib/site-packages/basyx/aas/model/submodel.py:744)     new.id_short = "generated_submodel_list_hack_" + uuid.uuid1(clock_seq=self._uuid_seq).hex

AASConstraintViolation: Objects with an id_short may not be added to a SubmodelElementList, got QosFlowStatus[generated_submodel_list_hack_4ecbd1f2c73f11ee8000f057a6e54ba0] with id_short=generated_submodel_list_hack_4ecbd1f2c73f11ee8000f057a6e54ba0 (Constraint AASd-120)

So now I try with id_short=None:

qos_flow.id_short=None
my_list.value.add(qos_flow)

And I have found this error:

---------------------------------------------------------------------------
AASConstraintViolation                    Traceback (most recent call last)
Cell In[10], [line 2](vscode-notebook-cell:?execution_count=10&line=2)
      [1](vscode-notebook-cell:?execution_count=10&line=1) qos_flow.id_short=None
----> [2](vscode-notebook-cell:?execution_count=10&line=2) my_list.value.add(qos_flow)

File [c:\Users\uwicore\anaconda3\Lib\site-packages\basyx\aas\model\base.py:2082](file:///C:/Users/uwicore/anaconda3/Lib/site-packages/basyx/aas/model/base.py:2082), in OrderedNamespaceSet.add(self, element)
   [2081](file:///C:/Users/uwicore/anaconda3/Lib/site-packages/basyx/aas/model/base.py:2081) def add(self, element: _NSO):
-> [2082](file:///C:/Users/uwicore/anaconda3/Lib/site-packages/basyx/aas/model/base.py:2082)     super().add(element)
   [2083](file:///C:/Users/uwicore/anaconda3/Lib/site-packages/basyx/aas/model/base.py:2083)     self._order.append(element)

File [c:\Users\uwicore\anaconda3\Lib\site-packages\basyx\aas\model\base.py:1886](file:///C:/Users/uwicore/anaconda3/Lib/site-packages/basyx/aas/model/base.py:1886), in NamespaceSet.add(self, element)
   [1884](file:///C:/Users/uwicore/anaconda3/Lib/site-packages/basyx/aas/model/base.py:1884) self._execute_item_id_set_hook(element)
   [1885](file:///C:/Users/uwicore/anaconda3/Lib/site-packages/basyx/aas/model/base.py:1885) self._validate_namespace_constraints(element)
-> [1886](file:///C:/Users/uwicore/anaconda3/Lib/site-packages/basyx/aas/model/base.py:1886) self._execute_item_add_hook(element)
   [1888](file:///C:/Users/uwicore/anaconda3/Lib/site-packages/basyx/aas/model/base.py:1888) element.parent = self.parent
   [1889](file:///C:/Users/uwicore/anaconda3/Lib/site-packages/basyx/aas/model/base.py:1889) for key_attr_name, (backend, case_sensitive) in self._backend.items():

File [c:\Users\uwicore\anaconda3\Lib\site-packages\basyx\aas\model\base.py:1926](file:///C:/Users/uwicore/anaconda3/Lib/site-packages/basyx/aas/model/base.py:1926), in NamespaceSet._execute_item_add_hook(self, element)
   [1924](file:///C:/Users/uwicore/anaconda3/Lib/site-packages/basyx/aas/model/base.py:1924) if self._item_add_hook is not None:
   [1925](file:///C:/Users/uwicore/anaconda3/Lib/site-packages/basyx/aas/model/base.py:1925)     try:
-> [1926](file:///C:/Users/uwicore/anaconda3/Lib/site-packages/basyx/aas/model/base.py:1926)         self._item_add_hook(element, self.__iter__())
   [1927](file:///C:/Users/uwicore/anaconda3/Lib/site-packages/basyx/aas/model/base.py:1927)     except Exception as e:
   [1928](file:///C:/Users/uwicore/anaconda3/Lib/site-packages/basyx/aas/model/base.py:1928)         self._execute_item_del_hook(element)
...
    [770](file:///C:/Users/uwicore/anaconda3/Lib/site-packages/basyx/aas/model/submodel.py:770)     raise base.AASConstraintViolation(107, f"If semantic_id_list_element={self.semantic_id_list_element!r} "
    [771](file:///C:/Users/uwicore/anaconda3/Lib/site-packages/basyx/aas/model/submodel.py:771)                                            "is specified all first level children must have the same "
    [772](file:///C:/Users/uwicore/anaconda3/Lib/site-packages/basyx/aas/model/submodel.py:772)                                            f"semantic_id, got {new!r} with semantic_id={new.semantic_id!r}")

AASConstraintViolation: All first level elements must be of the type specified in type_value_list_element=SubmodelElementCollection, got QosFlowStatus (Constraint AASd-108)

So, the last thing that I have tried is to ask if this qos_flow is a submodelElementCollection:

if isinstance(qos_flow,SubmodelElementCollection): print("Yes, it is")
Yes, it is

So now I don´t know what can I do with this list. If you need more information to try to find the solution to this problem, let me know.

Thank you in advance.

EDIT (by @s-heppner): I took the liberty to fix the syntax in your issue. Feel free to check the text, for example by pressing "edit" yourself, so that you can learn how to write more readable issues

Originally posted by @jorgegomezjumh in #47 (comment)

EDIT 2 (by @s-heppner): Since the question does fit to the other issue, I created a new one.

@s-heppner
Copy link
Contributor Author

Okay, the way I understand this, you managed to create a lot of problems for yourself, based on one relatively small thing, that hopefully is pretty easy to fix.

I think the problem at the very beginning when you tried to:

add this collection to QosFlowStatusList

Could it be that the specific collection already was part of some other Submodel or SubmodelElementCollection?
You could check that, by seeing if the collection's parent attribute is not None and where it points to.

Every Referable object can only be part of exactly one other Referable object.
The adding and removing of these objects is done via NamespaceSets and their respective add() or remove() function.
I would advice of sticking to these functions and not setting the parent attribute yourself, since that may cause further bugs.

Therefore, if you want to add a SubmodelElementCollection to a SubmodelElementList, make sure, the SubmodelElementCollection.parent is empty first, for example by calling the remove() function on the parent beforehand.

@s-heppner s-heppner added the question Further information is requested label Feb 12, 2024
@jorgegomezjumh
Copy link

Thank you for providing all the information. As you mentioned, I confirmed that my collection already has a parent by checking qos_flow.parent. Then, I attempted to remove it using the remove() function as you suggested. However, I encountered some confusion with the usage of the remove function. I tried using qos_flow.parent.remove_referable, but I received the following message: "<bound method UniqueIdShortNamespace.remove_referable of SubmodelElementList[https://example.com/ids/sm/3513_1160_4032_2400 / PDUSessionList[0] / QosFlowList]>" Despite this attempt, the parent did not change or disappear. Additionally, I also attempted qos_flow.parent.remove_referable(qos_flow.id_short), as an alternative approach. This resulted in the following message::


KeyError Traceback (most recent call last)
Cell In[11], line 1
----> 1 qos_flow.parent.remove_referable(qos_flow.id_short)

File c:\Users\uwicore\anaconda3\Lib\site-packages\basyx\aas\model\base.py:1725, in UniqueIdShortNamespace.remove_referable(self, id_short)
1718 def remove_referable(self, id_short: NameType) -> None:
1719 """
1720 Remove a :class:~.Referable from this Namespace by its id_short
1721
1722 :param id_short: id_short
1723 :raises KeyError: If no such :class:~.Referable can be found
1724 """
-> 1725 return super()._remove_object(Referable, "id_short", id_short)

File c:\Users\uwicore\anaconda3\Lib\site-packages\basyx\aas\model\base.py:522, in Namespace._remove_object(self, object_type, attribute_name, attribute)
520 except KeyError:
521 continue
--> 522 raise KeyError(f"{object_type.name} with {attribute_name} {attribute} not found in this namespace")

KeyError: 'Referable with id_short generated_submodel_list_hack_b1f50651ca5b11ee8000f057a6e54ba0 not found in this namespace'

@s-heppner
Copy link
Contributor Author

I think there's something weird with your code.
I don't see a solution yet, so let's analyze your steps together:

qos_flow.parent.remove_referable

In qos_flow.parent, qos_flow is an object with a property or attribute named parent. This parent is an attribute referencing another Python object, namely another AAS-object of class Referable.
.remove_referable itself is not a function call, as noted by the missing brackets (), rather it is the pointer that points to the function. Therefore, the return:

<bound method UniqueIdShortNamespace.remove_referable of SubmodelElementList[https://example.com/ids/sm/3513_1160_4032_2400 / PDUSessionList[0] / QosFlowList]>

is to be expected, considering it tells you that remove_referable is a "method" (or function) that stems originally from class UniqueIdShortNamespace. Currently, the object called parent seems to be an instance of class SubmodelElementList that in turn is in some kind of nested structure https://example.com/ids/sm/3513_1160_4032_2400 / PDUSessionList[0] / QosFlowList.

This nested structure gives us a clue. The parent object is a SubmodelElementList, part of the Submodel with Identifier https://example.com/ids/sm/3513_1160_4032_2400, inside another SubmodelElementList with id_short "PDUSessionList" at index 0.

Now, could it be that your SubmodelElementCollection qos_flow is already properly inside the SubmodelElementList that you wanted to add it to in the first place?

Using

qos_flow.parent.remove_referable(qos_flow.id_short)

should definitly be the correct way of removing an object from a parent, so I am not entirely sure why this wouldn't work, based on the information you provided.

@jorgegomezjumh
Copy link

Yes, I also don't understand why this command doesn't work, and I couldn't locate this element within the namespace, especially considering we are already searching by the parent of this element. It doesn't seem to make sense.

As you mentioned, this is a nested structure. I'm encountering difficulties with every list in my AAS when attempting to add a class that inherits from SubmodelElementCollection.

@s-heppner
Copy link
Contributor Author

Would you be able to provide a minimal working example of code that can show your problem?
This would make it easier for us to determine what's going on.

@jorgegomezjumh
Copy link

I have prepared an example with all the information that I can provide to offer you the maximum possible context. The ExampleSubmodel is the same structure I use for my submodel and gives me the same error.
ExampleZip.zip

@s-heppner
Copy link
Contributor Author

Thanks for reaching out! To assist you efficiently, could you please provide a minimal example that reproduces the issue? This could be a concise code snippet or a simplified version of your project that isolates the problem.

Please post it directly here into an issue comment, for example using three backticks for code snippets like so:

```Python
import foo

print("bar")
```

Sharing entire projects as zip files makes it challenging for us to pinpoint the exact issue. Also, for security reasons, we refrain from opening random zip files shared externally.

If you need any guidance on preparing the minimal example or have questions, feel free to ask.

@jorgegomezjumh
Copy link

Ok, here you have some classes for this example:

class AASExample(AssetAdministrationShell):
    def __init__(self,nameplate,identification_submodel,documentation,service, pruebas, asset_information: AssetInformation, id_: Identifier, id_short: NameType | None = None, display_name: MultiLanguageNameType | None = None, category: NameType | None = None, description: MultiLanguageTextType | None = None, parent: UniqueIdShortNamespace | None = None, administration: AdministrativeInformation | None = None, submodel: Set[ModelReference[Submodel]] | None = None, derived_from: ModelReference[AssetAdministrationShell] | None = None, embedded_data_specifications: Iterable[EmbeddedDataSpecification] = ..., extension: Iterable[Extension] = ...):
       self.nameplate=nameplate
       self.identification_submodel=identification_submodel
       self.documentation=documentation
       self.service=service
       self.pruebas=pruebas       
       super().__init__(asset_information, id_, id_short, display_name, category, description, parent, administration, submodel, derived_from, embedded_data_specifications, extension)


class PhysicalAddress(SubmodelElementCollection):
    def __init__(self, country_code, street, postal_code, city, state_county, id_short: NameType | None, value: Iterable[SubmodelElement] = ..., display_name: MultiLanguageNameType | None = None, category: NameType | None = None, description: MultiLanguageTextType | None = None, parent: UniqueIdShortNamespace | None = None, semantic_id: Reference | None = None, qualifier: Iterable[Qualifier] = ..., extension: Iterable[Extension] = ..., supplemental_semantic_id: Iterable[Reference] = ..., embedded_data_specifications: Iterable[EmbeddedDataSpecification] = ...):
        self.countryCode=country_code
        self.street=street
        self.postalCode=postal_code
        self.city=city
        self.stateCounty=state_county
        self.parent=parent
        self._id_short=id_short
        self.id_short=id_short
        self.value=value
        self.display_name=display_name
        self.category=category
        self.description=description
        self._supplemental_semantic_id=supplemental_semantic_id
        self.supplemental_semantic_id=supplemental_semantic_id  #Prueba del orden a ver si asi va bien
        self.semantic_id=semantic_id
        self.qualifier=qualifier
        self.extension=extension
        
        self.embedded_data_specifications=embedded_data_specifications
class Nameplate(Submodel):
    def __init__(self,manufacturer_name,manufacturer_typ_name,physical_address, typ_class, serialno, chargeid,countryoforigin,yearofconstruction, id_: Identifier, submodel_element: Iterable[SubmodelElement] = ..., id_short: NameType | None = None, display_name: MultiLanguageNameType | None = None, category: NameType | None = None, description: MultiLanguageTextType | None = None, parent: UniqueIdShortNamespace | None = None, administration: AdministrativeInformation | None = None, semantic_id: Reference | None = None, qualifier: Iterable[Qualifier] = ..., kind: ModellingKind = base.ModellingKind.INSTANCE, extension: Iterable[Extension] = ..., supplemental_semantic_id: Iterable[Reference] = ..., embedded_data_specifications: Iterable[EmbeddedDataSpecification] = ...):
        self.manufacturerName=manufacturer_name
        self.manufacturerTypName=manufacturer_typ_name
        self.physicalAddress=physical_address
        self.typClass=typ_class
        self.serialNo=serialno
        self.chargeId=chargeid
        self.countryOfOrigin= countryoforigin
        self.yearOfConstruction= yearofconstruction
        self.parent=parent
        self.id_=id_
        self.submodel_element=submodel_element
        self._id_short=id_short
        self.id_short=id_short
        self.display_name=display_name
        self.category=category
        self.description=description
        self.administration=administration
        self._supplemental_semantic_id=supplemental_semantic_id
        self.supplemental_semantic_id=supplemental_semantic_id  #Prueba del orden a ver si asi va bien
        self.semantic_id=semantic_id
        self.qualifier=qualifier
        self._kind= kind
        self.extension=extension

        self.embedded_data_specifications=embedded_data_specifications



#Identification
class ContactInfo(SubmodelElementCollection):
    def __init__(self,name,role,physical_address,email,url,phone, fax, id_short: NameType | None, value: Iterable[SubmodelElement] = ..., display_name: MultiLanguageNameType | None = None, category: NameType | None = None, description: MultiLanguageTextType | None = None, parent: UniqueIdShortNamespace | None = None, semantic_id: Reference | None = None, qualifier: Iterable[Qualifier] = ..., extension: Iterable[Extension] = ..., supplemental_semantic_id: Iterable[Reference] = ..., embedded_data_specifications: Iterable[EmbeddedDataSpecification] = ...):
        self.name=name
        self.role=role
        self.physicalAddress= physical_address
        self.email=email
        self.url=url
        self.phone=phone
        self.fax=fax
        self.parent=parent
        self._id_short=id_short
        self.id_short=id_short
        self.value=value
        self.display_name=display_name
        self.category=category
        self.description=description
        self._supplemental_semantic_id=supplemental_semantic_id
        self.supplemental_semantic_id=supplemental_semantic_id  #Prueba del orden a ver si asi va bien
        self.semantic_id=semantic_id
        self.qualifier=qualifier
        self.extension=extension
        
        self.embedded_data_specifications=embedded_data_specifications
class Identification(Submodel):
    def __init__(self, manufacturer_name, manufacturer_id, manufacturer_idprovider, manufacturer_typid, manufacturer_typname, manufacturer_typdesc, suppliername, supplierid,supplierid_provider, supplier_typid, supplier_typname, supplier_typdesc, typclass,classystem,
                 seckeytyp, asset_id, instance_id, chargeid,seckeyinst, manufacturing_date, device_rev, software_rev, hardware_rev, ContactInfo, url, id_: Identifier, submodel_element: Iterable[SubmodelElement] = ..., id_short: NameType | None = None, display_name: MultiLanguageNameType | None = None, category: NameType | None = None, description: MultiLanguageTextType | None = None, parent: UniqueIdShortNamespace | None = None, administration: AdministrativeInformation | None = None, semantic_id: Reference | None = None, qualifier: Iterable[Qualifier] = ..., kind: ModellingKind = base.ModellingKind.INSTANCE, extension: Iterable[Extension] = ..., supplemental_semantic_id: Iterable[Reference] = ..., embedded_data_specifications: Iterable[EmbeddedDataSpecification] = ...):
        self.manufacturerName=manufacturer_name
        self.manufacturerId=manufacturer_id
        self.manufacturerIdProvider=manufacturer_idprovider
        self.manufacturerTypId= manufacturer_typid
        self.manufacturerTypName= manufacturer_typname
        self.manufacturerTypDescription=manufacturer_typdesc
        self.supplierName=suppliername
        self.supplierId=supplierid
        self.supplierIdProvider=supplierid_provider
        self.supplierTypId=supplier_typid
        self.supplierTypName=supplier_typname
        self.supplierTypDescription=supplier_typdesc
        self.typClass=supplier_typdesc
        self.classificationSystem=classystem
        self.secondaryKeyTyp=seckeytyp
        self.assetId=asset_id
        self.instanceId=instance_id
        self.chargeId=chargeid
        self.secondaryKeyInstance=seckeyinst
        self.manufacturingDate=manufacturing_date
        self.deviceRevision=device_rev
        self.softwareRevision=software_rev
        self.hardwareRevision=hardware_rev
        self.contactInfo=ContactInfo
        self.url=url
        self.parent=parent
        self.id_=id_
        self.submodel_element=submodel_element
        self._id_short=id_short
        self.id_short=id_short
        self.display_name=display_name
        self.category=category
        self.description=description
        self.administration=administration
        self._supplemental_semantic_id=supplemental_semantic_id
        self.supplemental_semantic_id=supplemental_semantic_id  #Prueba del orden a ver si asi va bien
        self.semantic_id=semantic_id
        self.qualifier=qualifier
        self._kind= kind
        self.extension=extension

        self.embedded_data_specifications=embedded_data_specifications
                
#Documentation

class Documentation(Submodel):
    def __init__(self, id_: Identifier, submodel_element: Iterable[SubmodelElement] = ..., id_short: NameType | None = None, display_name: MultiLanguageNameType | None = None, category: NameType | None = None, description: MultiLanguageTextType | None = None, parent: UniqueIdShortNamespace | None = None, administration: AdministrativeInformation | None = None, semantic_id: Reference | None = None, qualifier: Iterable[Qualifier] = ..., kind: ModellingKind = base.ModellingKind.INSTANCE, extension: Iterable[Extension] = ..., supplemental_semantic_id: Iterable[Reference] = ..., embedded_data_specifications: Iterable[EmbeddedDataSpecification] = ...):
        self.parent=parent
        self.id_=id_
        self.submodel_element=submodel_element
        self._id_short=id_short
        self.id_short=id_short
        self.display_name=display_name
        self.category=category
        self.description=description
        self.administration=administration
        self._supplemental_semantic_id=supplemental_semantic_id
        self.supplemental_semantic_id=supplemental_semantic_id  #Prueba del orden a ver si asi va bien
        self.semantic_id=semantic_id
        self.qualifier=qualifier
        self._kind= kind
        self.extension=extension

        self.embedded_data_specifications=embedded_data_specifications




#Service
class Service(Submodel):
    def __init__(self, contact_info,id_: Identifier, submodel_element: Iterable[SubmodelElement] = ..., id_short: NameType | None = None, display_name: MultiLanguageNameType | None = None, category: NameType | None = None, description: MultiLanguageTextType | None = None, parent: UniqueIdShortNamespace | None = None, administration: AdministrativeInformation | None = None, semantic_id: Reference | None = None, qualifier: Iterable[Qualifier] = ..., kind: ModellingKind = base.ModellingKind.INSTANCE, extension: Iterable[Extension] = ..., supplemental_semantic_id: Iterable[Reference] = ..., embedded_data_specifications: Iterable[EmbeddedDataSpecification] = ...):
        self.contactInfo=contact_info
        self.parent=parent
        self.id_=id_
        self.submodel_element=submodel_element
        self._id_short=id_short
        self.id_short=id_short
        self.display_name=display_name
        self.category=category
        self.description=description
        self.administration=administration
        self._supplemental_semantic_id=supplemental_semantic_id
        self.supplemental_semantic_id=supplemental_semantic_id  #Prueba del orden a ver si asi va bien
        self.semantic_id=semantic_id
        self.qualifier=qualifier
        self._kind= kind
        self.extension=extension

        self.embedded_data_specifications=embedded_data_specifications







#Main part
        
class ExampleFlow(SubmodelElementCollection):                      
    def __init__(self, id_short: NameType | None, value: Iterable[SubmodelElement] = ..., display_name: MultiLanguageNameType | None = None, category: NameType | None = None, description: MultiLanguageTextType | None = None, parent: UniqueIdShortNamespace | None = None, semantic_id: Reference | None = None, qualifier: Iterable[Qualifier] = ..., extension: Iterable[Extension] = ..., supplemental_semantic_id: Iterable[Reference] = ..., embedded_data_specifications: Iterable[EmbeddedDataSpecification] = ...):
        self.parent=parent
        self._id_short=id_short
        self.id_short=id_short
        self.value=value
        self.display_name=display_name
        self.category=category
        self.description=description
        self._supplemental_semantic_id=supplemental_semantic_id
        self.supplemental_semantic_id=supplemental_semantic_id  #Prueba del orden a ver si asi va bien
        self.semantic_id=semantic_id
        self.qualifier=qualifier
        self.extension=extension
        
        self.embedded_data_specifications=embedded_data_specifications
class ExampleFlowList(SubmodelElementList):
    def __init__(self, id_short: NameType | None, type_value_list_element: type, value: Iterable = ..., semantic_id_list_element: Reference | None = None, value_type_list_element: DataTypeDefXsd | None = None, order_relevant: bool = True, display_name: MultiLanguageNameType | None = None, category: NameType | None = None, description: MultiLanguageTextType | None = None, parent: UniqueIdShortNamespace | None = None, semantic_id: Reference | None = None, qualifier: Iterable[Qualifier] = ..., extension: Iterable[Extension] = ..., supplemental_semantic_id: Iterable[Reference] = ..., embedded_data_specifications: Iterable[EmbeddedDataSpecification] = ...):
       
        self.parent=parent
        self._id_short=id_short
        self.id_short=id_short
        self._type_value_list_element=type_value_list_element   #Toquetear ambos para cumplir con lo que queremos y con lo que se supone que indican en submodel
        self._value_type_list_element= value_type_list_element        
        self._order_relevant= order_relevant
        self._semantic_id_list_element= semantic_id_list_element
        self._value=value
        self.value=value
        self.display_name=display_name
        self.category=category
        self.description=description
        self._supplemental_semantic_id=supplemental_semantic_id
        self.supplemental_semantic_id=supplemental_semantic_id  #Prueba del orden a ver si asi va bien
        self.semantic_id=semantic_id
        self.qualifier=qualifier
        self.extension=extension

        self.embedded_data_specifications=embedded_data_specifications 



class ExampleUpperCollection(SubmodelElementCollection):
    def __init__(self,flow_list, id_short: NameType | None, value: Iterable[SubmodelElement] = ..., display_name: MultiLanguageNameType | None = None, category: NameType | None = None, description: MultiLanguageTextType | None = None, parent: UniqueIdShortNamespace | None = None, semantic_id: Reference | None = None, qualifier: Iterable[Qualifier] = ..., extension: Iterable[Extension] = ..., supplemental_semantic_id: Iterable[Reference] = ..., embedded_data_specifications: Iterable[EmbeddedDataSpecification] = ...):

        self.flowList = flow_list
        self.parent=parent
        self._id_short=id_short
        self.id_short=id_short
        self.value=value
        self.display_name=display_name
        self.category=category
        self.description=description
        self._supplemental_semantic_id=supplemental_semantic_id
        self.supplemental_semantic_id=supplemental_semantic_id  #Prueba del orden a ver si asi va bien
        self.semantic_id=semantic_id
        self.qualifier=qualifier
        self.extension=extension
        
        self.embedded_data_specifications=embedded_data_specifications

class ExampleUpperList(SubmodelElementList):
    def __init__(self, id_short: NameType | None, type_value_list_element: type, value: Iterable = ..., semantic_id_list_element: Reference | None = None, value_type_list_element: DataTypeDefXsd | None = None, order_relevant: bool = True, display_name: MultiLanguageNameType | None = None, category: NameType | None = None, description: MultiLanguageTextType | None = None, parent: UniqueIdShortNamespace | None = None, semantic_id: Reference | None = None, qualifier: Iterable[Qualifier] = ..., extension: Iterable[Extension] = ..., supplemental_semantic_id: Iterable[Reference] = ..., embedded_data_specifications: Iterable[EmbeddedDataSpecification] = ...):

        self.parent=parent
        self._id_short=id_short
        self.id_short=id_short
        self._type_value_list_element=type_value_list_element   #Toquetear ambos para cumplir con lo que queremos y con lo que se supone que indican en submodel
        self._value_type_list_element= value_type_list_element        
        self._order_relevant= order_relevant
        self._semantic_id_list_element= semantic_id_list_element
        self._value=value
        self.value=value
        self.display_name=display_name
        self.category=category
        self.description=description
        self._supplemental_semantic_id=supplemental_semantic_id
        self.supplemental_semantic_id=supplemental_semantic_id  #Prueba del orden a ver si asi va bien
        self.semantic_id=semantic_id
        self.qualifier=qualifier
        self.extension=extension

        self.embedded_data_specifications=embedded_data_specifications       #super().__init__(id_short, value, category, description, parent,semantic_id, qualifier, kind)      




class ExampleSubmodel(Submodel):
    def __init__(self,upperList,  id_: Identifier, submodel_element: Iterable[SubmodelElement] = ..., id_short: NameType | None = None, display_name: MultiLanguageNameType | None = None, category: NameType | None = None, description: MultiLanguageTextType | None = None, parent: UniqueIdShortNamespace | None = None, administration: AdministrativeInformation | None = None, semantic_id: Reference | None = None, qualifier: Iterable[Qualifier] = ..., kind: ModellingKind = base.ModellingKind.INSTANCE, extension: Iterable[Extension] = ..., supplemental_semantic_id: Iterable[Reference] = ..., embedded_data_specifications: Iterable[EmbeddedDataSpecification] = ...):
        self.upperList = upperList
        self.parent=parent
        self.id_=id_
        self.submodel_element=submodel_element
        self._id_short=id_short
        self.id_short=id_short
        self.display_name=display_name
        self.category=category
        self.description=description
        self.administration=administration
        self._supplemental_semantic_id=supplemental_semantic_id
        self.supplemental_semantic_id=supplemental_semantic_id  #Prueba del orden a ver si asi va bien
        self.semantic_id=semantic_id
        self.qualifier=qualifier
        self._kind= kind
        self.extension=extension

        self.embedded_data_specifications=embedded_data_specifications

And now here you have an example of code I use in my jupiter notebook to read the aasx file and copy to my structure.

import datetime
from pathlib import Path  # Used for easier handling of auxiliary file's local path

import pyecma376_2  # The base library for Open Packaging Specifications. We will use the OPCCoreProperties class.
from basyx import aas
from basyx.aas import model
from basyx.aas.adapter import aasx
from basyx.aas.model import Submodel, SubmodelElement, Property,Operation, SubmodelElementCollection, SubmodelElementList, MultiLanguageProperty, AssetInformation, AssetAdministrationShell, ModelReference, LangStringSet, Namespace, AdministrativeInformation, Submodel,AbstractObjectProvider  # Importa las clases necesarias 
from Example import *

# We'll use a fresh ObjectStore and SupplementaryFileContainer to read AAS objects and auxiliary files into.
new_object_store: model.DictObjectStore[model.Identifiable] = model.DictObjectStore()
new_file_store = aasx.DictSupplementaryFileContainer()



# Again, we need to use the AASXReader as a context manager (or call `.close()` in the end) to make sure the AASX
# package file is properly closed when we are finished.
with aasx.AASXReader("AASPrueba.aasx") as reader:
    # Read all contained AAS objects and all referenced auxiliary files
    # In contrast to the AASX Package Explorer, we are not limited to a single XML part in the package, but instead we
    # will read the contents of all included JSON and XML parts into the ObjectStore
    reader.read_into(object_store=new_object_store,
                     file_store=new_file_store)

    # We can also read the meta data
    new_meta_data = reader.get_core_properties()



for obj in new_object_store:
    #Ahora el AAS y los submodelos
    
    if isinstance(obj, Submodel):
        if(obj.id_short=="Nameplate"):
            for elemento_contenido in obj:
                if elemento_contenido.id_short=="ManufacturerName": manufacturerName=elemento_contenido
                if elemento_contenido.id_short=="ManufacturerTypName": manufacturerTypName=elemento_contenido
                if isinstance(elemento_contenido, (SubmodelElementCollection)):       
                    for elemento_ref in elemento_contenido.value:   #SEGUNDO ESLABON, EN ESTE ESTÁ SOLO EL PHYSICALADDRESS
                        if elemento_ref.id_short=="CountryCode": countryCode=elemento_ref
                        if elemento_ref.id_short=="Street": street=elemento_ref
                        if elemento_ref.id_short=="PostalCode": postalCode=elemento_ref
                        if elemento_ref.id_short=="City": city=elemento_ref
                        if elemento_ref.id_short=="StateCounty": 
                            stateCounty=elemento_ref
                            physical_address=PhysicalAddress(countryCode,street, postalCode, city, stateCounty, elemento_contenido.id_short, elemento_contenido.value, elemento_contenido.display_name, elemento_contenido.category, elemento_contenido.description, elemento_contenido.parent, elemento_contenido.semantic_id, elemento_contenido.qualifier, elemento_contenido.extension, elemento_contenido.supplemental_semantic_id, elemento_contenido.embedded_data_specifications)                            
                            
                if elemento_contenido.id_short=="TypClass": typClass=elemento_contenido
                if elemento_contenido.id_short=="SerialNo": serialNo=elemento_contenido
                if elemento_contenido.id_short=="ChargeId": chargeId=elemento_contenido
                if elemento_contenido.id_short=="CountryOfOrigin": countryOfOrigin=elemento_contenido
                if elemento_contenido.id_short=="YearOfConstruction": yearOfConstruction=elemento_contenido
            nameplate=Nameplate(manufacturerName,manufacturerTypName,physical_address,typClass,serialNo,chargeId,countryOfOrigin,yearOfConstruction, obj.id, obj.submodel_element, obj.id_short, obj.display_name, obj.category, obj.description, obj.parent, obj.administration, obj.semantic_id, obj.qualifier, obj.kind, obj.extension, obj.supplemental_semantic_id, obj.embedded_data_specifications)
        elif(obj.id_short=="Identification"):
            for elemento_contenido in obj:
                if elemento_contenido.id_short=="ManufacturerName": manufacturerName=elemento_contenido
                if elemento_contenido.id_short=="ManufacturerId01": manufacturerId01=elemento_contenido
                if elemento_contenido.id_short=="ManufacturerIdProvider": manufacturerIdProvider=elemento_contenido
                if elemento_contenido.id_short=="ManufacturerTypId": manufacturerTypId=elemento_contenido
                if elemento_contenido.id_short=="ManufacturerTypName": manufacturerTypName=elemento_contenido
                if elemento_contenido.id_short=="ManufacturerTypDescription": manufacturerTypDescription=elemento_contenido
                if elemento_contenido.id_short=="SupplierName": supplierName=elemento_contenido
                if elemento_contenido.id_short=="SupplierId": supplierId=elemento_contenido
                if elemento_contenido.id_short=="SupplierIdProvider": supplierIdProvider=elemento_contenido
                if elemento_contenido.id_short=="SupplierTypId": supplierTypId=elemento_contenido
                if elemento_contenido.id_short=="SupplierTypName": supplierTypName=elemento_contenido
                if elemento_contenido.id_short=="SupplierTypDescription": supplierTypDescription=elemento_contenido
                if elemento_contenido.id_short=="TypClass": typClass=elemento_contenido
                if elemento_contenido.id_short=="ClassificationSystem": classificationSystem=elemento_contenido
                if elemento_contenido.id_short=="SecondaryKeyTyp": secondaryKeyTyp=elemento_contenido
                if elemento_contenido.id_short=="AssetId": assetId=elemento_contenido
                if elemento_contenido.id_short=="InstanceId": instanceId=elemento_contenido
                if elemento_contenido.id_short=="ChargeId": assetId=elemento_contenido
                if elemento_contenido.id_short=="SecondaryKeyInstance": secondaryKeyInstance=elemento_contenido
                if elemento_contenido.id_short=="ManufacturingDate": manufacturingDate=elemento_contenido
                if elemento_contenido.id_short=="DeviceRevision": deviceRevision=elemento_contenido
                if elemento_contenido.id_short=="SoftwareRevision": softwareRevision=elemento_contenido
                if elemento_contenido.id_short=="HardwareRevision": hardwareRevision=elemento_contenido
                if isinstance(elemento_contenido, (SubmodelElementCollection)):       
                    for elemento_ref in elemento_contenido.value:   #SEGUNDO ESLABON, EN ESTE ESTÁ SOLO EL CONTACTINFO
                        if elemento_ref.id_short=="Name": name=elemento_ref
                        if elemento_ref.id_short=="Role": role=elemento_ref
                        if isinstance(elemento_ref, (SubmodelElementCollection)): 
                            for elemento_ref_2 in elemento_ref.value:
                                if elemento_ref_2.id_short=="CountryCode": countryCode=elemento_ref_2
                                if elemento_ref_2.id_short=="Street": street=elemento_ref_2
                                if elemento_ref_2.id_short=="PostalCode": postalCode=elemento_ref_2
                                if elemento_ref_2.id_short=="City": city=elemento_ref_2
                                if elemento_ref_2.id_short=="StateCounty": 
                                    stateCounty=elemento_ref_2
                                    physical_address=PhysicalAddress(countryCode,street, postalCode, city, stateCounty, elemento_ref.id_short, elemento_ref.value, elemento_ref.display_name, elemento_ref.category, elemento_ref.description, elemento_ref.parent, elemento_ref.semantic_id, elemento_ref.qualifier, elemento_ref.extension, elemento_ref.supplemental_semantic_id, elemento_ref.embedded_data_specifications)

                        if elemento_ref.id_short=="Email": email=elemento_ref
                        if elemento_ref.id_short=="URL": url=elemento_ref
                        if elemento_ref.id_short=="Phone": phone=elemento_ref
                        if elemento_ref.id_short=="Fax":
                            fax=elemento_ref
                            contact_info=ContactInfo(name,role,physical_address,email,url,phone,fax, elemento_contenido.id_short, elemento_contenido.value, elemento_contenido.display_name, elemento_contenido.category, elemento_contenido.description, elemento_contenido.parent, elemento_contenido.semantic_id, elemento_contenido.qualifier, elemento_contenido.extension, elemento_contenido.supplemental_semantic_id, elemento_contenido.embedded_data_specifications)
                if elemento_contenido.id_short=="URL": url=elemento_contenido
            identification=Identification(manufacturerName,manufacturerId01,manufacturerIdProvider,manufacturerTypId,manufacturerTypName,manufacturerTypDescription,supplierName,supplierId,supplierIdProvider,supplierTypId,supplierTypName,supplierTypDescription,typClass,
                                          classificationSystem, secondaryKeyTyp,assetId,instanceId,chargeId,secondaryKeyInstance,manufacturingDate,deviceRevision,softwareRevision,hardwareRevision,contact_info,url,obj.id, obj.submodel_element, obj.id_short, obj.display_name, obj.category, obj.description, obj.parent, obj.administration, obj.semantic_id, obj.qualifier, obj.kind, obj.extension, obj.supplemental_semantic_id, obj.embedded_data_specifications)
        elif(obj.id_short=="Documentation"):
            documentation= Documentation(obj.id, obj.submodel_element, obj.id_short, obj.display_name, obj.category, obj.description, obj.parent, obj.administration, obj.semantic_id, obj.qualifier, obj.kind, obj.extension, obj.supplemental_semantic_id, obj.embedded_data_specifications)
        elif(obj.id_short=="Service"):
            for elemento_contenido in obj:
                if isinstance(elemento_contenido,(SubmodelElementCollection)):
                    for elemento_ref in elemento_contenido:
                        if elemento_ref.id_short=="NameOfSupplier": nameOfSupplier=elemento_ref
                        if elemento_ref.id_short=="ContactInfo_Role": contactInfo_role=elemento_ref
                        if isinstance(elemento_ref, (SubmodelElementCollection)): 
                            for elemento_ref_2 in elemento_ref.value:
                                if elemento_ref_2.id_short=="CountryCode": countryCode=elemento_ref_2
                                if elemento_ref_2.id_short=="Street": street=elemento_ref_2
                                if elemento_ref_2.id_short=="Zip": postalCode=elemento_ref_2
                                if elemento_ref_2.id_short=="CityTown": city=elemento_ref_2
                                if elemento_ref_2.id_short=="StateCounty": 
                                    stateCounty=elemento_ref_2
                                    physical_address=PhysicalAddress(countryCode,street, postalCode, city, stateCounty, elemento_ref.id_short, elemento_ref.value, elemento_ref.display_name, elemento_ref.category, elemento_ref.description, elemento_ref.parent, elemento_ref.semantic_id, elemento_ref.qualifier, elemento_ref.extension, elemento_ref.supplemental_semantic_id, elemento_ref.embedded_data_specifications)
                        if elemento_ref.id_short=="Email": email=elemento_ref
                        if elemento_ref.id_short=="URL": url=elemento_ref
                        if elemento_ref.id_short=="Phone": phone=elemento_ref
                        if elemento_ref.id_short=="Fax":
                            fax=elemento_ref
                            contact_info=ContactInfo(nameOfSupplier,contactInfo_role,physical_address,email,url,phone,fax, elemento_contenido.id_short, elemento_contenido.value, elemento_contenido.display_name, elemento_contenido.category, elemento_contenido.description, elemento_contenido.parent, elemento_contenido.semantic_id, elemento_contenido.qualifier, elemento_contenido.extension, elemento_contenido.supplemental_semantic_id, elemento_contenido.embedded_data_specifications)
            
            service=Service(contact_info, obj.id, obj.submodel_element, obj.id_short, obj.display_name, obj.category, obj.description, obj.parent, obj.administration, obj.semantic_id, obj.qualifier, obj.kind, obj.extension, obj.supplemental_semantic_id, obj.embedded_data_specifications)
 
        elif(obj.id_short=="ExampleSubmodel"):
            for elemento_contenido in obj:  #PRIMER ESLABÓN, pasamos a la colección y luego volveremos 
                if isinstance(elemento_contenido, (SubmodelElementList)):    
                    for elemento_ref in elemento_contenido:   #SEGUNDO ESLABON,                                                                                                    
                        if isinstance(elemento_ref, (SubmodelElementCollection)):                            
                            for elemento_ref_2 in elemento_ref.value:   #TERCER ESLABÓN,
                                if isinstance(elemento_ref_2, (SubmodelElementList)):
                                        for elemento_ref_3 in elemento_ref_2: #CUARTO ESLABÓN, aquí están los QosFlow
                                            exampleFlow=ExampleFlow(elemento_ref_3.id_short, elemento_ref_3.value, elemento_ref_3.display_name, elemento_ref_3.category, elemento_ref_3.description, elemento_ref_3.parent, elemento_ref_3.semantic_id, elemento_ref_3.qualifier, elemento_ref_3.extension, elemento_ref_3.supplemental_semantic_id, elemento_ref_3.embedded_data_specifications)
                                        exampleFlowList=ExampleFlowList(elemento_ref_2.id_short, elemento_ref_2._type_value_list_element, elemento_ref_2._value, elemento_ref_2._semantic_id_list_element, elemento_ref_2._value_type_list_element, elemento_ref_2._order_relevant, elemento_ref_2.display_name, elemento_ref_2.category, elemento_ref_2.description, elemento_ref_2.parent, elemento_ref_2.semantic_id, elemento_ref_2.qualifier, elemento_ref_2.extension, elemento_ref_2.supplemental_semantic_id, elemento_ref_2.embedded_data_specifications)
                                        exampleFlowList.value.add(exampleFlow)
                                
                            exampleUpperCollection=ExampleUpperCollection(exampleFlowList, elemento_ref.id_short, elemento_ref.value, elemento_ref.display_name, elemento_ref.category, elemento_ref.description, elemento_ref.parent, elemento_ref.semantic_id, elemento_ref.qualifier, elemento_ref.extension, elemento_ref.supplemental_semantic_id, elemento_ref.embedded_data_specifications)
                    
                        exampleUpperList=ExampleUpperList(elemento_contenido.id_short, elemento_contenido._type_value_list_element, elemento_contenido._value, elemento_contenido._semantic_id_list_element, elemento_contenido._value_type_list_element, elemento_contenido._order_relevant, elemento_contenido.display_name, elemento_contenido.category, elemento_contenido.description, elemento_contenido.parent, elemento_contenido.semantic_id, elemento_contenido.qualifier, elemento_contenido.extension, elemento_contenido.supplemental_semantic_id, elemento_contenido.embedded_data_specifications)
                        #pdu_session_list.value.add(pdu_session_status)
                        
            exampleSubmodel=ExampleSubmodel(exampleUpperList, obj.id, obj.submodel_element, obj.id_short, obj.display_name, obj.category, obj.description, obj.parent, obj.administration, obj.semantic_id, obj.qualifier, obj.kind, obj.extension, obj.supplemental_semantic_id, obj.embedded_data_specifications)

for obj in new_object_store:
    if isinstance(obj,AssetAdministrationShell):
        aasExample=AASExample(nameplate,identification,documentation,service,exampleSubmodel,obj.asset_information, obj.id, obj.id_short, obj.display_name, obj.category, obj.description, obj.parent, obj.administration, obj.submodel, obj.derived_from, obj.embedded_data_specifications, obj.extension)

@jkhsjdhjs
Copy link
Contributor

Your custom subclasses such as PhysicalAddress, Nameplate, etc. aren't calling the initializer of the superclass. This will cause several issues down the line as constraints aren't checked properly.
Also, when you're creating subclasses, you don't have to name each parameter of the superclass individually, instead you can use *args and **kwargs to collect all positional and keyword arguments. This keeps the code cleaner and avoids problems in case additional parameters are added in the future.

class Nameplate(Submodel):
    def __init__(self, manufacturer_name, manufacturer_typ_name, physical_address, typ_class, serialno, chargeid,
                 countryoforigin, yearofconstruction, *args, **kwargs):
        self.manufacturerName = manufacturer_name
        self.manufacturerTypName = manufacturer_typ_name
        self.physicalAddress = physical_address
        self.typClass = typ_class
        self.serialNo = serialno
        self.chargeId = chargeid
        self.countryOfOrigin = countryoforigin
        self.yearOfConstruction = yearofconstruction
        super().__init__(*args, **kwargs)

Aside that, you didn't include the file AASPrueba.aasx, so we cannot reproduce your issue.
Last but not least, this is not a minimal example, it's your entire codebase. Please provide minimal reproducers instead, in a lot of cases trying to create a minimal reproducible example will actually solve your issue, as you're narrowing down the cause.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

3 participants