|
6 | 6 | """ |
7 | 7 |
|
8 | 8 | from basyx.aas import model |
| 9 | +from typing import cast |
9 | 10 |
|
10 | 11 | # In this tutorial, you will learn how to create a Submodel with different kinds of SubmodelElements and how to navigate |
11 | 12 | # through them using IdShorts and IdShortPaths. |
|
108 | 109 | ######################################################################### |
109 | 110 |
|
110 | 111 | # Step 2.1: Access a single Property via its IdShort |
111 | | -my_property = submodel.get_referable("MyProperty") |
| 112 | +my_property = cast(model.Property, submodel.get_referable("MyProperty")) |
112 | 113 | print(f"my_property: id_short = {my_property.id_short}, value = {my_property.value}\n") |
113 | 114 |
|
114 | 115 | # Step 2.2.1: Access a Property within a Property Collection step by step via its IdShort |
115 | | -my_property_collection = submodel.get_referable("MyPropertyCollection") |
116 | | -my_property_collection_0 = my_property_collection.get_referable("MyProperty0") |
117 | | -print(f"my_property_collection_0: id_short = {my_property_collection_0}, value = {my_property_collection_0.value}") |
| 116 | +my_property_collection = cast(model.SubmodelElementCollection, submodel.get_referable("MyPropertyCollection")) |
| 117 | +my_property_collection_property_0 = cast(model.Property, my_property_collection.get_referable("MyProperty0")) |
| 118 | +print( |
| 119 | + f"my_property_collection_property_0: " |
| 120 | + f"id_short = {my_property_collection_property_0}, " |
| 121 | + f"value = {my_property_collection_property_0.value}" |
| 122 | +) |
118 | 123 |
|
119 | 124 | # Step 2.2.2: Access a Property within a Property Collection via its IdShortPath |
120 | | -my_property_collection_1 = submodel.get_referable(["MyPropertyCollection", "MyProperty1"]) |
121 | | -print(f"my_property_collection_1: id_short = {my_property_collection_1}, value = {my_property_collection_1.value}\n") |
| 125 | +my_property_collection_property_1 = cast( |
| 126 | + model.Property, |
| 127 | + submodel.get_referable(["MyPropertyCollection", "MyProperty1"]) |
| 128 | +) |
| 129 | +print( |
| 130 | + f"my_property_collection_property_1: " |
| 131 | + f"id_short = {my_property_collection_property_1}, " |
| 132 | + f"value = {my_property_collection_property_1.value}\n" |
| 133 | +) |
122 | 134 |
|
123 | 135 | # Step 2.3.1: Access a Property within a Property List step by step via its index |
124 | | -my_property_list = submodel.get_referable("MyPropertyList") |
125 | | -my_property_list_0 = my_property_list.get_referable("0") |
126 | | -print(f"my_property_list_0: id_short = {my_property_list_0}, value = {my_property_list_0.value}") |
| 136 | +my_property_list = cast(model.SubmodelElementList, submodel.get_referable("MyPropertyList")) |
| 137 | +my_property_list_property_0 = cast(model.Property, my_property_list.get_referable("0")) |
| 138 | +print( |
| 139 | + f"my_property_list_property_0: " |
| 140 | + f"id_short = {my_property_list_property_0}, " |
| 141 | + f"value = {my_property_list_property_0.value}" |
| 142 | +) |
127 | 143 |
|
128 | 144 | # Step 2.3.2: Access a Property within a Property List via its IdShortPath |
129 | | -my_property_list_1 = submodel.get_referable(["MyPropertyList", "1"]) |
130 | | -print(f"my_property_list_1: id_short = {my_property_list_1}, value = {my_property_list_1.value}\n") |
| 145 | +my_property_list_property_1 = cast(model.Property, submodel.get_referable(["MyPropertyList", "1"])) |
| 146 | +print( |
| 147 | + f"my_property_list_property_1: " |
| 148 | + f"id_short = {my_property_list_property_1}, " |
| 149 | + f"value = {my_property_list_property_1.value}\n" |
| 150 | +) |
131 | 151 |
|
132 | 152 | # Step 2.4.1: Access a Property within a Collection List step by step via its index and IdShort |
133 | | -my_collection_list = submodel.get_referable("MyCollectionList") |
134 | | -my_collection_list_0 = my_collection_list.get_referable("0") |
135 | | -my_collection_list_0_0 = my_collection_list_0.get_referable("MyProperty") |
136 | | -print(f"my_collection_list_0_0: id_short = {my_collection_list_0_0}, value = {my_collection_list_0_0.value}") |
| 153 | +my_collection_list = cast(model.SubmodelElementList, submodel.get_referable("MyCollectionList")) |
| 154 | +my_collection_list_collection_0 = cast(model.SubmodelElementCollection, my_collection_list.get_referable("0")) |
| 155 | +my_collection_list_collection_0_property_0 = cast( |
| 156 | + model.Property, |
| 157 | + my_collection_list_collection_0.get_referable("MyProperty") |
| 158 | +) |
| 159 | +print( |
| 160 | + f"my_collection_list_collection_0_property_0: " |
| 161 | + f"id_short = {my_collection_list_collection_0_property_0}, " |
| 162 | + f"value = {my_collection_list_collection_0_property_0.value}" |
| 163 | +) |
137 | 164 |
|
138 | 165 | # Step 2.4.2: Access a Property within a Collection List via its IdShortPath |
139 | | -my_collection_list_2_0 = submodel.get_referable(["MyCollectionList", "2", "MyProperty"]) |
140 | | -print(f"my_collection_list_2_0: id_short = {my_collection_list_2_0}, value = {my_collection_list_2_0.value}") |
| 166 | +my_collection_list_collection_2_property_0 = cast( |
| 167 | + model.Property, |
| 168 | + submodel.get_referable(["MyCollectionList", "2", "MyProperty"]) |
| 169 | +) |
| 170 | +print( |
| 171 | + f"my_collection_list_collection_2_property_0: " |
| 172 | + f"id_short = {my_collection_list_collection_2_property_0}, " |
| 173 | + f"value = {my_collection_list_collection_2_property_0.value}" |
| 174 | +) |
0 commit comments